mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
cloudstack: fix pep8 cloudstack inventory (#22092)
This commit is contained in:
parent
f761949cca
commit
87119479d8
1 changed files with 7 additions and 12 deletions
|
@ -72,7 +72,6 @@ usage: cloudstack.py [--list] [--host HOST] [--project PROJECT] [--domain DOMAI
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
@ -102,9 +101,8 @@ class CloudStackInventory(object):
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
try:
|
try:
|
||||||
self.cs = CloudStack(**read_config())
|
self.cs = CloudStack(**read_config())
|
||||||
except CloudStackException as e:
|
except CloudStackException:
|
||||||
print("Error: Could not connect to CloudStack API", file=sys.stderr)
|
print("Error: Could not connect to CloudStack API", file=sys.stderr)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
domain_id = None
|
domain_id = None
|
||||||
if options.domain:
|
if options.domain:
|
||||||
|
@ -122,8 +120,7 @@ class CloudStackInventory(object):
|
||||||
data = self.get_list(project_id, domain_id)
|
data = self.get_list(project_id, domain_id)
|
||||||
print(json.dumps(data, indent=2))
|
print(json.dumps(data, indent=2))
|
||||||
else:
|
else:
|
||||||
print("usage: --list | --host <hostname> [--project <project>] [--domain <domain_path>]",
|
print("usage: --list | --host <hostname> [--project <project>] [--domain <domain_path>]", file=sys.stderr)
|
||||||
file=sys.stderr)
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def get_domain_id(self, domain):
|
def get_domain_id(self, domain):
|
||||||
|
@ -144,7 +141,6 @@ class CloudStackInventory(object):
|
||||||
print("Error: Project %s not found." % project, file=sys.stderr)
|
print("Error: Project %s not found." % project, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def get_host(self, name, project_id=None, domain_id=None):
|
def get_host(self, name, project_id=None, domain_id=None):
|
||||||
hosts = self.cs.listVirtualMachines(projectid=project_id, domainid=domain_id)
|
hosts = self.cs.listVirtualMachines(projectid=project_id, domainid=domain_id)
|
||||||
data = {}
|
data = {}
|
||||||
|
@ -182,22 +178,21 @@ class CloudStackInventory(object):
|
||||||
break
|
break
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def get_list(self, project_id=None, domain_id=None):
|
def get_list(self, project_id=None, domain_id=None):
|
||||||
data = {
|
data = {
|
||||||
'all': {
|
'all': {
|
||||||
'hosts': [],
|
'hosts': [],
|
||||||
},
|
},
|
||||||
'_meta': {
|
'_meta': {
|
||||||
'hostvars': {},
|
'hostvars': {},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
groups = self.cs.listInstanceGroups(projectid=project_id, domainid=domain_id)
|
groups = self.cs.listInstanceGroups(projectid=project_id, domainid=domain_id)
|
||||||
if groups:
|
if groups:
|
||||||
for group in groups['instancegroup']:
|
for group in groups['instancegroup']:
|
||||||
group_name = group['name']
|
group_name = group['name']
|
||||||
if group_name and not group_name in data:
|
if group_name and group_name not in data:
|
||||||
data[group_name] = {
|
data[group_name] = {
|
||||||
'hosts': []
|
'hosts': []
|
||||||
}
|
}
|
||||||
|
@ -242,7 +237,7 @@ class CloudStackInventory(object):
|
||||||
'netmask': nic['netmask'],
|
'netmask': nic['netmask'],
|
||||||
'gateway': nic['gateway'],
|
'gateway': nic['gateway'],
|
||||||
'type': nic['type'],
|
'type': nic['type'],
|
||||||
})
|
})
|
||||||
if nic['isdefault']:
|
if nic['isdefault']:
|
||||||
data['_meta']['hostvars'][host_name]['default_ip'] = nic['ipaddress']
|
data['_meta']['hostvars'][host_name]['default_ip'] = nic['ipaddress']
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue