enh(hyperv): scvmm-discovery mode - better management (#3179)

This commit is contained in:
qgarnier 2021-10-07 16:33:44 +02:00 committed by GitHub
parent 6baf19c933
commit 0e4d2344f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 11 deletions

View File

@ -146,8 +146,8 @@ sub run {
my $disco_stats;
foreach my $entry (@$decoded) {
my $item = {};
$item->{type} = $entry->{type};
$item->{type} = $entry->{type};
if ($self->{option_results}->{resource_type} eq 'vm' && $entry->{type} eq 'vm') {
$item->{id} = $entry->{vmId};
$item->{name} = $entry->{name};
@ -158,9 +158,12 @@ sub run {
$item->{enabled} = ($entry->{enabled} =~ /True|1/i) ? 'yes' : 'no';
$item->{computer_name} = $entry->{computerName};
$item->{tag} = $entry->{tag};
$entry->{ipv4Addresses} = [$entry->{ipv4Addresses}] if (ref($entry->{ipv4Addresses}) ne 'ARRAY');
$item->{ipv4_addresses} = $entry->{ipv4Addresses};
$item->{ipv4_address} = defined($entry->{ipv4Addresses}->[0]) ? $entry->{ipv4Addresses}->[0] : '';
$item->{vmhost_name} = $hosts->{ $entry->{vmHostId} }->{name};
$item->{cluster_name} = $hosts->{ $entry->{vmHostId} }->{cluster_name};
push @$disco_data, $item;
} elsif ($self->{option_results}->{resource_type} eq 'host' && $entry->{type} eq 'host') {
$item->{id} = $entry->{id};
$item->{name} = $entry->{name};
@ -168,9 +171,8 @@ sub run {
$item->{fqdn} = $entry->{FQDN};
$item->{cluster_name} = $entry->{clusterName};
$item->{operating_system} = $entry->{operatingSystem};
push @$disco_data, $item;
}
push @$disco_data, $item;
}
$disco_stats->{end_time} = time();

View File

@ -68,7 +68,7 @@ Try {
$item.enabled = $vm.enabled
$item.computerName = $vm.ComputerName
$item.tag = $vm.Tag
$item.vmHostId = $vm.VMHost.ID
$item.vmHostId = $vm.VMHost.ID.Guid
$ipv4Addresses = @()
if ($vm.Status -eq "Running") {
@ -81,18 +81,18 @@ Try {
$items.Add($item)
}
$hosts = Get-SCVmHost -VMMServer $connection
Foreach ($host in $hosts) {
$vmhosts = Get-SCVmHost -VMMServer $connection
Foreach ($vmhost in $vmhosts) {
$item = @{}
$item.type = "host"
$item.id = $host.ID
$item.name = $host.Name
$item.id = $vmhost.ID.Guid
$item.name = $vmhost.Name
$desc = $host.Description -replace "\r",""
$item.description = $desc
$item.FQDN = $host.FQDN
$item.clusterName = $host.HostCluster.Name
$item.operatingSystem = $host.OperatingSystem.Name
$item.FQDN = $vmhost.FQDN
$item.clusterName = $vmhost.HostCluster.Name
$item.operatingSystem = $vmhost.OperatingSystem.Name
$items.Add($item)
}