def _Run(args, enable_labels=False, legacy_output=False): """Creates one or more subscriptions.""" flags.ValidateDeadLetterPolicy(args) client = subscriptions.SubscriptionsClient() topic_ref = args.CONCEPTS.topic.Parse() push_config = util.ParsePushConfig(args) enable_message_ordering = getattr(args, 'enable_message_ordering', None) filter_string = getattr(args, 'message_filter', None) dead_letter_topic = getattr(args, 'dead_letter_topic', None) max_delivery_attempts = getattr(args, 'max_delivery_attempts', None) retain_acked_messages = getattr(args, 'retain_acked_messages', None) retention_duration = getattr(args, 'message_retention_duration', None) if retention_duration: retention_duration = util.FormatDuration(retention_duration) min_retry_delay = getattr(args, 'min_retry_delay', None) if min_retry_delay: min_retry_delay = util.FormatDuration(min_retry_delay) max_retry_delay = getattr(args, 'max_retry_delay', None) if max_retry_delay: max_retry_delay = util.FormatDuration(max_retry_delay) no_expiration = False expiration_period = getattr(args, 'expiration_period', None) if expiration_period: if expiration_period == subscriptions.NEVER_EXPIRATION_PERIOD_VALUE: no_expiration = True expiration_period = None if dead_letter_topic: dead_letter_topic = args.CONCEPTS.dead_letter_topic.Parse().RelativeName() labels = None if enable_labels: labels = labels_util.ParseCreateArgs( args, client.messages.Subscription.LabelsValue) failed = [] for subscription_ref in args.CONCEPTS.subscription.Parse(): try: result = client.Create( subscription_ref, topic_ref, args.ack_deadline, push_config, retain_acked_messages, retention_duration, labels=labels, no_expiration=no_expiration, expiration_period=expiration_period, enable_message_ordering=enable_message_ordering, filter_string=filter_string, dead_letter_topic=dead_letter_topic, max_delivery_attempts=max_delivery_attempts, min_retry_delay=min_retry_delay, max_retry_delay=max_retry_delay) except api_ex.HttpError as error: exc = exceptions.HttpException(error) log.CreatedResource(subscription_ref.RelativeName(), kind='subscription', failed=exc.payload.status_message) failed.append(subscription_ref.subscriptionsId) continue if legacy_output: result = util.SubscriptionDisplayDict(result) log.CreatedResource(subscription_ref.RelativeName(), kind='subscription') yield result if failed: raise util.RequestsFailedError(failed, 'create')
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.projects.subscriptions'. Raises: An HttpException if there was a problem calling the API subscriptions.Patch command. """ flags.ValidateDeadLetterPolicy(args) client = subscriptions.SubscriptionsClient() subscription_ref = args.CONCEPTS.subscription.Parse() dead_letter_topic = getattr(args, 'dead_letter_topic', None) max_delivery_attempts = getattr(args, 'max_delivery_attempts', None) clear_dead_letter_policy = getattr(args, 'clear_dead_letter_policy', None) clear_retry_policy = getattr(args, 'clear_retry_policy', None) labels_update = labels_util.ProcessUpdateArgsLazy( args, client.messages.Subscription.LabelsValue, orig_labels_thunk=lambda: client.Get(subscription_ref).labels) no_expiration = False expiration_period = getattr(args, 'expiration_period', None) if expiration_period: if expiration_period == subscriptions.NEVER_EXPIRATION_PERIOD_VALUE: no_expiration = True expiration_period = None if dead_letter_topic: dead_letter_topic = args.CONCEPTS.dead_letter_topic.Parse().RelativeName() min_retry_delay = getattr(args, 'min_retry_delay', None) if min_retry_delay: min_retry_delay = util.FormatDuration(min_retry_delay) max_retry_delay = getattr(args, 'max_retry_delay', None) if max_retry_delay: max_retry_delay = util.FormatDuration(max_retry_delay) try: result = client.Patch( subscription_ref, ack_deadline=args.ack_deadline, push_config=util.ParsePushConfig(args), retain_acked_messages=args.retain_acked_messages, labels=labels_update.GetOrNone(), message_retention_duration=args.message_retention_duration, no_expiration=no_expiration, expiration_period=expiration_period, dead_letter_topic=dead_letter_topic, max_delivery_attempts=max_delivery_attempts, clear_dead_letter_policy=clear_dead_letter_policy, clear_retry_policy=clear_retry_policy, min_retry_delay=min_retry_delay, max_retry_delay=max_retry_delay) except subscriptions.NoFieldsSpecifiedError: if not any(args.IsSpecified(arg) for arg in ('clear_labels', 'update_labels', 'remove_labels')): raise log.status.Print('No update to perform.') result = None else: log.UpdatedResource(subscription_ref.RelativeName(), kind='subscription') return result
def Run(self, args): flags.ValidateDeadLetterPolicy(args) return super(UpdateAlpha, self).Run(args)