class DescribeVpcPeeringConnections(EC2Request): DESCRIPTION = 'Show information about VPC peering connections' ARGS = [Arg('VpcPeeringConnectionId', metavar='PEERCONN', nargs='*', help='limit results to specific VPC peering connections')] FILTERS = [Filter('accepter-vpc-info.cidr-block', help="the peer VPC's CIDR address block"), Filter('accepter-vpc-info.owner-id', help="the peer VPC's owner's account ID"), Filter('accepter-vpc-info.vpc-id', help="the peer VPC's ID"), Filter('expiration-time', help='when the peering connection request expires'), Filter('requester-vpc-info.cidr-block', help="the requester VPC's CIDR address block"), Filter('requester-vpc-info.owner-id', help="the requester VPC's owner's account ID"), Filter('requester-vpc-info.vpc-id', help="the requester VPC's ID"), Filter('status-code', help='''the peering connection's status (active, deleted, expired, failed, pending-acceptance, provisioning, rejected)'''), Filter('tag-key', help='key of a tag assigned to the peering connection'), Filter('tag-value', help='value of a tag assigned to the peering connection'), GenericTagFilter('tag:KEY', help='specific tag key/value combination'), Filter('vpc-peering-connection-id', help="the peering connection's ID")] LIST_TAGS = ['tagSet', 'vpcPeeringConnectionSet'] def print_result(self, result): for pcx in result.get('vpcPeeringConnectionSet') or []: self.print_peering_connection(pcx)
class DescribeDhcpOptions(EC2Request): DESCRIPTION = 'Show information about VPC DHCP option sets' ARGS = [ Arg('DhcpOptionsId', metavar='DHCPOPTS', nargs='*', help='limit results to specific DHCP option sets') ] FILTERS = [ Filter('dhcp-options-id', help='dhcp option set ID'), Filter('key', help='key for one of the options (e.g. domain-name)'), Filter('tag-key', help='key of a tag assigned to the DHCP option set'), Filter('tag-value', help='value of a tag assigned to the DHCP option set'), GenericTagFilter('tag:KEY', help='specific tag key/value combination'), Filter('value', help='value for one of the options') ] LIST_TAGS = [ 'dhcpConfigurationSet', 'dhcpOptionsSet', 'tagSet', 'valueSet' ] def print_result(self, result): for dopt in result.get('dhcpOptionsSet', []): self.print_dhcp_options(dopt)
class DescribeNatGateways(EC2Request): DESCRIPTION = 'Describe one or more VPC NAT gateways' ARGS = [ Arg('NatGatewayId', metavar='NGATEWAY', nargs='*', help='limit results to one or more NAT gateways') ] FILTERS = [ Filter('nat-gateway-id', "the Nat gateway's ID"), Filter('state', help=' the state of the NAT gateway'), Filter('subnet-id', help='the ID of the subnet in which the ' 'NAT gateway resides'), Filter('vpc-id', help='the ID of the VPC in which the NAT ' 'gateway resides'), GenericTagFilter('tag:KEY', help='specific tag key/value combination') ] LIST_TAGS = ['natGatewayAddressSet', 'natGatewaySet'] def print_result(self, result): for natgw in result.get('natGatewaySet') or []: self.print_nat_gateway(natgw)
class DescribeSubnets(EC2Request): DESCRIPTION = 'Show information about one or more VPC subnets' ARGS = [ Arg('SubnetId', metavar='SUBNET', nargs='*', help='limit results to specific subnets') ] FILTERS = [ Filter('availability-zone'), Filter('available-ip-address-count', help='the number of unused IP addresses in the subnet'), Filter('cidr-block', help="the subnet's CIDR address block"), # Aliases for cidr-block Filter('cidr', help=argparse.SUPPRESS), Filter('cidrBlock', help=argparse.SUPPRESS), Filter('default-for-az', choices=('true', 'false'), help='''whether this is the default subnet for the availability zone'''), Filter('state'), Filter('subnet-id'), Filter('tag-key', help='key of a tag assigned to the subnet'), Filter('tag-value', help='value of a tag assigned to the subnet'), GenericTagFilter('tag:KEY', help='specific tag key/value combination'), Filter('vpc-id', help="the associated VPC's ID") ] LIST_TAGS = ['subnetSet', 'tagSet'] def print_result(self, result): for subnet in result.get('subnetSet') or []: self.print_subnet(subnet)
class DescribeVpnGateways(EC2Request): DESCRIPTION = 'Show information about virtual private gateways' ARGS = [Arg('VpnGatewayId', metavar='VGATEWAY', nargs='*', help='limit results to specific virtual private gateways')] FILTERS = [Filter('attachment.state', help='state of attachment with a VPC'), Filter('attachment.vpc-id', help='''ID of a VPC the virtual private gateway is attached to'''), Filter('availability-zone', help='''availability zone in which the virtual private gateway resides'''), Filter('tag-key', help='key of a tag assigned to the customer gateway'), Filter('tag-value', help='value of a tag assigned to the customer gateway'), GenericTagFilter('tag:KEY', help='specific tag key/value combination'), Filter('type', help='the type of virtual private gateway (ipsec.1)'), Filter('vpn-gateway-id', help='ID of the virtual private gateway')] LIST_TAGS = ['attachments', 'vpnGatewaySet', 'tagSet'] def print_result(self, result): for vgw in result.get('vpnGatewaySet', []): self.print_vpn_gateway(vgw)
class DescribeCustomerGateways(EC2Request): DESCRIPTION = 'Show information about VPN customer gateways' ARGS = [ Arg('CustomerGatewayId', metavar='CGATEWAY', nargs='*', help='limit results to specific customer gateways') ] FILTERS = [ Filter('bgp-asn', help='BGP AS number in use'), Filter('customer-gateway-id', help='customer gateway ID'), Filter('ip-address', help='''ID of the customer gateway's cloud-facing interface'''), Filter('state', help='''customer gateway state (pending, available, deleting, deleted)'''), Filter('tag-key', help='key of a tag assigned to the customer gateway'), Filter('tag-value', help='value of a tag assigned to the customer gateway'), GenericTagFilter('tag:KEY', help='specific tag key/value combination'), Filter('type', help='the type of customer gateway (ipsec.1)') ] LIST_TAGS = ['customerGatewaySet', 'tagSet'] def print_result(self, result): for cgw in result.get('customerGatewaySet', []): self.print_customer_gateway(cgw)
class DescribeVolumes(EC2Request): DESCRIPTION = 'Display information about volumes' ARGS = [Arg('VolumeId', metavar='VOLUME', nargs='*', help='limit results to specific volumes')] FILTERS = [Filter('attachment.attach-time', help='attachment start time'), Filter('attachment.delete-on-termination', help='''whether the volume will be deleted upon instance termination'''), Filter('attachment.device', help='device node exposed to the instance'), Filter('attachment.instance-id', help='ID of the instance the volume is attached to'), Filter('attachment.status', help='attachment state'), Filter('availability-zone'), Filter('create-time', help='creation time'), Filter('size', type=int, help='size in GiB'), Filter('snapshot-id', help='snapshot from which the volume was created'), Filter('status'), Filter('tag-key', help='key of a tag assigned to the volume'), Filter('tag-value', help='value of a tag assigned to the volume'), GenericTagFilter('tag:KEY', help='specific tag key/value combination'), Filter(name='volume-id'), Filter(name='volume-type')] LIST_TAGS = ['volumeSet', 'attachmentSet', 'tagSet'] def print_result(self, result): for volume in result.get('volumeSet'): self.print_volume(volume)
class DescribeInternetGateways(EC2Request): DESCRIPTION = 'Describe one or more VPC Internet gateways' ARGS = [ Arg('InternetGatewayId', metavar='IGATEWAY', nargs='*', help='limit results to one or more Internet gateways') ] FILTERS = [ Filter('attachment.state', help='''if the Internet gateway is attached to a VPC, its attachment state (available)'''), Filter('attachment.vpc-id', help='''ID of the VPC the Internet gateway is attached to'''), Filter('internet-gateway-id', "the Internet gateway's ID"), Filter('tag-key', help='key of a tag assigned to the Internet gateway'), Filter('tag-value', help='value of a tag assigned to the Internet gateway'), GenericTagFilter('tag:KEY', help='specific tag key/value combination') ] LIST_TAGS = ['attachmentSet', 'internetGatewaySet', 'tagSet'] def print_result(self, result): for igw in result.get('internetGatewaySet') or []: self.print_internet_gateway(igw)
class DescribeRouteTables(EC2Request): DESCRIPTION = 'Describe one or more VPC route tables' ARGS = [ Arg('RouteTableId', metavar='RTABLE', nargs='*', help='limit results to specific route tables') ] FILTERS = [ Filter('association.route-table-association-id', help='ID of an association for the route table'), Filter('association.route-table-id', help='ID of a route table involved in an association'), Filter('association.subnet-id', help='ID of a subnet involved in an association'), Filter('association.main', choices=('true', 'false'), help='''whether the route table is the main route table for its VPC'''), Filter('route-table-id'), Filter('route.destination-cidr-block', help='''CIDR address block specified in one of the table's routes'''), Filter('route.gateway-id', help='''ID of a gateway specified by a route in the table'''), Filter('route.instance-id', help='''ID of an instance specified by a route in the table'''), Filter('route.nat-gateway-id', help='''ID of a NAT gateway specified by a route in the table'''), Filter('route.vpc-peering-connection-id', help='''ID of a VPC peering connection specified by a route in the table'''), Filter('route.origin', help='which operation created a route in the table'), Filter('route.state', help='''whether a route in the table has state "active" or "blackhole"'''), Filter('tag-key', help='key of a tag assigned to the route table'), Filter('tag-value', help='value of a tag assigned to the route table'), GenericTagFilter('tag:KEY', help='specific tag key/value combination'), Filter('vpc-id', help="the associated VPC's ID") ] LIST_TAGS = [ 'associationSet', 'propagatingVgwSet', 'routeTableSet', 'routeSet', 'tagSet' ] def print_result(self, result): for table in result.get('routeTableSet') or []: self.print_route_table(table)
class DescribeNetworkAcls(EC2Request): DESCRIPTION = 'Describe one or more network ACLs' ARGS = [Arg('NetworkAclId', metavar='NACL', nargs='*', help='limit results to one or more network ACLs')] FILTERS = [Filter('association.association-id', help='ID of an association ID for a network ACL'), Filter('association.network-acl-id', help='''ID of the network ACL involved in an association'''), Filter('association.subnet-id', help='ID of the subnet involved in an association'), Filter('default', choices=('true', 'false'), help='''whether the network ACL is the default for its VPC'''), Filter('entry.cidr', help='CIDR range for a network ACL entry'), Filter('entry.egress', choices=('true', 'false'), help='whether an entry applies to egress traffic'), Filter('entry.icmp.code', type=int, help='ICMP code for a network ACL entry'), Filter('entry.icmp.type', type=int, help='ICMP type for a network ACL entry'), Filter('entry.port-range.from', type=int, help='start of the port range for a network ACL entry'), Filter('entry.port-range.to', type=int, help='end of the port range for a network ACL entry'), Filter('entry.protocol', help='protocol for a network ACL entry'), Filter('entry.rule-action', choices=('allow', 'deny'), help=''' whether a network ACL entry allows or denies traffic'''), Filter('entry.rule-number', type=int, help='rule number of a network ACL entry'), Filter('network-acl-id'), Filter('tag-key', help='key of a tag assigned to the network ACL'), Filter('tag-value', help='value of a tag assigned to the network ACL'), GenericTagFilter('tag:KEY', help='specific tag key/value combination'), Filter('vpc-id', help="the VPC's ID")] LIST_TAGS = ['associationSet', 'entrySet', 'networkAclSet', 'tagSet'] def print_result(self, result): for acl in result.get('networkAclSet') or []: self.print_network_acl(acl)
class DescribeVpcs(EC2Request): DESCRIPTION = 'Show information about VPCs' ARGS = [ Arg('VpcId', metavar='VPC', nargs='*', help='limit results to specific VPCs') ] FILTERS = [ Filter('cidr', help="the VPC's CIDR address block"), Filter('dhcp-options-id', help='ID of the set of DHCP options'), Filter('isDefault', help='whether the VPC is a default VPC'), Filter('state'), Filter('tag-key', help='key of a tag assigned to the VPC'), Filter('tag-value', help='value of a tag assigned to the VPC'), GenericTagFilter('tag:KEY', help='specific tag key/value combination'), Filter('vpc-id', help="the VPC's ID") ] LIST_TAGS = ['tagSet', 'vpcSet'] def print_result(self, result): for vpc in result.get('vpcSet') or []: self.print_vpc(vpc)
class DescribeInstances(EC2Request): DESCRIPTION = 'Show information about instances' ARGS = [ Arg('InstanceId', metavar='INSTANCE', nargs='*', help='limit results to specific instances') ] FILTERS = [ Filter('architecture', help='CPU architecture'), Filter('association.allocation-id', help='''[VPC only] allocation ID bound to a network interface's elastic IP address'''), Filter('association.association-id', help='''[VPC only] association ID returned when an elastic IP was associated with a network interface'''), Filter('association.ip-owner-id', help='''[VPC only] ID of the owner of the elastic IP address associated with a network interface'''), Filter('association.public-ip', help='''[VPC only] address of the elastic IP address bound to a network interface'''), Filter('availability-zone'), Filter('block-device-mapping.attach-time', help='volume attachment time'), Filter('block-device-mapping.delete-on-termination', type=bool, help='''whether a volume is deleted upon instance termination'''), Filter('block-device-mapping.device-name', help='volume device name (e.g. /dev/sdf)'), Filter('block-device-mapping.status', help='volume status'), Filter('block-device-mapping.volume-id', help='volume ID'), Filter('client-token', help='idempotency token provided at instance run time'), Filter('dns-name', help='public DNS name'), # EC2's documentation for "group-id" refers VPC users to # "instance.group-id", while their documentation for the latter # refers them to the former. Consequently, I'm not going to # document a difference for either. They both seem to work for # non-VPC instances. Filter('group-id', help='security group ID'), Filter('group-name', help='security group name'), Filter('hypervisor', help='hypervisor type'), Filter('image-id', help='machine image ID'), Filter('instance.group-id', help='security group ID'), Filter('instance.group-name', help='security group name'), Filter('instance-id'), Filter('instance-lifecycle', help='whether this is a spot instance'), Filter('instance-state-code', type=int, help='numeric code identifying instance state'), Filter('instance-state-name', help='instance state'), Filter('instance-type'), Filter('ip-address', help='public IP address'), Filter('kernel-id', help='kernel image ID'), Filter('key-name', help='key pair name provided at instance launch time'), Filter('launch-index', help='launch index within a reservation'), Filter('launch-time', help='instance launch time'), Filter('monitoring-state', help='monitoring state ("enabled" or "disabled")'), Filter('network-interface.addresses.association.ip-owner-id', help='''[VPC only] ID of the owner of the private IP address associated with a network interface'''), Filter('network-interface.addresses.association.public-ip', help='''[VPC only] ID of the association of an elastic IP address with a network interface'''), Filter('network-interface.addresses.primary', help='''[VPC only] whether the IP address of the VPC network interface is the primary private IP address ("true" or "false")'''), Filter('network-interface.addresses.private-ip-address', help='''[VPC only] network interface's private IP address'''), Filter('network-interface.attachment.device-index', type=int, help='''[VPC only] device index to which a network interface is attached'''), Filter('network-interface.attachment.attach-time', help='''[VPC only] time a network interface was attached to an instance'''), Filter('network-interface.attachment.attachment-id', help='''[VPC only] ID of a network interface's attachment'''), Filter('network-interface.attachment.delete-on-termination', help='''[VPC only] whether a network interface attachment is deleted when an instance is terminated ("true" or "false")'''), Filter('network-interface.attachment.instance-owner-id', help='''[VPC only] ID of the instance to which a network interface is attached'''), Filter('network-interface.attachment.status', help="[VPC only] network interface's attachment status"), Filter('network-interface.availability-zone', help="[VPC only] network interface's availability zone"), Filter('network-interface.description', help='[VPC only] description of a network interface'), Filter('network-interface.group-id', help="[VPC only] network interface's security group ID"), Filter('network-interface.group-name', help='''[VPC only] network interface's security group name'''), Filter('network-interface.mac-address', help="[VPC only] network interface's hardware address"), Filter('network-interface.network-interface.id', help='[VPC only] ID of a network interface'), Filter('network-interface.owner-id', help="[VPC only] ID of a network interface's owner"), Filter('network-interface.private-dns-name', help="[VPC only] network interface's private DNS name"), Filter('network-interface.requester-id', help="[VPC only] network interface's requester ID"), Filter('network-interface.requester-managed', help='''[VPC only] whether the network interface is managed by the service'''), Filter('network-interface.source-destination-check', help='''[VPC only] whether source/destination checking is enabled for a network interface ("true" or "false")'''), Filter('network-interface.status', help="[VPC only] network interface's status"), Filter('network-interface.subnet-id', help="[VPC only] ID of a network interface's subnet"), Filter('network-interface.vpc-id', help="[VPC only] ID of a network interface's VPC"), Filter('owner-id', help="instance owner's account ID"), Filter('placement-group-name'), Filter('platform', help='"windows" for Windows instances'), Filter('private-dns-name'), Filter('private-ip-address'), Filter('product-code'), Filter('product-code.type', help='type of product code ("devpay" or "marketplace")'), Filter('ramdisk-id', help='ramdisk image ID'), Filter('reason', help="reason for the instance's current state"), Filter('requester-id', help='ID of the entity that launched an instance'), Filter('reservation-id'), Filter('root-device-name', help='root device name (e.g. /dev/sda1)'), Filter('root-device-type', help='root device type ("ebs" or "instance-store")'), Filter('spot-instance-request-id'), Filter('state-reason-code', help='reason code for the most recent state change'), Filter('state-reason-message', help='message describing the most recent state change'), Filter('subnet-id', help='[VPC only] ID of the subnet the instance is in'), Filter('tag-key', help='name of any tag assigned to the instance'), Filter('tag-value', help='value of any tag assigned to the instance'), GenericTagFilter('tag:KEY', help='specific tag key/value combination'), Filter('virtualization-type'), Filter('vpc-id', help='[VPC only] ID of the VPC the instance is in') ] LIST_TAGS = [ 'reservationSet', 'instancesSet', 'groupSet', 'tagSet', 'blockDeviceMapping', 'productCodes', 'networkInterfaceSet', 'privateIpAddressesSet' ] def print_result(self, result): for reservation in result.get('reservationSet'): self.print_reservation(reservation)
class DescribeImages(EucalyptusRequest): DESCRIPTION = ('Show information about images\n\nBy default, only images ' 'your account owns and images for which your account has ' 'explicit launch permissions are shown.') ARGS = [Arg('ImageId', metavar='IMAGE', nargs='*', help='limit results to specific images'), Arg('-a', '--all', action='store_true', route_to=None, help='describe all images'), Arg('-o', '--owner', dest='Owner', metavar='ACCOUNT', action='append', help='describe images owned by the specified owner'), Arg('-x', '--executable-by', dest='ExecutableBy', metavar='ACCOUNT', action='append', help='''describe images for which the specified account has explicit launch permissions''')] FILTERS = [Filter('architecture', choices=('i386', 'x86_64', 'armhf'), help='CPU architecture'), Filter('block-device-mapping.delete-on-termination', help='''whether a volume is deleted upon instance termination'''), Filter('block-device-mapping.device-name', help='device name for a volume mapped to the image'), Filter('block-device-mapping.snapshot-id', help='snapshot ID for a volume mapped to the image'), Filter('block-device-mapping.volume-size', help='volume size for a volume mapped to the image'), Filter('block-device-mapping.volume-type', help='volume type for a volume mapped to the image'), Filter('description', help='image description'), Filter('hypervisor', help='image\'s hypervisor type'), Filter('image-id'), Filter('image-type', choices=('machine', 'kernel', 'ramdisk'), help='image type ("machine", "kernel", or "ramdisk")'), Filter('is-public', help='whether the image is public'), Filter('kernel-id'), Filter('manifest-location'), Filter('name'), Filter('owner-alias', help="image owner's account alias"), Filter('owner-id', help="image owner's account ID"), Filter('platform', help='"windows" for Windows images'), Filter('product-code', help='product code associated with the image'), Filter('product-code.type', choices=('devpay', 'marketplace'), help='type of product code associated with the image'), Filter('ramdisk-id'), Filter('root-device-name'), Filter('root-device-type', choices=('ebs', 'instance-store'), help='root device type ("ebs" or "instance-store")'), Filter('state', choices=('available', 'pending', 'failed'), help='''image state ("available", "pending", or "failed")'''), Filter('state-reason-code', help='reason code for the most recent state change'), Filter('state-reason-message', help='message for the most recent state change'), Filter('tag-key', help='key of a tag assigned to the image'), Filter('tag-value', help='value of a tag assigned to the image'), GenericTagFilter('tag:KEY', help='specific tag key/value combination'), Filter('virtualization-type', choices=('paravirtual', 'hvm'), help='virtualization type ("paravirtual" or "hvm")')] LIST_TAGS = ['imagesSet', 'productCodes', 'blockDeviceMapping', 'tagSet'] # noinspection PyExceptionInherit def configure(self): EucalyptusRequest.configure(self) if self.args.get('all', False): if self.args.get('ImageId'): raise ArgumentError('argument -a/--all: not allowed with ' 'a list of images') if self.args.get('ExecutableBy'): raise ArgumentError('argument -a/--all: not allowed with ' 'argument -x/--executable-by') if self.args.get('Owner'): raise ArgumentError('argument -a/--all: not allowed with ' 'argument -o/--owner') def main(self): if not any(self.args.get(item) for item in ('all', 'ImageId', 'ExecutableBy', 'Owner')): # Default to owned images and images with explicit launch perms self.params['Owner'] = ['self'] owned = self.send() del self.params['Owner'] self.params['ExecutableBy'] = ['self'] executable = self.send() del self.params['ExecutableBy'] owned['imagesSet'] = (owned.get('imagesSet', []) + executable.get('imagesSet', [])) return owned else: return self.send() def print_result(self, result): images = {} for image in result.get('imagesSet', []): images.setdefault(image['imageId'], image) for image_id, image in sorted(images.iteritems()): self.print_image(image) def print_image(self, image): if image.get('name'): imagename = '/'.join((image.get('imageOwnerId', ''), image['name'])) else: imagename = image.get('imageLocation') print self.tabify(( 'IMAGE', image.get('imageId'), imagename, image.get('imageOwnerAlias') or image.get('imageOwnerId'), image.get('imageState'), ('public' if image.get('isPublic') == 'true' else 'private'), image.get('architecture'), image.get('imageType'), image.get('kernelId'), image.get('ramdiskId'), image.get('platform'), image.get('rootDeviceType'), image.get('virtualizationType'), image.get('hypervisor'))) for mapping in image.get('blockDeviceMapping', []): self.print_blockdevice_mapping(mapping) for tag in image.get('tagSet', []): self.print_resource_tag(tag, image.get('imageId')) def print_blockdevice_mapping(self, mapping): print self.tabify(('BLOCKDEVICEMAPPING', mapping.get('deviceName'), mapping.get('ebs', {}).get('snapshotId'), mapping.get('ebs', {}).get('volumeSize'), mapping.get('ebs', {}).get('deleteOnTermination')))
class DescribeVpnConnections(EC2Request): DESCRIPTION = 'Show information about VPN connections' ARGS = [ Arg('VpnConnectionId', metavar='VPNCONN', nargs='*', help='limit results to specific VPN connections'), Arg('--format', route_to=None, help='''show connection information in a specific format (cisco-ios-isr, juniper-junos-j, juniper-screenos-6.1, juniper-screenos-6.2, generic, xml, none) (default: none)'''), Arg('--stylesheet', route_to=None, help='''format the connection information using an XSL stylesheet. If the value contains "{format}" it will be replaced with the format chosen by the --format option. If the value is an HTTP or HTTPS URL it will be downloaded as needed. (default: value of "vpn-stylesheet" region option)''') ] FILTERS = [ Filter('bgp-asn', help='''the BGP AS number advertised by the customer gateway router'''), Filter('customer-gateway-configuration', help='connection information for the customer gateway'), Filter('customer-gateway-id', help='ID of the connected customer gateway'), Filter('state', help='''the VPN connection's state (available, deleting, deleted, pending)'''), Filter('option.static-routes-only', help='''whether the VPN connection is restricted to static routes instead of using BGP'''), Filter('route.destination-cidr-block', help='''the address block corresponding to the subnet used in the data center behind the customer gateway router'''), Filter('tag-key', help='key of a tag assigned to the VPN connection'), Filter('tag-value', help='value of a tag assigned to the VPN connection'), GenericTagFilter('tag:KEY', help='specific tag key/value combination'), Filter('type', help='the type of virtual private gateway (ipsec.1)'), Filter('vpn-connection-id', help='ID of the VPN connection'), Filter('vpn-gateway-id', help='ID of the connected virtual private gateway') ] LIST_TAGS = ['vpnConnectionSet', 'tagSet'] def print_result(self, result): if self.args.get('format') is None: stylesheet = self.args.get('stylesheet') show_conn_info = bool(stylesheet) elif self.args.get('format') == 'none': stylesheet = None show_conn_info = False elif self.args.get('format') == 'xml': stylesheet = None show_conn_info = True else: stylesheet = self.args.get('stylesheet') if not stylesheet: stylesheet = self.config.get_region_option('vpn-stylesheet') if stylesheet: stylesheet = stylesheet.format(format=self.args['format']) else: self.log.warn('current region has no stylesheet') msg = ('current region has no XSLT stylesheet to format ' 'output; connection info will not be shown (try ' 'specifying one with "--stylesheet" or using ' '"--format xml")') print >> sys.stderr, msg show_conn_info = bool(stylesheet) for vpn in result.get('vpnConnectionSet', []): self.print_vpn_connection(vpn, show_conn_info=show_conn_info, stylesheet=stylesheet)
class DescribeSecurityGroups(EC2Request): DESCRIPTION = ('Show information about security groups\n\nNote that ' 'filters are matched on literal strings only, so ' '"--filter ip-permission.from-port=22" will *not* match a ' 'group with a port range of 20 to 30.') ARGS = [ Arg('group', metavar='GROUP', nargs='*', route_to=None, default=[], help='limit results to specific security groups') ] FILTERS = [ Filter('description', help='group description'), Filter('group-id'), Filter('group-name'), Filter('ip-permission.cidr', help='CIDR IP range granted permission by the group'), Filter('ip-permission.from-port', help='start of TCP/UDP port range, or ICMP type number'), Filter('ip-permission.group-name', help='''name of another group granted permission by this group'''), Filter('ip-permission.group-id', help='''ID of another group granted permission by this group'''), Filter('ip-permission.protocol', help='IP protocol for the permission'), Filter('ip-permission.to-port', help='end of TCP/UDP port range, or ICMP code'), Filter('ip-permission.user-id', help='ID of an account granted permission'), Filter('owner-id', help="account ID of the group's owner"), Filter('tag-key', help='key of a tag assigned to the group'), Filter('tag-value', help='value of a tag assigned to the group'), GenericTagFilter('tag:KEY', help='specific tag key/value combination'), Filter('vpc-id', help='[VPC only] ID of a VPC the group belongs to') ] LIST_TAGS = [ 'securityGroupInfo', 'ipPermissions', 'ipPermissionsEgress', 'groups', 'ipRanges', 'tagSet' ] def preprocess(self): for group in self.args['group']: if group.startswith('sg-'): self.params.setdefault('GroupId', []) self.params['GroupId'].append(group) else: self.params.setdefault('GroupName', []) self.params['GroupName'].append(group) def print_result(self, result): for group in result.get('securityGroupInfo', []): self.print_group(group) def print_group(self, group): print self.tabify( ('GROUP', group.get('groupId'), group.get('ownerId'), group.get('groupName'), group.get('groupDescription'), group.get('vpcId'))) for perm in group.get('ipPermissions', []): perm_base = [ 'PERMISSION', group.get('ownerId'), group.get('groupName'), 'ALLOWS', perm.get('ipProtocol'), perm.get('fromPort'), perm.get('toPort') ] for cidr_range in perm.get('ipRanges', []): perm_item = [ 'FROM', 'CIDR', cidr_range.get('cidrIp'), 'ingress' ] print self.tabify(perm_base + perm_item) for othergroup in perm.get('groups', []): perm_item = ['FROM', 'USER', othergroup.get('userId')] if othergroup.get('groupName'): perm_item.extend(['NAME', othergroup['groupName']]) if othergroup.get('groupId'): perm_item.extend(['ID', othergroup['groupId']]) perm_item.append('ingress') print self.tabify(perm_base + perm_item) for perm in group.get('ipPermissionsEgress', []): perm_base = [ 'PERMISSION', group.get('ownerId'), group.get('groupName'), 'ALLOWS', perm.get('ipProtocol'), perm.get('fromPort'), perm.get('toPort') ] for cidr_range in perm.get('ipRanges', []): perm_item = ['TO', 'CIDR', cidr_range.get('cidrIp'), 'egress'] print self.tabify(perm_base + perm_item) for othergroup in perm.get('groups', []): perm_item = ['TO', 'USER', othergroup.get('userId')] if othergroup.get('groupName'): perm_item.extend(['NAME', othergroup['groupName']]) if othergroup.get('groupId'): perm_item.extend(['ID', othergroup['groupId']]) perm_item.append('egress') print self.tabify(perm_base + perm_item) for tag in group.get('tagSet', []): self.print_resource_tag( tag, (group.get('groupId') or group.get('groupName')))
class DescribeNetworkInterfaces(EC2Request): DESCRIPTION = 'Show information about VPC network interfaces' ARGS = [ Arg('NetworkInterfaceId', metavar='INTERFACE', nargs='*', help='limit results to specific network interfaces') ] FILTERS = [ Filter('addresses.private-ip-addresses', help="the interface's private IP addresses"), Filter('addresses.primary', help='''whether the private IP address is the network interface's primary IP address''' ), Filter('addresses.association.public-ip', help='''association ID for the network interface's elastic IP address'''), Filter('addresses.association.owner-id', help='''owner ID of the addresses associated with the network interface'''), Filter('association.association-id', help='''association ID of the network interface's IP Address'''), Filter('association.allocation-id', help='''allocation ID of the network interface's elastic IP address'''), Filter('association.ip-owner-id', help='''owner ID of the network interface's elastic IP address'''), Filter('association.public-ip', help="network interface's elastic IP address"), Filter('association.public-dns-name', help="network interface's public DNS name"), Filter('attachment.attachment-id', help="ID of the network interface's attachment"), Filter('attachment.instance-id', help='''ID of the instance the network interface is attached to'''), Filter('attachment.instance-owner-id', help='''owner ID of the instance the network interface is attached to'''), Filter('attachment.device-index', help='''device index to which the network interface is attached'''), Filter('attachment.status', help='''attachment status (attaching, attached, detaching, detached)'''), Filter('attachment.attach.time', help='time the network interface was attached'), Filter('attachment.delete-on-termination', help='''whether the attachment will be deleted when the associated instance is terminated'''), Filter('availability-zone', help='''availability zone in which the network interface resides'''), Filter('description', help="network interface's description"), Filter('group-id', help='''ID of a security group associated with the network interface'''), Filter('group-name', help='''name of a security group associated with the network interface'''), Filter('mac-address', help='MAC (hardware) address'), Filter('network-interface-id', help='ID of the network interface'), Filter('owner-id', help="account ID of the network interface's owner"), Filter('private-ip-address', help="the network interface's private address(es)"), Filter('private-dns-name', help="the network interface's private DNS name"), Filter('requester-id', help='''ID of the entity that created the network interface'''), Filter('requester-managed', help='''whether the network interface is being managed by one of the cloud's services'''), Filter('source-dest-check', help='''whether the network interface's traffic is subject to source/destination address checking'''), Filter('status', help="the interface's status (available, in-use)"), Filter('subnet-id', help='''ID of the subnet in which the network interface resides'''), Filter('tag-key', help='key of a tag assigned to the network interface'), Filter('tag-value', help='value of a tag assigned to the network interface'), GenericTagFilter('tag:KEY', help='specific tag key/value combination'), Filter('vpc-id', help='''ID of the VPC in which the network interface resides''') ] LIST_TAGS = [ 'groupSet', 'networkInterfaceSet', 'privateIpAddressesSet', 'tagSet' ] def print_result(self, result): for nic in result.get('networkInterfaceSet') or []: self.print_interface(nic)
class DescribeSnapshots(EucalyptusRequest): DESCRIPTION = ('Show information about snapshots\n\nBy default, only ' 'snapshots your account owns and snapshots for which your ' 'account has explicit restore permissions are shown.') ARGS = [ Arg('SnapshotId', nargs='*', metavar='SNAPSHOT', help='limit results to specific snapshots'), Arg('-a', '--all', action='store_true', route_to=None, help='describe all snapshots'), Arg('-o', '--owner', dest='Owner', metavar='ACCOUNT', action='append', default=[], help='limit results to snapshots owned by specific accounts'), Arg('-r', '--restorable-by', dest='RestorableBy', action='append', metavar='ACCOUNT', default=[], help='''limit results to snapahots restorable by specific accounts''') ] FILTERS = [ Filter('description', help='snapshot description'), Filter('owner-alias', help="snapshot owner's account alias"), Filter('owner-id', help="snapshot owner's account ID"), Filter('progress', help='snapshot progress, in percentage'), Filter('snapshot-id'), Filter('start-time', help='snapshot initiation time'), Filter('status', choices=('pending', 'completed', 'error')), Filter('tag-key', help='key of a tag assigned to the snapshot'), Filter('tag-value', help='value of a tag assigned to the snapshot'), GenericTagFilter('tag:KEY', help='specific tag key/value combination'), Filter('volume-id', help='source volume ID'), Filter('volume-size', type=int) ] LIST_TAGS = ['snapshotSet', 'tagSet'] # noinspection PyExceptionInherit def configure(self): EucalyptusRequest.configure(self) if self.args.get('all'): if self.args.get('Owner'): raise ArgumentError('argument -a/--all: not allowed with ' 'argument -o/--owner') if self.args.get('RestorableBy'): raise ArgumentError('argument -a/--all: not allowed with ' 'argument -r/--restorable-by') def main(self): if not any( self.args.get(item) for item in ('all', 'Owner', 'RestorableBy')): # Default to owned snapshots and those with explicit restore perms self.params['Owner'] = ['self'] owned = self.send() del self.params['Owner'] self.params['RestorableBy'] = ['self'] restorable = self.send() del self.params['RestorableBy'] owned['snapshotSet'] = (owned.get('snapshotSet', []) + restorable.get('snapshotSet', [])) return owned else: return self.send() def print_result(self, result): for snapshot in result.get('snapshotSet', []): self.print_snapshot(snapshot)