예제 #1
0
    def Run(self, args):
        self.ref = self.CreateReference(args)
        get_request = self.GetGetRequest(args)

        errors = []
        objects = list(
            request_helper.MakeRequests(requests=[get_request],
                                        http=self.http,
                                        batch_url=self.batch_url,
                                        errors=errors))
        if errors:
            utils.RaiseToolException(
                errors,
                error_message='There was a problem fetching the resource:')

        new_object = self.Modify(args, objects[0])

        # If existing object is equal to the proposed object or if
        # Modify() returns None, then there is no work to be done, so we
        # print the resource and return.
        if not new_object or objects[0] == new_object:
            for resource in lister.ProcessResults(
                    resources=[objects[0]],
                    field_selector=property_selector.PropertySelector(
                        properties=None,
                        transformations=self.transformations)):
                log.status.Print(
                    'No change requested; skipping update for [{0}].'.format(
                        resource[u'name']))
                yield resource
            return

        resource_list = request_helper.MakeRequests(
            requests=[self.GetSetRequest(args, new_object, objects[0])],
            http=self.http,
            batch_url=self.batch_url,
            errors=errors)

        resource_list = lister.ProcessResults(
            resources=resource_list,
            field_selector=property_selector.PropertySelector(
                properties=None, transformations=self.transformations))
        for resource in resource_list:
            yield resource

        if errors:
            utils.RaiseToolException(
                errors,
                error_message='There was a problem modifying the resource:')
예제 #2
0
  def Run(self, args):
    """Yields JSON-serializable dicts of resources."""
    ref = self.CreateReference(args)

    get_request_class = self.service.GetRequestType(self.method)

    request = get_request_class(project=getattr(ref, 'project', self.project))
    self.SetNameField(ref, request)
    self.ScopeRequest(ref, request)

    get_request = (self.service, self.method, request)

    errors = []
    objects = request_helper.MakeRequests(
        requests=[get_request],
        http=self.http,
        batch_url=self.batch_url,
        errors=errors)

    resource_list = lister.ProcessResults(objects, field_selector=None)
    resource_list = list(self.ComputeDynamicProperties(args, resource_list))

    if errors:
      utils.RaiseToolException(
          errors,
          error_message='Could not fetch resource:')
    return resource_list[0]
예제 #3
0
  def _Run(self, args):
    """Yields JSON-serializable dicts of resources or self links."""
    # Data structures used to perform client-side filtering of
    # resources by their names and/or URIs.
    self.self_links = set()
    self.names = set()
    self.resource_refs = []

    # The field selector should be constructed before any resources
    # are fetched, so if there are any syntactic errors with the
    # fields, we can fail fast.
    field_selector = property_selector.PropertySelector(
        properties=None,
        transformations=self.transformations)

    errors = []

    self.PopulateResourceFilteringStructures(args)
    items = self.FilterResults(
        args, self.GetResources(args, errors))
    items = lister.ProcessResults(
        resources=items,
        field_selector=field_selector)
    items = self.ComputeDynamicProperties(args, items)

    for item in items:
      yield item

    if errors:
      utils.RaiseToolException(errors)
예제 #4
0
    def Run(self, args):
        sort_key_fn = None
        descending = False
        errors = []

        if args.uri:
            field_selector = None
        else:
            field_selector = property_selector.PropertySelector(
                properties=None, transformations=self._FIELD_TRANSFORMS)

        sort_key_fn, descending = GetSortKey(args.sort_by, self._LIST_TABS)
        responses, errors = self.GetResources(args)
        if errors:
            utils.RaiseToolException(errors)
        items = lister.ProcessResults(resources=list(
            _UnwrapResponse(responses, self.list_field)),
                                      field_selector=field_selector,
                                      sort_key_fn=sort_key_fn,
                                      reverse_sort=descending,
                                      limit=args.limit)

        for item in items:
            if args.uri:
                yield item['instance']
            else:
                yield item
예제 #5
0
    def Run(self, args):
        request_protobufs = self.CreateRequests(args)
        requests = []
        for request in request_protobufs:
            requests.append((self.service, self.method, request))

        errors = []
        if args. async:
            resources, new_errors = batch_helper.MakeRequests(
                requests=requests, http=self.http, batch_url=self.batch_url)
            if not new_errors:
                for invalidation_operation in resources:
                    log.status.write('Invalidation pending for [{0}]\n'.format(
                        invalidation_operation.targetLink))
                    log.status.write('Monitor its progress at [{0}]\n'.format(
                        invalidation_operation.selfLink))
            errors.extend(new_errors)
        else:
            # We want to run through the generator that MakeRequests returns in order
            # to actually make the requests.
            resources = list(
                request_helper.MakeRequests(requests=requests,
                                            http=self.http,
                                            batch_url=self.batch_url,
                                            errors=errors))

        resources = lister.ProcessResults(
            resources=resources,
            field_selector=property_selector.PropertySelector(
                properties=None, transformations=self.transformations))

        if errors:
            utils.RaiseToolException(errors)

        return resources
예제 #6
0
 def Run(self, args):
     responses, errors = self.GetResources(args)
     if errors:
         utils.RaiseToolException(errors)
     return lister.ProcessResults(resources=list(
         _UnwrapResponse(responses, 'namedPorts')),
                                  field_selector=None,
                                  limit=args.limit)
    def Run(self, args):
        errors = []

        responses, errors = self.GetResources(args)
        if errors:
            utils.RaiseToolException(errors)
        items = lister.ProcessResults(resources=list(
            _UnwrapResponse(responses, self.list_field)),
                                      field_selector=None)

        for item in items:
            yield item
예제 #8
0
    def Run(self, args):
        field_selector = property_selector.PropertySelector(properties=None,
                                                            transformations=[])

        sort_key_fn, descending = GetSortKey(args.sort_by, self._COLUMNS)
        responses, errors = self.GetResources(args)
        if errors:
            utils.RaiseToolException(errors)
        return lister.ProcessResults(resources=list(
            _UnwrapResponse(responses, 'namedPorts')),
                                     field_selector=field_selector,
                                     sort_key_fn=sort_key_fn,
                                     reverse_sort=descending,
                                     limit=args.limit)
예제 #9
0
    def _GetSubnetwork(self, subnetwork_ref):
        get_request = (self.compute.subnetworks, 'Get',
                       self.messages.ComputeSubnetworksGetRequest(
                           project=self.project,
                           region=subnetwork_ref.region,
                           subnetwork=subnetwork_ref.Name()))

        errors = []
        objects = request_helper.MakeRequests(requests=[get_request],
                                              http=self.http,
                                              batch_url=self.batch_url,
                                              errors=errors)

        resources = list(lister.ProcessResults(objects, field_selector=None))
        return resources[0] if resources else None
예제 #10
0
    def Run(self, args):
        errors = []
        requests = self._CreateRequests(args)
        resource_list = self.compute_client.MakeRequests(requests, errors)

        # changes machine type uri to just machine type name
        resource_list = lister.ProcessResults(
            resources=resource_list,
            field_selector=property_selector.PropertySelector(
                properties=None, transformations=self.transformations))

        if errors:
            utils.RaiseToolException(errors)

        return resource_list
예제 #11
0
    def Run(self, args):
        errors = []
        resource_list = self.MakeRequests(self.CreateRequests(args), errors)

        resource_list = lister.ProcessResults(
            resources=resource_list,
            field_selector=property_selector.PropertySelector(
                properties=None, transformations=self.transformations))

        resource_list = self.ComputeDynamicProperties(args, resource_list)

        if errors:
            utils.RaiseToolException(errors)

        return resource_list
예제 #12
0
 def Run(self, args):
     cleared_fields = []
     (service, method, request) = self.CreateRequest(args, cleared_fields)
     errors = []
     with self.compute_client.apitools_client.IncludeFields(cleared_fields):
         resources = list(
             request_helper.MakeRequests(requests=[(service, method,
                                                    request)],
                                         http=self.http,
                                         batch_url=self.batch_url,
                                         errors=errors))
     resources = lister.ProcessResults(
         resources=resources,
         field_selector=property_selector.PropertySelector(
             properties=None, transformations=self.transformations))
     if errors:
         utils.RaiseToolException(errors)
     return resources