コード例 #1
0
    def Run(self, args):
        """Run 'rolling-updates pause'.

    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.ReplicapoolupdaterRollingUpdatesPauseRequest(
            project=ref.project,
            zone=ref.zone,
            rollingUpdate=ref.rollingUpdate)

        try:
            operation = client.rollingUpdates.Pause(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,
                                                   'Pausing the update')
            if result:
                log.status.write('Paused [{0}].\n'.format(ref))
            else:
                raise exceptions.ToolException(
                    'could not pause [{0}]'.format(ref))

        except apitools_exceptions.HttpError as error:
            raise exceptions.HttpException(error)
コード例 #2
0
    def _PrepareUpdate(self, args):
        """Creates an update object based on user-provided flags.

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

    Returns:
      Update, an update object prepared to be used by Insert method.

    Raises:
      SystemExit: Incorrect command line flags.
    """
        messages = updater_util.GetApiMessages()

        policy = messages.RollingUpdate.PolicyValue()
        if args.auto_pause_after_instances:
            policy.autoPauseAfterInstances = args.auto_pause_after_instances
        if args.max_num_concurrent_instances:
            policy.maxNumConcurrentInstances = args.max_num_concurrent_instances
        if args.min_instance_update_time:
            policy.minInstanceUpdateTimeSec = args.min_instance_update_time
        if args.instance_startup_timeout:
            policy.instanceStartupTimeoutSec = args.instance_startup_timeout
        if args.max_num_failed_instances:
            policy.maxNumFailedInstances = args.max_num_failed_instances

        group_ref = resources.REGISTRY.Parse(
            args.group,
            params={
                'project': properties.VALUES.core.project.GetOrFail,
                'zone': properties.VALUES.compute.zone.GetOrFail,
            },
            collection='compute.instanceGroupManagers')
        template_ref = resources.REGISTRY.Parse(
            args.template,
            params={'project': properties.VALUES.core.project.GetOrFail},
            collection='compute.instanceTemplates')

        return messages.RollingUpdate(
            instanceGroupManager=group_ref.SelfLink(),
            actionType=args.action,
            instanceTemplate=template_ref.SelfLink(),
            policy=policy)
コード例 #3
0
ファイル: rollback.py プロジェクト: TobiahRex/Wingman
  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 = updater_util.GetApiClientInstance()
    messages = updater_util.GetApiMessages()

    ref = resources.REGISTRY.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.REGISTRY.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_exceptions.HttpError as error:
      raise exceptions.HttpException(updater_util.GetError(error))
コード例 #4
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,
            params={
                'project': properties.VALUES.core.project.GetOrFail,
                'zone': properties.VALUES.compute.zone.GetOrFail,
            },
            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)
コード例 #5
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(b/36050943): 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(error)
コード例 #6
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)