PEP8 compliance
I seriously hope I didn't fuck something up.
This commit is contained in:
parent
9c9c2f51ab
commit
90d75824b7
19
proxmox.py
19
proxmox.py
|
@ -26,6 +26,7 @@
|
|||
# { "groups": ["utility", "databases"], "a": false, "b": true }
|
||||
|
||||
import urllib
|
||||
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
|
@ -38,10 +39,12 @@ from six import iteritems
|
|||
|
||||
from ansible.module_utils.urls import open_url
|
||||
|
||||
|
||||
class ProxmoxNodeList(list):
|
||||
def get_names(self):
|
||||
return [node['node'] for node in self]
|
||||
|
||||
|
||||
class ProxmoxVM(dict):
|
||||
def get_variables(self):
|
||||
variables = {}
|
||||
|
@ -49,6 +52,7 @@ class ProxmoxVM(dict):
|
|||
variables['proxmox_' + key] = value
|
||||
return variables
|
||||
|
||||
|
||||
class ProxmoxVMList(list):
|
||||
def __init__(self, data=[], pxmxver=0.0):
|
||||
self.ver = pxmxver
|
||||
|
@ -72,18 +76,22 @@ class ProxmoxVMList(list):
|
|||
|
||||
return variables
|
||||
|
||||
|
||||
class ProxmoxPoolList(list):
|
||||
def get_names(self):
|
||||
return [pool['poolid'] for pool in self]
|
||||
|
||||
|
||||
class ProxmoxVersion(dict):
|
||||
def get_version(self):
|
||||
return float(self['version'])
|
||||
|
||||
|
||||
class ProxmoxPool(dict):
|
||||
def get_members_name(self):
|
||||
return [member['name'] for member in self['members'] if member['template'] != 1]
|
||||
|
||||
|
||||
class ProxmoxAPI(object):
|
||||
def __init__(self, options, config_path):
|
||||
self.options = options
|
||||
|
@ -112,9 +120,11 @@ class ProxmoxAPI(object):
|
|||
if not options.url:
|
||||
raise Exception('Missing mandatory parameter --url (or PROXMOX_URL or "url" key in config file).')
|
||||
elif not options.username:
|
||||
raise Exception('Missing mandatory parameter --username (or PROXMOX_USERNAME or "username" key in config file).')
|
||||
raise Exception(
|
||||
'Missing mandatory parameter --username (or PROXMOX_USERNAME or "username" key in config file).')
|
||||
elif not options.password:
|
||||
raise Exception('Missing mandatory parameter --password (or PROXMOX_PASSWORD or "password" key in config file).')
|
||||
raise Exception(
|
||||
'Missing mandatory parameter --password (or PROXMOX_PASSWORD or "password" key in config file).')
|
||||
|
||||
def auth(self):
|
||||
request_path = '{}api2/json/access/ticket'.format(self.options.url)
|
||||
|
@ -124,7 +134,6 @@ class ProxmoxAPI(object):
|
|||
'password': self.options.password,
|
||||
})
|
||||
|
||||
|
||||
data = json.load(open_url(request_path, data=request_params,
|
||||
validate_certs=self.options.validate))
|
||||
|
||||
|
@ -179,6 +188,7 @@ class ProxmoxAPI(object):
|
|||
def version(self):
|
||||
return ProxmoxVersion(self.get('api2/json/version'))
|
||||
|
||||
|
||||
def main_list(options, config_path):
|
||||
results = {
|
||||
'all': {
|
||||
|
@ -262,6 +272,7 @@ def main_list(options, config_path):
|
|||
|
||||
return results
|
||||
|
||||
|
||||
def main_host(options, config_path):
|
||||
proxmox_api = ProxmoxAPI(options, config_path)
|
||||
proxmox_api.auth()
|
||||
|
@ -274,6 +285,7 @@ def main_host(options, config_path):
|
|||
|
||||
return {}
|
||||
|
||||
|
||||
def main():
|
||||
config_path = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
|
@ -315,5 +327,6 @@ def main():
|
|||
|
||||
print(json.dumps(data, indent=indent))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Reference in New Issue