Exemple #1
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Yields:
      A serialized object (dict) describing the results of the operation.
      This description fits the Resource described in the ResourceRegistry under
      'pubsub.projects.snapshots'.
    """
        msgs = self.context['pubsub_msgs']
        pubsub = self.context['pubsub']

        for snapshot_name in args.snapshot:
            snapshot_path = util.SnapshotFormat(snapshot_name)
            delete_req = msgs.PubsubProjectsSnapshotsDeleteRequest(
                snapshot=snapshot_path)

            try:
                pubsub.projects_snapshots.Delete(delete_req)
                failed = None
            except api_ex.HttpError as error:
                exc = exceptions.HttpException(error)
                failed = exc.payload.status_message

            result = util.SnapshotDisplayDict(
                msgs.Snapshot(name=snapshot_path), failed)
            log.DeletedResource(snapshot_path, kind='snapshot', failed=failed)
            yield result
Exemple #2
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Yields:
      A serialized object (dict) describing the results of the operation.
      This description fits the Resource described in the ResourceRegistry under
      'pubsub.projects.snapshots'.
    """
        msgs = self.context['pubsub_msgs']
        pubsub = self.context['pubsub']

        subscription_project = ''
        if args.subscription_project:
            subscription_project = projects_util.ParseProject(
                args.subscription_project).Name()
        subscription_name = args.subscription

        for snapshot_name in args.snapshot:
            snapshot_path = util.SnapshotFormat(snapshot_name)
            create_req = msgs.PubsubProjectsSnapshotsCreateRequest(
                createSnapshotRequest=msgs.CreateSnapshotRequest(
                    subscription=util.SubscriptionFormat(
                        subscription_name, subscription_project)),
                name=snapshot_path)

            # TODO(b/32275310): Conform to gcloud error handling guidelines.
            try:
                result = pubsub.projects_snapshots.Create(create_req)
                failed = None
            except api_ex.HttpError as error:
                result = msgs.Snapshot(name=snapshot_path)
                exc = exceptions.HttpException(error)
                failed = exc.payload.status_message

            result = util.SnapshotDisplayDict(result, failed)
            log.CreatedResource(snapshot_path, kind='snapshot', failed=failed)
            yield result
Exemple #3
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      A serialized object (dict) describing the results of the operation.  This
      description fits the Resource described in the ResourceRegistry under
      'pubsub.subscriptions.seek'.
    """
        msgs = self.context['pubsub_msgs']
        pubsub = self.context['pubsub']

        subscription_path = util.SubscriptionFormat(args.subscription)
        result = {'subscriptionId': subscription_path}

        seek_req = msgs.SeekRequest()
        if args.snapshot:
            if args.snapshot_project:
                snapshot_project = (projects_util.ParseProject(
                    args.snapshot_project).Name())
            else:
                snapshot_project = ''
            seek_req.snapshot = util.SnapshotFormat(args.snapshot,
                                                    snapshot_project)
            result['snapshotId'] = seek_req.snapshot
        else:
            seek_req.time = args.time.strftime('%Y-%m-%dT%H:%M:%S.%fZ')
            result['time'] = seek_req.time

        pubsub.projects_subscriptions.Seek(
            msgs.PubsubProjectsSubscriptionsSeekRequest(
                seekRequest=seek_req, subscription=subscription_path))

        return result