Beispiel #1
0
def output_lc_list(lc_list=None):
    """
    @type lc_list: list
    """
    if isinstance(lc_list, list):
        td = list()
        table_header = [
            Color('{autoblue}name{/autoblue}'),
            Color('{autoblue}image id{/autoblue}'),
            Color('{autoblue}instance type{/autoblue}'),
            Color('{autoblue}created{/autoblue}')
        ]
        for lc in lc_list:
            td.append([
                dash_if_none(lc.get('LaunchConfigurationName')),
                dash_if_none(lc.get('ImageId')),
                dash_if_none(lc.get('InstanceType')),
                dash_if_none(
                    lc.get('CreatedTime').replace(tzinfo=None, microsecond=0))
            ])
        output_ascii_table_list(
            table_title=Color('{autowhite}launch configurations{/autowhite}'),
            table_header=table_header,
            table_data=td,
            inner_heading_row_border=True)
    exit(0)
Beispiel #2
0
def output_vpc_list(vpcs=None):
    """
    @type vpcs: dict
    """
    td = list()
    table_header = [Color('{autoblue}vpc id{/autoblue}'), Color('{autoblue}name{/autoblue}'),
                    Color('{autoblue}CIDR block{/autoblue}'), Color('{autoblue}tenancy{/autoblue}'),
                    Color('{autoblue}state{/autoblue}'), Color('{autoblue}DHCP options{/autoblue}'),
                    Color('{autoblue}default vpc{/autoblue}')]
    for vpc in vpcs.get('Vpcs'):
        vpcid = vpc.get('VpcId')
        cidr_block = vpc.get('CidrBlock')
        tenancy = vpc.get('InstanceTenancy')
        state = vpc.get('State')
        dhcpoptions = vpc.get('DhcpOptionsId')
        default = str(vpc.get('IsDefault'))
        td.append([vpcid,
                   dash_if_none(get_tag(name='Name', tags=vpc.get('Tags'))),
                   dash_if_none(cidr_block),
                   dash_if_none(tenancy),
                   dash_if_none(state),
                   dash_if_none(dhcpoptions),
                   default])
    output_ascii_table_list(table_title=Color('{autowhite}VPCs{/autowhite}'),
                            table_data=td,
                            table_header=table_header,
                            inner_heading_row_border=True)
    exit(0)
Beispiel #3
0
def output_ec2_list(instances=None):
    """
    @type instances: list
    """
    td = list()
    table_header = [Color('{autoblue}id{/autoblue}'), Color('{autoblue}name{/autoblue}'),
                    Color('{autoblue}state{/autoblue}'), Color('{autoblue}type{/autoblue}'),
                    Color('{autoblue}image{/autoblue}'),
                    Color('{autoblue}public ip{/autoblue}'), Color('{autoblue}private ip{/autoblue}')]
    instances = sorted(instances,
                       key=lambda k: get_ec2_instance_tags(ec2_instance=k, tag_key='Name'))
    for instance in instances:
        if instance:
            instance_id = instance.get('InstanceId')
            instance_state = colour_state(instance.get('State').get('Name'))
            instance_type = dash_if_none(str(instance.get('InstanceType')))
            image_id = dash_if_none(instance.get('ImageId'))
            public_ip = dash_if_none(instance.get('PublicIpAddress'))
            private_ip = dash_if_none(instance.get('PrivateIpAddress'))
            instance_name = dash_if_none(get_ec2_instance_tags(ec2_instance=instance, tag_key='Name'))
            td.append([instance_id,
                       instance_name,
                       instance_state,
                       instance_type,
                       image_id,
                       public_ip,
                       private_ip])
    output_ascii_table_list(table_title=Color('{autowhite}ec2 instances{/autowhite}'),
                            table_header=table_header,
                            table_data=td,
                            inner_heading_row_border=True)
    exit(0)
Beispiel #4
0
def output_route53_list(zones=None):
    """
    @type zones: list | dict
    """
    td = list()
    table_header = list()
    if isinstance(zones, dict):
        zones = [zones]
    for hosted_zone_dict in zones:
        td = list()
        table_header = [Color('{autoblue}id{/autoblue}'), Color('{autoblue}name{/autoblue}'),
                        Color('{autoblue}count{/autoblue}'), Color('{autoblue}comment{/autoblue}'),
                        Color('{autoblue}private zone{/autoblue}')]
        hosted_zones = sorted(hosted_zone_dict.get('HostedZones'), key=lambda k: k['Name'])
        for hosted_zone in hosted_zones:
            zone_id = dash_if_none(hosted_zone.get('Id'))
            zone_name = dash_if_none(hosted_zone.get('Name'))
            record_count = str(hosted_zone.get('ResourceRecordSetCount'))
            comment = dash_if_none(hosted_zone.get('Config').get('Comment'))
            private_zone = dash_if_none(hosted_zone.get('Config').get('PrivateZone'))
            td.append([zone_id,
                       zone_name,
                       record_count,
                       comment,
                       private_zone])
    output_ascii_table_list(table_title=Color('{autowhite}route53 zones{/autowhite}'),
                            table_data=td,
                            table_header=table_header,
                            inner_heading_row_border=True)
    exit(0)
Beispiel #5
0
def output_route53_list(zones=None):
    """
    @type zones: list | dict
    """
    td = list()
    table_header = list()
    if isinstance(zones, dict):
        zones = [zones]
    for hosted_zone_dict in zones:
        td = list()
        table_header = [
            Color('{autoblue}id{/autoblue}'),
            Color('{autoblue}name{/autoblue}'),
            Color('{autoblue}count{/autoblue}'),
            Color('{autoblue}comment{/autoblue}'),
            Color('{autoblue}private zone{/autoblue}')
        ]
        hosted_zones = sorted(hosted_zone_dict.get('HostedZones'),
                              key=lambda k: k['Name'])
        for hosted_zone in hosted_zones:
            zone_id = dash_if_none(hosted_zone.get('Id'))
            zone_name = dash_if_none(hosted_zone.get('Name'))
            record_count = str(hosted_zone.get('ResourceRecordSetCount'))
            comment = dash_if_none(hosted_zone.get('Config').get('Comment'))
            private_zone = dash_if_none(
                hosted_zone.get('Config').get('PrivateZone'))
            td.append(
                [zone_id, zone_name, record_count, comment, private_zone])
    output_ascii_table_list(
        table_title=Color('{autowhite}route53 zones{/autowhite}'),
        table_data=td,
        table_header=table_header,
        inner_heading_row_border=True)
    exit(0)
Beispiel #6
0
def output_route53_info(zone=None, record_sets=None):
    """
    @type zone: zone
    @type record_sets: ResourceRecordSets
    """
    td = list()
    td.append([Color('{autoblue}id{/autoblue}'),
               dash_if_none(zone.get('HostedZone').get('Id'))])
    td.append([Color('{autoblue}name{/autoblue}'),
               dash_if_none(zone.get('HostedZone').get('Name'))])
    td.append([Color('{autoblue}records{/autoblue}'),
               dash_if_none(zone.get('HostedZone').get('ResourceRecordSetCount'))])
    td.append([Color('{autoblue}comment{/autoblue}'),
               dash_if_none(zone.get('HostedZone').get('Config').get('Comment'))])
    td.append([Color('{autoblue}private{/autoblue}'),
               dash_if_none(zone.get('HostedZone').get('Config').get('PrivateZone'))])
    td.append([Color('{autoblue}name servers{/autoblue}'),
               "\n".join(zone['DelegationSet']['NameServers'])])
    td.append([Color('{autoblue}records{/autoblue}'), ' '])
    td.append(['{0}'.format("-" * 12), '{0}'.format("-" * 20)])
    for record_set in record_sets['ResourceRecordSets']:
        td.append([Color('{autoblue}name{/autoblue}'),
                   record_set['Name']])
        td.append([Color('{autoblue} type{/autoblue}'),
                   record_set['Type']])
        td.append([Color('{autoblue} ttl{/autoblue}'),
                   str(record_set['TTL'])])
        td.append([Color('{autoblue} values{/autoblue}'),
                   "\n".join(get_record_set_values(record_set['ResourceRecords']))])
    output_ascii_table(table_title=Color('{autowhite}zone info{/autowhite}'),
                       table_data=td)
    exit(0)
Beispiel #7
0
def output_iam_user_list(users=None, mfa_devices=None):
    """
    @type users: list
    @type mfa_devices: list
    """
    td = list()
    table_header = [
        Color('{autoblue}user name{/autoblue}'),
        Color('{autoblue}created{/autoblue}'),
        Color('{autoblue}password last used{/autoblue}'),
        Color('{autoblue}mfa enabled{/autoblue}')
    ]
    for user in users:
        td.append([
            dash_if_none(user.get('UserName')),
            dash_if_none(user.get('CreateDate')),
            dash_if_none(user.get('PasswordLastUsed')),
            user_has_mfa_assigned(
                username=user.get('UserName'),
                password_last_used=user.get('PasswordLastUsed'),
                mfa_devices=mfa_devices)
        ])
    output_ascii_table_list(
        table_title=Color('{autowhite}user list{/autowhite}'),
        table_data=td,
        table_header=table_header,
        inner_heading_row_border=True)
    exit(0)
Beispiel #8
0
def output_ami_list(output_media='console', amis=None):
    """
    @type output_media: unicode
    @type amis: list
    """
    amis = sorted(amis, key=lambda k: k.get('CreationDate'), reverse=True)
    if output_media == 'console':
        td = list()
        table_header = [
            Color('{autoblue}image id{/autoblue}'),
            Color('{autoblue}name{/autoblue}'),
            Color('{autoblue}created (UTC){/autoblue}')
        ]
        for ami in amis:
            td.append([
                ami.get('ImageId'),
                dash_if_none(ami.get('Name')),
                dash_if_none(trim_creation_date(ami.get('CreationDate')))
            ])
        output_ascii_table_list(
            table_title=Color('{autowhite}AMIs{/autowhite}'),
            table_header=table_header,
            inner_heading_row_border=True,
            table_data=td)
    exit(0)
Beispiel #9
0
def output_account_info(account_id=None, account_aliases=None):
    """
    @type account_id: unicode
    @type account_aliases: list
    """
    td = list()
    td.append([Color('{autoblue}id{/autoblue}'), dash_if_none(account_id)])
    td.append([Color('{autoblue}aliases{/autoblue}'), dash_if_none(", ".join(account_aliases))])
    output_ascii_table(table_title=Color('{autowhite}Account Info{/autowhite}'),
                       table_data=td)
    exit(0)
Beispiel #10
0
def output_account_info(account_id=None, account_aliases=None):
    """
    @type account_id: unicode
    @type account_aliases: list
    """
    td = list()
    td.append([Color('{autoblue}id{/autoblue}'), dash_if_none(account_id)])
    td.append([
        Color('{autoblue}aliases{/autoblue}'),
        dash_if_none(", ".join(account_aliases))
    ])
    output_ascii_table(
        table_title=Color('{autowhite}Account Info{/autowhite}'),
        table_data=td)
    exit(0)
Beispiel #11
0
def output_vpc_info(vpc=None, subnets=None):
    """
    @type vpc: ec2.Vpc
    @type subnets: dict
    """
    if vpc:
        td = list()
        td.append([Color('{autoblue}vpc id{/autoblue}'), vpc.get('VpcId')])
        td.append([Color('{autoblue}CIDR block{/autoblue}'), vpc.get('CidrBlock')])
        td.append([Color('{autoblue}default{/autoblue}'), str(vpc.get('IsDefault'))])
        td.append([Color('{autoblue}tenancy{/autoblue}'), vpc.get('InstanceTenancy')])
        td.append([Color('{autoblue}state{/autoblue}'), dash_if_none(vpc.get('State'))])
        td.append([Color('{autoblue}tags{/autoblue}'), " "])
        if vpc.get('Tags'):
            for vpc_tag in vpc.get('Tags'):
                td.append([Color('{autoblue}' + "{0}".format(vpc_tag.get('Key'))+'{/autoblue}'),
                           " {0}".format(vpc_tag.get('Value'))])
        if subnets:
            td.append(["{0}".format('-' * 30), "{0}".format('-' * 30)])
            td.append([Color('{autowhite}SUBNETS{/autowhite}'), " "])
            for subnet in subnets.get('Subnets'):
                td.append(["{0}".format('-' * 30),
                           "{0}".format('-' * 30)])
                td.append([Color('{autoblue}subnet id{/autoblue}'),
                           subnet.get('SubnetId')])
                td.append([Color('{autoblue}az{/autoblue}'),
                           subnet.get('AvailabilityZone')])
                td.append([Color('{autoblue}state{/autoblue}'),
                           subnet.get('State')])
                td.append([Color('{autoblue}available IPs{/autoblue}'),
                           str(subnet.get('AvailableIpAddressCount'))])
                td.append([Color('{autoblue}CIDR block{/autoblue}'),
                           subnet.get('CidrBlock')])
                td.append([Color('{autoblue}default for az{/autoblue}'),
                           str(subnet.get('DefaultForAz'))])
                td.append([Color('{autoblue}map public ip on launch{/autoblue}'),
                           str(subnet.get('MapPublicIpOnLaunch'))])
                if subnet.get('Tags'):
                    td.append([Color('{autoblue}tags{/autoblue}'), "-"])
                    for tag in subnet.get('Tags'):
                        tag_key, tag_value = dash_if_none(tag.get('Key')), dash_if_none(tag.get('Value'))
                        td.append([Color('{autoblue}'+" {}".format(tag_key)+'{/autoblue}'), "{}".format(tag_value)])
        output_ascii_table(table_title=Color('{autowhite}vpc info{/autowhite}'),
                           table_data=td)
    else:
        exit('VPC does not exist.')
    exit(0)
Beispiel #12
0
def output_secgroup_info(secgroup=None):
    """
    @type secgroup: ec2.SecurityGroup
    """
    if secgroup:
        td = list()
        td.append([Color('{autoblue}group id{/autoblue}'), secgroup.get('GroupId')])
        td.append([Color('{autoblue}group name{/autoblue}'), secgroup.get('GroupName')])
        td.append([Color('{autoblue}description{/autoblue}'), secgroup.get('Description')])
        td.append([Color('{autoblue}vpc id{/autoblue}'), dash_if_none(secgroup.get('VpcId'))])
        if secgroup.get('IpPermissions'):
            td.append(['ip permissions', '{0}'.format("-" * 30)])
            for ip_perm in secgroup.get('IpPermissions'):
                td.append([Color('{autoblue}from port{/autoblue}'),
                           dash_if_none(ip_perm.get('FromPort'))])
                td.append([Color('{autoblue}to port{/autoblue}'),
                           dash_if_none(ip_perm.get('ToPort'))])
                td.append([Color('{autoblue}ip ranges{/autoblue}'),
                           dash_if_none(get_ip_ranges(ip_perm.get('IpRanges')))])
                td.append([Color('{autoblue}ip protocol{/autoblue}'),
                           dash_if_none(ip_perm.get('IpProtocol'))])
                if ip_perm.get('UserIdGroupPairs'):
                    td.append(['user id group pairs', '{0}'.format("-" * 30)])
                    td.append(['', get_uid_group_pairs(uid_gps=ip_perm.get('UserIdGroupPairs'))])

        if secgroup.get('IpPermissionsEgress'):
            td.append(['ip permissions egress', '{0}'.format("-" * 30)])
            for ip_perm_egress in secgroup.get('IpPermissionsEgress'):
                td.append([Color('{autoblue}prefix list ids{/autoblue}'),
                           dash_if_none(ip_perm_egress.get('PrefixListIds'))])
                td.append([Color('{autoblue}from port{/autoblue}'),
                           dash_if_none(ip_perm_egress.get('FromPort'))])
                td.append([Color('{autoblue}to port{/autoblue}'),
                           dash_if_none(ip_perm_egress.get('ToPort'))])
                td.append([Color('{autoblue}ip ranges{/autoblue}'),
                           dash_if_none(get_ip_ranges(ip_perm_egress.get('IpRanges')))])
                td.append([Color('{autoblue}ip protocol{/autoblue}'),
                           dash_if_none(ip_perm_egress.get('IpProtocol'))])
                if ip_perm_egress.get('UserIdGroupPairs'):
                    td.append(['user id group pairs', '{0}'.format("-" * 30)])
                    td.append(['', get_uid_group_pairs(uid_gps=ip_perm_egress.get('UserIdGroupPairs'))])
        output_ascii_table(table_title=Color('{autowhite}security group info{/autowhite}'),
                           table_data=td)
    else:
        exit('Security group does not exist.')
    exit(0)
Beispiel #13
0
def output_snapshot_list(snapshots=None):
    """
    @type snapshots: list
    """
    td = list()
    table_header = [Color('{autoblue}name{/autoblue}'),
                    Color('{autoblue}id{/autoblue}'),
                    Color('{autoblue}size (GiB){/autoblue}'),
                    Color('{autoblue}description{/autoblue}'),
                    Color('{autoblue}status{/autoblue}'),
                    Color('{autoblue}started{/autoblue}'),
                    Color('{autoblue}progress{/autoblue}'),
                    Color('{autoblue}encrypted{/autoblue}')]
    for snapshot in snapshots:
        td.append([dash_if_none(snapshot.get('Tags')),
                   dash_if_none(snapshot.get('SnapshotId')),
                   dash_if_none(snapshot.get('VolumeSize')),
                   dash_if_none(snapshot.get('Description')),
                   dash_if_none(snapshot.get('State')),
                   dash_if_none(snapshot.get('StartTime (UTC)')),
                   dash_if_none(snapshot.get('Progress')),
                   str(snapshot.get('Encrypted'))])
    output_ascii_table_list(table_title=Color('{autowhite}orphaned snapshots{/autowhite}'),
                            table_data=td,
                            table_header=table_header,
                            inner_heading_row_border=True)
    exit(0)
Beispiel #14
0
def output_snapshot_list(snapshots=None):
    """
    @type snapshots: list
    """
    td = list()
    table_header = [
        Color('{autoblue}name{/autoblue}'),
        Color('{autoblue}id{/autoblue}'),
        Color('{autoblue}size (GiB){/autoblue}'),
        Color('{autoblue}description{/autoblue}'),
        Color('{autoblue}status{/autoblue}'),
        Color('{autoblue}started{/autoblue}'),
        Color('{autoblue}progress{/autoblue}'),
        Color('{autoblue}encrypted{/autoblue}')
    ]
    for snapshot in snapshots:
        td.append([
            dash_if_none(snapshot.get('Tags')),
            dash_if_none(snapshot.get('SnapshotId')),
            dash_if_none(snapshot.get('VolumeSize')),
            dash_if_none(snapshot.get('Description')),
            dash_if_none(snapshot.get('State')),
            dash_if_none(snapshot.get('StartTime (UTC)')),
            dash_if_none(snapshot.get('Progress')),
            str(snapshot.get('Encrypted'))
        ])
    output_ascii_table_list(
        table_title=Color('{autowhite}orphaned snapshots{/autowhite}'),
        table_data=td,
        table_header=table_header,
        inner_heading_row_border=True)
    exit(0)
Beispiel #15
0
def output_eip_list(addresses=None):
    """
    @type addresses: list
    """
    td = list()
    table_header = [Color('{autoblue}public ip{/autoblue}'),
                    Color('{autoblue}instance id{/autoblue}'),
                    Color('{autoblue}domain{/autoblue}'),
                    Color('{autoblue}private ip address{/autoblue}')]
    for addr in addresses:
        td.append([dash_if_none(addr.get('PublicIp')),
                   dash_if_none(addr.get('InstanceId')),
                   dash_if_none(addr.get('Domain')),
                   dash_if_none(addr.get('PrivateIpAddress'))])
    output_ascii_table_list(table_title=Color('{autowhite}address list{/autowhite}'),
                            table_data=td,
                            table_header=table_header,
                            inner_heading_row_border=True)
    exit(0)
Beispiel #16
0
def output_route53_info(zone=None, record_sets=None):
    """
    @type zone: zone
    @type record_sets: ResourceRecordSets
    """
    td = list()
    td.append([
        Color('{autoblue}id{/autoblue}'),
        dash_if_none(zone.get('HostedZone').get('Id'))
    ])
    td.append([
        Color('{autoblue}name{/autoblue}'),
        dash_if_none(zone.get('HostedZone').get('Name'))
    ])
    td.append([
        Color('{autoblue}records{/autoblue}'),
        dash_if_none(zone.get('HostedZone').get('ResourceRecordSetCount'))
    ])
    td.append([
        Color('{autoblue}comment{/autoblue}'),
        dash_if_none(zone.get('HostedZone').get('Config').get('Comment'))
    ])
    td.append([
        Color('{autoblue}private{/autoblue}'),
        dash_if_none(zone.get('HostedZone').get('Config').get('PrivateZone'))
    ])
    td.append([
        Color('{autoblue}name servers{/autoblue}'),
        "\n".join(zone['DelegationSet']['NameServers'])
    ])
    td.append([Color('{autoblue}records{/autoblue}'), ' '])
    td.append(['{0}'.format("-" * 12), '{0}'.format("-" * 20)])
    for record_set in record_sets['ResourceRecordSets']:
        td.append([Color('{autoblue}name{/autoblue}'), record_set['Name']])
        td.append([Color('{autoblue} type{/autoblue}'), record_set['Type']])
        td.append([Color('{autoblue} ttl{/autoblue}'), str(record_set['TTL'])])
        td.append([
            Color('{autoblue} values{/autoblue}'),
            "\n".join(get_record_set_values(record_set['ResourceRecords']))
        ])
    output_ascii_table(table_title=Color('{autowhite}zone info{/autowhite}'),
                       table_data=td)
    exit(0)
Beispiel #17
0
def output_ami_list(output_media='console', amis=None):
    """
    @type output_media: unicode
    @type amis: list
    """
    amis = sorted(amis, key=lambda k: k.get('CreationDate'), reverse=True)
    if output_media == 'console':
        td = list()
        table_header = [Color('{autoblue}image id{/autoblue}'),
                        Color('{autoblue}name{/autoblue}'),
                        Color('{autoblue}created (UTC){/autoblue}')]
        for ami in amis:
            td.append([ami.get('ImageId'),
                       dash_if_none(ami.get('Name')),
                       dash_if_none(trim_creation_date(ami.get('CreationDate')))])
        output_ascii_table_list(table_title=Color('{autowhite}AMIs{/autowhite}'),
                                table_header=table_header,
                                inner_heading_row_border=True,
                                table_data=td)
    exit(0)
Beispiel #18
0
def output_filesystems(filesystems=None):
    """
    @type filesystems: dict
    """
    td = list()
    table_header = [Color('{autoblue}id{/autoblue}'),
                    Color('{autoblue}owner id{/autoblue}'),
                    Color('{autoblue}name{/autoblue}'),
                    Color('{autoblue}state{/autoblue}'),
                    Color('{autoblue}size / time (UTC){/autoblue}'),
                    Color('{autoblue}mode{/autoblue}'),
                    Color('{autoblue}mount targets{/autoblue}'),
                    Color('{autoblue}created (UTC){/autoblue}')
                    ]
    for fs in filesystems:
        size_in_bytes = fs.get('SizeInBytes')
        size_in_bytes_value = size_in_bytes.get('Value')
        if size_in_bytes_value:
            size_in_bytes_value = humanize.naturalsize(size_in_bytes_value)
        size_in_bytes_timestamp = size_in_bytes.get('Timestamp')
        if size_in_bytes_timestamp:
            size_in_bytes_timestamp = size_in_bytes_timestamp.replace(tzinfo=None, second=0)
        created_time = fs.get('CreationTime')
        if created_time:
            created_time = created_time.replace(tzinfo=None, second=0)

        td.append([fs.get('FileSystemId'),
                   fs.get('OwnerId'),
                   fs.get('Name'),
                   colour_state(fs.get('LifeCycleState')),
                   '{0} / {1}'.format(size_in_bytes_value,
                                      dash_if_none(size_in_bytes_timestamp)),
                   fs.get('PerformanceMode'),
                   fs.get('NumberOfMountTargets'),
                   dash_if_none(created_time)
                   ])
    output_ascii_table_list(table_title=Color('{autowhite}EFS{/autowhite}'),
                            table_data=td,
                            table_header=table_header,
                            inner_heading_row_border=True)
    exit(0)
Beispiel #19
0
def output_elb_info(elb=None):
    """
    @type elb: dict
    """
    td = list()
    td.append(
        [Color('{autoblue}name{/autoblue}'),
         elb.get('LoadBalancerName')])
    td.append([Color('{autoblue}dns name{/autoblue}'), elb.get('DNSName')])
    # print(elb.get('ListenerDescriptions'))
    td.append([
        Color('{autoblue}listeners{/autoblue}'),
        dash_if_none(get_elb_listeners(elb.get('ListenerDescriptions')))
    ])
    td.append([
        Color('{autoblue}canonical hosted zone name{/autoblue}'),
        dash_if_none(elb.get('CanonicalHostedZoneName'))
    ])
    td.append([
        Color('{autoblue}canonical hosted zone name id{/autoblue}'),
        dash_if_none(elb.get('CanonicalHostedZoneNameID'))
    ])
    # td.append(['connection', str(elb.connection)])
    # td.append(['policies', dash_if_none(get_elb_policies(elb.get('Policies)))])
    td.append([
        Color('{autoblue}health check{/autoblue}'),
        dash_if_none(get_healthcheck(elb.get('HealthCheck')))
    ])
    td.append([
        Color('{autoblue}created{/autoblue}'),
        str(
            dash_if_none(
                elb.get('CreatedTime').replace(tzinfo=None, microsecond=0)))
    ])
    # td.append(['instances', get_elb_instances(elb.get('Instances'))])
    td.append([
        Color('{autoblue}availability zones{/autoblue}'),
        ",".join(elb.get('AvailabilityZones'))
    ])
    td.append([
        Color('{autoblue}source security group{/autoblue}'),
        dash_if_none(get_source_secgroup_name(elb.get('SourceSecurityGroup')))
    ])
    td.append([
        Color('{autoblue}security groups{/autoblue}'),
        ",".join(elb.get('SecurityGroups'))
    ])
    td.append(
        [Color('{autoblue}subnets{/autoblue}'), ",".join(elb.get('Subnets'))])
    td.append(
        [Color('{autoblue}vpc id{/autoblue}'),
         dash_if_none(elb.get('VPCId'))])
    output_ascii_table(table_title=Color('{autowhite}elb info{/autowhite}'),
                       table_data=td)
    exit(0)
Beispiel #20
0
def output_lc_list(lc_list=None):
    """
    @type lc_list: list
    """
    if isinstance(lc_list, list):
        td = list()
        table_header = [Color('{autoblue}name{/autoblue}'),
                        Color('{autoblue}image id{/autoblue}'),
                        Color('{autoblue}instance type{/autoblue}'),
                        Color('{autoblue}created{/autoblue}')]
        for lc in lc_list:
            td.append([
                      dash_if_none(lc.get('LaunchConfigurationName')),
                      dash_if_none(lc.get('ImageId')),
                      dash_if_none(lc.get('InstanceType')),
                      dash_if_none(lc.get('CreatedTime').replace(tzinfo=None, microsecond=0))
                      ])
        output_ascii_table_list(table_title=Color('{autowhite}launch configurations{/autowhite}'),
                                table_header=table_header,
                                table_data=td,
                                inner_heading_row_border=True)
    exit(0)
Beispiel #21
0
def output_ec2_list(instances=None):
    """
    @type instances: list
    """
    td = list()
    table_header = [
        Color('{autoblue}id{/autoblue}'),
        Color('{autoblue}name{/autoblue}'),
        Color('{autoblue}state{/autoblue}'),
        Color('{autoblue}type{/autoblue}'),
        Color('{autoblue}image{/autoblue}'),
        Color('{autoblue}public ip{/autoblue}'),
        Color('{autoblue}private ip{/autoblue}')
    ]
    instances = sorted(
        instances,
        key=lambda k: get_ec2_instance_tags(ec2_instance=k, tag_key='Name'))
    for instance in instances:
        if instance:
            instance_id = instance.get('InstanceId')
            instance_state = colour_state(instance.get('State').get('Name'))
            instance_type = dash_if_none(str(instance.get('InstanceType')))
            image_id = dash_if_none(instance.get('ImageId'))
            public_ip = dash_if_none(instance.get('PublicIpAddress'))
            private_ip = dash_if_none(instance.get('PrivateIpAddress'))
            instance_name = dash_if_none(
                get_ec2_instance_tags(ec2_instance=instance, tag_key='Name'))
            td.append([
                instance_id, instance_name, instance_state, instance_type,
                image_id, public_ip, private_ip
            ])
    output_ascii_table_list(
        table_title=Color('{autowhite}ec2 instances{/autowhite}'),
        table_header=table_header,
        table_data=td,
        inner_heading_row_border=True)
    exit(0)
Beispiel #22
0
def output_eip_list(addresses=None):
    """
    @type addresses: list
    """
    td = list()
    table_header = [
        Color('{autoblue}public ip{/autoblue}'),
        Color('{autoblue}instance id{/autoblue}'),
        Color('{autoblue}domain{/autoblue}'),
        Color('{autoblue}private ip address{/autoblue}')
    ]
    for addr in addresses:
        td.append([
            dash_if_none(addr.get('PublicIp')),
            dash_if_none(addr.get('InstanceId')),
            dash_if_none(addr.get('Domain')),
            dash_if_none(addr.get('PrivateIpAddress'))
        ])
    output_ascii_table_list(
        table_title=Color('{autowhite}address list{/autowhite}'),
        table_data=td,
        table_header=table_header,
        inner_heading_row_border=True)
    exit(0)
Beispiel #23
0
def output_s3_info(s3_object=None, key=None, bucket=None, owner=None):
    """
    @type s3_object: dict
    @type key: unicode
    @type bucket: unicode
    @type owner: dict
    """
    if key:
        td = list()
        last_modified = str(s3_object['LastModified'].replace(tzinfo=None,
                                                              second=0))
        etag = str(s3_object['ETag'])[1:-1]
        multipart = 'yes' if '-' in etag else 'no'
        td.append(
            [Color('{autoblue}name{/autoblue}'),
             str(key.split('/')[-1])])
        td.append(
            [Color('{autoblue}last modified (UTC){/autoblue}'), last_modified])
        td.append([Color('{autoblue}ETag{/autoblue}'), etag])
        td.append([
            Color('{autoblue}size (bytes){/autoblue}'),
            str(s3_object['ContentLength'])
        ])
        td.append([
            Color('{autoblue}content type{/autoblue}'),
            str(s3_object['ContentType'])
        ])
        td.append([Color('{autoblue}multipart{/autoblue}'), multipart])
        td.append([
            Color('{autoblue}version id{/autoblue}'),
            str(dash_if_none(s3_object.get('VersionId')))
        ])
        table_title = '{0}/{1}/'.format(bucket, '/'.join(key.split('/')[:-1]))
        output_ascii_table(table_title=Color('{autowhite}' + table_title +
                                             '{/autowhite}'),
                           table_data=td)
    else:
        td = list()
        td.append([
            Color('{autoblue}Owner{/autoblue}'),
            Color('{autoblue}Owner ID{/autoblue}')
        ])
        td.append([owner.get('DisplayName'), owner.get('ID')])
        output_ascii_table(
            table_title=Color('{autowhite}s3 buckets owner{/autowhite}'),
            table_data=td,
            inner_heading_row_border=True)
    exit(0)
Beispiel #24
0
def output_eip_info(address=None):
    """
    @type address: dict
    """
    td = list()
    td.append([
        Color('{autoblue}public ip{/autoblue}'),
        dash_if_none(address.get('PublicIp'))
    ])
    td.append([
        Color('{autoblue}allocation id{/autoblue}'),
        dash_if_none(address.get('AllocationId'))
    ])
    td.append([
        Color('{autoblue}instance id{/autoblue}'),
        dash_if_none(address.get('InstanceId'))
    ])
    td.append([
        Color('{autoblue}association id{/autoblue}'),
        dash_if_none(address.get('AssociationId'))
    ])
    td.append([
        Color('{autoblue}domain{/autoblue}'),
        dash_if_none(address.get('Domain'))
    ])
    td.append([
        Color('{autoblue}network interface id{/autoblue}'),
        dash_if_none(address.get('NetworkInterfaceId'))
    ])
    td.append([
        Color('{autoblue}network interface owner id{/autoblue}'),
        dash_if_none(address.get('NetworkInterfaceOwnerId'))
    ])
    td.append([
        Color('{autoblue}private ip{/autoblue}'),
        dash_if_none(address.get('PrivateIpAddress'))
    ])
    output_ascii_table(table_title=Color('{autowhite}eip info{/autowhite}'),
                       table_data=td)
    exit(0)
Beispiel #25
0
def output_eip_info(address=None):
    """
    @type address: dict
    """
    td = list()
    td.append([Color('{autoblue}public ip{/autoblue}'),
               dash_if_none(address.get('PublicIp'))])
    td.append([Color('{autoblue}allocation id{/autoblue}'),
               dash_if_none(address.get('AllocationId'))])
    td.append([Color('{autoblue}instance id{/autoblue}'),
               dash_if_none(address.get('InstanceId'))])
    td.append([Color('{autoblue}association id{/autoblue}'),
               dash_if_none(address.get('AssociationId'))])
    td.append([Color('{autoblue}domain{/autoblue}'),
               dash_if_none(address.get('Domain'))])
    td.append([Color('{autoblue}network interface id{/autoblue}'),
               dash_if_none(address.get('NetworkInterfaceId'))])
    td.append([Color('{autoblue}network interface owner id{/autoblue}'),
               dash_if_none(address.get('NetworkInterfaceOwnerId'))])
    td.append([Color('{autoblue}private ip{/autoblue}'),
               dash_if_none(address.get('PrivateIpAddress'))])
    output_ascii_table(table_title=Color('{autowhite}eip info{/autowhite}'),
                       table_data=td)
    exit(0)
Beispiel #26
0
def get_ec2_instance_tags(ec2_instance=None, tag_key=None, max_length=40):
    """
    @type ec2_instance: ec2.Instance
    @type tag_key: unicode
    @type max_length: int
    """
    if ec2_instance.get('Tags'):
        ret = []
        for tag in ec2_instance.get('Tags'):
            val = tag.get('Value')
            key = tag.get('Key')
            # Return specific tag if provided
            if tag_key and key == tag_key:
                if len(val) >= 1:
                    return val
            else:
                # Return all tags
                if val and len(val) > max_length:
                    val = "{0}...".format(val[:max_length - 3])
                ret.append('{0}: {1}\n'.format(key, dash_if_none(val)))
        return "".join(ret).rstrip()
    else:
        return ""
Beispiel #27
0
def output_s3_info(s3_object=None, key=None, bucket=None, owner=None):
    """
    @type s3_object: dict
    @type key: unicode
    @type bucket: unicode
    @type owner: dict
    """
    if key:
        td = list()
        last_modified = str(s3_object['LastModified'].replace(tzinfo=None, second=0))
        etag = str(s3_object['ETag'])[1:-1]
        multipart = 'yes' if '-' in etag else 'no'
        td.append([Color('{autoblue}name{/autoblue}'),
                   str(key.split('/')[-1])])
        td.append([Color('{autoblue}last modified (UTC){/autoblue}'),
                   last_modified])
        td.append([Color('{autoblue}ETag{/autoblue}'),
                   etag])
        td.append([Color('{autoblue}size (bytes){/autoblue}'),
                   str(s3_object['ContentLength'])])
        td.append([Color('{autoblue}content type{/autoblue}'),
                   str(s3_object['ContentType'])])
        td.append([Color('{autoblue}multipart{/autoblue}'),
                   multipart])
        td.append([Color('{autoblue}version id{/autoblue}'),
                   str(dash_if_none(s3_object.get('VersionId')))])
        table_title = '{0}/{1}/'.format(bucket, '/'.join(key.split('/')[:-1]))
        output_ascii_table(table_title=Color('{autowhite}' + table_title + '{/autowhite}'),
                           table_data=td)
    else:
        td = list()
        td.append([Color('{autoblue}Owner{/autoblue}'), Color('{autoblue}Owner ID{/autoblue}')])
        td.append([owner.get('DisplayName'), owner.get('ID')])
        output_ascii_table(table_title=Color('{autowhite}s3 buckets owner{/autowhite}'),
                           table_data=td,
                           inner_heading_row_border=True)
    exit(0)
Beispiel #28
0
def get_ec2_instance_tags(ec2_instance=None, tag_key=None,
                          max_length=40):
    """
    @type ec2_instance: ec2.Instance
    @type tag_key: unicode
    @type max_length: int
    """
    if ec2_instance.get('Tags'):
        ret = []
        for tag in ec2_instance.get('Tags'):
            val = tag.get('Value')
            key = tag.get('Key')
            # Return specific tag if provided
            if tag_key and key == tag_key:
                if len(val) >= 1:
                    return val
            else:
                # Return all tags
                if val and len(val) > max_length:
                    val = "{0}...".format(val[:max_length - 3])
                ret.append('{0}: {1}\n'.format(key, dash_if_none(val)))
        return "".join(ret).rstrip()
    else:
        return ""
Beispiel #29
0
def output_elb_info(elb=None):
    """
    @type elb: dict
    """
    td = list()
    td.append([Color('{autoblue}name{/autoblue}'),
               elb.get('LoadBalancerName')])
    td.append([Color('{autoblue}dns name{/autoblue}'),
               elb.get('DNSName')])
    # print(elb.get('ListenerDescriptions'))
    td.append([Color('{autoblue}listeners{/autoblue}'),
               dash_if_none(get_elb_listeners(elb.get('ListenerDescriptions')))])
    td.append([Color('{autoblue}canonical hosted zone name{/autoblue}'),
               dash_if_none(elb.get('CanonicalHostedZoneName'))])
    td.append([Color('{autoblue}canonical hosted zone name id{/autoblue}'),
               dash_if_none(elb.get('CanonicalHostedZoneNameID'))])
    # td.append(['connection', str(elb.connection)])
    # td.append(['policies', dash_if_none(get_elb_policies(elb.get('Policies)))])
    td.append([Color('{autoblue}health check{/autoblue}'),
               dash_if_none(get_healthcheck(elb.get('HealthCheck')))])
    td.append([Color('{autoblue}created{/autoblue}'),
               str(dash_if_none(elb.get('CreatedTime').replace(tzinfo=None, microsecond=0)))])
    # td.append(['instances', get_elb_instances(elb.get('Instances'))])
    td.append([Color('{autoblue}availability zones{/autoblue}'),
               ",".join(elb.get('AvailabilityZones'))])
    td.append([Color('{autoblue}source security group{/autoblue}'),
               dash_if_none(get_source_secgroup_name(elb.get('SourceSecurityGroup')))])
    td.append([Color('{autoblue}security groups{/autoblue}'),
               ",".join(elb.get('SecurityGroups'))])
    td.append([Color('{autoblue}subnets{/autoblue}'),
               ",".join(elb.get('Subnets'))])
    td.append([Color('{autoblue}vpc id{/autoblue}'),
               dash_if_none(elb.get('VPCId'))])
    output_ascii_table(table_title=Color('{autowhite}elb info{/autowhite}'),
                       table_data=td)
    exit(0)
Beispiel #30
0
def output_lc_info(lc=None):
    """
    @type lc: dict
    """
    td = list()
    td.append([Color('{autoblue}name{/autoblue}'),
               dash_if_none(lc.get('LaunchConfigurationName'))])
    td.append([Color('{autoblue}image id{/autoblue}'),
               dash_if_none(lc.get('ImageId'))])
    td.append([Color('{autoblue}instance type{/autoblue}'),
               dash_if_none(lc.get('InstanceType'))])
    td.append([Color('{autoblue}created (UTC){/autoblue}'),
               str(dash_if_none(lc.get('CreatedTime').replace(tzinfo=None, microsecond=0)))])
    td.append([Color('{autoblue}iam instance profile{/autoblue}'),
               dash_if_none(lc.get('IamInstanceProfile'))])
    td.append([Color('{autoblue}ebs optimised{/autoblue}'),
               dash_if_none("Yes" if lc.get('EbsOptimized') else "No")])
    td.append([Color('{autoblue}instance monitoring{/autoblue}'),
               dash_if_none("Yes" if lc.get('InstanceMonitoring').get('Enabled') else "No")])
    td.append([Color('{autoblue}classiclink VPC sec groups{/autoblue}'),
               dash_if_none(lc.get('ClassicLinkVPCSecurityGroups'))])
    td.append([Color('{autoblue}block device mappings{/autoblue}'),
               dash_if_none(lc.get('BlockDeviceMappings'))])
    td.append([Color('{autoblue}keypair{/autoblue}'),
               dash_if_none(lc.get('KeyName'))])
    td.append([Color('{autoblue}security groups{/autoblue}'),
               dash_if_none(", ".join(lc.get('SecurityGroups')))])
    td.append([Color('{autoblue}kernel ID{/autoblue}'),
               dash_if_none(lc.get('KernelId'))])
    td.append([Color('{autoblue}ramdisk id{/autoblue}'),
               dash_if_none(lc.get('RamdiskId'))])
    td.append([Color('{autoblue}image id{/autoblue}'),
               dash_if_none(lc.get('ImageId'))])
    td.append([Color('{autoblue}instance typr{/autoblue}'),
               dash_if_none(lc.get('InstanceType'))])
    td.append([Color('{autoblue}associate public ip{/autoblue}'),
               dash_if_none(lc.get('AssociatePublicIpAddress'))])
    td.append([Color('{autoblue}user data{/autoblue}'),
               dash_if_none(lc.get('UserData'))])
    output_ascii_table(table_title=Color('{autowhite}launch configuration info{/autowhite}'),
                       table_data=td)
    exit(0)
Beispiel #31
0
def output_iam_summary(summary_map=None):
    """
    @type summary_map: dict
    """
    td = list()
    td.append([
        Color('{autoblue}users{/autoblue}'),
        dash_if_none(summary_map.get('Users'))
    ])
    td.append([
        Color('{autoblue}groups{/autoblue}'),
        dash_if_none(summary_map.get('Groups'))
    ])
    td.append([
        Color('{autoblue}roles{/autoblue}'),
        dash_if_none(summary_map.get('Roles'))
    ])
    td.append(
        [Color('{autoblue}policies{/autoblue}'),
         summary_map.get('Policies')])
    td.append([
        Color('{autoblue}account access keys present{/autoblue}'),
        summary_map.get('AccountAccessKeysPresent')
    ])
    td.append([
        Color('{autoblue}policy versions in use{/autoblue}'),
        summary_map.get('PolicyVersionsInUse')
    ])
    td.append([
        Color('{autoblue}server certificates{/autoblue}'),
        summary_map.get('ServerCertificates')
    ])
    td.append([
        Color('{autoblue}mfa devices{/autoblue}'),
        dash_if_none(summary_map.get('MFADevices'))
    ])
    td.append([
        Color('{autoblue}mfa devices in use{/autoblue}'),
        summary_map.get('MFADevicesInUse')
    ])
    td.append([
        Color('{autoblue}account MFA enabled{/autoblue}'),
        dash_if_none(summary_map.get('AccountMFAEnabled'))
    ])
    td.append([
        Color('{autoblue}providers{/autoblue}'),
        summary_map.get('Providers')
    ])
    td.append([
        Color('{autoblue}instance profiles{/autoblue}'),
        dash_if_none(summary_map.get('InstanceProfiles'))
    ])
    td.append(["", ""])
    td.append([Color('{autowhite}quotas{/autowhite}'), ""])

    td.append([
        Color('{autoblue}user policy size quota{/autoblue}'),
        dash_if_none(summary_map.get('UserPolicySizeQuota'))
    ])
    td.append([
        Color('{autoblue}assume role policy size quota{/autoblue}'),
        dash_if_none(summary_map.get('AssumeRolePolicySizeQuota'))
    ])
    td.append([
        Color('{autoblue}server certificates quota{/autoblue}'),
        dash_if_none(summary_map.get('ServerCertificatesQuota'))
    ])
    td.append([
        Color('{autoblue}users quota{/autoblue}'),
        dash_if_none(summary_map.get('UsersQuota'))
    ])

    td.append([
        Color('{autoblue}policy size quota{/autoblue}'),
        dash_if_none(summary_map.get('PolicySizeQuota'))
    ])

    td.append([
        Color('{autoblue}attached policies per group quota{/autoblue}'),
        dash_if_none(summary_map.get('AttachedPoliciesPerGroupQuota'))
    ])

    td.append([
        Color('{autoblue}groups per user quota{/autoblue}'),
        dash_if_none(summary_map.get('GroupsPerUserQuota'))
    ])
    td.append([
        Color('{autoblue}groups quota{/autoblue}'),
        dash_if_none(summary_map.get('GroupsQuota'))
    ])
    td.append([
        Color('{autoblue}instance profiles quota{/autoblue}'),
        dash_if_none(summary_map.get('InstanceProfilesQuota'))
    ])
    td.append([
        Color('{autoblue}attached policies per role quota{/autoblue}'),
        dash_if_none(summary_map.get('AttachedPoliciesPerRoleQuota'))
    ])
    td.append([
        Color('{autoblue}access keys per user quota{/autoblue}'),
        dash_if_none(summary_map.get('AccessKeysPerUserQuota'))
    ])
    td.append([
        Color('{autoblue}group policy size quota{/autoblue}'),
        dash_if_none(summary_map.get('GroupPolicySizeQuota'))
    ])
    td.append([
        Color('{autoblue}versions per policy quota{/autoblue}'),
        dash_if_none(summary_map.get('VersionsPerPolicyQuota'))
    ])

    td.append([
        Color('{autoblue}roles quota{/autoblue}'),
        dash_if_none(summary_map.get('RolesQuota'))
    ])

    td.append([
        Color('{autoblue}policy version in use quota{/autoblue}'),
        dash_if_none(summary_map.get('PolicyVersionsInUseQuota'))
    ])
    td.append([
        Color('{autoblue}policies quota{/autoblue}'),
        dash_if_none(summary_map.get('PoliciesQuota'))
    ])
    td.append([
        Color('{autoblue}role policy size quota{/autoblue}'),
        dash_if_none(summary_map.get('RolePolicySizeQuota'))
    ])
    output_ascii_table(
        table_title=Color('{autowhite}iam account summary{/autowhite}'),
        table_data=td)
    exit(0)
Beispiel #32
0
def output_secgroup_info(secgroup=None):
    """
    @type secgroup: ec2.SecurityGroup
    """
    if secgroup:
        td = list()
        td.append(
            [Color('{autoblue}group id{/autoblue}'),
             secgroup.get('GroupId')])
        td.append([
            Color('{autoblue}group name{/autoblue}'),
            secgroup.get('GroupName')
        ])
        td.append([
            Color('{autoblue}description{/autoblue}'),
            secgroup.get('Description')
        ])
        td.append([
            Color('{autoblue}vpc id{/autoblue}'),
            dash_if_none(secgroup.get('VpcId'))
        ])
        if secgroup.get('IpPermissions'):
            td.append(['ip permissions', '{0}'.format("-" * 30)])
            for ip_perm in secgroup.get('IpPermissions'):
                td.append([
                    Color('{autoblue}from port{/autoblue}'),
                    dash_if_none(ip_perm.get('FromPort'))
                ])
                td.append([
                    Color('{autoblue}to port{/autoblue}'),
                    dash_if_none(ip_perm.get('ToPort'))
                ])
                td.append([
                    Color('{autoblue}ip ranges{/autoblue}'),
                    dash_if_none(get_ip_ranges(ip_perm.get('IpRanges')))
                ])
                td.append([
                    Color('{autoblue}ip protocol{/autoblue}'),
                    dash_if_none(ip_perm.get('IpProtocol'))
                ])
                if ip_perm.get('UserIdGroupPairs'):
                    td.append(['user id group pairs', '{0}'.format("-" * 30)])
                    td.append([
                        '',
                        get_uid_group_pairs(
                            uid_gps=ip_perm.get('UserIdGroupPairs'))
                    ])

        if secgroup.get('IpPermissionsEgress'):
            td.append(['ip permissions egress', '{0}'.format("-" * 30)])
            for ip_perm_egress in secgroup.get('IpPermissionsEgress'):
                td.append([
                    Color('{autoblue}prefix list ids{/autoblue}'),
                    dash_if_none(ip_perm_egress.get('PrefixListIds'))
                ])
                td.append([
                    Color('{autoblue}from port{/autoblue}'),
                    dash_if_none(ip_perm_egress.get('FromPort'))
                ])
                td.append([
                    Color('{autoblue}to port{/autoblue}'),
                    dash_if_none(ip_perm_egress.get('ToPort'))
                ])
                td.append([
                    Color('{autoblue}ip ranges{/autoblue}'),
                    dash_if_none(get_ip_ranges(ip_perm_egress.get('IpRanges')))
                ])
                td.append([
                    Color('{autoblue}ip protocol{/autoblue}'),
                    dash_if_none(ip_perm_egress.get('IpProtocol'))
                ])
                if ip_perm_egress.get('UserIdGroupPairs'):
                    td.append(['user id group pairs', '{0}'.format("-" * 30)])
                    td.append([
                        '',
                        get_uid_group_pairs(
                            uid_gps=ip_perm_egress.get('UserIdGroupPairs'))
                    ])
        output_ascii_table(
            table_title=Color('{autowhite}security group info{/autowhite}'),
            table_data=td)
    else:
        exit('Security group does not exist.')
    exit(0)
Beispiel #33
0
def output_iam_user_info(user=None,
                         user_mfa_devices=None,
                         user_access_keys=None,
                         user_policies=None,
                         user_groups=None):
    """
    @type user: dict
    @type user_mfa_devices: list
    @type user_access_keys: list
    @type user_policies: list
    @type user_groups: list
    """
    td = list()
    td.append([
        Color('{autoblue}name{/autoblue}'),
        dash_if_none(user.get('UserName'))
    ])
    td.append(
        [Color('{autoblue}id{/autoblue}'),
         dash_if_none(user.get('UserId'))])
    td.append(
        [Color('{autoblue}arn{/autoblue}'),
         dash_if_none(user.get('Arn'))])
    td.append(
        [Color('{autoblue}path{/autoblue}'),
         dash_if_none(user.get('Path'))])
    td.append([
        Color('{autoblue}password last used{/autoblue}'),
        dash_if_none(user.get('PasswordLastUsed'))
    ])
    td.append([
        Color('{autoblue}created{/autoblue}'),
        dash_if_none(user.get('CreateDate'))
    ])
    if user_groups:
        td.append(
            [Color('{autoblue}groups{/autoblue}'), ",".join(user_groups)])
    else:
        td.append([Color('{autoblue}groups{/autoblue}'), dash_if_none()])
    td.append([
        Color('{autoblue}policies{/autoblue}'),
        dash_if_none(",".join(user_policies))
    ])
    if not user_access_keys:
        td.append([Color('{autoblue}access keys{/autoblue}'), dash_if_none()])
    else:
        td.append([Color('{autowhite}access keys{/autowhite}'), ""])
        for key in user_access_keys:
            td.append([
                Color('{autoblue}  id / status / enabled{/autoblue}'),
                "{0} / {1} / {2}".format(key.get('AccessKeyId'),
                                         colour_staus(key.get('Status')),
                                         key.get('CreateDate'))
            ])
    if not user_mfa_devices:
        td.append([Color('{autoblue}mfa devices{/autoblue}'), dash_if_none()])
    else:
        td.append([Color('{autowhite}mfa devices{/autowhite}'), ""])
        for md in user_mfa_devices:
            td.append([
                Color('{autoblue}  serial / enabled{/autoblue}'),
                "{0} / {1}".format(md.get('SerialNumber'),
                                   md.get('EnableDate'))
            ])

    output_ascii_table(table_title=Color('{autowhite}user info{/autowhite}'),
                       table_data=td)
    exit(0)
Beispiel #34
0
def output_ami_info(output_media='console', ami=None, launch_permissions=None):
    """
    @type output_media: unicode
    @type ami: ec2.Ami
    @type launch_permissions=dict
    """
    if output_media == 'console':
        td = list()
        td.append([Color('{autoblue}id{/autoblue}'),
                   ami.get('ImageId')])
        td.append([Color('{autoblue}name{/autoblue}'),
                   ami.get('Name')])
        td.append([Color('{autoblue}created (UTC){/autoblue}'),
                   dash_if_none(trim_creation_date(ami.get('CreationDate')))])
        td.append([Color('{autoblue}description{/autoblue}'),
                   dash_if_none(ami.get('Description'))])
        td.append([Color('{autoblue}hypervisor{/autoblue}'),
                   dash_if_none(ami.get('Hypervisor'))])
        td.append([Color('{autoblue}public{/autoblue}'),
                   dash_if_none(str(ami.get('Public')))])
        td.append([Color('{autoblue}permissions{/autoblue}'),
                   dash_if_none(str(output_ami_permissions(perms=launch_permissions)))])
        td.append([Color('{autoblue}kernel id{/autoblue}'),
                   dash_if_none(ami.get('KernelId'))])
        td.append([Color('{autoblue}location{/autoblue}'),
                   dash_if_none(ami.get('ImageLocation'))])
        td.append([Color('{autoblue}owner id{/autoblue}'),
                   dash_if_none(ami.get('OwnerId'))])
        td.append([Color('{autoblue}owner alias{/autoblue}'),
                   dash_if_none(ami.get('ImageOwnerAlias'))])
        td.append([Color('{autoblue}platform{/autoblue}'),
                   dash_if_none(ami.get('Platform'))])
        td.append([Color('{autoblue}product codes{/autoblue}'),
                   dash_if_none(get_product_codes(ami.get('ProductCodes')))])
        td.append([Color('{autoblue}root device name{/autoblue}'),
                   dash_if_none(ami.get('RootDeviceName'))])
        td.append([Color('{autoblue}root device typr{/autoblue}'),
                   dash_if_none(ami.get('RootDeviceType'))])
        td.append([Color('{autoblue}sriov net support{/autoblue}'),
                   dash_if_none(ami.get('SriovNetSupport'))])
        td.append([Color('{autoblue}state{/autoblue}'),
                   dash_if_none(ami.get('State'))])
        td.append([Color('{autoblue}virtualisation type{/autoblue}'),
                   dash_if_none(ami.get('VirtualizationType'))])
        td.append([Color('{autoblue}block device mapping{/autoblue}'),
                   get_block_devices(bdms=ami.get('BlockDeviceMappings'))])
        output_ascii_table(table_title=Color('{autowhite}AMI info{/autowhite}'),
                           table_data=td)
    exit(0)
Beispiel #35
0
def output_lc_info(lc=None):
    """
    @type lc: dict
    """
    td = list()
    td.append([
        Color('{autoblue}name{/autoblue}'),
        dash_if_none(lc.get('LaunchConfigurationName'))
    ])
    td.append([
        Color('{autoblue}image id{/autoblue}'),
        dash_if_none(lc.get('ImageId'))
    ])
    td.append([
        Color('{autoblue}instance type{/autoblue}'),
        dash_if_none(lc.get('InstanceType'))
    ])
    td.append([
        Color('{autoblue}created (UTC){/autoblue}'),
        str(
            dash_if_none(
                lc.get('CreatedTime').replace(tzinfo=None, microsecond=0)))
    ])
    td.append([
        Color('{autoblue}iam instance profile{/autoblue}'),
        dash_if_none(lc.get('IamInstanceProfile'))
    ])
    td.append([
        Color('{autoblue}ebs optimised{/autoblue}'),
        dash_if_none("Yes" if lc.get('EbsOptimized') else "No")
    ])
    td.append([
        Color('{autoblue}instance monitoring{/autoblue}'),
        dash_if_none(
            "Yes" if lc.get('InstanceMonitoring').get('Enabled') else "No")
    ])
    td.append([
        Color('{autoblue}classiclink VPC sec groups{/autoblue}'),
        dash_if_none(lc.get('ClassicLinkVPCSecurityGroups'))
    ])
    td.append([
        Color('{autoblue}block device mappings{/autoblue}'),
        dash_if_none(lc.get('BlockDeviceMappings'))
    ])
    td.append([
        Color('{autoblue}keypair{/autoblue}'),
        dash_if_none(lc.get('KeyName'))
    ])
    td.append([
        Color('{autoblue}security groups{/autoblue}'),
        dash_if_none(", ".join(lc.get('SecurityGroups')))
    ])
    td.append([
        Color('{autoblue}kernel ID{/autoblue}'),
        dash_if_none(lc.get('KernelId'))
    ])
    td.append([
        Color('{autoblue}ramdisk id{/autoblue}'),
        dash_if_none(lc.get('RamdiskId'))
    ])
    td.append([
        Color('{autoblue}image id{/autoblue}'),
        dash_if_none(lc.get('ImageId'))
    ])
    td.append([
        Color('{autoblue}instance typr{/autoblue}'),
        dash_if_none(lc.get('InstanceType'))
    ])
    td.append([
        Color('{autoblue}associate public ip{/autoblue}'),
        dash_if_none(lc.get('AssociatePublicIpAddress'))
    ])
    td.append([
        Color('{autoblue}user data{/autoblue}'),
        dash_if_none(lc.get('UserData'))
    ])
    output_ascii_table(
        table_title=Color('{autowhite}launch configuration info{/autowhite}'),
        table_data=td)
    exit(0)
Beispiel #36
0
def output_filesystems(filesystems=None, mount_targets=None):
    """
    @type filesystems: dict
    @type mount_targets: list
    """
    td = list()
    table_header = [
        Color('{autoblue}id{/autoblue}'),
        Color('{autoblue}name{/autoblue}'),
        Color('{autoblue}state{/autoblue}'),
        Color('{autoblue}size / time (UTC){/autoblue}'),
        Color('{autoblue}mode{/autoblue}'),
        Color('{autoblue}mount targets{/autoblue}')
    ]
    fs_ids = list()
    for fs in filesystems:
        size_in_bytes = fs.get('SizeInBytes')
        size_in_bytes_value = size_in_bytes.get('Value')
        if size_in_bytes_value:
            size_in_bytes_value = humanize.naturalsize(size_in_bytes_value)
        size_in_bytes_timestamp = size_in_bytes.get('Timestamp')
        if size_in_bytes_timestamp:
            size_in_bytes_timestamp = size_in_bytes_timestamp.replace(
                tzinfo=None, second=0)
        created_time = fs.get('CreationTime')
        if created_time:
            created_time = created_time.replace(tzinfo=None, second=0)

        td.append([
            fs.get('FileSystemId'),
            dash_if_none(fs.get('Name')),
            colour_state(fs.get('LifeCycleState')),
            '{0} / {1}'.format(size_in_bytes_value,
                               dash_if_none(size_in_bytes_timestamp)),
            fs.get('PerformanceMode'),
            dash_if_none(fs.get('NumberOfMountTargets'))
        ])
        fs_ids.append(fs.get('FileSystemId'))
    output_ascii_table_list(
        table_title=Color('{autowhite}EFS Filesystems{/autowhite}'),
        table_data=td,
        table_header=table_header,
        inner_heading_row_border=True)
    # Output mount targets
    td = list()
    table_header = [
        Color('{autoblue}mount target id{/autoblue}'),
        Color('{autoblue}filesystem id{/autoblue}'),
        Color('{autoblue}lifecycle state{/autoblue}')
    ]
    for mt in mount_targets:
        td.append([
            mt.get('MountTargetId'),
            mt.get('FileSystemId'),
            colour_state(mt.get('LifeCycleState'))
        ])
    output_ascii_table_list(
        table_title=Color('{autowhite}EFS Mount Targets{/autowhite}'),
        table_data=td,
        table_header=table_header,
        inner_heading_row_border=True)
    exit(0)
Beispiel #37
0
def output_ec2_info(instance=None):
    """
    @type instance: ec2.Instance
    """
    td = list()
    td.append([Color('{autoblue}id{/autoblue}'),
               instance.get('InstanceId')])
    td.append([Color('{autoblue}name{/autoblue}'),
               dash_if_none(get_ec2_instance_tags(ec2_instance=instance, tag_key='Name'))])
    td.append([Color('{autoblue}groups{/autoblue}'),
               dash_if_none(get_sec_groups_name_and_id(instance.get('SecurityGroups')))])
    td.append([Color('{autoblue}public ip{/autoblue}'),
               dash_if_none(instance.get('PublicIpAddress'))])
    td.append([Color('{autoblue}public dns name{/autoblue}'),
               dash_if_none(instance.get('PublicDnsName'))])
    td.append([Color('{autoblue}private ip{/autoblue}'),
               dash_if_none(instance.get('PrivateIpAddress'))])
    td.append([Color('{autoblue}private dns name{/autoblue}'),
               dash_if_none(instance.get('PrivateDnsName'))])
    td.append([Color('{autoblue}state{/autoblue}'),
               colour_state(instance.get('State')['Name'])])
    td.append([Color('{autoblue}key name{/autoblue}'),
               dash_if_none(instance.get('KeyName'))])
    td.append([Color('{autoblue}instance type{/autoblue}'),
               dash_if_none(instance.get('InstanceType'))])
    td.append([Color('{autoblue}launch time{/autoblue}'),
               str(instance.get('LaunchTime'))])
    td.append([Color('{autoblue}image id{/autoblue}'),
               dash_if_none(instance.get('ImageId'))])
    td.append([Color('{autoblue}placement{/autoblue}'),
               get_placement_details(instance.get('Placement'))])
    td.append([Color('{autoblue}monitored{/autoblue}'),
               'enabled' if instance.get('Monitoring')['State'] == 'enabled' else 'disabled'])
    td.append([Color('{autoblue}subnet id{/autoblue}'),
               dash_if_none(instance.get('SubnetId'))])
    td.append([Color('{autoblue}vpc id{/autoblue}'),
               dash_if_none(instance.get('VpcId'))])
    td.append([Color('{autoblue}root device type{/autoblue}'),
               dash_if_none(instance.get('RootDeviceType'))])
    td.append([Color('{autoblue}state transition reason{/autoblue}'),
               dash_if_none(instance.get('StateTransitionReason'))])
    td.append([Color('{autoblue}ebs optimized{/autoblue}'),
               dash_if_none(instance.get('EbsOptimized'))])
    td.append([Color('{autoblue}instance profile{/autoblue}'),
               dash_if_none(short_instance_profile(instance.get('IamInstanceProfile')))])
    td.append([Color('{autoblue}tags{/autoblue}'),
               dash_if_none(get_ec2_instance_tags(ec2_instance=instance))])
    td.append([Color('{autoblue}block devices{/autoblue}'),
               dash_if_none(get_block_devices(instance.get('BlockDeviceMappings')))])
    td.append([Color('{autoblue}interfaces{/autoblue}'),
               dash_if_none(get_interfaces(instance.get('NetworkInterfaces')))])
    output_ascii_table(table_title=Color('{autowhite}instance info{/autowhite}'),
                       table_data=td)
    exit(0)
Beispiel #38
0
def output_asg_info(asg=None):
    """
    @type asg: dict
    """
    td = list()
    td.append([Color('{autoblue}name{/autoblue}'),
               dash_if_none(asg.get('AutoScalingGroupName'))])
    # td.append([Color('{autoblue}arn{/autoblue}'), dash_if_none(asg.get('AutoScalingGroupARN'))])
    td.append([Color('{autoblue}lc{/autoblue}'),
               dash_if_none(asg.get('LaunchConfigurationName'))])
    td.append([Color('{autoblue}min size{/autoblue}'),
               str(dash_if_none(asg.get('MinSize')))])
    td.append([Color('{autoblue}max size{/autoblue}'),
               str(dash_if_none(asg.get('MaxSize')))])
    td.append([Color('{autoblue}desired size{/autoblue}'),
               str(dash_if_none(asg.get('DesiredCapacity')))])
    td.append([Color('{autoblue}default cooldown{/autoblue}'),
               str(dash_if_none(asg.get('DefaultCooldown')))])
    td.append([Color('{autoblue}availability zones{/autoblue}'),
               str(dash_if_none('\n'.join(asg.get('AvailabilityZones'))))])
    td.append([Color('{autoblue}load balancer names{/autoblue}'),
               str(dash_if_none('\n'.join(asg.get('LoadBalancerNames'))))])
    td.append([Color('{autoblue}health check type{/autoblue}'),
               str(dash_if_none(asg.get('HealthCheckType')))])
    td.append([Color('{autoblue}health check grace period{/autoblue}'),
               str(dash_if_none(asg.get('HealthCheckGracePeriod')))])
    td.append([Color('{autoblue}instances{/autoblue}'),
               dash_if_none(get_instances_output(asg.get('Instances')))])
    td.append([Color('{autoblue}created{/autoblue}'),
               str(dash_if_none(asg.get('CreatedTime').replace(tzinfo=None, microsecond=0)))])
    td.append([Color('{autoblue}suspended processes{/autoblue}'),
               dash_if_none(asg.get('SuspendedProcesses'))])
    td.append([Color('{autoblue}placement group{/autoblue}'),
               dash_if_none(asg.get('PlacementGroup'))])
    td.append([Color('{autoblue}vpc zone identifier{/autoblue}'),
               str(dash_if_none(asg.get('VPCZoneIdentifier')))])
    td.append([Color('{autoblue}metrics enabled{/autoblue}'),
               dash_if_none(asg.get('EnabledMetrics'))])
    td.append([Color('{autoblue}status{/autoblue}'),
               dash_if_none(asg.get('Status'))])
    td.append([Color('{autoblue}tags{/autoblue}'),
               dash_if_none(get_tags(asg.get('Tags')))])
    td.append([Color('{autoblue}termination policies{/autoblue}'),
               str(dash_if_none(asg.get('TerminationPolicies')))])
    output_ascii_table(table_title=Color('{autowhite}asg info{/autowhite}'),
                       table_data=td)
    exit(0)
Beispiel #39
0
def output_asg_info(asg=None):
    """
    @type asg: dict
    """
    td = list()
    td.append([
        Color('{autoblue}name{/autoblue}'),
        dash_if_none(asg.get('AutoScalingGroupName'))
    ])
    # td.append([Color('{autoblue}arn{/autoblue}'), dash_if_none(asg.get('AutoScalingGroupARN'))])
    td.append([
        Color('{autoblue}lc{/autoblue}'),
        dash_if_none(asg.get('LaunchConfigurationName'))
    ])
    td.append([
        Color('{autoblue}min size{/autoblue}'),
        str(dash_if_none(asg.get('MinSize')))
    ])
    td.append([
        Color('{autoblue}max size{/autoblue}'),
        str(dash_if_none(asg.get('MaxSize')))
    ])
    td.append([
        Color('{autoblue}desired size{/autoblue}'),
        str(dash_if_none(asg.get('DesiredCapacity')))
    ])
    td.append([
        Color('{autoblue}default cooldown{/autoblue}'),
        str(dash_if_none(asg.get('DefaultCooldown')))
    ])
    td.append([
        Color('{autoblue}availability zones{/autoblue}'),
        str(dash_if_none('\n'.join(asg.get('AvailabilityZones'))))
    ])
    td.append([
        Color('{autoblue}load balancer names{/autoblue}'),
        str(dash_if_none('\n'.join(asg.get('LoadBalancerNames'))))
    ])
    td.append([
        Color('{autoblue}health check type{/autoblue}'),
        str(dash_if_none(asg.get('HealthCheckType')))
    ])
    td.append([
        Color('{autoblue}health check grace period{/autoblue}'),
        str(dash_if_none(asg.get('HealthCheckGracePeriod')))
    ])
    td.append([
        Color('{autoblue}instances{/autoblue}'),
        dash_if_none(get_instances_output(asg.get('Instances')))
    ])
    td.append([
        Color('{autoblue}created{/autoblue}'),
        str(
            dash_if_none(
                asg.get('CreatedTime').replace(tzinfo=None, microsecond=0)))
    ])
    td.append([
        Color('{autoblue}suspended processes{/autoblue}'),
        dash_if_none(asg.get('SuspendedProcesses'))
    ])
    td.append([
        Color('{autoblue}placement group{/autoblue}'),
        dash_if_none(asg.get('PlacementGroup'))
    ])
    td.append([
        Color('{autoblue}vpc zone identifier{/autoblue}'),
        str(dash_if_none(asg.get('VPCZoneIdentifier')))
    ])
    td.append([
        Color('{autoblue}metrics enabled{/autoblue}'),
        dash_if_none(asg.get('EnabledMetrics'))
    ])
    td.append([
        Color('{autoblue}status{/autoblue}'),
        dash_if_none(asg.get('Status'))
    ])
    td.append([
        Color('{autoblue}tags{/autoblue}'),
        dash_if_none(get_tags(asg.get('Tags')))
    ])
    td.append([
        Color('{autoblue}termination policies{/autoblue}'),
        str(dash_if_none(asg.get('TerminationPolicies')))
    ])
    output_ascii_table(table_title=Color('{autowhite}asg info{/autowhite}'),
                       table_data=td)
    exit(0)
Beispiel #40
0
def output_ec2_info(instance=None):
    """
    @type instance: ec2.Instance
    """
    td = list()
    td.append([Color('{autoblue}id{/autoblue}'), instance.get('InstanceId')])
    td.append([
        Color('{autoblue}name{/autoblue}'),
        dash_if_none(
            get_ec2_instance_tags(ec2_instance=instance, tag_key='Name'))
    ])
    td.append([
        Color('{autoblue}groups{/autoblue}'),
        dash_if_none(get_sec_groups_name_and_id(
            instance.get('SecurityGroups')))
    ])
    td.append([
        Color('{autoblue}public ip{/autoblue}'),
        dash_if_none(instance.get('PublicIpAddress'))
    ])
    td.append([
        Color('{autoblue}public dns name{/autoblue}'),
        dash_if_none(instance.get('PublicDnsName'))
    ])
    td.append([
        Color('{autoblue}private ip{/autoblue}'),
        dash_if_none(instance.get('PrivateIpAddress'))
    ])
    td.append([
        Color('{autoblue}private dns name{/autoblue}'),
        dash_if_none(instance.get('PrivateDnsName'))
    ])
    td.append([
        Color('{autoblue}state{/autoblue}'),
        colour_state(instance.get('State')['Name'])
    ])
    td.append([
        Color('{autoblue}key name{/autoblue}'),
        dash_if_none(instance.get('KeyName'))
    ])
    td.append([
        Color('{autoblue}instance type{/autoblue}'),
        dash_if_none(instance.get('InstanceType'))
    ])
    td.append([
        Color('{autoblue}launch time{/autoblue}'),
        str(instance.get('LaunchTime'))
    ])
    td.append([
        Color('{autoblue}image id{/autoblue}'),
        dash_if_none(instance.get('ImageId'))
    ])
    td.append([
        Color('{autoblue}placement{/autoblue}'),
        get_placement_details(instance.get('Placement'))
    ])
    td.append([
        Color('{autoblue}monitored{/autoblue}'), 'enabled'
        if instance.get('Monitoring')['State'] == 'enabled' else 'disabled'
    ])
    td.append([
        Color('{autoblue}subnet id{/autoblue}'),
        dash_if_none(instance.get('SubnetId'))
    ])
    td.append([
        Color('{autoblue}vpc id{/autoblue}'),
        dash_if_none(instance.get('VpcId'))
    ])
    td.append([
        Color('{autoblue}root device type{/autoblue}'),
        dash_if_none(instance.get('RootDeviceType'))
    ])
    td.append([
        Color('{autoblue}state transition reason{/autoblue}'),
        dash_if_none(instance.get('StateTransitionReason'))
    ])
    td.append([
        Color('{autoblue}ebs optimized{/autoblue}'),
        dash_if_none(instance.get('EbsOptimized'))
    ])
    td.append([
        Color('{autoblue}instance profile{/autoblue}'),
        dash_if_none(short_instance_profile(
            instance.get('IamInstanceProfile')))
    ])
    td.append([
        Color('{autoblue}tags{/autoblue}'),
        dash_if_none(get_ec2_instance_tags(ec2_instance=instance))
    ])
    td.append([
        Color('{autoblue}block devices{/autoblue}'),
        dash_if_none(get_block_devices(instance.get('BlockDeviceMappings')))
    ])
    td.append([
        Color('{autoblue}interfaces{/autoblue}'),
        dash_if_none(get_interfaces(instance.get('NetworkInterfaces')))
    ])
    output_ascii_table(
        table_title=Color('{autowhite}instance info{/autowhite}'),
        table_data=td)
    exit(0)
Beispiel #41
0
def output_filesystem_info(filesystem=None, mount_targets=None):
    """
    @type filesystem: dict
    @type mount_targets: list
    """
    if filesystem:
        filesystem_details = filesystem.get('FileSystems')[0]
        td = list()
        td.append([
            Color('{autoblue}filesystem name{/autoblue}'),
            dash_if_none(filesystem_details.get('Name'))
        ])
        td.append([
            Color('{autoblue}id{/autoblue}'),
            filesystem_details.get('FileSystemId')
        ])
        td.append([
            Color('{autoblue}size{/autoblue}'),
            filesystem_details['SizeInBytes']['Value']
        ])
        td.append([
            Color('{autoblue}owner id{/autoblue}'),
            dash_if_none(filesystem_details.get('OwnerId'))
        ])
        td.append([
            Color('{autoblue}creation time{/autoblue}'),
            dash_if_none(filesystem_details.get('CreationTime'))
        ])
        td.append([
            Color('{autoblue}lifecycle state{/autoblue}'),
            dash_if_none(filesystem_details.get('LifeCycleState'))
        ])
        td.append([
            Color('{autoblue}no. mount targets{/autoblue}'),
            dash_if_none(filesystem_details.get('NumberOfMountTargets'))
        ])
        td.append([
            Color('{autoblue}performance mode{/autoblue}'),
            dash_if_none(filesystem_details.get('PerformanceMode'))
        ])
        td.append([
            Color('{autoblue}creation token{/autoblue}'),
            dash_if_none(filesystem_details.get('CreationToken'))
        ])
        output_ascii_table(
            table_title=Color('{autowhite}EFS filesystem info{/autowhite}'),
            table_data=td)
    else:
        exit('filesystem does not exist.')

    if mount_targets:
        table_header = [
            Color('{autoblue}mount target id{/autoblue}'),
            Color('{autoblue}filesystem id{/autoblue}'),
            Color('{autoblue}lifecycle state{/autoblue}'),
            Color('{autoblue}ip address{/autoblue}'),
            Color('{autoblue}subnet id{/autoblue}'),
            Color('{autoblue}interface id{/autoblue}'),
            Color('{autoblue}owner id{/autoblue}')
        ]
        td = list()
        for mt in mount_targets:
            td.append([
                mt.get('MountTargetId'),
                mt.get('FileSystemId'),
                colour_state(mt.get('LifeCycleState')),
                mt.get('IpAddress'),
                mt.get('SubnetId'),
                mt.get('NetworkInterfaceId'),
                mt.get('OwnerId')
            ])
        output_ascii_table_list(
            table_title=Color('{autowhite}EFS Mount Targets{/autowhite}'),
            table_header=table_header,
            table_data=td,
            inner_heading_row_border=True)
    exit(0)
Beispiel #42
0
def output_ami_info(output_media='console', ami=None, launch_permissions=None):
    """
    @type output_media: unicode
    @type ami: ec2.Ami
    @type launch_permissions=dict
    """
    if output_media == 'console':
        td = list()
        td.append([Color('{autoblue}id{/autoblue}'), ami.get('ImageId')])
        td.append([Color('{autoblue}name{/autoblue}'), ami.get('Name')])
        td.append([
            Color('{autoblue}created (UTC){/autoblue}'),
            dash_if_none(trim_creation_date(ami.get('CreationDate')))
        ])
        td.append([
            Color('{autoblue}description{/autoblue}'),
            dash_if_none(ami.get('Description'))
        ])
        td.append([
            Color('{autoblue}hypervisor{/autoblue}'),
            dash_if_none(ami.get('Hypervisor'))
        ])
        td.append([
            Color('{autoblue}public{/autoblue}'),
            dash_if_none(str(ami.get('Public')))
        ])
        td.append([
            Color('{autoblue}permissions{/autoblue}'),
            dash_if_none(str(output_ami_permissions(perms=launch_permissions)))
        ])
        td.append([
            Color('{autoblue}kernel id{/autoblue}'),
            dash_if_none(ami.get('KernelId'))
        ])
        td.append([
            Color('{autoblue}location{/autoblue}'),
            dash_if_none(ami.get('ImageLocation'))
        ])
        td.append([
            Color('{autoblue}owner id{/autoblue}'),
            dash_if_none(ami.get('OwnerId'))
        ])
        td.append([
            Color('{autoblue}owner alias{/autoblue}'),
            dash_if_none(ami.get('ImageOwnerAlias'))
        ])
        td.append([
            Color('{autoblue}platform{/autoblue}'),
            dash_if_none(ami.get('Platform'))
        ])
        td.append([
            Color('{autoblue}product codes{/autoblue}'),
            dash_if_none(get_product_codes(ami.get('ProductCodes')))
        ])
        td.append([
            Color('{autoblue}root device name{/autoblue}'),
            dash_if_none(ami.get('RootDeviceName'))
        ])
        td.append([
            Color('{autoblue}root device typr{/autoblue}'),
            dash_if_none(ami.get('RootDeviceType'))
        ])
        td.append([
            Color('{autoblue}sriov net support{/autoblue}'),
            dash_if_none(ami.get('SriovNetSupport'))
        ])
        td.append([
            Color('{autoblue}state{/autoblue}'),
            dash_if_none(ami.get('State'))
        ])
        td.append([
            Color('{autoblue}virtualisation type{/autoblue}'),
            dash_if_none(ami.get('VirtualizationType'))
        ])
        td.append([
            Color('{autoblue}block device mapping{/autoblue}'),
            get_block_devices(bdms=ami.get('BlockDeviceMappings'))
        ])
        output_ascii_table(
            table_title=Color('{autowhite}AMI info{/autowhite}'),
            table_data=td)
    exit(0)