Skip to content

Commit

Permalink
Add vps ignore option to configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
rvojcik committed Mar 12, 2021
1 parent f5dca86 commit 3efa386
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions rt_server_client/sysinfo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,40 @@ def getHwAddr(self, ifname):
def GetVirtualServers(self, virt='xen'):
"""Create list of virtual servers"""

if self.config.has_option('global','vps_hostname_ignore'):
vps_ignore = self.config.get('global', 'vps_hostname_ignore')
else:
vps_ignore = False

if virt == 'xen':
command = 'xm list'
index = 0
ignore = 2
elif virt == 'qemu':
command = 'virsh list --all'
index = 1
ignore = 2
elif virt == 'proxmox':
command = 'qm list'
index = 1
ignore = 1
else:
print('Unsupported virtualization')
sys.exit(1)

output = sp.run(command, shell=True, universal_newlines=True, stdout=sp.PIPE).stdout
virtuals = []

for line in output.splitlines()[2:]:
for line in output.splitlines()[ignore:]:
if line != '':
virtual = line.split()[index]
virtuals.append(virtual)
if vps_ignore:
if not re.match(vps_ignore, virtual):
virtuals.append(virtual)
else
self.debug.print_message("Ignoring virtual: %s, ignore pattern: %s" % (str(virtual), vps_ignore))
else:
virtuals.append(virtual)

self.debug.print_message("Virtual servers: "+str(virtuals))

Expand Down

0 comments on commit 3efa386

Please sign in to comment.