コード例 #1
0
ファイル: snapshots.py プロジェクト: jonhadfield/acli
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)
コード例 #2
0
ファイル: vpc.py プロジェクト: kalaiser/acli
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)
コード例 #3
0
def output_elbs(elbs=None):
    """
    @type elbs: list
    """
    if elbs:
        elbs.sort(key=lambda k: k.get('DNSName'))
        td = list()
        table_header = [
            Color('{autoblue}name{/autoblue}'),
            Color('{autoblue}instances{/autoblue}'),
            Color('{autoblue}dns name{/autoblue}')
        ]
        for elb in elbs:
            td.append([
                elb.get('LoadBalancerName'),
                str(len(elb.get('Instances'))),
                elb.get('DNSName')
            ])
        output_ascii_table_list(
            table_title=Color('{autowhite}ELBs{/autowhite}'),
            table_data=td,
            table_header=table_header,
            inner_heading_row_border=True)
    else:
        print("No ELBs found.")
    exit(0)
コード例 #4
0
ファイル: snapshots.py プロジェクト: kalaiser/acli
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)
コード例 #5
0
ファイル: route53.py プロジェクト: kalaiser/acli
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)
コード例 #6
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)
コード例 #7
0
ファイル: ec2.py プロジェクト: kalaiser/acli
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)
コード例 #8
0
ファイル: ec2.py プロジェクト: jonhadfield/acli
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)
コード例 #9
0
ファイル: route53.py プロジェクト: jonhadfield/acli
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)
コード例 #10
0
ファイル: asg.py プロジェクト: kalaiser/acli
def output_asg_list(asg_list=None):
    """
    @type asg_list: list
    """
    if isinstance(asg_list, list):
        td = list()
        table_header = [
            Color('{autoblue}name{/autoblue}'),
            Color('{autoblue}instances{/autoblue}'),
            Color('{autoblue}desired{/autoblue}'),
            Color('{autoblue}min{/autoblue}'),
            Color('{autoblue}max{/autoblue}'),
            Color('{autoblue}lc{/autoblue}')
        ]
        for asg in asg_list:
            td.append([
                asg.get('AutoScalingGroupName', '-'),
                str(len(asg.get('Instances', '-'))),
                str(asg.get('DesiredCapacity', '-')),
                str(asg.get('MinSize', '-')),
                str(asg.get('MaxSize', '-')),
                asg.get('LaunchConfigurationName', '-')
            ])
        output_ascii_table_list(
            table_title=Color('{autowhite}ASGs{/autowhite}'),
            table_data=td,
            table_header=table_header,
            inner_heading_row_border=True)
    exit(0)
コード例 #11
0
ファイル: asg.py プロジェクト: kalaiser/acli
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)
コード例 #12
0
ファイル: s3.py プロジェクト: jonhadfield/acli
def output_s3_list(buckets=None, bucket_name=None,
                   objects=None, folders=None, item=None):
    """
    @type buckets: dict
    @type bucket_name: unicode
    @type objects: dict
    @type bucket_name: unicode
    @type objects: dict
    @type folders: list
    @type item: unicode
    """
    to_remove_len = 0
    if bucket_name:
        to_remove_len = len(re.sub(bucket_name, '', item)) - 1
    if buckets:
        sorted_buckets = sorted(buckets, key=lambda k: ['Name'])
        td = list()
        td.append([Color('{autoblue}name{/autoblue}'), Color('{autoblue}created{/autoblue}')])
        for bucket in sorted_buckets:
            td.append([bucket.get('Name'),
                       str(bucket.get('CreationDate').replace(tzinfo=None, microsecond=0))])
        output_ascii_table(table_title=Color('{autowhite}s3 buckets{/autowhite}'),
                           table_data=td,
                           inner_heading_row_border=True)

    if any((objects, folders)):
        td = list()
        table_header = [Color('{autoblue}item{/autoblue}'), Color('{autoblue}size (bytes){/autoblue}'),
                        Color('{autoblue}last modified (UTC){/autoblue}'),
                        Color('{autoblue}class{/autoblue}'), Color('{autoblue}etag{/autoblue}')]
        if folders:
            for folder in folders:
                td.append([Color('{autogreen}' + folder.get('Prefix')[to_remove_len:] + '{/autogreen}'),
                           Color('{autoblack}-{/autoblack}'),
                           Color('{autoblack}-{/autoblack}'),
                           Color('{autoblack}-{/autoblack}'),
                           Color('{autoblack}-{/autoblack}')])
        object_list = objects.get('Contents')
        if object_list:
            sorted_object_list = sorted(object_list, key=lambda k: ['Key'])
            for an_object in sorted_object_list:
                an_object_key = an_object.get('Key')[to_remove_len:]
                if an_object_key:
                    td.append([an_object_key,
                               str(an_object.get('Size')),
                               str(an_object.get('LastModified').replace(tzinfo=None, microsecond=0)),
                               str(an_object.get('StorageClass')),
                               str(an_object.get('ETag')[1:-1])])
            if not folders and not td:
                td.append(['', ' ', ' ', ' ', ' '])
        output_ascii_table_list(table_title=Color('{autowhite}' + item + '{/autowhite}'),
                                table_data=td,
                                table_header=table_header,
                                inner_heading_row_border=True)
    exit(0)
コード例 #13
0
ファイル: es.py プロジェクト: jonhadfield/acli
def output_domain_list(domains=None):
    """
    @type domains: dict
    """
    td = list()
    table_header = [Color('{autoblue}domain name{/autoblue}')]
    for domain in domains:
        td.append([domain.get('DomainName')])
    output_ascii_table_list(table_title=Color('{autowhite}ES domains{/autowhite}'),
                            table_data=td,
                            table_header=table_header,
                            inner_heading_row_border=True)
    exit(0)
コード例 #14
0
ファイル: es.py プロジェクト: kalaiser/acli
def output_domain_list(domains=None):
    """
    @type domains: dict
    """
    td = list()
    table_header = [Color('{autoblue}domain name{/autoblue}')]
    for domain in domains:
        td.append([domain.get('DomainName')])
    output_ascii_table_list(
        table_title=Color('{autowhite}ES domains{/autowhite}'),
        table_data=td,
        table_header=table_header,
        inner_heading_row_border=True)
    exit(0)
コード例 #15
0
ファイル: secgroup.py プロジェクト: jonhadfield/acli
def output_secgroup_list(secgroups=None):
    """
    @type secgroups: dict
    """
    td = list()
    table_header = [Color('{autoblue}group id{/autoblue}'),
                    Color('{autoblue}group name{/autoblue}'),
                    Color('{autoblue}description{/autoblue}')]
    for secgroup in secgroups.get('SecurityGroups'):
        td.append([secgroup.get('GroupId'),
                  split_string(secgroup.get('GroupName'), chunk_size=30),
                  split_string(secgroup.get('Description'), chunk_size=40)])
    output_ascii_table_list(table_title=Color('{autowhite}security groups{/autowhite}'),
                            table_data=td,
                            table_header=table_header,
                            inner_heading_row_border=True)
    exit(0)
コード例 #16
0
ファイル: eip.py プロジェクト: jonhadfield/acli
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)
コード例 #17
0
ファイル: elb.py プロジェクト: jonhadfield/acli
def output_elbs(elbs=None):
    """
    @type elbs: list
    """
    if elbs:
        elbs.sort(key=lambda k: k.get('DNSName'))
        td = list()
        table_header = [Color('{autoblue}name{/autoblue}'),
                        Color('{autoblue}instances{/autoblue}'),
                        Color('{autoblue}dns name{/autoblue}')]
        for elb in elbs:
            td.append([elb.get('LoadBalancerName'), str(len(elb.get('Instances'))), elb.get('DNSName')])
        output_ascii_table_list(table_title=Color('{autowhite}ELBs{/autowhite}'),
                                table_data=td,
                                table_header=table_header,
                                inner_heading_row_border=True)
    else:
        print("No ELBs found.")
    exit(0)
コード例 #18
0
ファイル: ec2.py プロジェクト: jonhadfield/acli
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)
コード例 #19
0
ファイル: efs.py プロジェクト: jonhadfield/acli
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)
コード例 #20
0
ファイル: asg.py プロジェクト: jonhadfield/acli
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)
コード例 #21
0
def output_secgroup_list(secgroups=None):
    """
    @type secgroups: dict
    """
    td = list()
    table_header = [
        Color('{autoblue}group id{/autoblue}'),
        Color('{autoblue}group name{/autoblue}'),
        Color('{autoblue}description{/autoblue}')
    ]
    for secgroup in secgroups.get('SecurityGroups'):
        td.append([
            secgroup.get('GroupId'),
            split_string(secgroup.get('GroupName'), chunk_size=30),
            split_string(secgroup.get('Description'), chunk_size=40)
        ])
    output_ascii_table_list(
        table_title=Color('{autowhite}security groups{/autowhite}'),
        table_data=td,
        table_header=table_header,
        inner_heading_row_border=True)
    exit(0)
コード例 #22
0
ファイル: asg.py プロジェクト: jonhadfield/acli
def output_asg_list(asg_list=None):
    """
    @type asg_list: list
    """
    if isinstance(asg_list, list):
        td = list()
        table_header = [Color('{autoblue}name{/autoblue}'), Color('{autoblue}instances{/autoblue}'),
                        Color('{autoblue}desired{/autoblue}'), Color('{autoblue}min{/autoblue}'),
                        Color('{autoblue}max{/autoblue}'),
                        Color('{autoblue}lc{/autoblue}')]
        for asg in asg_list:
            td.append([asg.get('AutoScalingGroupName', '-'),
                       str(len(asg.get('Instances', '-'))),
                       str(asg.get('DesiredCapacity', '-')),
                       str(asg.get('MinSize', '-')),
                       str(asg.get('MaxSize', '-')),
                       asg.get('LaunchConfigurationName', '-')
                       ])
        output_ascii_table_list(table_title=Color('{autowhite}ASGs{/autowhite}'),
                                table_data=td,
                                table_header=table_header,
                                inner_heading_row_border=True)
    exit(0)
コード例 #23
0
ファイル: ec2.py プロジェクト: kalaiser/acli
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)
コード例 #24
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)
コード例 #25
0
ファイル: s3.py プロジェクト: kalaiser/acli
def output_s3_list(buckets=None,
                   bucket_name=None,
                   objects=None,
                   folders=None,
                   item=None):
    """
    @type buckets: dict
    @type bucket_name: unicode
    @type objects: dict
    @type bucket_name: unicode
    @type objects: dict
    @type folders: list
    @type item: unicode
    """
    to_remove_len = 0
    if bucket_name:
        to_remove_len = len(re.sub(bucket_name, '', item)) - 1
    if buckets:
        sorted_buckets = sorted(buckets, key=lambda k: ['Name'])
        td = list()
        td.append([
            Color('{autoblue}name{/autoblue}'),
            Color('{autoblue}created{/autoblue}')
        ])
        for bucket in sorted_buckets:
            td.append([
                bucket.get('Name'),
                str(
                    bucket.get('CreationDate').replace(tzinfo=None,
                                                       microsecond=0))
            ])
        output_ascii_table(
            table_title=Color('{autowhite}s3 buckets{/autowhite}'),
            table_data=td,
            inner_heading_row_border=True)

    if any((objects, folders)):
        td = list()
        table_header = [
            Color('{autoblue}item{/autoblue}'),
            Color('{autoblue}size (bytes){/autoblue}'),
            Color('{autoblue}last modified (UTC){/autoblue}'),
            Color('{autoblue}class{/autoblue}'),
            Color('{autoblue}etag{/autoblue}')
        ]
        if folders:
            for folder in folders:
                td.append([
                    Color('{autogreen}' +
                          folder.get('Prefix')[to_remove_len:] +
                          '{/autogreen}'),
                    Color('{autoblack}-{/autoblack}'),
                    Color('{autoblack}-{/autoblack}'),
                    Color('{autoblack}-{/autoblack}'),
                    Color('{autoblack}-{/autoblack}')
                ])
        object_list = objects.get('Contents')
        if object_list:
            sorted_object_list = sorted(object_list, key=lambda k: ['Key'])
            for an_object in sorted_object_list:
                an_object_key = an_object.get('Key')[to_remove_len:]
                if an_object_key:
                    td.append([
                        an_object_key,
                        str(an_object.get('Size')),
                        str(
                            an_object.get('LastModified').replace(
                                tzinfo=None, microsecond=0)),
                        str(an_object.get('StorageClass')),
                        str(an_object.get('ETag')[1:-1])
                    ])
            if not folders and not td:
                td.append(['', ' ', ' ', ' ', ' '])
        output_ascii_table_list(table_title=Color('{autowhite}' + item +
                                                  '{/autowhite}'),
                                table_data=td,
                                table_header=table_header,
                                inner_heading_row_border=True)
    exit(0)
コード例 #26
0
ファイル: efs.py プロジェクト: kalaiser/acli
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)
コード例 #27
0
ファイル: efs.py プロジェクト: kalaiser/acli
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)