Example #1
0
    def Run(self, args):
        """Run 'rolling-updates describe'.

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

    Returns:
      Update, representation of the update if the Get call was
      successful.

    Raises:
      HttpException: An http error response was received while executing api
          request.
      ToolException: An error other than http error occured while executing
          the command.
    """
        client = updater_util.GetApiClientInstance()
        messages = updater_util.GetApiMessages()

        ref = resources.REGISTRY.Parse(
            args.update,
            params={
                'project': properties.VALUES.core.project.GetOrFail,
                'zone': properties.VALUES.compute.zone.GetOrFail,
            },
            collection='replicapoolupdater.rollingUpdates')
        request = messages.ReplicapoolupdaterRollingUpdatesGetRequest(
            project=ref.project,
            zone=ref.zone,
            rollingUpdate=ref.rollingUpdate)

        return client.rollingUpdates.Get(request)
Example #2
0
    def Run(self, args):
        """Run 'rolling-updates list'.

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

    Yields:
      List of all the updates.

    Raises:
      HttpException: An http error response was received while executing api
          request.
      ToolException: An error other than http error occured while executing
          the command.
    """
        client = updater_util.GetApiClientInstance()
        messages = updater_util.GetApiMessages()

        request = messages.ReplicapoolupdaterRollingUpdatesListRequest(
            project=properties.VALUES.core.project.Get(required=True),
            zone=properties.VALUES.compute.zone.Get(required=True))
        if args.group:
            request.filter = 'instanceGroup eq %s' % args.group

        try:
            for item in list_pager.YieldFromList(client.rollingUpdates,
                                                 request,
                                                 limit=args.limit):
                # TODO(user): Consider getting rid of instance group manager in api.
                if item.instanceGroup:
                    item.instanceGroupManager = item.instanceGroup
                yield item
        except apitools_exceptions.HttpError as error:
            raise exceptions.HttpException(updater_util.GetError(error))
Example #3
0
  def Run(self, args):
    """Run 'rolling-updates list-instance-updates'.

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

    Returns:
      List of all the instance updates.

    Raises:
      HttpException: An http error response was received while executing api
          request.
      ToolException: An error other than http error occured while executing
          the command.
    """
    client = updater_util.GetApiClientInstance()
    messages = updater_util.GetApiMessages()

    ref = resources.REGISTRY.Parse(
        args.update,
        collection='replicapoolupdater.rollingUpdates')
    request = (
        messages.ReplicapoolupdaterRollingUpdatesListInstanceUpdatesRequest(
            project=ref.project,
            zone=ref.zone,
            rollingUpdate=ref.rollingUpdate))

    try:
      return list_pager.YieldFromList(
          client.rollingUpdates, request, method='ListInstanceUpdates')
    except apitools_exceptions.HttpError as error:
      raise exceptions.HttpException(error)
Example #4
0
    def Run(self, args):
        """Run 'rolling-updates resume'.

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

    Raises:
      HttpException: An http error response was received while executing api
          request.
      ToolException: An error other than http error occured while executing
          the command.
    """
        client = updater_util.GetApiClientInstance()
        messages = updater_util.GetApiMessages()

        ref = resources.REGISTRY.Parse(
            args.update,
            params={
                'project': properties.VALUES.core.project.GetOrFail,
                'zone': properties.VALUES.compute.zone.GetOrFail,
            },
            collection='replicapoolupdater.rollingUpdates')
        request = messages.ReplicapoolupdaterRollingUpdatesResumeRequest(
            project=ref.project,
            zone=ref.zone,
            rollingUpdate=ref.rollingUpdate)

        try:
            operation = client.rollingUpdates.Resume(request)
            operation_ref = resources.REGISTRY.Parse(
                operation.name,
                params={
                    'project': properties.VALUES.core.project.GetOrFail,
                    'zone': properties.VALUES.compute.zone.GetOrFail,
                },
                collection='replicapoolupdater.zoneOperations')
            result = updater_util.WaitForOperation(client, operation_ref,
                                                   'Resuming the update')
            if result:
                log.status.write('Resumed [{0}].\n'.format(ref))
            else:
                raise exceptions.ToolException(
                    'could not resume [{0}]'.format(ref))

        except apitools_exceptions.HttpError as error:
            raise exceptions.HttpException(error)
Example #5
0
    def Run(self, args):
        """Run 'rolling-updates start'.

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

    Raises:
      HttpException: An http error response was received while executing api
          request.
      ToolException: An error other than http error occured while executing
          the command.
    """
        client = updater_util.GetApiClientInstance()
        messages = updater_util.GetApiMessages()

        request = messages.ReplicapoolupdaterRollingUpdatesInsertRequest(
            project=properties.VALUES.core.project.Get(required=True),
            zone=properties.VALUES.compute.zone.Get(required=True),
            rollingUpdate=self._PrepareUpdate(args))

        try:
            operation = client.rollingUpdates.Insert(request)
            operation_ref = resources.REGISTRY.Parse(
                operation.name, collection='replicapoolupdater.zoneOperations')
            result = updater_util.WaitForOperation(client, operation_ref,
                                                   'Starting a new update')
            if result:
                log.status.write('Started [{0}].\n'.format(
                    operation.targetLink))
            else:
                raise exceptions.ToolException('could not start [{0}]'.format(
                    operation.targetLink))

        except apitools_exceptions.HttpError as error:
            raise exceptions.HttpException(error)