mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Merge pull request #44938 from The-Loeki/libcloud_dns_fixes
Libcloud dns fixes
This commit is contained in:
commit
d9a4b9681e
@ -70,7 +70,7 @@ def __init__(opts):
|
||||
def _get_driver(profile):
|
||||
config = __salt__['config.option']('libcloud_dns')[profile]
|
||||
cls = get_driver(config['driver'])
|
||||
args = config
|
||||
args = config.copy()
|
||||
del args['driver']
|
||||
args['key'] = config.get('key')
|
||||
args['secret'] = config.get('secret', None)
|
||||
|
@ -59,8 +59,13 @@ def __init__(opts):
|
||||
salt.utils.compat.pack_dunder(__name__)
|
||||
|
||||
|
||||
def state_result(result, message):
|
||||
return {'result': result, 'comment': message}
|
||||
def state_result(name, result, message):
|
||||
return {
|
||||
'name': name,
|
||||
'result': result,
|
||||
'changes': {},
|
||||
'comment': message
|
||||
}
|
||||
|
||||
|
||||
def zone_present(domain, type, profile):
|
||||
@ -81,10 +86,10 @@ def zone_present(domain, type, profile):
|
||||
type = 'master'
|
||||
matching_zone = [z for z in zones if z.domain == domain]
|
||||
if len(matching_zone) > 0:
|
||||
return state_result(True, "Zone already exists")
|
||||
return state_result(domain, True, 'Zone already exists')
|
||||
else:
|
||||
result = __salt__['libcloud_dns.create_zone'](domain, profile, type)
|
||||
return state_result(result, "Created new zone")
|
||||
return state_result(domain, result, 'Created new zone')
|
||||
|
||||
|
||||
def zone_absent(domain, profile):
|
||||
@ -100,10 +105,10 @@ def zone_absent(domain, profile):
|
||||
zones = __salt__['libcloud_dns.list_zones'](profile)
|
||||
matching_zone = [z for z in zones if z.domain == domain]
|
||||
if len(matching_zone) == 0:
|
||||
return state_result(True, "Zone already absent")
|
||||
return state_result(domain, True, 'Zone already absent')
|
||||
else:
|
||||
result = __salt__['libcloud_dns.delete_zone'](matching_zone[0].id, profile)
|
||||
return state_result(result, "Deleted zone")
|
||||
return state_result(domain, result, 'Deleted zone')
|
||||
|
||||
|
||||
def record_present(name, zone, type, data, profile):
|
||||
@ -132,7 +137,7 @@ def record_present(name, zone, type, data, profile):
|
||||
try:
|
||||
matching_zone = [z for z in zones if z.domain == zone][0]
|
||||
except IndexError:
|
||||
return state_result(False, "Could not locate zone")
|
||||
return state_result(zone, False, 'Could not locate zone')
|
||||
records = __salt__['libcloud_dns.list_records'](matching_zone.id, profile)
|
||||
matching_records = [record for record in records
|
||||
if record.name == name and
|
||||
@ -142,9 +147,9 @@ def record_present(name, zone, type, data, profile):
|
||||
result = __salt__['libcloud_dns.create_record'](
|
||||
name, matching_zone.id,
|
||||
type, data, profile)
|
||||
return state_result(result, "Created new record")
|
||||
return state_result(name, result, 'Created new record')
|
||||
else:
|
||||
return state_result(True, "Record already exists")
|
||||
return state_result(name, True, 'Record already exists')
|
||||
|
||||
|
||||
def record_absent(name, zone, type, data, profile):
|
||||
@ -173,7 +178,7 @@ def record_absent(name, zone, type, data, profile):
|
||||
try:
|
||||
matching_zone = [z for z in zones if z.domain == zone][0]
|
||||
except IndexError:
|
||||
return state_result(False, "Zone could not be found")
|
||||
return state_result(zone, False, 'Zone could not be found')
|
||||
records = __salt__['libcloud_dns.list_records'](matching_zone.id, profile)
|
||||
matching_records = [record for record in records
|
||||
if record.name == name and
|
||||
@ -186,6 +191,6 @@ def record_absent(name, zone, type, data, profile):
|
||||
matching_zone.id,
|
||||
record.id,
|
||||
profile))
|
||||
return state_result(all(result), "Removed {0} records".format(len(result)))
|
||||
return state_result(name, all(result), 'Removed {0} records'.format(len(result)))
|
||||
else:
|
||||
return state_result(True, "Records already absent")
|
||||
return state_result(name, True, 'Records already absent')
|
||||
|
Loading…
Reference in New Issue
Block a user