mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
Bulk autopep8 (modules)
As agreed in 2017-12-07 Core meeting bulk fix pep8 issues Generated using: autopep8 1.3.3 (pycodestyle: 2.3.1) autopep8 -r --max-line-length 160 --in-place --ignore E305,E402,E722,E741 lib/ansible/modules Manually fix issues that autopep8 has introduced
This commit is contained in:
committed by
John R Barker
parent
d13d7e9404
commit
c57a7f05e1
@@ -278,35 +278,34 @@ from ansible.module_utils._text import to_native, to_text
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
|
||||
|
||||
|
||||
class CloudflareAPI(object):
|
||||
|
||||
cf_api_endpoint = 'https://api.cloudflare.com/client/v4'
|
||||
changed = False
|
||||
|
||||
def __init__(self, module):
|
||||
self.module = module
|
||||
self.module = module
|
||||
self.account_api_token = module.params['account_api_token']
|
||||
self.account_email = module.params['account_email']
|
||||
self.port = module.params['port']
|
||||
self.priority = module.params['priority']
|
||||
self.proto = module.params['proto']
|
||||
self.proxied = module.params['proxied']
|
||||
self.record = module.params['record']
|
||||
self.service = module.params['service']
|
||||
self.is_solo = module.params['solo']
|
||||
self.state = module.params['state']
|
||||
self.timeout = module.params['timeout']
|
||||
self.ttl = module.params['ttl']
|
||||
self.type = module.params['type']
|
||||
self.value = module.params['value']
|
||||
self.weight = module.params['weight']
|
||||
self.zone = module.params['zone']
|
||||
self.account_email = module.params['account_email']
|
||||
self.port = module.params['port']
|
||||
self.priority = module.params['priority']
|
||||
self.proto = module.params['proto']
|
||||
self.proxied = module.params['proxied']
|
||||
self.record = module.params['record']
|
||||
self.service = module.params['service']
|
||||
self.is_solo = module.params['solo']
|
||||
self.state = module.params['state']
|
||||
self.timeout = module.params['timeout']
|
||||
self.ttl = module.params['ttl']
|
||||
self.type = module.params['type']
|
||||
self.value = module.params['value']
|
||||
self.weight = module.params['weight']
|
||||
self.zone = module.params['zone']
|
||||
|
||||
if self.record == '@':
|
||||
self.record = self.zone
|
||||
|
||||
if (self.type in ['CNAME','NS','MX','SRV']) and (self.value is not None):
|
||||
if (self.type in ['CNAME', 'NS', 'MX', 'SRV']) and (self.value is not None):
|
||||
self.value = self.value.rstrip('.')
|
||||
|
||||
if (self.type == 'SRV'):
|
||||
@@ -318,10 +317,10 @@ class CloudflareAPI(object):
|
||||
if not self.record.endswith(self.zone):
|
||||
self.record = self.record + '.' + self.zone
|
||||
|
||||
def _cf_simple_api_call(self,api_call,method='GET',payload=None):
|
||||
headers = { 'X-Auth-Email': self.account_email,
|
||||
'X-Auth-Key': self.account_api_token,
|
||||
'Content-Type': 'application/json' }
|
||||
def _cf_simple_api_call(self, api_call, method='GET', payload=None):
|
||||
headers = {'X-Auth-Email': self.account_email,
|
||||
'X-Auth-Key': self.account_api_token,
|
||||
'Content-Type': 'application/json'}
|
||||
data = None
|
||||
if payload:
|
||||
try:
|
||||
@@ -336,28 +335,28 @@ class CloudflareAPI(object):
|
||||
method=method,
|
||||
timeout=self.timeout)
|
||||
|
||||
if info['status'] not in [200,304,400,401,403,429,405,415]:
|
||||
self.module.fail_json(msg="Failed API call {0}; got unexpected HTTP code {1}".format(api_call,info['status']))
|
||||
if info['status'] not in [200, 304, 400, 401, 403, 429, 405, 415]:
|
||||
self.module.fail_json(msg="Failed API call {0}; got unexpected HTTP code {1}".format(api_call, info['status']))
|
||||
|
||||
error_msg = ''
|
||||
if info['status'] == 401:
|
||||
# Unauthorized
|
||||
error_msg = "API user does not have permission; Status: {0}; Method: {1}: Call: {2}".format(info['status'],method,api_call)
|
||||
error_msg = "API user does not have permission; Status: {0}; Method: {1}: Call: {2}".format(info['status'], method, api_call)
|
||||
elif info['status'] == 403:
|
||||
# Forbidden
|
||||
error_msg = "API request not authenticated; Status: {0}; Method: {1}: Call: {2}".format(info['status'],method,api_call)
|
||||
error_msg = "API request not authenticated; Status: {0}; Method: {1}: Call: {2}".format(info['status'], method, api_call)
|
||||
elif info['status'] == 429:
|
||||
# Too many requests
|
||||
error_msg = "API client is rate limited; Status: {0}; Method: {1}: Call: {2}".format(info['status'],method,api_call)
|
||||
error_msg = "API client is rate limited; Status: {0}; Method: {1}: Call: {2}".format(info['status'], method, api_call)
|
||||
elif info['status'] == 405:
|
||||
# Method not allowed
|
||||
error_msg = "API incorrect HTTP method provided; Status: {0}; Method: {1}: Call: {2}".format(info['status'],method,api_call)
|
||||
error_msg = "API incorrect HTTP method provided; Status: {0}; Method: {1}: Call: {2}".format(info['status'], method, api_call)
|
||||
elif info['status'] == 415:
|
||||
# Unsupported Media Type
|
||||
error_msg = "API request is not valid JSON; Status: {0}; Method: {1}: Call: {2}".format(info['status'],method,api_call)
|
||||
elif info ['status'] == 400:
|
||||
error_msg = "API request is not valid JSON; Status: {0}; Method: {1}: Call: {2}".format(info['status'], method, api_call)
|
||||
elif info['status'] == 400:
|
||||
# Bad Request
|
||||
error_msg = "API bad request; Status: {0}; Method: {1}: Call: {2}".format(info['status'],method,api_call)
|
||||
error_msg = "API bad request; Status: {0}; Method: {1}: Call: {2}".format(info['status'], method, api_call)
|
||||
|
||||
result = None
|
||||
try:
|
||||
@@ -375,22 +374,22 @@ class CloudflareAPI(object):
|
||||
error_msg += "; Failed to parse API response with error {0}: {1}".format(to_native(e), content)
|
||||
|
||||
# received an error status but no data with details on what failed
|
||||
if (info['status'] not in [200,304]) and (result is None):
|
||||
if (info['status'] not in [200, 304]) and (result is None):
|
||||
self.module.fail_json(msg=error_msg)
|
||||
|
||||
if not result['success']:
|
||||
error_msg += "; Error details: "
|
||||
for error in result['errors']:
|
||||
error_msg += "code: {0}, error: {1}; ".format(error['code'],error['message'])
|
||||
error_msg += "code: {0}, error: {1}; ".format(error['code'], error['message'])
|
||||
if 'error_chain' in error:
|
||||
for chain_error in error['error_chain']:
|
||||
error_msg += "code: {0}, error: {1}; ".format(chain_error['code'],chain_error['message'])
|
||||
error_msg += "code: {0}, error: {1}; ".format(chain_error['code'], chain_error['message'])
|
||||
self.module.fail_json(msg=error_msg)
|
||||
|
||||
return result, info['status']
|
||||
|
||||
def _cf_api_call(self,api_call,method='GET',payload=None):
|
||||
result, status = self._cf_simple_api_call(api_call,method,payload)
|
||||
def _cf_api_call(self, api_call, method='GET', payload=None):
|
||||
result, status = self._cf_simple_api_call(api_call, method, payload)
|
||||
|
||||
data = result['result']
|
||||
|
||||
@@ -401,19 +400,19 @@ class CloudflareAPI(object):
|
||||
parameters = ['page={0}'.format(next_page)]
|
||||
# strip "page" parameter from call parameters (if there are any)
|
||||
if '?' in api_call:
|
||||
raw_api_call,query = api_call.split('?',1)
|
||||
raw_api_call, query = api_call.split('?', 1)
|
||||
parameters += [param for param in query.split('&') if not param.startswith('page')]
|
||||
else:
|
||||
raw_api_call = api_call
|
||||
while next_page <= pagination['total_pages']:
|
||||
raw_api_call += '?' + '&'.join(parameters)
|
||||
result, status = self._cf_simple_api_call(raw_api_call,method,payload)
|
||||
result, status = self._cf_simple_api_call(raw_api_call, method, payload)
|
||||
data += result['result']
|
||||
next_page += 1
|
||||
|
||||
return data, status
|
||||
|
||||
def _get_zone_id(self,zone=None):
|
||||
def _get_zone_id(self, zone=None):
|
||||
if not zone:
|
||||
zone = self.zone
|
||||
|
||||
@@ -426,16 +425,16 @@ class CloudflareAPI(object):
|
||||
|
||||
return zones[0]['id']
|
||||
|
||||
def get_zones(self,name=None):
|
||||
def get_zones(self, name=None):
|
||||
if not name:
|
||||
name = self.zone
|
||||
param = ''
|
||||
if name:
|
||||
param = '?' + urlencode({'name' : name})
|
||||
zones,status = self._cf_api_call('/zones' + param)
|
||||
param = '?' + urlencode({'name': name})
|
||||
zones, status = self._cf_api_call('/zones' + param)
|
||||
return zones
|
||||
|
||||
def get_dns_records(self,zone_name=None,type=None,record=None,value=''):
|
||||
def get_dns_records(self, zone_name=None, type=None, record=None, value=''):
|
||||
if not zone_name:
|
||||
zone_name = self.zone
|
||||
if not type:
|
||||
@@ -459,16 +458,16 @@ class CloudflareAPI(object):
|
||||
if query:
|
||||
api_call += '?' + urlencode(query)
|
||||
|
||||
records,status = self._cf_api_call(api_call)
|
||||
records, status = self._cf_api_call(api_call)
|
||||
return records
|
||||
|
||||
def delete_dns_records(self,**kwargs):
|
||||
def delete_dns_records(self, **kwargs):
|
||||
params = {}
|
||||
for param in ['port','proto','service','solo','type','record','value','weight','zone']:
|
||||
for param in ['port', 'proto', 'service', 'solo', 'type', 'record', 'value', 'weight', 'zone']:
|
||||
if param in kwargs:
|
||||
params[param] = kwargs[param]
|
||||
else:
|
||||
params[param] = getattr(self,param)
|
||||
params[param] = getattr(self, param)
|
||||
|
||||
records = []
|
||||
content = params['value']
|
||||
@@ -481,27 +480,27 @@ class CloudflareAPI(object):
|
||||
else:
|
||||
search_value = content
|
||||
|
||||
records = self.get_dns_records(params['zone'],params['type'],search_record,search_value)
|
||||
records = self.get_dns_records(params['zone'], params['type'], search_record, search_value)
|
||||
|
||||
for rr in records:
|
||||
if params['solo']:
|
||||
if not ((rr['type'] == params['type']) and (rr['name'] == search_record) and (rr['content'] == content)):
|
||||
self.changed = True
|
||||
if not self.module.check_mode:
|
||||
result, info = self._cf_api_call('/zones/{0}/dns_records/{1}'.format(rr['zone_id'],rr['id']),'DELETE')
|
||||
result, info = self._cf_api_call('/zones/{0}/dns_records/{1}'.format(rr['zone_id'], rr['id']), 'DELETE')
|
||||
else:
|
||||
self.changed = True
|
||||
if not self.module.check_mode:
|
||||
result, info = self._cf_api_call('/zones/{0}/dns_records/{1}'.format(rr['zone_id'],rr['id']),'DELETE')
|
||||
result, info = self._cf_api_call('/zones/{0}/dns_records/{1}'.format(rr['zone_id'], rr['id']), 'DELETE')
|
||||
return self.changed
|
||||
|
||||
def ensure_dns_record(self,**kwargs):
|
||||
def ensure_dns_record(self, **kwargs):
|
||||
params = {}
|
||||
for param in ['port','priority','proto','proxied','service','ttl','type','record','value','weight','zone']:
|
||||
for param in ['port', 'priority', 'proto', 'proxied', 'service', 'ttl', 'type', 'record', 'value', 'weight', 'zone']:
|
||||
if param in kwargs:
|
||||
params[param] = kwargs[param]
|
||||
else:
|
||||
params[param] = getattr(self,param)
|
||||
params[param] = getattr(self, param)
|
||||
|
||||
search_value = params['value']
|
||||
search_record = params['record']
|
||||
@@ -509,7 +508,7 @@ class CloudflareAPI(object):
|
||||
if (params['type'] is None) or (params['record'] is None):
|
||||
self.module.fail_json(msg="You must provide a type and a record to create a new record")
|
||||
|
||||
if (params['type'] in [ 'A','AAAA','CNAME','TXT','MX','NS','SPF']):
|
||||
if (params['type'] in ['A', 'AAAA', 'CNAME', 'TXT', 'MX', 'NS', 'SPF']):
|
||||
if not params['value']:
|
||||
self.module.fail_json(msg="You must provide a non-empty value to create this record type")
|
||||
|
||||
@@ -527,11 +526,11 @@ class CloudflareAPI(object):
|
||||
"ttl": params['ttl']
|
||||
}
|
||||
|
||||
if (params['type'] in [ 'A', 'AAAA', 'CNAME' ]):
|
||||
if (params['type'] in ['A', 'AAAA', 'CNAME']):
|
||||
new_record["proxied"] = params["proxied"]
|
||||
|
||||
if params['type'] == 'MX':
|
||||
for attr in [params['priority'],params['value']]:
|
||||
for attr in [params['priority'], params['value']]:
|
||||
if (attr is None) or (attr == ''):
|
||||
self.module.fail_json(msg="You must provide priority and a value to create this record type")
|
||||
new_record = {
|
||||
@@ -543,7 +542,7 @@ class CloudflareAPI(object):
|
||||
}
|
||||
|
||||
if params['type'] == 'SRV':
|
||||
for attr in [params['port'],params['priority'],params['proto'],params['service'],params['weight'],params['value']]:
|
||||
for attr in [params['port'], params['priority'], params['proto'], params['service'], params['weight'], params['value']]:
|
||||
if (attr is None) or (attr == ''):
|
||||
self.module.fail_json(msg="You must provide port, priority, proto, service, weight and a value to create this record type")
|
||||
srv_data = {
|
||||
@@ -555,12 +554,12 @@ class CloudflareAPI(object):
|
||||
"proto": params['proto'],
|
||||
"service": params['service']
|
||||
}
|
||||
new_record = { "type": params['type'], "ttl": params['ttl'], 'data': srv_data }
|
||||
new_record = {"type": params['type'], "ttl": params['ttl'], 'data': srv_data}
|
||||
search_value = str(params['weight']) + '\t' + str(params['port']) + '\t' + params['value']
|
||||
search_record = params['service'] + '.' + params['proto'] + '.' + params['record']
|
||||
|
||||
zone_id = self._get_zone_id(params['zone'])
|
||||
records = self.get_dns_records(params['zone'],params['type'],search_record,search_value)
|
||||
records = self.get_dns_records(params['zone'], params['type'], search_record, search_value)
|
||||
# in theory this should be impossible as cloudflare does not allow
|
||||
# the creation of duplicate records but lets cover it anyways
|
||||
if len(records) > 1:
|
||||
@@ -569,7 +568,7 @@ class CloudflareAPI(object):
|
||||
if len(records) == 1:
|
||||
cur_record = records[0]
|
||||
do_update = False
|
||||
if (params['ttl'] is not None) and (cur_record['ttl'] != params['ttl'] ):
|
||||
if (params['ttl'] is not None) and (cur_record['ttl'] != params['ttl']):
|
||||
do_update = True
|
||||
if (params['priority'] is not None) and ('priority' in cur_record) and (cur_record['priority'] != params['priority']):
|
||||
do_update = True
|
||||
@@ -582,53 +581,54 @@ class CloudflareAPI(object):
|
||||
if self.module.check_mode:
|
||||
result = new_record
|
||||
else:
|
||||
result, info = self._cf_api_call('/zones/{0}/dns_records/{1}'.format(zone_id,records[0]['id']),'PUT',new_record)
|
||||
result, info = self._cf_api_call('/zones/{0}/dns_records/{1}'.format(zone_id, records[0]['id']), 'PUT', new_record)
|
||||
self.changed = True
|
||||
return result,self.changed
|
||||
return result, self.changed
|
||||
else:
|
||||
return records,self.changed
|
||||
return records, self.changed
|
||||
if self.module.check_mode:
|
||||
result = new_record
|
||||
else:
|
||||
result, info = self._cf_api_call('/zones/{0}/dns_records'.format(zone_id),'POST',new_record)
|
||||
result, info = self._cf_api_call('/zones/{0}/dns_records'.format(zone_id), 'POST', new_record)
|
||||
self.changed = True
|
||||
return result,self.changed
|
||||
return result, self.changed
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
account_api_token = dict(required=True, no_log=True, type='str'),
|
||||
account_email = dict(required=True, type='str'),
|
||||
port = dict(required=False, default=None, type='int'),
|
||||
priority = dict(required=False, default=1, type='int'),
|
||||
proto = dict(required=False, default=None, choices=[ 'tcp', 'udp' ], type='str'),
|
||||
proxied = dict(required=False, default=False, type='bool'),
|
||||
record = dict(required=False, default='@', aliases=['name'], type='str'),
|
||||
service = dict(required=False, default=None, type='str'),
|
||||
solo = dict(required=False, default=None, type='bool'),
|
||||
state = dict(required=False, default='present', choices=['present', 'absent'], type='str'),
|
||||
timeout = dict(required=False, default=30, type='int'),
|
||||
ttl = dict(required=False, default=1, type='int'),
|
||||
type = dict(required=False, default=None, choices=[ 'A', 'AAAA', 'CNAME', 'TXT', 'SRV', 'MX', 'NS', 'SPF' ], type='str'),
|
||||
value = dict(required=False, default=None, aliases=['content'], type='str'),
|
||||
weight = dict(required=False, default=1, type='int'),
|
||||
zone = dict(required=True, default=None, aliases=['domain'], type='str'),
|
||||
argument_spec=dict(
|
||||
account_api_token=dict(required=True, no_log=True, type='str'),
|
||||
account_email=dict(required=True, type='str'),
|
||||
port=dict(required=False, default=None, type='int'),
|
||||
priority=dict(required=False, default=1, type='int'),
|
||||
proto=dict(required=False, default=None, choices=['tcp', 'udp'], type='str'),
|
||||
proxied=dict(required=False, default=False, type='bool'),
|
||||
record=dict(required=False, default='@', aliases=['name'], type='str'),
|
||||
service=dict(required=False, default=None, type='str'),
|
||||
solo=dict(required=False, default=None, type='bool'),
|
||||
state=dict(required=False, default='present', choices=['present', 'absent'], type='str'),
|
||||
timeout=dict(required=False, default=30, type='int'),
|
||||
ttl=dict(required=False, default=1, type='int'),
|
||||
type=dict(required=False, default=None, choices=['A', 'AAAA', 'CNAME', 'TXT', 'SRV', 'MX', 'NS', 'SPF'], type='str'),
|
||||
value=dict(required=False, default=None, aliases=['content'], type='str'),
|
||||
weight=dict(required=False, default=1, type='int'),
|
||||
zone=dict(required=True, default=None, aliases=['domain'], type='str'),
|
||||
),
|
||||
supports_check_mode = True,
|
||||
required_if = ([
|
||||
('state','present',['record','type']),
|
||||
('type','MX',['priority','value']),
|
||||
('type','SRV',['port','priority','proto','service','value','weight']),
|
||||
('type','A',['value']),
|
||||
('type','AAAA',['value']),
|
||||
('type','CNAME',['value']),
|
||||
('type','TXT',['value']),
|
||||
('type','NS',['value']),
|
||||
('type','SPF',['value'])
|
||||
supports_check_mode=True,
|
||||
required_if=([
|
||||
('state', 'present', ['record', 'type']),
|
||||
('type', 'MX', ['priority', 'value']),
|
||||
('type', 'SRV', ['port', 'priority', 'proto', 'service', 'value', 'weight']),
|
||||
('type', 'A', ['value']),
|
||||
('type', 'AAAA', ['value']),
|
||||
('type', 'CNAME', ['value']),
|
||||
('type', 'TXT', ['value']),
|
||||
('type', 'NS', ['value']),
|
||||
('type', 'SPF', ['value'])
|
||||
]
|
||||
),
|
||||
required_one_of = (
|
||||
[['record','value','type']]
|
||||
required_one_of=(
|
||||
[['record', 'value', 'type']]
|
||||
)
|
||||
)
|
||||
|
||||
@@ -645,11 +645,11 @@ def main():
|
||||
# delete all records matching record name + type
|
||||
if cf_api.is_solo:
|
||||
changed = cf_api.delete_dns_records(solo=cf_api.is_solo)
|
||||
result,changed = cf_api.ensure_dns_record()
|
||||
if isinstance(result,list):
|
||||
module.exit_json(changed=changed,result={'record': result[0]})
|
||||
result, changed = cf_api.ensure_dns_record()
|
||||
if isinstance(result, list):
|
||||
module.exit_json(changed=changed, result={'record': result[0]})
|
||||
else:
|
||||
module.exit_json(changed=changed,result={'record': result})
|
||||
module.exit_json(changed=changed, result={'record': result})
|
||||
else:
|
||||
# force solo to False, just to be sure
|
||||
changed = cf_api.delete_dns_records(solo=False)
|
||||
|
||||
@@ -188,26 +188,26 @@ def main():
|
||||
state=dict(required=False, choices=['present', 'absent']),
|
||||
solo=dict(required=False, type='bool'),
|
||||
),
|
||||
required_together = (
|
||||
required_together=(
|
||||
['record', 'value']
|
||||
),
|
||||
supports_check_mode = True,
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
if not HAS_DNSIMPLE:
|
||||
module.fail_json(msg="dnsimple required for this module")
|
||||
|
||||
account_email = module.params.get('account_email')
|
||||
account_email = module.params.get('account_email')
|
||||
account_api_token = module.params.get('account_api_token')
|
||||
domain = module.params.get('domain')
|
||||
record = module.params.get('record')
|
||||
record_ids = module.params.get('record_ids')
|
||||
record_type = module.params.get('type')
|
||||
ttl = module.params.get('ttl')
|
||||
value = module.params.get('value')
|
||||
priority = module.params.get('priority')
|
||||
state = module.params.get('state')
|
||||
is_solo = module.params.get('solo')
|
||||
domain = module.params.get('domain')
|
||||
record = module.params.get('record')
|
||||
record_ids = module.params.get('record_ids')
|
||||
record_type = module.params.get('type')
|
||||
ttl = module.params.get('ttl')
|
||||
value = module.params.get('value')
|
||||
priority = module.params.get('priority')
|
||||
state = module.params.get('state')
|
||||
is_solo = module.params.get('solo')
|
||||
|
||||
if account_email and account_api_token:
|
||||
client = DNSimple(email=account_email, api_token=account_api_token)
|
||||
@@ -278,7 +278,7 @@ def main():
|
||||
if rr['ttl'] != ttl or rr['prio'] != priority:
|
||||
data = {}
|
||||
if ttl:
|
||||
data['ttl'] = ttl
|
||||
data['ttl'] = ttl
|
||||
if priority:
|
||||
data['prio'] = priority
|
||||
if module.check_mode:
|
||||
@@ -290,12 +290,12 @@ def main():
|
||||
else:
|
||||
# create it
|
||||
data = {
|
||||
'name': record,
|
||||
'name': record,
|
||||
'record_type': record_type,
|
||||
'content': value,
|
||||
'content': value,
|
||||
}
|
||||
if ttl:
|
||||
data['ttl'] = ttl
|
||||
data['ttl'] = ttl
|
||||
if priority:
|
||||
data['prio'] = priority
|
||||
if module.check_mode:
|
||||
@@ -315,7 +315,7 @@ def main():
|
||||
# Make sure these record_ids either all exist or none
|
||||
if domain and record_ids:
|
||||
current_records = [str(r['record']['id']) for r in client.records(str(domain))]
|
||||
wanted_records = [str(r) for r in record_ids]
|
||||
wanted_records = [str(r) for r in record_ids]
|
||||
if state == 'present':
|
||||
difference = list(set(wanted_records) - set(current_records))
|
||||
if difference:
|
||||
|
||||
@@ -401,7 +401,7 @@ class DME2(object):
|
||||
self.record_map = None # ["record_name"] => ID
|
||||
self.records = None # ["record_ID"] => <record>
|
||||
self.all_records = None
|
||||
self.contactList_map = None # ["contactList_name"] => ID
|
||||
self.contactList_map = None # ["contactList_name"] => ID
|
||||
|
||||
# Lookup the domain ID if passed as a domain name vs. ID
|
||||
if not self.domain.isdigit():
|
||||
@@ -551,6 +551,7 @@ class DME2(object):
|
||||
# Module execution.
|
||||
#
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
module = AnsibleModule(
|
||||
@@ -581,7 +582,7 @@ def main():
|
||||
ip3=dict(required=False),
|
||||
ip4=dict(required=False),
|
||||
ip5=dict(required=False),
|
||||
validate_certs = dict(default='yes', type='bool'),
|
||||
validate_certs=dict(default='yes', type='bool'),
|
||||
),
|
||||
required_together=(
|
||||
['record_value', 'record_ttl', 'record_type']
|
||||
|
||||
@@ -96,7 +96,7 @@ class IpinfoioFacts(object):
|
||||
self.module = module
|
||||
|
||||
def get_geo_data(self):
|
||||
response, info = fetch_url(self.module, self.url, force=True, # NOQA
|
||||
response, info = fetch_url(self.module, self.url, force=True, # NOQA
|
||||
timeout=self.timeout)
|
||||
try:
|
||||
info['status'] == 200
|
||||
@@ -116,7 +116,7 @@ class IpinfoioFacts(object):
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule( # NOQA
|
||||
module = AnsibleModule( # NOQA
|
||||
argument_spec=dict(
|
||||
http_agent=dict(default=USER_AGENT),
|
||||
timeout=dict(type='int', default=10),
|
||||
|
||||
@@ -13,7 +13,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'supported_by': 'community'}
|
||||
|
||||
|
||||
DOCUMENTATION='''
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: nmcli
|
||||
author: "Chris Long (@alcamie101)"
|
||||
@@ -208,7 +208,7 @@ options:
|
||||
|
||||
'''
|
||||
|
||||
EXAMPLES='''
|
||||
EXAMPLES = '''
|
||||
# These examples are using the following inventory:
|
||||
#
|
||||
# ## Directory layout:
|
||||
@@ -482,17 +482,17 @@ EXAMPLES='''
|
||||
# - 10 Connection, device, or access point does not exist.
|
||||
'''
|
||||
|
||||
HAVE_DBUS=False
|
||||
HAVE_DBUS = False
|
||||
try:
|
||||
import dbus
|
||||
HAVE_DBUS=True
|
||||
HAVE_DBUS = True
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
HAVE_NM_CLIENT=False
|
||||
HAVE_NM_CLIENT = False
|
||||
try:
|
||||
from gi.repository import NetworkManager, NMClient
|
||||
HAVE_NM_CLIENT=True
|
||||
HAVE_NM_CLIENT = True
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
@@ -512,75 +512,74 @@ class Nmcli(object):
|
||||
All subclasses MUST define platform and distribution (which may be None).
|
||||
"""
|
||||
|
||||
platform='Generic'
|
||||
distribution=None
|
||||
platform = 'Generic'
|
||||
distribution = None
|
||||
if HAVE_DBUS:
|
||||
bus=dbus.SystemBus()
|
||||
bus = dbus.SystemBus()
|
||||
# The following is going to be used in dbus code
|
||||
DEVTYPES={1: "Ethernet",
|
||||
2: "Wi-Fi",
|
||||
5: "Bluetooth",
|
||||
6: "OLPC",
|
||||
7: "WiMAX",
|
||||
8: "Modem",
|
||||
9: "InfiniBand",
|
||||
10: "Bond",
|
||||
11: "VLAN",
|
||||
12: "ADSL",
|
||||
13: "Bridge",
|
||||
14: "Generic",
|
||||
15: "Team"
|
||||
DEVTYPES = {1: "Ethernet",
|
||||
2: "Wi-Fi",
|
||||
5: "Bluetooth",
|
||||
6: "OLPC",
|
||||
7: "WiMAX",
|
||||
8: "Modem",
|
||||
9: "InfiniBand",
|
||||
10: "Bond",
|
||||
11: "VLAN",
|
||||
12: "ADSL",
|
||||
13: "Bridge",
|
||||
14: "Generic",
|
||||
15: "Team"
|
||||
}
|
||||
STATES={0: "Unknown",
|
||||
10: "Unmanaged",
|
||||
20: "Unavailable",
|
||||
30: "Disconnected",
|
||||
40: "Prepare",
|
||||
50: "Config",
|
||||
60: "Need Auth",
|
||||
70: "IP Config",
|
||||
80: "IP Check",
|
||||
90: "Secondaries",
|
||||
100: "Activated",
|
||||
110: "Deactivating",
|
||||
120: "Failed"
|
||||
}
|
||||
|
||||
STATES = {0: "Unknown",
|
||||
10: "Unmanaged",
|
||||
20: "Unavailable",
|
||||
30: "Disconnected",
|
||||
40: "Prepare",
|
||||
50: "Config",
|
||||
60: "Need Auth",
|
||||
70: "IP Config",
|
||||
80: "IP Check",
|
||||
90: "Secondaries",
|
||||
100: "Activated",
|
||||
110: "Deactivating",
|
||||
120: "Failed"
|
||||
}
|
||||
|
||||
def __init__(self, module):
|
||||
self.module=module
|
||||
self.state=module.params['state']
|
||||
self.autoconnect=module.params['autoconnect']
|
||||
self.conn_name=module.params['conn_name']
|
||||
self.master=module.params['master']
|
||||
self.ifname=module.params['ifname']
|
||||
self.type=module.params['type']
|
||||
self.ip4=module.params['ip4']
|
||||
self.gw4=module.params['gw4']
|
||||
self.dns4=' '.join(module.params['dns4'])
|
||||
self.ip6=module.params['ip6']
|
||||
self.gw6=module.params['gw6']
|
||||
self.dns6=module.params['dns6']
|
||||
self.mtu=module.params['mtu']
|
||||
self.stp=module.params['stp']
|
||||
self.priority=module.params['priority']
|
||||
self.mode=module.params['mode']
|
||||
self.miimon=module.params['miimon']
|
||||
self.downdelay=module.params['downdelay']
|
||||
self.updelay=module.params['updelay']
|
||||
self.arp_interval=module.params['arp_interval']
|
||||
self.arp_ip_target=module.params['arp_ip_target']
|
||||
self.slavepriority=module.params['slavepriority']
|
||||
self.forwarddelay=module.params['forwarddelay']
|
||||
self.hellotime=module.params['hellotime']
|
||||
self.maxage=module.params['maxage']
|
||||
self.ageingtime=module.params['ageingtime']
|
||||
self.mac=module.params['mac']
|
||||
self.vlanid=module.params['vlanid']
|
||||
self.vlandev=module.params['vlandev']
|
||||
self.flags=module.params['flags']
|
||||
self.ingress=module.params['ingress']
|
||||
self.egress=module.params['egress']
|
||||
self.module = module
|
||||
self.state = module.params['state']
|
||||
self.autoconnect = module.params['autoconnect']
|
||||
self.conn_name = module.params['conn_name']
|
||||
self.master = module.params['master']
|
||||
self.ifname = module.params['ifname']
|
||||
self.type = module.params['type']
|
||||
self.ip4 = module.params['ip4']
|
||||
self.gw4 = module.params['gw4']
|
||||
self.dns4 = ' '.join(module.params['dns4'])
|
||||
self.ip6 = module.params['ip6']
|
||||
self.gw6 = module.params['gw6']
|
||||
self.dns6 = module.params['dns6']
|
||||
self.mtu = module.params['mtu']
|
||||
self.stp = module.params['stp']
|
||||
self.priority = module.params['priority']
|
||||
self.mode = module.params['mode']
|
||||
self.miimon = module.params['miimon']
|
||||
self.downdelay = module.params['downdelay']
|
||||
self.updelay = module.params['updelay']
|
||||
self.arp_interval = module.params['arp_interval']
|
||||
self.arp_ip_target = module.params['arp_ip_target']
|
||||
self.slavepriority = module.params['slavepriority']
|
||||
self.forwarddelay = module.params['forwarddelay']
|
||||
self.hellotime = module.params['hellotime']
|
||||
self.maxage = module.params['maxage']
|
||||
self.ageingtime = module.params['ageingtime']
|
||||
self.mac = module.params['mac']
|
||||
self.vlanid = module.params['vlanid']
|
||||
self.vlandev = module.params['vlandev']
|
||||
self.flags = module.params['flags']
|
||||
self.ingress = module.params['ingress']
|
||||
self.egress = module.params['egress']
|
||||
|
||||
def execute_command(self, cmd, use_unsafe_shell=False, data=None):
|
||||
return self.module.run_command(cmd, use_unsafe_shell=use_unsafe_shell, data=data)
|
||||
@@ -589,41 +588,41 @@ class Nmcli(object):
|
||||
try:
|
||||
# returns a dict of dicts mapping name::setting, where setting is a dict
|
||||
# mapping key::value. Each member of the 'setting' dict is a secret
|
||||
secrets=proxy.GetSecrets(setting_name)
|
||||
secrets = proxy.GetSecrets(setting_name)
|
||||
|
||||
# Copy the secrets into our connection config
|
||||
for setting in secrets:
|
||||
for key in secrets[setting]:
|
||||
config[setting_name][key]=secrets[setting][key]
|
||||
config[setting_name][key] = secrets[setting][key]
|
||||
except:
|
||||
pass
|
||||
|
||||
def dict_to_string(self, d):
|
||||
# Try to trivially translate a dictionary's elements into nice string
|
||||
# formatting.
|
||||
dstr=""
|
||||
dstr = ""
|
||||
for key in d:
|
||||
val=d[key]
|
||||
str_val=""
|
||||
add_string=True
|
||||
val = d[key]
|
||||
str_val = ""
|
||||
add_string = True
|
||||
if isinstance(val, dbus.Array):
|
||||
for elt in val:
|
||||
if isinstance(elt, dbus.Byte):
|
||||
str_val+="%s " % int(elt)
|
||||
str_val += "%s " % int(elt)
|
||||
elif isinstance(elt, dbus.String):
|
||||
str_val+="%s" % elt
|
||||
str_val += "%s" % elt
|
||||
elif isinstance(val, dbus.Dictionary):
|
||||
dstr+=self.dict_to_string(val)
|
||||
add_string=False
|
||||
dstr += self.dict_to_string(val)
|
||||
add_string = False
|
||||
else:
|
||||
str_val=val
|
||||
str_val = val
|
||||
if add_string:
|
||||
dstr+="%s: %s\n" % ( key, str_val)
|
||||
dstr += "%s: %s\n" % (key, str_val)
|
||||
return dstr
|
||||
|
||||
def connection_to_string(self, config):
|
||||
# dump a connection configuration to use in list_connection_info
|
||||
setting_list=[]
|
||||
setting_list = []
|
||||
for setting_name in config:
|
||||
setting_list.append(self.dict_to_string(config[setting_name]))
|
||||
return setting_list
|
||||
@@ -637,18 +636,18 @@ class Nmcli(object):
|
||||
|
||||
def list_connection_info(self):
|
||||
# Ask the settings service for the list of connections it provides
|
||||
bus=dbus.SystemBus()
|
||||
bus = dbus.SystemBus()
|
||||
|
||||
service_name="org.freedesktop.NetworkManager"
|
||||
proxy=bus.get_object(service_name, "/org/freedesktop/NetworkManager/Settings")
|
||||
settings=dbus.Interface(proxy, "org.freedesktop.NetworkManager.Settings")
|
||||
connection_paths=settings.ListConnections()
|
||||
connection_list=[]
|
||||
service_name = "org.freedesktop.NetworkManager"
|
||||
proxy = bus.get_object(service_name, "/org/freedesktop/NetworkManager/Settings")
|
||||
settings = dbus.Interface(proxy, "org.freedesktop.NetworkManager.Settings")
|
||||
connection_paths = settings.ListConnections()
|
||||
connection_list = []
|
||||
# List each connection's name, UUID, and type
|
||||
for path in connection_paths:
|
||||
con_proxy=bus.get_object(service_name, path)
|
||||
settings_connection=dbus.Interface(con_proxy, "org.freedesktop.NetworkManager.Settings.Connection")
|
||||
config=settings_connection.GetSettings()
|
||||
con_proxy = bus.get_object(service_name, path)
|
||||
settings_connection = dbus.Interface(con_proxy, "org.freedesktop.NetworkManager.Settings.Connection")
|
||||
config = settings_connection.GetSettings()
|
||||
|
||||
# Now get secrets too; we grab the secrets for each type of connection
|
||||
# (since there isn't a "get all secrets" call because most of the time
|
||||
@@ -662,7 +661,7 @@ class Nmcli(object):
|
||||
self.merge_secrets(settings_connection, config, 'ppp')
|
||||
|
||||
# Get the details of the 'connection' setting
|
||||
s_con=config['connection']
|
||||
s_con = config['connection']
|
||||
connection_list.append(s_con['id'])
|
||||
connection_list.append(s_con['uuid'])
|
||||
connection_list.append(s_con['type'])
|
||||
@@ -671,14 +670,14 @@ class Nmcli(object):
|
||||
|
||||
def connection_exists(self):
|
||||
# we are going to use name and type in this instance to find if that connection exists and is of type x
|
||||
connections=self.list_connection_info()
|
||||
connections = self.list_connection_info()
|
||||
|
||||
for con_item in connections:
|
||||
if self.conn_name==con_item:
|
||||
if self.conn_name == con_item:
|
||||
return True
|
||||
|
||||
def down_connection(self):
|
||||
cmd=[self.module.get_bin_path('nmcli', True)]
|
||||
cmd = [self.module.get_bin_path('nmcli', True)]
|
||||
# if self.connection_exists():
|
||||
cmd.append('con')
|
||||
cmd.append('down')
|
||||
@@ -686,14 +685,14 @@ class Nmcli(object):
|
||||
return self.execute_command(cmd)
|
||||
|
||||
def up_connection(self):
|
||||
cmd=[self.module.get_bin_path('nmcli', True)]
|
||||
cmd = [self.module.get_bin_path('nmcli', True)]
|
||||
cmd.append('con')
|
||||
cmd.append('up')
|
||||
cmd.append(self.conn_name)
|
||||
return self.execute_command(cmd)
|
||||
|
||||
def create_connection_team(self):
|
||||
cmd=[self.module.get_bin_path('nmcli', True)]
|
||||
cmd = [self.module.get_bin_path('nmcli', True)]
|
||||
# format for creating team interface
|
||||
cmd.append('con')
|
||||
cmd.append('add')
|
||||
@@ -727,7 +726,7 @@ class Nmcli(object):
|
||||
return cmd
|
||||
|
||||
def modify_connection_team(self):
|
||||
cmd=[self.module.get_bin_path('nmcli', True)]
|
||||
cmd = [self.module.get_bin_path('nmcli', True)]
|
||||
# format for modifying team interface
|
||||
cmd.append('con')
|
||||
cmd.append('mod')
|
||||
@@ -757,7 +756,7 @@ class Nmcli(object):
|
||||
return cmd
|
||||
|
||||
def create_connection_team_slave(self):
|
||||
cmd=[self.module.get_bin_path('nmcli', True)]
|
||||
cmd = [self.module.get_bin_path('nmcli', True)]
|
||||
# format for creating team-slave interface
|
||||
cmd.append('connection')
|
||||
cmd.append('add')
|
||||
@@ -782,7 +781,7 @@ class Nmcli(object):
|
||||
return cmd
|
||||
|
||||
def modify_connection_team_slave(self):
|
||||
cmd=[self.module.get_bin_path('nmcli', True)]
|
||||
cmd = [self.module.get_bin_path('nmcli', True)]
|
||||
# format for modifying team-slave interface
|
||||
cmd.append('con')
|
||||
cmd.append('mod')
|
||||
@@ -795,7 +794,7 @@ class Nmcli(object):
|
||||
return cmd
|
||||
|
||||
def create_connection_bond(self):
|
||||
cmd=[self.module.get_bin_path('nmcli', True)]
|
||||
cmd = [self.module.get_bin_path('nmcli', True)]
|
||||
# format for creating bond interface
|
||||
cmd.append('con')
|
||||
cmd.append('add')
|
||||
@@ -847,7 +846,7 @@ class Nmcli(object):
|
||||
return cmd
|
||||
|
||||
def modify_connection_bond(self):
|
||||
cmd=[self.module.get_bin_path('nmcli', True)]
|
||||
cmd = [self.module.get_bin_path('nmcli', True)]
|
||||
# format for modifying bond interface
|
||||
cmd.append('con')
|
||||
cmd.append('mod')
|
||||
@@ -876,7 +875,7 @@ class Nmcli(object):
|
||||
return cmd
|
||||
|
||||
def create_connection_bond_slave(self):
|
||||
cmd=[self.module.get_bin_path('nmcli', True)]
|
||||
cmd = [self.module.get_bin_path('nmcli', True)]
|
||||
# format for creating bond-slave interface
|
||||
cmd.append('connection')
|
||||
cmd.append('add')
|
||||
@@ -898,7 +897,7 @@ class Nmcli(object):
|
||||
return cmd
|
||||
|
||||
def modify_connection_bond_slave(self):
|
||||
cmd=[self.module.get_bin_path('nmcli', True)]
|
||||
cmd = [self.module.get_bin_path('nmcli', True)]
|
||||
# format for modifying bond-slave interface
|
||||
cmd.append('con')
|
||||
cmd.append('mod')
|
||||
@@ -908,7 +907,7 @@ class Nmcli(object):
|
||||
return cmd
|
||||
|
||||
def create_connection_ethernet(self):
|
||||
cmd=[self.module.get_bin_path('nmcli', True)]
|
||||
cmd = [self.module.get_bin_path('nmcli', True)]
|
||||
# format for creating ethernet interface
|
||||
# To add an Ethernet connection with static IP configuration, issue a command as follows
|
||||
# - nmcli: name=add conn_name=my-eth1 ifname=eth1 type=ethernet ip4=192.0.2.100/24 gw4=192.0.2.1 state=present
|
||||
@@ -945,7 +944,7 @@ class Nmcli(object):
|
||||
return cmd
|
||||
|
||||
def modify_connection_ethernet(self):
|
||||
cmd=[self.module.get_bin_path('nmcli', True)]
|
||||
cmd = [self.module.get_bin_path('nmcli', True)]
|
||||
# format for modifying ethernet interface
|
||||
# To add an Ethernet connection with static IP configuration, issue a command as follows
|
||||
# - nmcli: name=add conn_name=my-eth1 ifname=eth1 type=ethernet ip4=192.0.2.100/24 gw4=192.0.2.1 state=present
|
||||
@@ -980,110 +979,110 @@ class Nmcli(object):
|
||||
return cmd
|
||||
|
||||
def create_connection_bridge(self):
|
||||
cmd=[self.module.get_bin_path('nmcli', True)]
|
||||
cmd = [self.module.get_bin_path('nmcli', True)]
|
||||
# format for creating bridge interface
|
||||
return cmd
|
||||
|
||||
def modify_connection_bridge(self):
|
||||
cmd=[self.module.get_bin_path('nmcli', True)]
|
||||
cmd = [self.module.get_bin_path('nmcli', True)]
|
||||
# format for modifying bridge interface
|
||||
return cmd
|
||||
|
||||
def create_connection_vlan(self):
|
||||
cmd=[self.module.get_bin_path('nmcli', True)]
|
||||
cmd = [self.module.get_bin_path('nmcli', True)]
|
||||
# format for creating ethernet interface
|
||||
return cmd
|
||||
|
||||
def modify_connection_vlan(self):
|
||||
cmd=[self.module.get_bin_path('nmcli', True)]
|
||||
cmd = [self.module.get_bin_path('nmcli', True)]
|
||||
# format for modifying ethernet interface
|
||||
return cmd
|
||||
|
||||
def create_connection(self):
|
||||
cmd=[]
|
||||
if self.type=='team':
|
||||
cmd = []
|
||||
if self.type == 'team':
|
||||
# cmd=self.create_connection_team()
|
||||
if (self.dns4 is not None) or (self.dns6 is not None):
|
||||
cmd=self.create_connection_team()
|
||||
cmd = self.create_connection_team()
|
||||
self.execute_command(cmd)
|
||||
cmd=self.modify_connection_team()
|
||||
cmd = self.modify_connection_team()
|
||||
self.execute_command(cmd)
|
||||
cmd=self.up_connection()
|
||||
cmd = self.up_connection()
|
||||
return self.execute_command(cmd)
|
||||
elif (self.dns4 is None) or (self.dns6 is None):
|
||||
cmd=self.create_connection_team()
|
||||
cmd = self.create_connection_team()
|
||||
return self.execute_command(cmd)
|
||||
elif self.type=='team-slave':
|
||||
elif self.type == 'team-slave':
|
||||
if self.mtu is not None:
|
||||
cmd=self.create_connection_team_slave()
|
||||
cmd = self.create_connection_team_slave()
|
||||
self.execute_command(cmd)
|
||||
cmd=self.modify_connection_team_slave()
|
||||
cmd = self.modify_connection_team_slave()
|
||||
self.execute_command(cmd)
|
||||
# cmd=self.up_connection()
|
||||
return self.execute_command(cmd)
|
||||
else:
|
||||
cmd=self.create_connection_team_slave()
|
||||
cmd = self.create_connection_team_slave()
|
||||
return self.execute_command(cmd)
|
||||
elif self.type=='bond':
|
||||
elif self.type == 'bond':
|
||||
if (self.mtu is not None) or (self.dns4 is not None) or (self.dns6 is not None):
|
||||
cmd=self.create_connection_bond()
|
||||
cmd = self.create_connection_bond()
|
||||
self.execute_command(cmd)
|
||||
cmd=self.modify_connection_bond()
|
||||
cmd = self.modify_connection_bond()
|
||||
self.execute_command(cmd)
|
||||
cmd=self.up_connection()
|
||||
cmd = self.up_connection()
|
||||
return self.execute_command(cmd)
|
||||
else:
|
||||
cmd=self.create_connection_bond()
|
||||
cmd = self.create_connection_bond()
|
||||
return self.execute_command(cmd)
|
||||
elif self.type=='bond-slave':
|
||||
cmd=self.create_connection_bond_slave()
|
||||
elif self.type=='ethernet':
|
||||
elif self.type == 'bond-slave':
|
||||
cmd = self.create_connection_bond_slave()
|
||||
elif self.type == 'ethernet':
|
||||
if (self.mtu is not None) or (self.dns4 is not None) or (self.dns6 is not None):
|
||||
cmd=self.create_connection_ethernet()
|
||||
cmd = self.create_connection_ethernet()
|
||||
self.execute_command(cmd)
|
||||
cmd=self.modify_connection_ethernet()
|
||||
cmd = self.modify_connection_ethernet()
|
||||
self.execute_command(cmd)
|
||||
cmd=self.up_connection()
|
||||
cmd = self.up_connection()
|
||||
return self.execute_command(cmd)
|
||||
else:
|
||||
cmd=self.create_connection_ethernet()
|
||||
cmd = self.create_connection_ethernet()
|
||||
return self.execute_command(cmd)
|
||||
elif self.type=='bridge':
|
||||
cmd=self.create_connection_bridge()
|
||||
elif self.type=='vlan':
|
||||
cmd=self.create_connection_vlan()
|
||||
elif self.type == 'bridge':
|
||||
cmd = self.create_connection_bridge()
|
||||
elif self.type == 'vlan':
|
||||
cmd = self.create_connection_vlan()
|
||||
return self.execute_command(cmd)
|
||||
|
||||
def remove_connection(self):
|
||||
# self.down_connection()
|
||||
cmd=[self.module.get_bin_path('nmcli', True)]
|
||||
cmd = [self.module.get_bin_path('nmcli', True)]
|
||||
cmd.append('con')
|
||||
cmd.append('del')
|
||||
cmd.append(self.conn_name)
|
||||
return self.execute_command(cmd)
|
||||
|
||||
def modify_connection(self):
|
||||
cmd=[]
|
||||
if self.type=='team':
|
||||
cmd=self.modify_connection_team()
|
||||
elif self.type=='team-slave':
|
||||
cmd=self.modify_connection_team_slave()
|
||||
elif self.type=='bond':
|
||||
cmd=self.modify_connection_bond()
|
||||
elif self.type=='bond-slave':
|
||||
cmd=self.modify_connection_bond_slave()
|
||||
elif self.type=='ethernet':
|
||||
cmd=self.modify_connection_ethernet()
|
||||
elif self.type=='bridge':
|
||||
cmd=self.modify_connection_bridge()
|
||||
elif self.type=='vlan':
|
||||
cmd=self.modify_connection_vlan()
|
||||
cmd = []
|
||||
if self.type == 'team':
|
||||
cmd = self.modify_connection_team()
|
||||
elif self.type == 'team-slave':
|
||||
cmd = self.modify_connection_team_slave()
|
||||
elif self.type == 'bond':
|
||||
cmd = self.modify_connection_bond()
|
||||
elif self.type == 'bond-slave':
|
||||
cmd = self.modify_connection_bond_slave()
|
||||
elif self.type == 'ethernet':
|
||||
cmd = self.modify_connection_ethernet()
|
||||
elif self.type == 'bridge':
|
||||
cmd = self.modify_connection_bridge()
|
||||
elif self.type == 'vlan':
|
||||
cmd = self.modify_connection_vlan()
|
||||
return self.execute_command(cmd)
|
||||
|
||||
|
||||
def main():
|
||||
# Parsing argument file
|
||||
module=AnsibleModule(
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
autoconnect=dict(required=False, default=None, type='bool'),
|
||||
state=dict(required=True, choices=['present', 'absent'], type='str'),
|
||||
@@ -1132,57 +1131,57 @@ def main():
|
||||
if not HAVE_NM_CLIENT:
|
||||
module.fail_json(msg="This module requires NetworkManager glib API")
|
||||
|
||||
nmcli=Nmcli(module)
|
||||
nmcli = Nmcli(module)
|
||||
|
||||
rc=None
|
||||
out=''
|
||||
err=''
|
||||
result={}
|
||||
result['conn_name']=nmcli.conn_name
|
||||
result['state']=nmcli.state
|
||||
rc = None
|
||||
out = ''
|
||||
err = ''
|
||||
result = {}
|
||||
result['conn_name'] = nmcli.conn_name
|
||||
result['state'] = nmcli.state
|
||||
|
||||
# check for issues
|
||||
if nmcli.conn_name is None:
|
||||
nmcli.module.fail_json(msg="You haven't specified a name for the connection")
|
||||
# team-slave checks
|
||||
if nmcli.type=='team-slave' and nmcli.master is None:
|
||||
if nmcli.type == 'team-slave' and nmcli.master is None:
|
||||
nmcli.module.fail_json(msg="You haven't specified a name for the master so we're not changing a thing")
|
||||
if nmcli.type=='team-slave' and nmcli.ifname is None:
|
||||
if nmcli.type == 'team-slave' and nmcli.ifname is None:
|
||||
nmcli.module.fail_json(msg="You haven't specified a name for the connection")
|
||||
|
||||
if nmcli.state=='absent':
|
||||
if nmcli.state == 'absent':
|
||||
if nmcli.connection_exists():
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
(rc, out, err)=nmcli.down_connection()
|
||||
(rc, out, err)=nmcli.remove_connection()
|
||||
if rc!=0:
|
||||
module.fail_json(name =('No Connection named %s exists' % nmcli.conn_name), msg=err, rc=rc)
|
||||
(rc, out, err) = nmcli.down_connection()
|
||||
(rc, out, err) = nmcli.remove_connection()
|
||||
if rc != 0:
|
||||
module.fail_json(name=('No Connection named %s exists' % nmcli.conn_name), msg=err, rc=rc)
|
||||
|
||||
elif nmcli.state=='present':
|
||||
elif nmcli.state == 'present':
|
||||
if nmcli.connection_exists():
|
||||
# modify connection (note: this function is check mode aware)
|
||||
# result['Connection']=('Connection %s of Type %s is not being added' % (nmcli.conn_name, nmcli.type))
|
||||
result['Exists']='Connections do exist so we are modifying them'
|
||||
result['Exists'] = 'Connections do exist so we are modifying them'
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
(rc, out, err)=nmcli.modify_connection()
|
||||
(rc, out, err) = nmcli.modify_connection()
|
||||
if not nmcli.connection_exists():
|
||||
result['Connection']=('Connection %s of Type %s is being added' % (nmcli.conn_name, nmcli.type))
|
||||
result['Connection'] = ('Connection %s of Type %s is being added' % (nmcli.conn_name, nmcli.type))
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
(rc, out, err)=nmcli.create_connection()
|
||||
if rc is not None and rc!=0:
|
||||
(rc, out, err) = nmcli.create_connection()
|
||||
if rc is not None and rc != 0:
|
||||
module.fail_json(name=nmcli.conn_name, msg=err, rc=rc)
|
||||
|
||||
if rc is None:
|
||||
result['changed']=False
|
||||
result['changed'] = False
|
||||
else:
|
||||
result['changed']=True
|
||||
result['changed'] = True
|
||||
if out:
|
||||
result['stdout']=out
|
||||
result['stdout'] = out
|
||||
if err:
|
||||
result['stderr']=err
|
||||
result['stderr'] = err
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ class OmapiHostManager:
|
||||
fields_to_update = {}
|
||||
|
||||
if to_bytes('ip-address', errors='surrogate_or_strict') not in response_obj or \
|
||||
unpack_ip(response_obj[to_bytes('ip-address', errors='surrogate_or_strict')]) != self.module.params['ip']:
|
||||
unpack_ip(response_obj[to_bytes('ip-address', errors='surrogate_or_strict')]) != self.module.params['ip']:
|
||||
fields_to_update['ip-address'] = pack_ip(self.module.params['ip'])
|
||||
|
||||
# Name cannot be changed
|
||||
|
||||
@@ -102,32 +102,32 @@ from ansible.module_utils._text import to_text
|
||||
|
||||
class DefineOid(object):
|
||||
|
||||
def __init__(self,dotprefix=False):
|
||||
def __init__(self, dotprefix=False):
|
||||
if dotprefix:
|
||||
dp = "."
|
||||
else:
|
||||
dp = ""
|
||||
|
||||
# From SNMPv2-MIB
|
||||
self.sysDescr = dp + "1.3.6.1.2.1.1.1.0"
|
||||
self.sysDescr = dp + "1.3.6.1.2.1.1.1.0"
|
||||
self.sysObjectId = dp + "1.3.6.1.2.1.1.2.0"
|
||||
self.sysUpTime = dp + "1.3.6.1.2.1.1.3.0"
|
||||
self.sysContact = dp + "1.3.6.1.2.1.1.4.0"
|
||||
self.sysName = dp + "1.3.6.1.2.1.1.5.0"
|
||||
self.sysUpTime = dp + "1.3.6.1.2.1.1.3.0"
|
||||
self.sysContact = dp + "1.3.6.1.2.1.1.4.0"
|
||||
self.sysName = dp + "1.3.6.1.2.1.1.5.0"
|
||||
self.sysLocation = dp + "1.3.6.1.2.1.1.6.0"
|
||||
|
||||
# From IF-MIB
|
||||
self.ifIndex = dp + "1.3.6.1.2.1.2.2.1.1"
|
||||
self.ifDescr = dp + "1.3.6.1.2.1.2.2.1.2"
|
||||
self.ifMtu = dp + "1.3.6.1.2.1.2.2.1.4"
|
||||
self.ifSpeed = dp + "1.3.6.1.2.1.2.2.1.5"
|
||||
self.ifIndex = dp + "1.3.6.1.2.1.2.2.1.1"
|
||||
self.ifDescr = dp + "1.3.6.1.2.1.2.2.1.2"
|
||||
self.ifMtu = dp + "1.3.6.1.2.1.2.2.1.4"
|
||||
self.ifSpeed = dp + "1.3.6.1.2.1.2.2.1.5"
|
||||
self.ifPhysAddress = dp + "1.3.6.1.2.1.2.2.1.6"
|
||||
self.ifAdminStatus = dp + "1.3.6.1.2.1.2.2.1.7"
|
||||
self.ifOperStatus = dp + "1.3.6.1.2.1.2.2.1.8"
|
||||
self.ifAlias = dp + "1.3.6.1.2.1.31.1.1.1.18"
|
||||
self.ifOperStatus = dp + "1.3.6.1.2.1.2.2.1.8"
|
||||
self.ifAlias = dp + "1.3.6.1.2.1.31.1.1.1.18"
|
||||
|
||||
# From IP-MIB
|
||||
self.ipAdEntAddr = dp + "1.3.6.1.2.1.4.20.1.1"
|
||||
self.ipAdEntAddr = dp + "1.3.6.1.2.1.4.20.1.1"
|
||||
self.ipAdEntIfIndex = dp + "1.3.6.1.2.1.4.20.1.2"
|
||||
self.ipAdEntNetMask = dp + "1.3.6.1.2.1.4.20.1.3"
|
||||
|
||||
@@ -141,6 +141,7 @@ def decode_hex(hexstring):
|
||||
else:
|
||||
return hexstring
|
||||
|
||||
|
||||
def decode_mac(hexstring):
|
||||
|
||||
if len(hexstring) != 14:
|
||||
@@ -150,17 +151,19 @@ def decode_mac(hexstring):
|
||||
else:
|
||||
return hexstring
|
||||
|
||||
|
||||
def lookup_adminstatus(int_adminstatus):
|
||||
adminstatus_options = {
|
||||
1: 'up',
|
||||
2: 'down',
|
||||
3: 'testing'
|
||||
}
|
||||
}
|
||||
if int_adminstatus in adminstatus_options:
|
||||
return adminstatus_options[int_adminstatus]
|
||||
else:
|
||||
return ""
|
||||
|
||||
|
||||
def lookup_operstatus(int_operstatus):
|
||||
operstatus_options = {
|
||||
1: 'up',
|
||||
@@ -170,12 +173,13 @@ def lookup_operstatus(int_operstatus):
|
||||
5: 'dormant',
|
||||
6: 'notPresent',
|
||||
7: 'lowerLayerDown'
|
||||
}
|
||||
}
|
||||
if int_operstatus in operstatus_options:
|
||||
return operstatus_options[int_operstatus]
|
||||
else:
|
||||
return ""
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
@@ -189,7 +193,7 @@ def main():
|
||||
authkey=dict(required=False),
|
||||
privkey=dict(required=False),
|
||||
removeplaceholder=dict(required=False)),
|
||||
required_together = ( ['username','level','integrity','authkey'],['privacy','privkey'],),
|
||||
required_together=(['username', 'level', 'integrity', 'authkey'], ['privacy', 'privkey'],),
|
||||
supports_check_mode=False)
|
||||
|
||||
m_args = module.params
|
||||
@@ -211,7 +215,6 @@ def main():
|
||||
if m_args['level'] == "authPriv" and m_args['privacy'] is None:
|
||||
module.fail_json(msg='Privacy algorithm not set when using authPriv')
|
||||
|
||||
|
||||
if m_args['integrity'] == "sha":
|
||||
integrity_proto = cmdgen.usmHMACSHAAuthProtocol
|
||||
elif m_args['integrity'] == "md5":
|
||||
@@ -240,7 +243,7 @@ def main():
|
||||
# Use v without a prefix to use with return values
|
||||
v = DefineOid(dotprefix=False)
|
||||
|
||||
Tree = lambda: defaultdict(Tree)
|
||||
def Tree(): return defaultdict(Tree)
|
||||
|
||||
results = Tree()
|
||||
|
||||
@@ -256,7 +259,6 @@ def main():
|
||||
lookupMib=False
|
||||
)
|
||||
|
||||
|
||||
if errorIndication:
|
||||
module.fail_json(msg=str(errorIndication))
|
||||
|
||||
@@ -294,7 +296,6 @@ def main():
|
||||
lookupMib=False
|
||||
)
|
||||
|
||||
|
||||
if errorIndication:
|
||||
module.fail_json(msg=str(errorIndication))
|
||||
|
||||
@@ -351,9 +352,9 @@ def main():
|
||||
for ipv4_network in ipv4_networks:
|
||||
current_interface = ipv4_networks[ipv4_network]['interface']
|
||||
current_network = {
|
||||
'address': ipv4_networks[ipv4_network]['address'],
|
||||
'netmask': ipv4_networks[ipv4_network]['netmask']
|
||||
}
|
||||
'address': ipv4_networks[ipv4_network]['address'],
|
||||
'netmask': ipv4_networks[ipv4_network]['netmask']
|
||||
}
|
||||
if not current_interface in interface_to_ipv4:
|
||||
interface_to_ipv4[current_interface] = []
|
||||
interface_to_ipv4[current_interface].append(current_network)
|
||||
|
||||
Reference in New Issue
Block a user