Пример #1
0
    def Run(self, args):
        """Run 'replicapool get'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Raises:
      HttpException: A http error response was received while executing api
          request.
      ToolException: An error other than http error occured while executing
          the command.

    Returns:
      The get API's response
    """
        client = self.context['replicapool']
        project = properties.VALUES.core.project.Get(required=True)

        request = client.pools().get(projectName=project,
                                     zone=args.zone,
                                     poolName=args.pool)

        try:
            response = request.execute()
            util.PrettyPrint(response, args.format or 'yaml')
            return response
        except errors.HttpError as error:
            raise exceptions.HttpException(util.GetError(error))
        except errors.Error as error:
            raise exceptions.ToolException(error)
Пример #2
0
    def Run(self, args):
        """Run 'resourceviews get'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      The object representing the resource views.

    Raises:
      HttpException: A http error response was received while executing api
          request.
      ToolException: An error other than http error occured while executing
          the command.
    """
        zone_views_client = self.context['zoneViewsClient']
        region_views_client = self.context['regionViewsClient']

        project = properties.VALUES.core.project.Get(required=True)

        if 'v1beta1' in self.context['api_version']:
            if args.region:
                request = region_views_client.get(projectName=project,
                                                  region=args.region,
                                                  resourceViewName=args.name)
            else:
                request = zone_views_client.get(projectName=project,
                                                zone=args.zone,
                                                resourceViewName=args.name)
        else:
            request = zone_views_client.get(project=project,
                                            zone=args.zone,
                                            resourceView=args.name)

        try:
            response = request.execute()
            if not args.format:
                util.PrettyPrint(response, 'yaml')
            return response
        except errors.HttpError as error:
            raise exceptions.HttpException(util.GetError(error))
        except errors.Error as error:
            raise exceptions.ToolException(error)
Пример #3
0
    def Display(self, args, result):
        """Display prints information about what just happened to stdout.

    Args:
      args: The same as the args in Run.
      result: a list of dicts, where each dict has information about one
          Replica

    Raises:
      ValueError: if result is None or not a list
    """
        if not isinstance(result, list):
            raise ValueError('result must be a list')

        if not result:
            log.Print('No Replicas were found!')
            return

        if args.human_readable:
            util.PrintTable(result, 'replica')
        else:
            for replica in result:
                util.PrettyPrint(replica, args.format or 'yaml')