示例#1
0
    else:
      operation_collection = 'compute.regionOperations'
      replacement = labels_util.UpdateLabels(
          disk.labels,
          messages.RegionSetLabelsRequest.LabelsValue,
          remove_labels=remove_labels)
      request = messages.ComputeRegionDisksSetLabelsRequest(
          project=disk_ref.project,
          resource=disk_ref.disk,
          region=disk_ref.region,
          regionSetLabelsRequest=messages.RegionSetLabelsRequest(
              labelFingerprint=disk.labelFingerprint,
              labels=replacement))

    if not replacement:
      return disk

    operation = service.SetLabels(request)
    operation_ref = holder.resources.Parse(
        operation.selfLink, collection=operation_collection)

    operation_poller = poller.Poller(service)
    return waiter.WaitFor(
        operation_poller, operation_ref,
        'Updating labels of disk [{0}]'.format(
            disk_ref.Name()))


RemoveLabels.detailed_help = (
    labels_doc_helper.GenerateDetailedHelpForRemoveLabels('disk'))
示例#2
0
            # removing all existing labels from the image.
            remove_labels = {}
            if image.labels:
                for label in image.labels.additionalProperties:
                    remove_labels[label.key] = label.value

        labels_update = labels_util.Diff(subtractions=remove_labels).Apply(
            messages.GlobalSetLabelsRequest.LabelsValue, image.labels)
        if not labels_update.needs_update:
            return image

        request = messages.ComputeImagesSetLabelsRequest(
            project=image_ref.project,
            resource=image_ref.image,
            globalSetLabelsRequest=messages.GlobalSetLabelsRequest(
                labelFingerprint=image.labelFingerprint,
                labels=labels_update.labels))

        operation = client.images.SetLabels(request)
        operation_ref = holder.resources.Parse(
            operation.selfLink, collection='compute.globalOperations')

        operation_poller = poller.Poller(client.images)
        return waiter.WaitFor(
            operation_poller, operation_ref,
            'Updating labels of image [{0}]'.format(image_ref.Name()))


ImagesRemoveLabels.detailed_help = (
    labels_doc_helper.GenerateDetailedHelpForRemoveLabels('image'))
            # removing all existing labels from the snapshot.
            remove_labels = {}
            if snapshot.labels:
                for label in snapshot.labels.additionalProperties:
                    remove_labels[label.key] = label.value

        labels_update = labels_util.Diff(subtractions=remove_labels).Apply(
            messages.GlobalSetLabelsRequest.LabelsValue, snapshot.labels)
        if not labels_update.needs_update:
            return snapshot

        request = messages.ComputeSnapshotsSetLabelsRequest(
            project=snapshot_ref.project,
            resource=snapshot_ref.snapshot,
            globalSetLabelsRequest=messages.GlobalSetLabelsRequest(
                labelFingerprint=snapshot.labelFingerprint,
                labels=labels_update.labels))

        operation = client.snapshots.SetLabels(request)
        operation_ref = holder.resources.Parse(
            operation.selfLink, collection='compute.globalOperations')

        operation_poller = poller.Poller(client.snapshots)
        return waiter.WaitFor(
            operation_poller, operation_ref,
            'Updating labels of snapshot [{0}]'.format(snapshot_ref.Name()))


SnapshotsRemoveLabels.detailed_help = (
    labels_doc_helper.GenerateDetailedHelpForRemoveLabels('snapshot'))