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