Esempio n. 1
0
    def get_history(cls,
                    start_date,
                    end_date,
                    name=None,
                    item_type=None,
                    alarm_types=None,
                    sort_descending=True):
        """ Retrieves the history for the specified alarm.
        :param start_date: StartDate=datetime(2015, 1, 1)
        :param end_date: EndDate=datetime(2015, 1, 1)
        :param name: AlarmName='string'
        :param item_type: HistoryItemType='ConfigurationUpdate StateUpdate Action'
        :param alarm_types: AlarmTypes=['CompositeAlarm MetricAlarm']
        :param sort_descending: bool -> ScanBy='TimestampDescending TimestampAscending'
        :return:
        """
        search_kwargs = dict(StartDate=start_date,
                             EndDate=end_date,
                             AlarmTypes=alarm_types,
                             ScanBy='TimestampDescending'
                             if sort_descending else 'TimestampAscending')
        if name:
            search_kwargs['AlarmName'] = name
        if item_type:
            search_kwargs['HistoryItemType'] = item_type

        search_fnc = cls._client.get(
            cls.boto3_client_name).describe_alarm_history
        results = paginated_search(search_fnc, search_kwargs,
                                   'AlarmHistoryItems')
        return [cls(_loaded=True, **result) for result in results]
Esempio n. 2
0
    async def _list(cls, **kwargs) -> list:
        """Returns an instance for each object
        JMESPath for filtering: https://jmespath.org
        :param kwargs:
        :return: list<cls()>
        """
        kwargs = {cls._to_boto3_case(k): v for k, v in kwargs.items() if k not in ['list_kwargs', 'describe_kwargs']}
        response_key = cls._boto3_describe_def.get('response_key', f'{cls.key_prefix}s')
        fnc_base = camel_to_snake(cls.key_prefix)
        fnc_name = cls._boto3_describe_def.get('client_call', f'describe_{fnc_base}s')
        return_val = []

        client = cls._client.get(cls.boto3_client_name)
        boto3_fnc = getattr(client, fnc_name)
        response = paginated_search(boto3_fnc, kwargs, response_key)
        for obj in response:
            loaded_obj = json.loads(obj)
            attributes = loaded_obj['product']['attributes']
            for k, v in attributes.items():
                if attributes[k] == 'Yes':
                    attributes[k] = True
                elif attributes[k] == 'No':
                    attributes[k] = False

            return_val.append(dict(**loaded_obj['terms'], **attributes))

        return [cls(_loaded=True, **obj) for obj in return_val]
Esempio n. 3
0
File: ec2.py Progetto: WillNye/nab3
    async def _list(cls, filters=[], instance_ids=[], **kwargs) -> list:
        """

        :param instance_ids: list<str>
        :param filters: list<dict> Available filter options available in the boto3 link above
        :return:
        """
        search_kwargs = dict(Filters=filters, InstanceIds=instance_ids)
        search_fnc = cls._client.get(cls.boto3_client_name).describe_instances
        results = paginated_search(search_fnc, search_kwargs, 'Reservations')
        instances = list(chain.from_iterable([obj['Instances'] for obj in results]))
        return [cls(_loaded=True, **result) for result in instances]
Esempio n. 4
0
    async def list(cls,
                   fnc_name=None,
                   response_key=None,
                   **kwargs) -> ServiceWrapper:
        """Returns an instance for each object

        :param fnc_name:
        :param response_key:
        :param kwargs:
        :return: list<cls()>
        """
        resp = ServiceWrapper(cls)
        service_list = kwargs.pop('service_list', [])
        boto3_params = cls._boto3_list_def['call_params']
        if not fnc_name:
            fnc_name = cls._boto3_list_def['client_call']
            response_key = cls._boto3_list_def['response_key']

        for param_name, param_attrs in boto3_params.items():
            default_val = param_attrs.get('default')
            value_list = [
                getattr(service, param_name, None) for service in service_list
            ]
            value_list = [v for v in value_list if v]
            kwarg_val = kwargs.pop(param_name, [])
            value_list += kwarg_val if isinstance(kwarg_val,
                                                  list) else [kwarg_val]

            if default_val:
                kwargs[param_attrs['name']] = default_val

            for value in value_list:
                if value:
                    if param_attrs['type'] == list:
                        value = value if isinstance(value, list) else [value]
                        param_val = kwargs.get(param_attrs['name'], []) + value
                        kwargs[param_attrs['name']] = param_val
                    else:
                        kwargs[param_attrs['name']] = value

        kwargs = {cls._to_boto3_case(k): v for k, v in kwargs.items()}
        client = cls._client.get(cls.boto3_client_name)
        boto3_fnc = getattr(client, fnc_name)
        response = paginated_search(boto3_fnc, kwargs, response_key)
        resp.service = [cls(_loaded=True, **obj) for obj in response]

        return resp
Esempio n. 5
0
File: ec2.py Progetto: WillNye/nab3
    async def _list(cls, **kwargs) -> list:
        """Returns an instance for each object
        :param kwargs:
        :return: list<cls()>
        """
        kwargs = {cls._to_boto3_case(k): v for k, v in kwargs.items() if k not in ['list_kwargs', 'describe_kwargs']}
        if not kwargs:
            # If no params are provided only return private images
            kwargs['Filters'] = [dict(Name='is-public', Values=['false'])]

        response_key = cls._boto3_describe_def.get('response_key', f'{cls.key_prefix}s')
        fnc_base = camel_to_snake(cls.key_prefix)
        fnc_name = cls._boto3_describe_def.get('client_call', f'describe_{fnc_base}s')

        client = cls._client.get(cls.boto3_client_name)
        boto3_fnc = getattr(client, fnc_name)
        response = paginated_search(boto3_fnc, kwargs, response_key)
        return [cls(_loaded=True, **obj) for obj in response]