博客园  :: 首页  :: 管理

关于AWS-SDK-for-Python-路由表条目信息的收集

Posted on 2024-01-31 09:46  520_1351  阅读(11)  评论(0编辑  收藏  举报

对于aws路由表,至少都会有一个路由条目,即VPC段的local路由,如下

192.168.115.0/24 local Active No

这样,在获取路由表及条目时,我们可以根据Routes键获得的所有的路由表条目,多个字典组成

笔者工作环境常用到的路由表条目的键值,如下

['DestinationCidrBlock', 'GatewayId', 'Origin', 'State']
['DestinationCidrBlock', 'InstanceId', 'InstanceOwnerId', 'NetworkInterfaceId', 'Origin', 'State']
['DestinationCidrBlock', 'NatGatewayId', 'Origin', 'State']
['DestinationCidrBlock', 'NetworkInterfaceId', 'Origin', 'State']
['DestinationCidrBlock', 'Origin', 'State', 'VpcPeeringConnectionId']
['DestinationPrefixListId', 'GatewayId', 'Origin', 'State']

为了生成路由表条目CMDB数据,获得全部的路由表条目,可以for循环Routes,将每条路由表ID及其他信息,追加到一个数据列表之中

当然也还有一些其他键值,可以通过官网得到如下完整的键值

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2/client/describe_route_tables.html

  • Routes (list) –

    The routes in the route table.

    • (dict) –

      Describes a route in a route table.

      • DestinationCidrBlock (string) –

        The IPv4 CIDR block used for the destination match.

      • DestinationIpv6CidrBlock (string) –

        The IPv6 CIDR block used for the destination match.

      • DestinationPrefixListId (string) –

        The prefix of the Amazon Web Service.

      • EgressOnlyInternetGatewayId (string) –

        The ID of the egress-only internet gateway.

      • GatewayId (string) –

        The ID of a gateway attached to your VPC.

      • InstanceId (string) –

        The ID of a NAT instance in your VPC.

      • InstanceOwnerId (string) –

        The ID of Amazon Web Services account that owns the instance.

      • NatGatewayId (string) –

        The ID of a NAT gateway.

      • TransitGatewayId (string) –

        The ID of a transit gateway.

      • LocalGatewayId (string) –

        The ID of the local gateway.

      • CarrierGatewayId (string) –

        The ID of the carrier gateway.

      • NetworkInterfaceId (string) –

        The ID of the network interface.

      • Origin (string) –

        Describes how the route was created.

        • CreateRouteTable - The route was automatically created when the route table was created.

        • CreateRoute - The route was manually added to the route table.

        • EnableVgwRoutePropagation - The route was propagated by route propagation.

      • State (string) –

        The state of the route. The blackhole state indicates that the route’s target isn’t available (for example, the specified gateway isn’t attached to the VPC, or the specified NAT instance has been terminated).

      • VpcPeeringConnectionId (string) –

        The ID of a VPC peering connection.

      • CoreNetworkArn (string) –

        The Amazon Resource Name (ARN) of the core network.

 

 

 

尊重别人的劳动成果 转载请务必注明出处:https://www.cnblogs.com/5201351/p/17998588