예제 #1
0
파일: route53.py 프로젝트: jonhadfield/acli
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)
예제 #2
0
파일: ec2.py 프로젝트: jonhadfield/acli
def output_ec2_summary(output_media='console', summary=None):
    """
    @type output_media: unicode
    @type summary: dict
    """
    if output_media == 'console':
        td = list()
        instances = summary.get('instances')
        running_count = sum(1 for instance in instances if instance['State']['Name'] in ('pending', 'running'))
        stopped_count = sum(1 for instance in instances if instance['State']['Name'] in ('stopping', 'stopped'))
        no_running_instances = running_count if running_count else 0
        no_stopped_instances = stopped_count if stopped_count else 0
        gp2_no = 0
        io1_no = 0
        standard_no = 0
        gp2_space_sum = 0
        io1_space_sum = 0
        standard_space_sum = 0
        for volume in summary.get('volumes'):
            if volume.get('VolumeType') == 'gp2':
                gp2_no += 1
                gp2_space_sum += volume.get('Size')
            if volume.get('VolumeType') == 'io1':
                io1_no += 1
                io1_space_sum += volume.get('Size')
            if volume.get('VolumeType') == 'standard':
                standard_no += 1
                standard_space_sum += volume.get('Size')

        type_counts = dict()
        type_list = (instance.get('InstanceType') for instance in summary.get('instances'))
        for instance_type in type_list:
            if instance_type in type_counts:
                type_counts[instance_type] += 1
            else:
                type_counts[instance_type] = 1
        import operator
        sorted_type_counts = sorted(type_counts.items(), key=operator.itemgetter(1), reverse=True)
        td.append([Color('{autoblue}running instances{/autoblue}'), str(no_running_instances)])
        td.append([Color('{autoblue}stopped instances{/autoblue}'), str(no_stopped_instances)])
        td.append([Color('{autoblue}load balancers{/autoblue}'), str(summary.get('elbs', '0'))])
        td.append([Color('{autoblue}elastic IPs{/autoblue}'), str(summary.get('eips', '0'))])
        td.append([Color('{autoblue}AMIs{/autoblue}'), str(summary.get('amis', '0'))])
        td.append([Color('{autoblue}security groups{/autoblue}'), str(summary.get('secgroups', '0'))])
        td.append([Color('{autoblue}types{/autoblue}'), '-' * 20])
        for instance_type_count in sorted_type_counts:
            td.append([Color('{autoblue} ' + instance_type_count[0] + '{/autoblue}'), str(instance_type_count[1])])
        td.append([Color('{autoblue}volumes{/autoblue}'), '-' * 20])
        td.append([Color('{autoblue} standard{/autoblue}'),
                   '{0} -Total space: {1} GiB'.format(standard_no, standard_space_sum)])
        td.append([Color('{autoblue} gp2{/autoblue}'), '{0} - Total space: {1} GiB'.format(gp2_no, gp2_space_sum)])
        td.append([Color('{autoblue} io1{/autoblue}'), '{0} - Total space: {1} GiB'.format(io1_no, io1_space_sum)])

        output_ascii_table(table_title=Color('{autowhite}ec2 summary{/autowhite}'),
                           table_data=td)
    exit(0)
예제 #3
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)
예제 #4
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)
예제 #5
0
파일: ec2.py 프로젝트: jonhadfield/acli
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)
예제 #6
0
파일: account.py 프로젝트: jonhadfield/acli
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)
예제 #7
0
파일: ec2.py 프로젝트: jonhadfield/acli
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)
예제 #8
0
파일: account.py 프로젝트: kalaiser/acli
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)
예제 #9
0
파일: s3.py 프로젝트: kalaiser/acli
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)
예제 #10
0
파일: vpc.py 프로젝트: kalaiser/acli
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)
예제 #11
0
파일: asg.py 프로젝트: jonhadfield/acli
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)
예제 #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)
예제 #13
0
파일: route53.py 프로젝트: kalaiser/acli
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)
예제 #14
0
파일: asg.py 프로젝트: jonhadfield/acli
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)
예제 #15
0
파일: efs.py 프로젝트: jonhadfield/acli
def output_filesystem_info(domain=None):
    """
    @type domain: dict
    """
    if domain:
        domain_details = domain.get('DomainStatusList')[0]
        cluster_conf = domain_details.get('ElasticsearchClusterConfig')
        td = list()
        td.append([Color('{autoblue}domain name{/autoblue}'),
                   domain_details.get('DomainName')])
        td.append([Color('{autoblue}endpoint{/autoblue}'),
                   domain_details.get('Endpoint')])
        td.append([Color('{autoblue}created{/autoblue}'),
                   colour_created(domain_details.get('Created'))])
        td.append([Color('{autoblue}deleted{/autoblue}'),
                   colour_deleted(domain_details.get('Deleted'))])
        td.append([Color('{autoblue}processing{/autoblue}'),
                   colour_processing(domain_details.get('Processing'))])
        td.append([Color('{autoblue}cluster config{/autoblue}'),
                   ' '])
        td.append([Color('{autoblue} dedicated master enabled{/autoblue}'),
                   str(cluster_conf.get('DedicatedMasterEnabled'))])
        td.append([Color('{autoblue} instance type{/autoblue}'),
                   str(cluster_conf.get('InstanceType'))])
        td.append([Color('{autoblue} instance count{/autoblue}'),
                   str(cluster_conf.get('InstanceCount'))])
        td.append([Color('{autoblue} zone awareness{/autoblue}'),
                   str(cluster_conf.get('ZoneAwarenessEnabled'))])
        td.append([Color('{autoblue}domain id{/autoblue}'),
                   domain_details.get('DomainId')])
        td.append([Color('{autoblue}snapshot options{/autoblue}'),
                   output_dict(domain_details.get('SnapshotOptions'))])
        td.append([Color('{autoblue}advanced options{/autoblue}'),
                   output_dict(domain_details.get('AdvancedOptions'))])
        td.append([Color('{autoblue}ARN{/autoblue}'),
                   domain_details.get('ARN')])
        output_ascii_table(table_title=Color('{autowhite}ES domain info{/autowhite}'),
                           table_data=td)
    else:
        exit('Domain does not exist.')
    exit(0)
예제 #16
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)
예제 #17
0
파일: s3.py 프로젝트: jonhadfield/acli
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)
예제 #18
0
파일: eip.py 프로젝트: jonhadfield/acli
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)
예제 #19
0
파일: elb.py 프로젝트: jonhadfield/acli
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)
예제 #20
0
파일: es.py 프로젝트: kalaiser/acli
def output_domain_info(domain=None):
    """
    @type domain: dict
    """
    if domain:
        domain_details = domain.get('DomainStatusList')[0]
        cluster_conf = domain_details.get('ElasticsearchClusterConfig')
        td = list()
        td.append([
            Color('{autoblue}domain name{/autoblue}'),
            domain_details.get('DomainName')
        ])
        td.append([
            Color('{autoblue}endpoint{/autoblue}'),
            domain_details.get('Endpoint')
        ])
        td.append([
            Color('{autoblue}created{/autoblue}'),
            colour_created(domain_details.get('Created'))
        ])
        td.append([
            Color('{autoblue}deleted{/autoblue}'),
            colour_deleted(domain_details.get('Deleted'))
        ])
        td.append([
            Color('{autoblue}processing{/autoblue}'),
            colour_processing(domain_details.get('Processing'))
        ])
        td.append([Color('{autoblue}cluster config{/autoblue}'), ' '])
        td.append([
            Color('{autoblue} dedicated master enabled{/autoblue}'),
            str(cluster_conf.get('DedicatedMasterEnabled'))
        ])
        td.append([
            Color('{autoblue} instance type{/autoblue}'),
            str(cluster_conf.get('InstanceType'))
        ])
        td.append([
            Color('{autoblue} instance count{/autoblue}'),
            str(cluster_conf.get('InstanceCount'))
        ])
        td.append([
            Color('{autoblue} zone awareness{/autoblue}'),
            str(cluster_conf.get('ZoneAwarenessEnabled'))
        ])
        td.append([
            Color('{autoblue}domain id{/autoblue}'),
            domain_details.get('DomainId')
        ])
        td.append([
            Color('{autoblue}snapshot options{/autoblue}'),
            output_dict(domain_details.get('SnapshotOptions'))
        ])
        td.append([
            Color('{autoblue}advanced options{/autoblue}'),
            output_dict(domain_details.get('AdvancedOptions'))
        ])
        td.append(
            [Color('{autoblue}ARN{/autoblue}'),
             domain_details.get('ARN')])
        output_ascii_table(
            table_title=Color('{autowhite}ES domain info{/autowhite}'),
            table_data=td)
    else:
        exit('Domain does not exist.')
    exit(0)
예제 #21
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)
예제 #22
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)
예제 #23
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)
예제 #24
0
파일: ec2.py 프로젝트: kalaiser/acli
def output_ec2_summary(output_media='console', summary=None):
    """
    @type output_media: unicode
    @type summary: dict
    """
    if output_media == 'console':
        td = list()
        instances = summary.get('instances')
        running_count = sum(1 for instance in instances
                            if instance['State']['Name'] in ('pending',
                                                             'running'))
        stopped_count = sum(1 for instance in instances
                            if instance['State']['Name'] in ('stopping',
                                                             'stopped'))
        no_running_instances = running_count if running_count else 0
        no_stopped_instances = stopped_count if stopped_count else 0
        gp2_no = 0
        io1_no = 0
        standard_no = 0
        gp2_space_sum = 0
        io1_space_sum = 0
        standard_space_sum = 0
        for volume in summary.get('volumes'):
            if volume.get('VolumeType') == 'gp2':
                gp2_no += 1
                gp2_space_sum += volume.get('Size')
            if volume.get('VolumeType') == 'io1':
                io1_no += 1
                io1_space_sum += volume.get('Size')
            if volume.get('VolumeType') == 'standard':
                standard_no += 1
                standard_space_sum += volume.get('Size')

        type_counts = dict()
        type_list = (instance.get('InstanceType')
                     for instance in summary.get('instances'))
        for instance_type in type_list:
            if instance_type in type_counts:
                type_counts[instance_type] += 1
            else:
                type_counts[instance_type] = 1
        import operator
        sorted_type_counts = sorted(type_counts.items(),
                                    key=operator.itemgetter(1),
                                    reverse=True)
        td.append([
            Color('{autoblue}running instances{/autoblue}'),
            str(no_running_instances)
        ])
        td.append([
            Color('{autoblue}stopped instances{/autoblue}'),
            str(no_stopped_instances)
        ])
        td.append([
            Color('{autoblue}load balancers{/autoblue}'),
            str(summary.get('elbs', '0'))
        ])
        td.append([
            Color('{autoblue}elastic IPs{/autoblue}'),
            str(summary.get('eips', '0'))
        ])
        td.append([
            Color('{autoblue}AMIs{/autoblue}'),
            str(summary.get('amis', '0'))
        ])
        td.append([
            Color('{autoblue}security groups{/autoblue}'),
            str(summary.get('secgroups', '0'))
        ])
        td.append([Color('{autoblue}types{/autoblue}'), '-' * 20])
        for instance_type_count in sorted_type_counts:
            td.append([
                Color('{autoblue} ' + instance_type_count[0] + '{/autoblue}'),
                str(instance_type_count[1])
            ])
        td.append([Color('{autoblue}volumes{/autoblue}'), '-' * 20])
        td.append([
            Color('{autoblue} standard{/autoblue}'),
            '{0} -Total space: {1} GiB'.format(standard_no, standard_space_sum)
        ])
        td.append([
            Color('{autoblue} gp2{/autoblue}'),
            '{0} - Total space: {1} GiB'.format(gp2_no, gp2_space_sum)
        ])
        td.append([
            Color('{autoblue} io1{/autoblue}'),
            '{0} - Total space: {1} GiB'.format(io1_no, io1_space_sum)
        ])

        output_ascii_table(
            table_title=Color('{autowhite}ec2 summary{/autowhite}'),
            table_data=td)
    exit(0)
예제 #25
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)
예제 #26
0
파일: asg.py 프로젝트: kalaiser/acli
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)
예제 #27
0
파일: ec2.py 프로젝트: kalaiser/acli
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)
예제 #28
0
파일: ec2.py 프로젝트: kalaiser/acli
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)
예제 #29
0
파일: asg.py 프로젝트: kalaiser/acli
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)
예제 #30
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)