in source/state_machine_handler.py [0:0]
def _describe_vpc(self):
try:
self.logger.info("Executing: " + self.__class__.__name__ + "/" + inspect.stack()[0][3])
ec2 = self._session(self.spoke_region, self.spoke_account_id)
# describe the vpc in the spoke account
response = ec2.describe_vpcs(self.event.get('VpcId'))
self._print('Describe VPC', response)
# the response should return a list with single item
self._check_list_length(response, 1)
# update event with subnet details
index = 0
vpc = response[index]
# Cidr block associated with this VPC
self.event.update({'VpcCidr': vpc.get('CidrBlock')})
# Assuming VPC is not tagged
self.event.update({'VpcTagFound': 'no'})
tag_key_list = []
if vpc.get('Tags') is not None:
for tag in vpc.get('Tags'):
tag_key_list.append(tag.get('Key').lower().strip())
self._print('list of tag keys', tag_key_list)
else:
self.logger.info("No tags found for the VPC associated with the tagged Subnet.")
if tag_key_list is not None:
# check if tags exist for the VPC
if environ.get('ASSOCIATION_TAG').lower().strip() in tag_key_list or \
environ.get('PROPAGATION_TAG').lower().strip() in tag_key_list:
self.logger.info('Found association or propagation tag for the VPC: {}'.format(self.event.get('VpcId')))
self.event.update({'VpcTagFound': 'yes'})
# event source is subnet tag change, then obtain the Tag Event Sources from VPC tags
if self.event.get('TagEventSource') == 'subnet':
self._update_event_with_vpc_tags(vpc.get('Tags'))
else:
self._update_event_with_vpc_tags(self.event.get('detail', {}).get('tags'))
return self.event
except Exception as e:
message = self._message(inspect.stack()[0][3], e)
self.logger.exception(message)
self._update_ddb_failed(e)
raise