Merge pull request #44938 from The-Loeki/libcloud_dns_fixes

Libcloud dns fixes
This commit is contained in:
Nicole Thomas 2017-12-18 10:47:18 -05:00 committed by GitHub
commit d9a4b9681e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 13 deletions

View File

@ -70,7 +70,7 @@ def __init__(opts):
def _get_driver(profile): def _get_driver(profile):
config = __salt__['config.option']('libcloud_dns')[profile] config = __salt__['config.option']('libcloud_dns')[profile]
cls = get_driver(config['driver']) cls = get_driver(config['driver'])
args = config args = config.copy()
del args['driver'] del args['driver']
args['key'] = config.get('key') args['key'] = config.get('key')
args['secret'] = config.get('secret', None) args['secret'] = config.get('secret', None)

View File

@ -59,8 +59,13 @@ def __init__(opts):
salt.utils.compat.pack_dunder(__name__) salt.utils.compat.pack_dunder(__name__)
def state_result(result, message): def state_result(name, result, message):
return {'result': result, 'comment': message} return {
'name': name,
'result': result,
'changes': {},
'comment': message
}
def zone_present(domain, type, profile): def zone_present(domain, type, profile):
@ -81,10 +86,10 @@ def zone_present(domain, type, profile):
type = 'master' type = 'master'
matching_zone = [z for z in zones if z.domain == domain] matching_zone = [z for z in zones if z.domain == domain]
if len(matching_zone) > 0: if len(matching_zone) > 0:
return state_result(True, "Zone already exists") return state_result(domain, True, 'Zone already exists')
else: else:
result = __salt__['libcloud_dns.create_zone'](domain, profile, type) 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): def zone_absent(domain, profile):
@ -100,10 +105,10 @@ def zone_absent(domain, profile):
zones = __salt__['libcloud_dns.list_zones'](profile) zones = __salt__['libcloud_dns.list_zones'](profile)
matching_zone = [z for z in zones if z.domain == domain] matching_zone = [z for z in zones if z.domain == domain]
if len(matching_zone) == 0: if len(matching_zone) == 0:
return state_result(True, "Zone already absent") return state_result(domain, True, 'Zone already absent')
else: else:
result = __salt__['libcloud_dns.delete_zone'](matching_zone[0].id, profile) 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): def record_present(name, zone, type, data, profile):
@ -132,7 +137,7 @@ def record_present(name, zone, type, data, profile):
try: try:
matching_zone = [z for z in zones if z.domain == zone][0] matching_zone = [z for z in zones if z.domain == zone][0]
except IndexError: 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) records = __salt__['libcloud_dns.list_records'](matching_zone.id, profile)
matching_records = [record for record in records matching_records = [record for record in records
if record.name == name and if record.name == name and
@ -142,9 +147,9 @@ def record_present(name, zone, type, data, profile):
result = __salt__['libcloud_dns.create_record']( result = __salt__['libcloud_dns.create_record'](
name, matching_zone.id, name, matching_zone.id,
type, data, profile) type, data, profile)
return state_result(result, "Created new record") return state_result(name, result, 'Created new record')
else: else:
return state_result(True, "Record already exists") return state_result(name, True, 'Record already exists')
def record_absent(name, zone, type, data, profile): def record_absent(name, zone, type, data, profile):
@ -173,7 +178,7 @@ def record_absent(name, zone, type, data, profile):
try: try:
matching_zone = [z for z in zones if z.domain == zone][0] matching_zone = [z for z in zones if z.domain == zone][0]
except IndexError: 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) records = __salt__['libcloud_dns.list_records'](matching_zone.id, profile)
matching_records = [record for record in records matching_records = [record for record in records
if record.name == name and if record.name == name and
@ -186,6 +191,6 @@ def record_absent(name, zone, type, data, profile):
matching_zone.id, matching_zone.id,
record.id, record.id,
profile)) 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: else:
return state_result(True, "Records already absent") return state_result(name, True, 'Records already absent')