Exemplo n.º 1
0
    def get_instances(self, **kwargs):
        # include_pattern
        # exclude_pattern

        raw_res = self.__client[0].describe_instances()
        instances_list = self.__get_just_instances_from_response(raw_res)

        all_running_instances = instances_list  #list(filter(lambda instance: instance['State']['Name'] == 'running', instances_list ))

        res = []
        for instance in all_running_instances:
            instance_tag_name_dict = list(
                filter(lambda tag: tag['Key'] == 'Name',
                       instance.get('Tags', [])))

            if len(instance_tag_name_dict) > 0:
                instance_tag_name_dict = instance_tag_name_dict[0]
            else:
                instance_tag_name_dict = {
                    'Value': "Default"
                } if instance.get('IsDefault') else {
                    'Value': "No Name"
                }

            res.append({
                'Name:': instance_tag_name_dict.get('Value'),
                'InstanceId': instance.get('InstanceId'),
                'VpcId': instance.get('VpcId')
            })

        if self.__debug_mode:
            print_utils.print_list(self.__LOG_OR_STD, self.__SERVICE_NAME,
                                   'instance', res)
        return res
Exemplo n.º 2
0
    def get_vpcs(self, **kwargs):
        # include_pattern
        # exclude_pattern
        vpc_list = self.__client[0].describe_vpcs()['Vpcs']
        res = []
        for vpc in vpc_list:
            vpc_tag_name_dict = list(
                filter(lambda tag: tag['Key'] == 'Name', vpc.get('Tags', [])))

            if len(vpc_tag_name_dict) > 0:
                vpc_tag_name_dict = vpc_tag_name_dict[0]
            else:
                vpc_tag_name_dict = {
                    'Value': "Default"
                } if vpc.get('IsDefault') else {
                    'Value': "No Name"
                }

            res.append({
                'Name:': vpc_tag_name_dict.get('Value'),
                'VpcId': vpc.get('VpcId')
            })

        if self.__debug_mode:
            print_utils.print_list(self.__LOG_OR_STD, self.__SERVICE_NAME,
                                   'Vpc', res)
        return res
Exemplo n.º 3
0
    def _get_clusters(self, **kwargs):
        # include_pattern
        # exclude_pattern
        clusters_arn_list = self.__client[0].list_clusters()['clusterArns']

        res = []
        for cluster_arn in clusters_arn_list:
            container_instance_arns = self.__client[0].list_container_instances(cluster=cluster_arn)['containerInstanceArns']

            container_ec2_instance_list = []
            if len(container_instance_arns) > 0:
                container_ec2_instance_list = self.__client[0].describe_container_instances(
                    cluster=cluster_arn,
                    containerInstances = container_instance_arns,
                )['containerInstances']

            container_ec2_instance_ids = list(map(lambda ec2_instance_dict : ec2_instance_dict.get('ec2InstanceId') , container_ec2_instance_list))

            res.append({
                'Name:' : cluster_arn,
                'container_ec2_instance_ids' : container_ec2_instance_ids
            })

        if self.__debug_mode:
            print_utils.print_list(self.__LOG_OR_STD, self.__SERVICE_NAME ,'clusterArns',res)
        return res
Exemplo n.º 4
0
    def get_subnets(self, **kwargs):
        # include_pattern
        # exclude_pattern
        subnets_list = self.__client[0].describe_subnets()['Subnets']
        res = []
        for subnet in subnets_list:
            subnet_tag_name_dict = list(
                filter(lambda tag: tag['Key'] == 'Name',
                       subnet.get('Tags', [])))

            if len(subnet_tag_name_dict) > 0:
                subnet_tag_name_dict = subnet_tag_name_dict[0]
            else:
                subnet_tag_name_dict = {
                    'Value': "Default"
                } if subnet.get('IsDefault') else {
                    'Value': "No Name"
                }

            res.append({
                'Name:': subnet_tag_name_dict.get('Value'),
                'AvailabilityZone': subnet.get('AvailabilityZone'),
                'SubnetId': subnet.get('SubnetId'),
                'VpcId': subnet.get('VpcId'),
                'MapPublicIpOnLaunch': subnet.get('MapPublicIpOnLaunch')
            })

        if self.__debug_mode:
            print_utils.print_list(self.__LOG_OR_STD, self.__SERVICE_NAME,
                                   'Subnets', res)
        return res
Exemplo n.º 5
0
 def _get_keys_aliases(self, **kwargs):
     # include_pattern
     # exclude_pattern
     keys_list = self.__client[0].list_web_acls()['WebACLs']
     res = list(map(lambda item:item.get('Name'), keys_list))
     if self.__debug_mode:
         print_utils.print_list(self.__LOG_OR_STD, self.__SERVICE_NAME ,'WAF_Web_ACLs',res)
     return res
    def get_trails(self, **kwargs):
        # include_pattern
        # exclude_pattern
        trail_list = self.__client[0].list_trails()['Trails']
        res = list(map(lambda item:item.get('Name'), trail_list))

        if self.__debug_mode:
            print_utils.print_list(self.__LOG_OR_STD, self.__SERVICE_NAME, 'Trails', res)
        return res
Exemplo n.º 7
0
 def _get_queues(self, **kwargs):
     # include_pattern
     # exclude_pattern
     queue_url_list = self.__client[0].list_queues()['QueueUrls']
     res = queue_url_list  # In this case no need for map
     if self.__debug_mode:
         print_utils.print_list(self.__LOG_OR_STD, self.__SERVICE_NAME,
                                'Subscriptions', res)
     return res
    def get_stacks(self, **kwargs):
        # include_pattern
        # exclude_pattern
        stacks_list = self.__client[0].list_stacks()['StackSummaries']
        res = list(map(lambda item: item.get('StackName'), stacks_list))

        if self.__debug_mode:
            print_utils.print_list(self.__LOG_OR_STD, self.__SERVICE_NAME,
                                   'Stacks', res)
        return res
Exemplo n.º 9
0
    def get_hosted_zones(self, **kwargs):
        # include_pattern
        # exclude_pattern
        hosted_zones_list = self.__client[0].list_hosted_zones()['HostedZones']
        res = list(map(lambda item: item.get('Name'), hosted_zones_list))

        if self.__debug_mode:
            print_utils.print_list(self.__LOG_OR_STD, self.__SERVICE_NAME,
                                   'HostedZones', res)
        return res
Exemplo n.º 10
0
 def _get_subscriptions(self, **kwargs):
     # include_pattern
     # exclude_pattern
     subscriptions_list = self.__client[0].list_subscriptions(
     )['Subscriptions']
     res = list(
         map(lambda item: item.get('SubscriptionArn'), subscriptions_list))
     if self.__debug_mode:
         print_utils.print_list(self.__LOG_OR_STD, self.__SERVICE_NAME,
                                'Subscriptions', res)
     return res
 def _get_auto_scaling_groups(self, **kwargs):
     # include_pattern
     # exclude_pattern
     auto_scaling_groups_list = self.__client[
         0].describe_auto_scaling_groups()['AutoScalingGroups']
     res = list(
         map(lambda item: item.get('AutoScalingGroupName'),
             auto_scaling_groups_list))
     if self.__debug_mode:
         print_utils.print_list(self.__LOG_OR_STD, self.__SERVICE_NAME,
                                'AutoScalingGroups', res)
     return res
Exemplo n.º 12
0
def print_deployments(deployments):
    for dep in deployments:
        inputs_view = []
        inputs_line = "%s : %s"
        for i in range(len(dep["inputs"].keys())):
            value = dep["inputs"].values()[i]
            if "password" in dep["inputs"].keys()[i]:
                value = "************"
            if len(str(value)) > 50:
                value = value[:50] + "..."
            inputs_view.append(inputs_line % (dep["inputs"].keys()[i], value))
        dep["inputs"] = "\n".join(inputs_view)
        print_utils.print_list([dep], ["blueprint_id", "id", "created_at", "inputs"], obj_is_dict=True)
Exemplo n.º 13
0
def print_deployments(deployments):
    for dep in deployments:
        inputs_view = []
        inputs_line = "%s : %s"
        for i in range(len(dep['inputs'].keys())):
            value = dep['inputs'].values()[i]
            if 'password' in dep['inputs'].keys()[i]:
                value = '************'
            if len(str(value)) > 50:
                value = value[:50] + '...'
            inputs_view.append(inputs_line % (
                dep['inputs'].keys()[i],
                value))
        dep['inputs'] = "\n".join(inputs_view)
        print_utils.print_list(
            [dep],
            ['blueprint_id', 'id', 'created_at', 'inputs'],
            obj_is_dict=True)
    def _describe_auto_scaling_instances(self, **kwargs):
        # include_pattern
        # exclude_pattern
        asg_instances_list = self.__client[0].describe_auto_scaling_instances(
        )['AutoScalingInstances']

        res = []
        for asg_instance in asg_instances_list:

            res.append({
                'InstanceId:':
                asg_instance.get('InstanceId'),
                'AutoScalingGroupName':
                asg_instance.get('AutoScalingGroupName'),
                'LaunchConfigurationName':
                asg_instance.get('LaunchConfigurationName')
            })

        if self.__debug_mode:
            print_utils.print_list(self.__LOG_OR_STD, self.__SERVICE_NAME,
                                   'AutoScalingInstances', res)
        return res