def get_attachment_id(self, remote_tgw_and_tgw_attach_id_map):
     # get attachment id for attachment deletion workflow
     if self.peer_tgw_id == 'None':
         # build list of tgw id peering in the same region
         same_region_tag = "%s%s%s" % (environ.get('TGW_PEERING_TAG_PREFIX'),
                                       get_delimiter(environ.get(
                                           'TGW_PEERING_TAG_DELIMITER')),
                                       self.event.get('PeerRegion'))
         tags = self.tag_details.get('tags')
         self.logger.info(f"Same Region Tag: {same_region_tag}")
         self.logger.info(f"Tags in Event: {tags}")
         tgw_in_tags = [value for key, value in tags.items() if
                        key.startswith(same_region_tag)]
         self.logger.info(f"Peer Tgw IDs in the Tag: {tgw_in_tags}")
         # remove tgw and attachment map for existing tags
         for tgw in tgw_in_tags:
             remote_tgw_and_tgw_attach_id_map.pop(tgw, None)
         self.logger.info(
             f"TGW ID:TGW Attach ID Reduced Map: "
             f"{remote_tgw_and_tgw_attach_id_map}")
         # After popping all the keys, we will always be left with just one
         # key
         final_attachment_id = list(
             remote_tgw_and_tgw_attach_id_map.values())[0]
     else:  # get attachment id for attachment creation workflow
         final_attachment_id = remote_tgw_and_tgw_attach_id_map.get(
             self.peer_tgw_id)
     return final_attachment_id
 def _get_peer_region(self) -> str:
     """
     parse changed tag key to get the peer region name
     :return: parsed value of peer region from the peering tag
     """
     peer_region = self.peering_tag.split(get_delimiter(environ.get(
         'TGW_PEERING_TAG_DELIMITER')))[1]
     stripped_peer_region = self.strip_white_spaces(peer_region)
     return stripped_peer_region
Example #3
0
def test_pipe_delimiter_type():
    peer_region = 'us-east-1'
    tag = 'PeerTgw|us-east-1|3'
    region = tag.split(get_delimiter('Pipe (|)'))[1]
    assert region == peer_region
Example #4
0
def test_underscore_delimiter_type():
    peer_region = 'us-east-1'
    tag = 'PeerTgw_us-east-1_2'
    region = tag.split(get_delimiter('Underscore (_)'))[1]
    assert region == peer_region
Example #5
0
def test_dot_delimiter_type():
    peer_region = 'us-east-1'
    tag = 'PeerTgw.us-east-1.1'
    region = tag.split(get_delimiter('Dot (.)'))[1]
    assert region == peer_region
Example #6
0
def test_colon_delimiter_type():
    peer_region = 'us-east-1'
    tag = 'PeerTgw:us-east-1'
    region = tag.split(get_delimiter('Colon (:)'))[1]
    assert region == peer_region