Ejemplo n.º 1
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)
Ejemplo n.º 2
0
  def Run(self, args):
    """Run 'rolling-updates rollback'.

    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 = self.context['updater_api']
    messages = self.context['updater_messages']
    resources = self.context['updater_resources']

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

    try:
      operation = client.rollingUpdates.Rollback(request)
      operation_ref = resources.Parse(
          operation.name,
          collection='replicapoolupdater.zoneOperations')
      result = updater_util.WaitForOperation(
          client, operation_ref, 'Initiating rollback of the update')
      if result:
        log.status.write('Initiated rollback of [{0}].\n'.format(ref))
      else:
        raise exceptions.ToolException(
            'could not initiate rollback of [{0}]'.format(ref))

    except apitools_base.HttpError as error:
      raise exceptions.HttpException(updater_util.GetError(error))
Ejemplo n.º 3
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 = self.context['updater_api']
    messages = self.context['updater_messages']
    resources = self.context['updater_resources']

    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.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(updater_util.GetError(error))