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 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 DescribeBundleTasks(EucalyptusRequest): DESCRIPTION = 'Describe current instance-bundling tasks' ARGS = [ Arg('BundleId', metavar='BUNDLE', nargs='*', help='limit results to specific bundle tasks') ] FILTERS = [ Filter('bundle-id', help='bundle task ID'), Filter('error-code', help='if the task failed, the error code returned'), Filter('error-message', help='if the task failed, the error message returned'), Filter('instance-id', help='ID of the bundled instance'), Filter('progress', help='level of task completion, in percent'), Filter('s3-bucket', help='bucket where the image will be stored'), Filter('s3-prefix', help='beginning of the bundle name'), Filter('start-time', help='task start time'), Filter('state', help='task state', choices=('pending', 'waiting-for-shutdown', 'bundling', 'storing', 'cancelling', 'complete', 'failed')), Filter('update-time', help='most recent task update time') ] LIST_TAGS = ['bundleInstanceTasksSet'] def print_result(self, result): for task in result.get('bundleInstanceTasksSet', []): self.print_bundle_task(task)
class DescribeServiceCertificates(EmpyreanRequest): DESCRIPTION = 'Show information about one or more service certificates' ARGS = [Arg('--format', dest='Format', choices=('pem', 'der'), type=str.lower, help='format to output certificates in'), Arg('--digest', dest='FingerprintDigest', type=str.upper, choices=('SHA-1', 'SHA-256'), help='digest algorithm to use for certificate fingerprints')] FILTERS = [Filter('certificate-usage'), Filter('service-type')] LIST_TAGS = ['serviceCertificates']
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"), 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 DescribeKeyPairs(EucalyptusRequest): DESCRIPTION = 'Display information about available key pairs' ARGS = [Arg('KeyName', nargs='*', metavar='KEYPAIR', help='limit results to specific key pairs')] FILTERS = [Filter('fingerprint', help='fingerprint of the key pair'), Filter('key-name', help='name of the key pair')] LIST_TAGS = ['keySet'] def print_result(self, result): for key in result.get('keySet', []): print self.tabify(('KEYPAIR', key.get('keyName'), key.get('keyFingerprint')))
class DescribeRegions(EucalyptusRequest): DESCRIPTION = 'Display information about regions' ARGS = [Arg('RegionName', nargs='*', metavar='REGION', help='limit results to specific regions')] FILTERS = [Filter('endpoint'), Filter('region-name')] LIST_TAGS = ['regionInfo'] def print_result(self, result): for region in result.get('regionInfo', []): print self.tabify(('REGION', region.get('regionName'), region.get('regionEndpoint')))
class DescribeTags(EC2Request): DESCRIPTION = "List tags associated with your account's resources" FILTERS = [Filter('key'), Filter('resource-id'), Filter('resource-type'), Filter('value')] LIST_TAGS = ['tagSet'] def print_result(self, result): for tag in result.get('tagSet', []): print self.tabify(['TAG', tag.get('resourceId'), tag.get('resourceType'), tag.get('key'), tag.get('value')])
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 DescribeTags(EucalyptusRequest): DESCRIPTION = "List tags associated with your account's resources" FILTERS = [ Filter('key'), Filter('resource-id'), Filter('resource-type', choices=sorted(tuple(RESOURCE_TYPE_MAP))), Filter('value') ] LIST_TAGS = ['tagSet'] def print_result(self, result): for tag in result.get('tagSet', []): print self.tabify([ 'TAG', tag.get('resourceId'), tag.get('resourceType'), tag.get('key'), tag.get('value') ])
class DescribeAvailabilityZones(EucalyptusRequest): DESCRIPTION = 'Display availability zones within the current region' ARGS = [ Arg('ZoneName', metavar='ZONE', nargs='*', help='limit results to specific availability zones') ] FILTERS = [ Filter('message', help='''message giving information about the availability zone'''), Filter('region-name', help='region the availability zone is in'), Filter('state', help='state of the availability zone'), Filter('zone-name', help='name of the availability zone') ] LIST_TAGS = ['availabilityZoneInfo', 'messageSet'] def print_result(self, result): for zone in result.get('availabilityZoneInfo', []): msgs = ', '.join(msg for msg in zone.get('messageSet', [])) print self.tabify(('AVAILABILITYZONE', zone.get('zoneName'), zone.get('zoneState'), msgs))
class DescribeAddresses(EucalyptusRequest): DESCRIPTION = 'Show information about elastic IP addresses' ARGS = [ Arg('address', metavar='ADDRESS', nargs='*', route_to=None, help='''limit results to specific elastic IP addresses or VPC allocation IDs''') ] FILTERS = [ Filter('allocation-id', help='[VPC only] allocation ID'), Filter('association-id', help='[VPC only] association ID'), Filter('domain', choices=('standard', 'vpc'), help='whether the address is a standard or VPC address'), Filter('instance-id', help='instance the address is associated with'), Filter('network-interface-id', help='''[VPC only] network interface the address is associated with'''), Filter('network-interface-owner-id', help='''[VPC only] ID of the network interface's owner'''), Filter('private-ip-address', help='''[VPC only] private address associated with the public address'''), Filter('public-ip', help='the elastic IP address') ] LIST_TAGS = ['addressesSet'] def preprocess(self): alloc_ids = set(addr for addr in self.args.get('address', []) if addr.startswith('eipalloc-')) public_ips = set(self.args.get('address', [])) - alloc_ids if alloc_ids: self.params['AllocationId'] = list(sorted(alloc_ids)) if public_ips: self.params['PublicIp'] = list(sorted(public_ips)) def print_result(self, result): for addr in result.get('addressesSet', []): print self.tabify( ('ADDRESS', addr.get('publicIp'), addr.get('instanceId'), addr.get('domain', 'standard'), addr.get('allocationId'), addr.get('associationId'), addr.get('networkInterfaceId'), addr.get('privateIpAddress')))
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 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.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'), 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('groupId'): perm_item.extend(['ID', othergroup['groupId']]) else: perm_item.extend(['GRPNAME', othergroup['groupName']]) 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('groupId'): perm_item.extend(['ID', othergroup['groupId']]) else: perm_item.extend(['GRPNAME', othergroup['groupName']]) 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 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)
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 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 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 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 DescribeServices(EmpyreanRequest, TableOutputMixin): DESCRIPTION = "Show information about the cloud's services" ARGS = [ Arg('ServiceName', metavar='SVCINSTANCE', nargs='*', help='limit results to specific instances of services'), Arg('-a', '--all', dest='ListAll', action='store_true', help='show all services regardless of type'), MutuallyExclusiveArgList( Arg('--by-type', action='store_true', route_to=None, help='show services by service type (default)'), Arg('--by-zone', action='store_true', route_to=None, help='show services by availability zone'), Arg('--by-host', action='store_true', route_to=None, help='show services by host'), Arg('--expert', action='store_true', route_to=None, help='show advanced information')) ] FILTERS = [ _RenamingFilter('availability-zone', 'partition', help="the service's availability zone"), Filter('host', help='the machine running the service'), Filter('internal', help='''whether the service is used only internally (true or false)'''), Filter('public', help='whether the service is public (true or false)'), Filter('service-group', help='''whether the service is a member of a specific service group'''), Filter('service-group-member', help='''whether the service is a member of any service group (true or false)'''), Filter('service-type', help='the type of service'), Filter('state', help="the service's state"), # TODO: this is wrong! # https://eucalyptus.atlassian.net/browse/EUCA-11006 Filter('user-service', help='''whether the service is user-facing (true or false)''') ] LIST_TAGS = ['serviceStatuses', 'uris', 'serviceAccounts'] def print_result(self, result): services = result.get('serviceStatuses') or [] if self.args.get('expert'): table = self.get_table(('SERVICE', 'arn', 'state', 'epoch', 'uri', 'service-accounts')) table.sortby = 'arn' for service in services: svcid = service.get('serviceId') or {} accounts = service.get('serviceAccounts') or {} accounts_str = ','.join([ account.get('accountName') + ':' + account.get('accountNumber') + ':' + account.get('accountCanonicalId') for account in accounts ]) table.add_row( ('SERVICE', svcid.get('fullName'), _colorize_state(service.get('localState').lower()), service.get('localEpoch'), svcid.get('uri'), accounts_str)) elif self.args.get('by_host'): hosts = {} for service in services: svcid = service.get('serviceId') or {} hosts.setdefault(svcid.get('host'), []) hosts[svcid.get('host')].append(service) table = self.get_table(('SERVICE', 'host', 'type', 'name', 'state', 'service-accounts')) for host, services in sorted(hosts.iteritems()): host = _colorize(host, _get_service_list_color(services)) for service in services: svcid = service.get('serviceId') or {} accounts = service.get('serviceAccounts') or {} accounts_str = ','.join([ account.get('accountName') + ':' + account.get('accountNumber') + ':' + account.get('accountCanonicalId') for account in accounts ]) table.add_row( ('SERVICE', host, svcid.get('type'), svcid.get('name'), _colorize_state(service.get('localState').lower()), accounts_str)) elif self.args.get('by_zone'): by_zone = {} for service in services: svcid = service.get('serviceId') or {} by_zone.setdefault(svcid.get('partition'), {}) by_zone[svcid.get('partition')].setdefault( svcid.get('type'), []) by_zone[svcid.get('partition')][svcid.get('type')].append( service) table = self.get_table(('SERVICE', 'zone', 'type', 'name', 'state', 'service-accounts')) for zone, svctypes in sorted(by_zone.iteritems()): if not zone: continue zone_color = 'green' for svctype, services in sorted(svctypes.iteritems()): svctype_color = _get_service_list_color(services) if svctype_color == 'red': zone_color = 'red' elif svctype_color == 'brown' and zone_color == 'green': zone_color = 'brown' zone = _colorize(zone, zone_color) for svctype, services in sorted(svctypes.iteritems()): svctype = _colorize(svctype, _get_service_list_color(services)) for service in services: svcid = service.get('serviceId') or {} state = service.get('localState').lower() accounts = service.get('serviceAccounts') or {} accounts_str = ','.join([ account.get('accountName') + ':' + account.get('accountNumber') + ':' + account.get('accountCanonicalId') for account in accounts ]) table.add_row( ('SERVICE', zone, svctype, svcid.get('name'), _colorize_state(state), accounts_str)) # TODO: by_group (needs EUCA-10816) # https://eucalyptus.atlassian.net/browse/EUCA-10816 else: # by_type svctypes = {} for service in services: svcid = service.get('serviceId') or {} svctypes.setdefault(svcid.get('type'), []) svctypes[svcid.get('type')].append(service) table = self.get_table( ('SERVICE', 'type', 'zone', 'name', 'state', 'accounts')) for svctype, services in sorted(svctypes.iteritems()): svctype = _colorize(svctype, _get_service_list_color(services)) for service in services: svcid = service.get('serviceId') or {} accounts = service.get('serviceAccounts') or {} accounts_str = ','.join([ account.get('accountName') + ':' + account.get('accountNumber') + ':' + account.get('accountCanonicalId') for account in accounts ]) table.add_row( ('SERVICE', svctype, svcid.get('partition'), svcid.get('name'), _colorize_state(service.get('localState').lower()), accounts_str)) print table
def __init__(self, name, server_name, **kwargs): Filter.__init__(self, name, **kwargs) self.__server_name = server_name
def convert(self, argval): _, value = Filter.convert(self, argval) return (self.__server_name, value)
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 DescribeServices(BootstrapRequest, TableOutputMixin): DESCRIPTION = "Show information about the cloud's services" ARGS = [ Arg('ServiceName', metavar='SVCINSTANCE', nargs='*', help='limit results to specific instances of services'), Arg('-a', '--all', dest='ListAll', action='store_true', help='show all services regardless of type'), Arg('--show-events', dest='ShowEvents', action='store_true', help=argparse.SUPPRESS), Arg('--show-stack-traces', dest='ShowEventStacks', action='store_true', help=argparse.SUPPRESS), MutuallyExclusiveArgList( Arg('--group-by-type', action='store_true', route_to=None, help='collate services by service type (default)'), Arg('--group-by-zone', action='store_true', route_to=None, help='collate services by availability zone'), Arg('--group-by-host', action='store_true', route_to=None, help='collate services by host'), Arg('--expert', action='store_true', route_to=None, help=('show advanced information, including service ' 'accounts'))) ] FILTERS = [ _RenamingFilter('availability-zone', 'partition', help="the service's availability zone"), Filter('host', help='the machine running the service'), Filter('internal', help='''whether the service is used only internally (true or false)'''), Filter('public', help='whether the service is public (true or false)'), Filter('service-group', help='''whether the service is a member of a specific service group'''), Filter('service-group-member', help='''whether the service is a member of any service group (true or false)'''), Filter('service-type', help='the type of service'), Filter('state', help="the service's state") ] # A "user-service" filter used to appear here, but it was # a mirror of an option with that name in the old admin # tool set that doesn't match what that term means today, # so we removed it at least for now. See # https://eucalyptus.atlassian.net/browse/EUCA-11006 LIST_TAGS = ['serviceAccounts', 'serviceStatuses', 'statusDetails', 'uris'] def print_result(self, result): services = result.get('serviceStatuses') or [] if self.args.get('expert'): table = self.get_table( ('SERVICE', 'arn', 'state', 'epoch', 'uri', 'accounts')) table.sortby = 'arn' for service in services: svcid = service.get('serviceId') or {} accounts = [] for account in service.get('serviceAccounts') or []: accounts.append('{0}={1}:{2}'.format( account.get('accountName'), account.get('accountNumber'), account.get('accountCanonicalId'))) table.add_row( ('SERVICE', svcid.get('fullName'), _colorize_state(service.get('localState').lower()), service.get('localEpoch'), svcid.get('uri'), ','.join(sorted(accounts)))) elif self.args.get('group_by_host'): hosts = {} for service in services: svcid = service.get('serviceId') or {} hosts.setdefault(svcid.get('host'), []) hosts[svcid.get('host')].append(service) table = self.get_table( ('SERVICE', 'host', 'type', 'name', 'state')) for host, services in sorted(hosts.iteritems()): host = _colorize(host, _get_service_list_color(services)) for service in services: svcid = service.get('serviceId') or {} table.add_row( ('SERVICE', host, svcid.get('type'), svcid.get('name'), _colorize_state(service.get('localState').lower()))) elif self.args.get('group_by_zone'): by_zone = {} for service in services: svcid = service.get('serviceId') or {} by_zone.setdefault(svcid.get('partition'), {}) by_zone[svcid.get('partition')].setdefault( svcid.get('type'), []) by_zone[svcid.get('partition')][svcid.get('type')].append( service) table = self.get_table( ('SERVICE', 'zone', 'type', 'name', 'state')) for zone, svctypes in sorted(by_zone.iteritems()): if not zone: continue zone_color = 'green' for svctype, services in sorted(svctypes.iteritems()): svctype_color = _get_service_list_color(services) if svctype_color == 'red': zone_color = 'red' elif svctype_color == 'brown' and zone_color == 'green': zone_color = 'brown' zone = _colorize(zone, zone_color) for svctype, services in sorted(svctypes.iteritems()): svctype = _colorize(svctype, _get_service_list_color(services)) for service in services: svcid = service.get('serviceId') or {} state = service.get('localState').lower() table.add_row( ('SERVICE', zone, svctype, svcid.get('name'), _colorize_state(state))) # TODO: group_by_group (needs EUCA-10816) # https://eucalyptus.atlassian.net/browse/EUCA-10816 else: # group_by_type svctypes = {} for service in services: svcid = service.get('serviceId') or {} svctypes.setdefault(svcid.get('type'), []) svctypes[svcid.get('type')].append(service) table = self.get_table( ('SERVICE', 'type', 'zone', 'name', 'state')) for svctype, services in sorted(svctypes.iteritems()): svctype = _colorize(svctype, _get_service_list_color(services)) for service in services: svcid = service.get('serviceId') or {} table.add_row( ('SERVICE', svctype, svcid.get('partition'), svcid.get('name'), _colorize_state(service.get('localState').lower()))) print table
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 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 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 DescribeInstanceStatus(EC2Request): DESCRIPTION = 'Show information about instance status and scheduled events' ARGS = [Arg('InstanceId', metavar='INSTANCE', nargs='*', help='limit results to specific instances'), Arg('--hide-healthy', action='store_true', route_to=None, help='hide instances where all status checks pass'), Arg('--include-all-instances', dest='IncludeAllInstances', action='store_true', help='show all instances, not just those that are running')] FILTERS = [Filter('availability-zone'), Filter('event.code', choices=('instance-reboot', 'instance-retirement', 'instance-stop', 'system-maintenance', 'instance-retirement'), help='the code identifying the type of event'), Filter('event.description', help="an event's description"), Filter('event.not-after', help="an event's latest possible end time"), Filter('event.not-before', help="an event's earliest possible start time"), Filter('instance-state-code', type=int, help='numeric code identifying instance state'), Filter('instance-state-name', help='instance state'), Filter('instance-status.status', help="instance's status", choices=('ok', 'impaired', 'initializing', 'insufficient-data', 'not-applicable')), Filter('instance-status.reachability', choices=('passed', 'failed', 'initializing', 'insufficient-data'), help="instance's reachability status"), Filter('system-status.status', help="instance's system status", choices=('ok', 'impaired', 'initializing', 'insufficient-data', 'not-applicable')), Filter('system-status.reachability', choices=('passed', 'failed', 'initializing', 'insufficient-data'), help="instance's system reachability status")] LIST_TAGS = ['instanceStatusSet', 'details', 'eventsSet'] def print_result(self, result): for sset in result.get('instanceStatusSet') or []: if (self.args.get('hide_healthy', False) and sset.get('systemStatus', {}).get('status') == 'ok' and sset.get('instanceStatus', {}).get('status') == 'ok'): continue print self.tabify(( 'INSTANCE', sset.get('instanceId'), sset.get('availabilityZone'), sset.get('instanceState', {}).get('name'), sset.get('instanceState', {}).get('code'), sset.get('instanceStatus', {}).get('status'), sset.get('systemStatus', {}).get('status'), get_retirement_status(sset), get_retirement_date(sset))) for sstatus in sset.get('systemStatus', {}).get('details') or []: print self.tabify(( 'SYSTEMSTATUS', sstatus.get('name'), sstatus.get('status'), sstatus.get('impairedSince'))) for istatus in sset.get('systemStatus', {}).get('details') or []: print self.tabify(( 'INSTANCESTATUS', istatus.get('name'), istatus.get('status'), istatus.get('impairedSince'))) for event in sset.get('eventsSet') or []: print self.tabify(( 'EVENT', event.get('code'), event.get('notBefore'), event.get('notAfter'), event.get('description')))