示例#1
0
 def GetResources(self, args, errors):
   zone_names = [
       self.CreateGlobalReference(zone, resource_type='zones').Name()
       for zone in args.zones]
   return lister.GetZonalResources(
       service=self.service,
       project=self.project,
       requested_zones=zone_names,
       filter_expr=self.GetFilterExpr(args),
       http=self.http,
       batch_url=self.batch_url,
       errors=errors)
示例#2
0
def AutoscalersForZone(zone,
                       project,
                       compute,
                       http,
                       batch_url,
                       fail_when_api_not_supported=True):
    """Finds all Autoscalers defined for a given project and zone.

  Args:
    zone: target zone
    project: project owning resources.
    compute: module representing compute api.
    http: communication channel.
    batch_url: batch url.
    fail_when_api_not_supported: If true, raise tool exception if API does not
        support autoscaling.
  Returns:
    A list of Autoscaler objects.
  """
    # Errors is passed through library calls and modified with
    # (ERROR_CODE, ERROR_MESSAGE) tuples.
    errors = []

    if hasattr(compute, 'autoscalers'):
        # Explicit list() is required to unwind the generator and make sure errors
        # are detected at this level.
        autoscalers = list(
            lister.GetZonalResources(
                service=compute.autoscalers,
                project=project,
                requested_zones=[zone],
                http=http,
                batch_url=batch_url,
                errors=errors,
                filter_expr=None,
            ))
    else:
        autoscalers = []
        if fail_when_api_not_supported:
            errors.append((None, 'API does not support autoscaling'))

    if errors:
        utils.RaiseToolException(
            errors,
            error_message='Could not check if the Managed Instance Group is '
            'Autoscaled.')

    return autoscalers
示例#3
0
    def GetInstances(self):
        """Returns a generator of all instances in the project."""
        compute = self.compute
        errors = []
        instances = lister.GetZonalResources(service=compute.instances,
                                             project=self.project,
                                             requested_zones=None,
                                             filter_expr=None,
                                             http=self.http,
                                             batch_url=self.batch_url,
                                             errors=errors)

        if errors:
            base_classes.RaiseToolException(
                errors, error_message='Could not fetch all instances:')
        return instances