mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Patch around ResourceRecords needing to be present for AliasTarget entries to work
This commit is contained in:
parent
d20ff89414
commit
ebb244396b
@ -595,54 +595,55 @@ def rr_present(name, HostedZoneId=None, DomainName=None, PrivateZone=False, Name
|
||||
|
||||
# Convert any magic RR values to something AWS will understand, and otherwise clean them up.
|
||||
fixed_rrs = []
|
||||
for rr in ResourceRecords:
|
||||
if rr.startswith('magic:'):
|
||||
fields = rr.split(':')
|
||||
if fields[1] == 'ec2_instance_tag':
|
||||
if len(fields) != 5:
|
||||
log.warning("Invalid magic RR value seen: '{}'. Passing as-is.".format(rr))
|
||||
fixed_rrs += [rr]
|
||||
continue
|
||||
tag_name = fields[2]
|
||||
tag_value = fields[3]
|
||||
instance_attr = fields[4]
|
||||
good_states = ('pending', 'rebooting', 'running', 'stopping', 'stopped')
|
||||
r = __salt__['boto_ec2.find_instances'](
|
||||
tags={tag_name: tag_value}, return_objs=True, in_states=good_states,
|
||||
region=region, key=key, keyid=keyid, profile=profile)
|
||||
if len(r) < 1:
|
||||
ret['comment'] = 'No EC2 instance with tag {} == {} found'.format(tag_name,
|
||||
tag_value)
|
||||
log.error(ret['comment'])
|
||||
ret['result'] = False
|
||||
return ret
|
||||
if len(r) > 1:
|
||||
ret['comment'] = 'Multiple EC2 instances with tag {} == {} found'.format(
|
||||
tag_name, tag_value)
|
||||
log.error(ret['comment'])
|
||||
ret['result'] = False
|
||||
return ret
|
||||
instance = r[0]
|
||||
res = getattr(instance, instance_attr, None)
|
||||
if res:
|
||||
log.debug('Found {} {} for instance {}'.format(instance_attr, res, instance.id))
|
||||
fixed_rrs += [_to_aws_encoding(res)]
|
||||
if ResourceRecords:
|
||||
for rr in ResourceRecords:
|
||||
if rr.startswith('magic:'):
|
||||
fields = rr.split(':')
|
||||
if fields[1] == 'ec2_instance_tag':
|
||||
if len(fields) != 5:
|
||||
log.warning("Invalid magic RR value seen: '{}'. Passing as-is.".format(rr))
|
||||
fixed_rrs += [rr]
|
||||
continue
|
||||
tag_name = fields[2]
|
||||
tag_value = fields[3]
|
||||
instance_attr = fields[4]
|
||||
good_states = ('pending', 'rebooting', 'running', 'stopping', 'stopped')
|
||||
r = __salt__['boto_ec2.find_instances'](
|
||||
tags={tag_name: tag_value}, return_objs=True, in_states=good_states,
|
||||
region=region, key=key, keyid=keyid, profile=profile)
|
||||
if len(r) < 1:
|
||||
ret['comment'] = 'No EC2 instance with tag {} == {} found'.format(tag_name,
|
||||
tag_value)
|
||||
log.error(ret['comment'])
|
||||
ret['result'] = False
|
||||
return ret
|
||||
if len(r) > 1:
|
||||
ret['comment'] = 'Multiple EC2 instances with tag {} == {} found'.format(
|
||||
tag_name, tag_value)
|
||||
log.error(ret['comment'])
|
||||
ret['result'] = False
|
||||
return ret
|
||||
instance = r[0]
|
||||
res = getattr(instance, instance_attr, None)
|
||||
if res:
|
||||
log.debug('Found {} {} for instance {}'.format(instance_attr, res, instance.id))
|
||||
fixed_rrs += [_to_aws_encoding(res)]
|
||||
else:
|
||||
ret['comment'] = 'Attribute {} not found on instance {}'.format(instance_attr,
|
||||
instance.id)
|
||||
log.error(ret['comment'])
|
||||
ret['result'] = False
|
||||
return ret
|
||||
else:
|
||||
ret['comment'] = 'Attribute {} not found on instance {}'.format(instance_attr,
|
||||
instance.id)
|
||||
ret['comment'] = ('Unknown RR magic value seen: {}. Please extend the '
|
||||
'boto3_route53 state module to add support for your preferred '
|
||||
'incantation.'.format(fields[1]))
|
||||
log.error(ret['comment'])
|
||||
ret['result'] = False
|
||||
return ret
|
||||
else:
|
||||
ret['comment'] = ('Unknown RR magic value seen: {}. Please extend the '
|
||||
'boto3_route53 state module to add support for your preferred '
|
||||
'incantation.'.format(fields[1]))
|
||||
log.error(ret['comment'])
|
||||
ret['result'] = False
|
||||
return ret
|
||||
else:
|
||||
fixed_rrs += [rr]
|
||||
ResourceRecords = [{'Value': rr} for rr in sorted(fixed_rrs)]
|
||||
fixed_rrs += [rr]
|
||||
ResourceRecords = [{'Value': rr} for rr in sorted(fixed_rrs)]
|
||||
|
||||
recordsets = __salt__['boto3_route53.get_resource_records'](HostedZoneId=HostedZoneId,
|
||||
StartRecordName=Name, StartRecordType=Type, region=region, key=key, keyid=keyid,
|
||||
@ -691,9 +692,10 @@ def rr_present(name, HostedZoneId=None, DomainName=None, PrivateZone=False, Name
|
||||
return ret
|
||||
ResourceRecordSet = {
|
||||
'Name': Name,
|
||||
'Type': Type,
|
||||
'ResourceRecords': ResourceRecords
|
||||
'Type': Type
|
||||
}
|
||||
if ResourceRecords:
|
||||
ResourceRecordSet['ResourceRecords'] = ResourceRecords
|
||||
for u in updatable:
|
||||
ResourceRecordSet.update({u: locals().get(u)}) if locals().get(u) else None
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user