vSphere

 View Only
  • 1.  Add Host to Datacenter

    Posted Apr 18, 2013 06:29 PM

    Hello, I want to add a host to a datacenter not a cluster using the perl sdk. I already figured out how to add one to the cluster. In order to call the AddHost it seems that I need a ClusterComputeResource Object, but the datacenter does not seem to be one. However in the vsphere client I also can add a host to the cluster. I tried:

    sub
    add_host
    {
            my $hostname = shift || die;
            my $certificate;
            for (split(/\n/, `openssl s_client -connect ${hostname}:443 2> /dev/null < /dev/null`)) {
                    $certificate .= "$_\n" if /^-----BEGIN CERTIFICATE-----/ .. /^-----END CERTIFICATE-----$/;
            }
            my ($wtr, $rdr, $err);
            open3($wtr, $rdr, $err, 'openssl', 'x509', '-noout', '-fingerprint') || die;
            print $wtr $certificate;
            close($wtr);
            my $fingerprint = <$rdr>;
            chomp($fingerprint);
            $fingerprint =~ s/SHA1 Fingerprint=//;
            my $host_connect_spec = HostConnectSpec->new(
                            force => 0,
                            hostName => ${hostname},
                            userName => 'root',
                            password => $c{esx_password},
                            port => '443',
                            sslThumbprint => $fingerprint,
            );
            my $datacenter = Vim::find_entity_view(view_type => 'Datacenter',
                            filter => {name => $c{datacenter}});
            die "Datacenter '$c{datacenter}' not found" unless defined $datacenter;
            $datacenter->AddHost(spec => $host_connect_spec, asConnected => 1);
    }
    I got:
    <
    Undefined subroutine &Datacenter::AddHost called at ./create_inventory.pl line 95
    Cheers,
        Thomas


  • 2.  RE: Add Host to Datacenter

    Posted Apr 24, 2013 02:44 PM

    You need to specify a ClusterComputeResource for the AddHost_Task(), can't use the datacenter object.  You can also use a Folder object to do an AddStandaloneHost_Task().  But you won't be able to make that call on the Datacenter object, it's not defined in the SDK.  If you want to add a host without a cluster, then get the Datacenter Host folder object (Datacenter.hostFolder), and make the AddStandaloneHost_Task() call.