def Run(self, args):
    client = BmsClient()
    volume = args.CONCEPTS.volume.Parse()
    labels_update = None
    labels_diff = labels_util.Diff.FromUpdateArgs(args)

    if not labels_diff.MayHaveUpdates():
      raise exceptions.NoConfigurationChangeError(
          'No configuration change was requested. Did you mean to include the '
          'flags `--update-labels`, `--remove-labels`, or `--clear-labels?`')

    orig_resource = client.GetVolume(volume)
    labels_update = labels_diff.Apply(
        client.messages.Volume.LabelsValue,
        orig_resource.labels).GetOrNone()

    op_ref = client.UpdateVolume(
        volume_resource=volume,
        labels=labels_update,
        snapshot_schedule_policy_resource=None,
        remove_snapshot_schedule_policy=None,
        snapshot_auto_delete=None)

    if op_ref.done:
      log.UpdatedResource(volume.Name(), kind='volume')
      return op_ref

    if args.async_:
      log.status.Print('Update request issued for: [{}]\nCheck operation '
                       '[{}] for status.'.format(volume.Name(), op_ref.name))
      return op_ref

    op_resource = resources.REGISTRY.ParseRelativeName(
        op_ref.name,
        collection='baremetalsolution.operations',
        api_version='v1')
    poller = waiter.CloudOperationPollerNoResources(
        client.operation_service)
    res = waiter.WaitFor(poller, op_resource,
                         'Waiting for operation [{}] to complete'.format(
                             op_ref.name))
    log.UpdatedResource(volume.Name(), kind='volume')
    return res
Esempio n. 2
0
    def Run(self, args):
        client = BmsClient()
        policy = args.CONCEPTS.snapshot_schedule_policy.Parse()
        description = args.description
        schedules = args.schedule
        labels_update = None
        labels_diff = labels_util.Diff.FromUpdateArgs(args)
        if labels_diff.MayHaveUpdates():
            orig_resource = client.GetSnapshotSchedulePolicy(policy)
            labels_update = labels_diff.Apply(
                client.messages.SnapshotSchedulePolicy.LabelsValue,
                orig_resource.labels).GetOrNone()

        if not description and not schedules and not labels_diff.MayHaveUpdates(
        ):
            raise exceptions.NoConfigurationChangeError(
                'No configuration change was requested. Did you mean to include the '
                'flags `--description` `--schedule` `--update-labels`'
                '`--remove-labels` or `--clear-labels`?')

        return client.UpdateSnapshotSchedulePolicy(policy_resource=policy,
                                                   labels=labels_update,
                                                   description=description,
                                                   schedules=schedules)