예제 #1
0
파일: __init__.py 프로젝트: lbernail/skew
 def _enumerate_resources(self, service, service_name, region, account,
                          resource_re):
     all_resources = skew.resources.all_types('aws', service_name)
     LOG.debug('account: %s', account)
     LOG.debug('all_resources: %s', all_resources)
     if '/' in resource_re:
         resource_type, resource_id = resource_re.split('/', 1)
     elif ':' in resource_re:
         resource_type, resource_id = resource_re.split(':', 1)
     else:
         resource_type = resource_re
         resource_id = None
     resource_matcher = Matcher(all_resources, resource_type)
     endpoint = Endpoint(service, region, account)
     for resource_type in resource_matcher:
         kwargs = {}
         resource_path = '.'.join(['aws', service_name, resource_type])
         resource_cls = skew.resources.find_resource_class(resource_path)
         do_client_side_filtering = False
         if resource_id and resource_id != '*':
             # If we are looking for a specific resource and the
             # API provides a way to filter on a specific resource
             # id then let's insert the right parameter to do the filtering.
             # If the API does not support that, we will have to filter
             # after we get all of the results.
             filter_name = resource_cls.Meta.filter_name
             if filter_name:
                 if resource_cls.Meta.filter_type == 'list':
                     kwargs[filter_name] = [resource_id]
                 else:
                     kwargs[filter_name] = resource_id
             else:
                 do_client_side_filtering = True
         enum_op, path = resource_cls.Meta.enum_spec
         data = endpoint.call(enum_op, query=path, **kwargs)
         for d in data:
             LOG.debug(d)
             if do_client_side_filtering:
                 # If the API does not support filtering, the resource
                 # class should provide a filter method that will
                 # return True if the returned data matches the
                 # resource ID we are looking for.
                 if not resource_cls.filter(resource_id, d):
                     continue
             resource = resource_cls(endpoint, d)
             self._fire_event('resource-create',
                              self._groups['provider'],
                              service_name,
                              region,
                              account,
                              resource_type,
                              resource.id,
                              resource=resource)
             yield resource
예제 #2
0
def resource_from_arn(arn, data):
    session = botocore.session.get_session()
    parts = ArnComponents(*arn.split(':', 6))
    service = session.get_service(parts.service)
    if ':' in parts.resource:
        resource_type, resource_id = parts.resource.split(':')
    elif '/' in parts.resource:
        resource_type, resource_id = parts.resource.split('/')
    else:
        resource_type = parts.resource
    endpoint = Endpoint(service, parts.region, parts.account)
    resource_path = '.'.join(['aws', parts.service, resource_type])
    resource_cls = find_resource_class(resource_path)
    return resource_cls(endpoint, data)
예제 #3
0
 def __init__(self, endpoint, data):
     self._endpoint = endpoint
     self._region = endpoint.region
     self._account = endpoint.account
     if data is None:
         data = {}
     self.data = data
     if hasattr(self.Meta, 'id') and isinstance(self.data, dict):
         self._id = self.data.get(self.Meta.id, '')
     else:
         self._id = ''
     self._cloudwatch = None
     if hasattr(self.Meta, 'dimension') and self.Meta.dimension:
         cloudwatch = self._endpoint.service.session.get_service(
             'cloudwatch')
         self._cloudwatch = Endpoint(cloudwatch, self._region,
                                     self._account)
     self._metrics = None
     self._name = None
     self._date = None
     self._tags = None