Skip to content

Commit dd04d55

Browse files
committed
feat: Use uts.name for LXC container name under Proxmox
Backport of fusioninventory/fusioninventory-agent#993
1 parent 4aec548 commit dd04d55

File tree

3 files changed

+32
-1
lines changed
  • lib/GLPI/Agent/Task/Inventory/Virtualization
  • resources/virtualization/lxc
  • t/tasks/inventory/virtualization

3 files changed

+32
-1
lines changed

lib/GLPI/Agent/Task/Inventory/Virtualization/Lxc.pm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,19 @@ sub _getVirtualMachine {
6666
)
6767
};
6868

69+
# Proxmox environment sets name as number
70+
my $proxmox = $name =~ /^\d+$/ ? 1 : 0;
71+
6972
my $command = "lxc-info -n '$name' -c lxc.cgroup.memory.limit_in_bytes -c lxc.cgroup.cpuset.cpus";
7073
if ($params{version} < 2.1) {
7174
# Before 2.1, we need to find MAC as lxc.network.hwaddr in config
7275
$command .= "; grep lxc.network.hwaddr $params{config}";
76+
# Look for lxc.utsname from config file in Proxmox environment
77+
$command .= "; grep utsname $params{config}" if $proxmox;
7378
} else {
7479
$command .= " -c lxc.net.0.hwaddr";
80+
# Look for lxc.uts.name in Proxmox environment
81+
$command .= " -c lxc.uts.name" if $proxmox;
7582
}
7683

7784
my $handle = getFileHandle(
@@ -96,6 +103,11 @@ sub _getVirtualMachine {
96103
$container->{MEMORY} = $val;
97104
}
98105

106+
# Update container name in Proxmox environment
107+
if ($proxmox && ($key eq 'lxc.uts.name' || $key eq 'lxc.utsname')) {
108+
$container->{NAME} = $val;
109+
}
110+
99111
if ($key eq 'lxc.cgroup.cpuset.cpus') {
100112
###eg: lxc.cgroup.cpuset.cpus = 0,3-5,7,2,1
101113
foreach my $cpu ( split( /,/, $val ) ){
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# 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
2+
State: RUNNING
3+
lxc.cgroup.memory.limit_in_bytes = 2147483648
4+
5+
lxc.cgroup.cpuset.cpus = 0,2
6+
7+
lxc.net.0.hwaddr = FA:EE:26:EF:6B:1C
8+
lxc.uts.name = glpi-10-rc1

t/tasks/inventory/virtualization/lxc.t

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ my %container_tests = (
4848
VCPU => 3
4949
}
5050
},
51+
'200-proxmox' => {
52+
version => 3.0,
53+
result => {
54+
NAME => 'glpi-10-rc1',
55+
VMTYPE => 'lxc',
56+
STATUS => STATUS_RUNNING,
57+
MAC => 'fa:ee:26:ef:6b:1c',
58+
MEMORY => 2147483648,
59+
VCPU => 2
60+
}
61+
},
5162
);
5263

5364
plan tests => keys(%result_lxc_info) + keys(%container_tests) + 1;
@@ -63,7 +74,7 @@ foreach my $name (keys(%container_tests)) {
6374
my $file = "resources/virtualization/lxc/$name";
6475
$file =~ s|/|\\|g if $OSNAME eq "MSWin32";
6576
my $config = GLPI::Agent::Task::Inventory::Virtualization::Lxc::_getVirtualMachine(
66-
name => $name,
77+
name => $name =~ /(^.*)-proxmox$/ ? $1 : $name,
6778
version => $container_tests{$name}->{version},
6879
test_cmdstate => $OSNAME eq "MSWin32" ? "type $file" : "cat $file",
6980
test_cmdinfo => $OSNAME eq "MSWin32" ? "type $file" : "cat $file",

0 commit comments

Comments
 (0)