Example #1
0
    def Run(self, args):
        """Yields images from (potentially) multiple projects."""
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        client = holder.client

        request_data = lister.ParseNamesAndRegexpFlags(args, holder.resources)

        def ParseProject(project):
            return holder.resources.Parse(None, {'project': project},
                                          collection='compute.projects')

        if args.standard_images:
            for project in constants.PUBLIC_IMAGE_PROJECTS:
                request_data.scope_set.add(ParseProject(project))

        if args.preview_images:
            for project in constants.PREVIEW_IMAGE_PROJECTS:
                request_data.scope_set.add(ParseProject(project))

        list_implementation = lister.MultiScopeLister(
            client, global_service=client.apitools_client.images)

        images = lister.Invoke(request_data, list_implementation)

        return self.AugmentImagesStatus(holder.resources,
                                        self._FilterDeprecated(args, images))
def _Run(args, holder):
    """Issues requests necessary to list Target gRPC Proxies."""
    client = holder.client

    request_data = lister.ParseNamesAndRegexpFlags(args, holder.resources)
    list_implementation = lister.GlobalLister(
        client, client.apitools_client.targetGrpcProxies)

    return lister.Invoke(request_data, list_implementation)
Example #3
0
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        client = holder.client

        request_data = lister.ParseNamesAndRegexpFlags(args, holder.resources)

        list_implementation = lister.GlobalLister(
            client, client.apitools_client.httpsHealthChecks)

        return lister.Invoke(request_data, list_implementation)
Example #4
0
  def Run(self, args):
    holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
    client = holder.client

    request_data = lister.ParseNamesAndRegexpFlags(
        args, holder.resources, client.messages.PublicAdvertisedPrefix)
    list_implementation = lister.GlobalLister(
        client, client.apitools_client.publicAdvertisedPrefixes)

    return lister.Invoke(request_data, list_implementation)
Example #5
0
  def Run(self, args):
    holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
    client = holder.client

    request_data = lister.ParseNamesAndRegexpFlags(args, holder.resources)

    list_implementation = lister.GlobalLister(
        client, client.apitools_client.networks)

    return (networks_utils.AddModesForListFormat(resource)
            for resource in lister.Invoke(request_data, list_implementation))
Example #6
0
  def Run(self, args):
    log.status.Print(flags.LIST_NOTICE)
    holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
    client = holder.client

    request_data = lister.ParseNamesAndRegexpFlags(args, holder.resources)

    list_implementation = lister.GlobalLister(client,
                                              client.apitools_client.firewalls)

    return lister.Invoke(request_data, list_implementation)
Example #7
0
def _Run(args, holder, include_l7_internal_load_balancing):
    """Issues requests necessary to list URL maps."""
    client = holder.client

    if include_l7_internal_load_balancing:
        request_data = lister.ParseMultiScopeFlags(args, holder.resources)
        list_implementation = lister.MultiScopeLister(
            client,
            regional_service=client.apitools_client.regionUrlMaps,
            global_service=client.apitools_client.urlMaps,
            aggregation_service=client.apitools_client.urlMaps)
    else:
        request_data = lister.ParseNamesAndRegexpFlags(args, holder.resources)
        list_implementation = lister.GlobalLister(
            client, client.apitools_client.urlMaps)
    return lister.Invoke(request_data, list_implementation)
Example #8
0
def _Run(args, holder, include_l7_internal_load_balancing,
         return_partial_success):
    """Issues requests necessary to list Target HTTPS Proxies."""
    client = holder.client
    if include_l7_internal_load_balancing:
        request_data = lister.ParseMultiScopeFlags(args, holder.resources)
        list_implementation = lister.MultiScopeLister(
            client,
            regional_service=client.apitools_client.regionTargetHttpsProxies,
            global_service=client.apitools_client.targetHttpsProxies,
            aggregation_service=client.apitools_client.targetHttpsProxies,
            return_partial_success=return_partial_success)
    else:
        request_data = lister.ParseNamesAndRegexpFlags(args, holder.resources)
        list_implementation = lister.GlobalLister(
            client, client.apitools_client.targetHttpsProxies)

    return lister.Invoke(request_data, list_implementation)
Example #9
0
  def testSimple(self):
    resource_registry = resources.REGISTRY.Clone()
    resource_registry.RegisterApiByName('compute', 'v1')

    project = resource_registry.Parse(
        self.Project(), collection='compute.projects')

    args = MockArgs(
        filter=None,
        page_size=None,
        limit=None,
        names=None,
        regexp=None,
    )

    frontend = lister.ParseNamesAndRegexpFlags(args, resource_registry)

    self.assertEqual(args.filter, None)
    self.assertEqual(frontend.filter, None)
    self.assertIsNone(frontend.max_results)
    self.assertEqual(frontend.scope_set, lister.GlobalScope([project]))
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        cua_holder = base_classes.ComputeUserAccountsApiHolder(
            self.ReleaseTrack())
        client = holder.client

        request_data = lister.ParseNamesAndRegexpFlags(args, holder.resources)

        errors = []

        for item in lister.GetGlobalResourcesDicts(
                service=cua_holder.client.users,
                project=list(request_data.scope_set)[0].project,
                filter_expr=request_data.filter,
                http=client.apitools_client.http,
                batch_url='https://www.googleapis.com/batch/',
                errors=errors):
            yield item

        if errors:
            utils.RaiseToolException(errors)
Example #11
0
  def Run(self, args):
    """Yields zonal, regional, and/or global resources."""
    compute_holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
    compute_client = compute_holder.client

    # This is True if the user provided no flags indicating scope.
    no_scope_flags = self.NoArguments(args)

    requests = []
    request_data = lister.ParseNamesAndRegexpFlags(args,
                                                   compute_holder.resources)

    # TODO(b/36050874): Start using aggregatedList for zones and regions when
    # the operations list API supports them.
    if no_scope_flags:
      requests.append(
          (compute_client.apitools_client.globalOperations, 'AggregatedList',
           compute_client.apitools_client.globalOperations.GetRequestType(
               'AggregatedList')(
                   filter=request_data.filter,
                   maxResults=request_data.max_results,
                   project=list(request_data.scope_set)[0].project)))
    else:
      if getattr(args, 'global'):
        requests.append(
            (compute_client.apitools_client.globalOperations, 'List',
             compute_client.apitools_client.globalOperations.GetRequestType(
                 'List')(
                     filter=request_data.filter,
                     maxResults=request_data.max_results,
                     project=list(request_data.scope_set)[0].project)))
      if args.regions is not None:
        args_region_names = [
            compute_holder.resources.Parse(  # pylint:disable=g-complex-comprehension
                region,
                params={'project': properties.VALUES.core.project.GetOrFail},
                collection='compute.regions').Name()
            for region in args.regions or []]
        # If no regions were provided by the user, fetch a list.
        errors = []
        region_names = (
            args_region_names or [res.name for res in lister.GetGlobalResources(  # pylint:disable=g-complex-comprehension
                service=compute_client.apitools_client.regions,
                project=properties.VALUES.core.project.GetOrFail(),
                filter_expr=None,
                http=compute_client.apitools_client.http,
                batch_url=compute_client.batch_url,
                errors=errors)])
        if errors:
          utils.RaiseToolException(
              errors,
              'Unable to fetch a list of regions. Specifying [--regions] may '
              'fix this issue:')
        for region_name in region_names:
          requests.append(
              (compute_client.apitools_client.regionOperations, 'List',
               compute_client.apitools_client.regionOperations.GetRequestType(
                   'List')(
                       filter=request_data.filter,
                       maxResults=request_data.max_results,
                       region=region_name,
                       project=list(request_data.scope_set)[0].project)))
      if args.zones is not None:
        args_zone_names = [
            compute_holder.resources.Parse(  # pylint:disable=g-complex-comprehension
                zone,
                params={
                    'project': properties.VALUES.core.project.GetOrFail,
                },
                collection='compute.zones').Name()
            for zone in args.zones or []]
        # If no zones were provided by the user, fetch a list.
        errors = []
        zone_names = (
            args_zone_names or [res.name for res in lister.GetGlobalResources(  # pylint:disable=g-complex-comprehension
                service=compute_client.apitools_client.zones,
                project=properties.VALUES.core.project.GetOrFail(),
                filter_expr=None,
                http=compute_client.apitools_client.http,
                batch_url=compute_client.batch_url,
                errors=errors)])
        if errors:
          utils.RaiseToolException(
              errors,
              'Unable to fetch a list of zones. Specifying [--zones] may '
              'fix this issue:')
        for zone_name in zone_names:
          requests.append(
              (compute_client.apitools_client.zoneOperations, 'List',
               compute_client.apitools_client.zoneOperations.GetRequestType(
                   'List')(
                       filter=request_data.filter,
                       maxResults=request_data.max_results,
                       zone=zone_name,
                       project=list(request_data.scope_set)[0].project)))
    errors = []
    results = list(
        request_helper.ListJson(
            requests=requests,
            http=compute_client.apitools_client.http,
            batch_url=compute_client.batch_url,
            errors=errors))

    if errors:
      utils.RaiseToolException(errors)

    return results