diff --git a/lib/GLPI/Agent/Task/Inventory/Virtualization/Lxc.pm b/lib/GLPI/Agent/Task/Inventory/Virtualization/Lxc.pm index 2a16b402c..64325079c 100644 --- a/lib/GLPI/Agent/Task/Inventory/Virtualization/Lxc.pm +++ b/lib/GLPI/Agent/Task/Inventory/Virtualization/Lxc.pm @@ -66,12 +66,19 @@ sub _getVirtualMachine { ) }; + # Proxmox environment sets name as number + my $proxmox = $name =~ /^\d+$/ ? 1 : 0; + my $command = "lxc-info -n '$name' -c lxc.cgroup.memory.limit_in_bytes -c lxc.cgroup.cpuset.cpus"; if ($params{version} < 2.1) { # Before 2.1, we need to find MAC as lxc.network.hwaddr in config $command .= "; grep lxc.network.hwaddr $params{config}"; + # Look for lxc.utsname from config file in Proxmox environment + $command .= "; grep utsname $params{config}" if $proxmox; } else { $command .= " -c lxc.net.0.hwaddr"; + # Look for lxc.uts.name in Proxmox environment + $command .= " -c lxc.uts.name" if $proxmox; } my $handle = getFileHandle( @@ -96,6 +103,11 @@ sub _getVirtualMachine { $container->{MEMORY} = $val; } + # Update container name in Proxmox environment + if ($proxmox && ($key eq 'lxc.uts.name' || $key eq 'lxc.utsname')) { + $container->{NAME} = $val; + } + if ($key eq 'lxc.cgroup.cpuset.cpus') { ###eg: lxc.cgroup.cpuset.cpus = 0,3-5,7,2,1 foreach my $cpu ( split( /,/, $val ) ){ diff --git a/resources/virtualization/lxc/200-proxmox b/resources/virtualization/lxc/200-proxmox new file mode 100644 index 000000000..28ca8b8d9 --- /dev/null +++ b/resources/virtualization/lxc/200-proxmox @@ -0,0 +1,8 @@ +# lxc-info -n 200 -s -c lxc.cgroup.memory.limit_in_bytes -c lxc.cgroup.cpuset.cpus -c lxc.net.0.hwaddr -c lxc.uts.name +State: RUNNING +lxc.cgroup.memory.limit_in_bytes = 2147483648 + +lxc.cgroup.cpuset.cpus = 0,2 + +lxc.net.0.hwaddr = FA:EE:26:EF:6B:1C +lxc.uts.name = glpi-10-rc1 diff --git a/t/tasks/inventory/virtualization/lxc.t b/t/tasks/inventory/virtualization/lxc.t index 8e535a5f3..abfcbdc42 100755 --- a/t/tasks/inventory/virtualization/lxc.t +++ b/t/tasks/inventory/virtualization/lxc.t @@ -48,6 +48,17 @@ my %container_tests = ( VCPU => 3 } }, + '200-proxmox' => { + version => 3.0, + result => { + NAME => 'glpi-10-rc1', + VMTYPE => 'lxc', + STATUS => STATUS_RUNNING, + MAC => 'fa:ee:26:ef:6b:1c', + MEMORY => 2147483648, + VCPU => 2 + } + }, ); plan tests => keys(%result_lxc_info) + keys(%container_tests) + 1; @@ -63,7 +74,7 @@ foreach my $name (keys(%container_tests)) { my $file = "resources/virtualization/lxc/$name"; $file =~ s|/|\\|g if $OSNAME eq "MSWin32"; my $config = GLPI::Agent::Task::Inventory::Virtualization::Lxc::_getVirtualMachine( - name => $name, + name => $name =~ /(^.*)-proxmox$/ ? $1 : $name, version => $container_tests{$name}->{version}, test_cmdstate => $OSNAME eq "MSWin32" ? "type $file" : "cat $file", test_cmdinfo => $OSNAME eq "MSWin32" ? "type $file" : "cat $file",