Skip to content

Commit

Permalink
Merge pull request #55 from jihyungSong/master
Browse files Browse the repository at this point in the history
Modify filter for describe vpc peering connection
  • Loading branch information
jihyungSong authored Aug 7, 2023
2 parents 98f3e8e + 7b93ae4 commit 4706c54
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
from spaceone.inventory.libs.common_parser import *
from spaceone.inventory.libs.schema.dynamic_widget import ChartWidget, CardWidget
from spaceone.inventory.libs.schema.dynamic_field import TextDyField, DateTimeDyField, EnumDyField, \
BadgeDyField, SearchField, ListDyField
from spaceone.inventory.libs.schema.dynamic_field import TextDyField, DateTimeDyField, EnumDyField, SearchField, ListDyField
from spaceone.inventory.libs.schema.resource import CloudServiceTypeResource, CloudServiceTypeResponse, CloudServiceTypeMeta
from spaceone.inventory.conf.cloud_service_conf import *

Expand Down
22 changes: 16 additions & 6 deletions src/spaceone/inventory/connector/aws_vpc_connector/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,27 @@ def describe_vpc_attribute(self, vpc_id, attribute):
def request_peering_connection_data(self, region_name):
self.cloud_service_type = 'PeeringConnection'
cloudtrail_resource_type = 'AWS::EC2::VPCPeeringConnection'
vpc_peering_connections = []

response = {}
if self.include_default:
response = self.client.describe_vpc_peering_connections()
vpc_peering_connections = response.get('VpcPeeringConnections', [])
elif len(self.vpc_ids) > 0:
_filters = [{'Name': 'accepter-vpc-info.vpc-id', 'Values': self.vpc_ids},
{'Name': 'requester-vpc-info.vpc-id', 'Values': self.vpc_ids}]
response = self.client.describe_vpc_peering_connections(Filters=_filters)
accepter_response = self.client.describe_vpc_peering_connections(
Filters=[{'Name': 'accepter-vpc-info.vpc-id', 'Values': self.vpc_ids}])

vpc_peering_connections = accepter_response.get('VpcPeeringConnections', [])
peerx_ids = [_peerx.get('VpcPeeringConnectionId') for _peerx in
accepter_response.get('VpcPeeringConnections', []) ]

requester_response = self.client.describe_vpc_peering_connections(
Filters=[{'Name': 'requester-vpc-info.vpc-id', 'Values': self.vpc_ids}])

for peerx in response.get('VpcPeeringConnections', []):
for _peerx in requester_response.get('VpcPeeringConnections', []):
if _peerx.get('VpcPeeringConnectionId') not in peerx_ids:
vpc_peering_connections.append(_peerx)

for peerx in vpc_peering_connections:
try:
peerx.update({
'arn': self.generate_arn(service=self.service_name, region=region_name, account_id=self.account_id,
Expand Down Expand Up @@ -682,7 +693,6 @@ def request_vpn_connection_data(self, region_name):
cloudtrail_resource_type = 'AWS::EC2::VPNConnection'

response = self.client.describe_vpn_connections()

for vpn_connection in response.get('VpnConnections', []):
try:
vpn_connection.update({
Expand Down

0 comments on commit 4706c54

Please sign in to comment.