zoneSetLabelsRequest=messages.ZoneSetLabelsRequest( labelFingerprint=disk.labelFingerprint, labels=labels_update.GetOrNone())) else: operation_collection = 'compute.regionOperations' labels_update = labels_util.Diff(additions=add_labels).Apply( messages.RegionSetLabelsRequest.LabelsValue, disk.labels) request = messages.ComputeRegionDisksSetLabelsRequest( project=disk_ref.project, resource=disk_ref.disk, region=disk_ref.region, regionSetLabelsRequest=messages.RegionSetLabelsRequest( labelFingerprint=disk.labelFingerprint, labels=labels_update.GetOrNone())) if not labels_update.needs_update: 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())) AddLabels.detailed_help = ( labels_doc_helper.GenerateDetailedHelpForAddLabels('disk'))
scope_lister=flags.GetDefaultScopeLister(holder.client)) add_labels = labels_util.GetUpdateLabelsDictFromArgs(args) ips_info = api_util.GetInPlaceSnapshotInfo(ips_ref, client, messages) ips = ips_info.GetInPlaceSnapshotResource() set_label_req = ips_info.GetSetLabelsRequestMessage() labels_update = labels_util.Diff(additions=add_labels).Apply( set_label_req.LabelsValue, ips.labels) request = ips_info.GetSetInPlaceSnapshotLabelsRequestMessage( ips, labels_update.GetOrNone()) if not labels_update.needs_update: return ips service = ips_info.GetService() operation = service.SetLabels(request) operation_ref = holder.resources.Parse( operation.selfLink, collection=ips_info.GetOperationCollection()) operation_poller = poller.Poller(service) return waiter.WaitFor( operation_poller, operation_ref, 'Updating labels of in-place snapshot [{0}]'.format( ips_ref.Name())) AddLabels.detailed_help = ( labels_doc_helper.GenerateDetailedHelpForAddLabels('in-place-snapshots'))
add_labels = labels_util.GetUpdateLabelsDictFromArgs(args) snapshot = client.snapshots.Get( messages.ComputeSnapshotsGetRequest(**snapshot_ref.AsDict())) labels_update = labels_util.Diff(additions=add_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())) SnapshotsAddLabels.detailed_help = ( labels_doc_helper.GenerateDetailedHelpForAddLabels('snapshot'))
instance = client.instances.Get( messages.ComputeInstancesGetRequest(**instance_ref.AsDict())) labels_update = labels_util.Diff(additions=add_labels).Apply( messages.InstancesSetLabelsRequest.LabelsValue, instance.labels) if not labels_update.needs_update: return instance request = messages.ComputeInstancesSetLabelsRequest( project=instance_ref.project, instance=instance_ref.instance, zone=instance_ref.zone, instancesSetLabelsRequest=messages.InstancesSetLabelsRequest( labelFingerprint=instance.labelFingerprint, labels=labels_update.labels)) operation = client.instances.SetLabels(request) operation_ref = holder.resources.Parse( operation.selfLink, collection='compute.zoneOperations') operation_poller = poller.Poller(client.instances) return waiter.WaitFor( operation_poller, operation_ref, 'Updating labels of instance [{0}]'.format(instance_ref.Name())) InstancesAddLabels.detailed_help = ( labels_doc_helper.GenerateDetailedHelpForAddLabels('instance'))
image = client.images.Get( messages.ComputeImagesGetRequest(**image_ref.AsDict())) replacement = labels_util.UpdateLabels( image.labels, messages.GlobalSetLabelsRequest.LabelsValue, update_labels=add_labels) if not replacement: return image request = messages.ComputeImagesSetLabelsRequest( project=image_ref.project, resource=image_ref.image, globalSetLabelsRequest=messages.GlobalSetLabelsRequest( labelFingerprint=image.labelFingerprint, labels=replacement)) 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())) ImagesAddLabels.detailed_help = ( labels_doc_helper.GenerateDetailedHelpForAddLabels('image'))