mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-05 03:37:01 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -18,9 +18,9 @@ import urllib.error as urllib_error
|
|||
|
||||
|
||||
class Response:
|
||||
'''
|
||||
"""
|
||||
Create a response object to mimic that of requests.
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.content = None
|
||||
|
|
@ -32,12 +32,12 @@ class Response:
|
|||
|
||||
|
||||
def memset_api_call(api_key, api_method, payload=None):
|
||||
'''
|
||||
"""
|
||||
Generic function which returns results back to calling function.
|
||||
|
||||
Requires an API key and an API method to assemble the API URL.
|
||||
Returns response text to be analysed.
|
||||
'''
|
||||
"""
|
||||
# instantiate a response object
|
||||
response = Response()
|
||||
|
||||
|
|
@ -53,13 +53,13 @@ def memset_api_call(api_key, api_method, payload=None):
|
|||
msg = None
|
||||
|
||||
data = urlencode(payload)
|
||||
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
|
||||
api_uri_base = 'https://api.memset.com/v1/json/'
|
||||
api_uri = f'{api_uri_base}{api_method}/'
|
||||
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
||||
api_uri_base = "https://api.memset.com/v1/json/"
|
||||
api_uri = f"{api_uri_base}{api_method}/"
|
||||
|
||||
try:
|
||||
resp = open_url(api_uri, data=data, headers=headers, method="POST", force_basic_auth=True, url_username=api_key)
|
||||
response.content = resp.read().decode('utf-8')
|
||||
response.content = resp.read().decode("utf-8")
|
||||
response.status_code = resp.getcode()
|
||||
except urllib_error.HTTPError as e:
|
||||
try:
|
||||
|
|
@ -68,7 +68,7 @@ def memset_api_call(api_key, api_method, payload=None):
|
|||
errorcode = None
|
||||
|
||||
has_failed = True
|
||||
response.content = e.read().decode('utf8')
|
||||
response.content = e.read().decode("utf8")
|
||||
response.status_code = errorcode
|
||||
|
||||
if response.status_code is not None:
|
||||
|
|
@ -87,29 +87,29 @@ def memset_api_call(api_key, api_method, payload=None):
|
|||
|
||||
|
||||
def check_zone_domain(data, domain):
|
||||
'''
|
||||
"""
|
||||
Returns true if domain already exists, and false if not.
|
||||
'''
|
||||
"""
|
||||
exists = False
|
||||
|
||||
if data.status_code in [201, 200]:
|
||||
for zone_domain in data.json():
|
||||
if zone_domain['domain'] == domain:
|
||||
if zone_domain["domain"] == domain:
|
||||
exists = True
|
||||
|
||||
return exists
|
||||
|
||||
|
||||
def check_zone(data, name):
|
||||
'''
|
||||
"""
|
||||
Returns true if zone already exists, and false if not.
|
||||
'''
|
||||
"""
|
||||
counter = 0
|
||||
exists = False
|
||||
|
||||
if data.status_code in [201, 200]:
|
||||
for zone in data.json():
|
||||
if zone['nickname'] == name:
|
||||
if zone["nickname"] == name:
|
||||
counter += 1
|
||||
if counter == 1:
|
||||
exists = True
|
||||
|
|
@ -118,26 +118,26 @@ def check_zone(data, name):
|
|||
|
||||
|
||||
def get_zone_id(zone_name, current_zones):
|
||||
'''
|
||||
"""
|
||||
Returns the zone's id if it exists and is unique
|
||||
'''
|
||||
"""
|
||||
zone_exists = False
|
||||
zone_id, msg = None, None
|
||||
zone_list = []
|
||||
|
||||
for zone in current_zones:
|
||||
if zone['nickname'] == zone_name:
|
||||
zone_list.append(zone['id'])
|
||||
if zone["nickname"] == zone_name:
|
||||
zone_list.append(zone["id"])
|
||||
|
||||
counter = len(zone_list)
|
||||
|
||||
if counter == 0:
|
||||
msg = 'No matching zone found'
|
||||
msg = "No matching zone found"
|
||||
elif counter == 1:
|
||||
zone_id = zone_list[0]
|
||||
zone_exists = True
|
||||
elif counter > 1:
|
||||
zone_id = None
|
||||
msg = 'Zone ID could not be returned as duplicate zone names were detected'
|
||||
msg = "Zone ID could not be returned as duplicate zone names were detected"
|
||||
|
||||
return zone_exists, msg, counter, zone_id
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue