def GetLabelBindingNameFromLabelValueAndResource(label_value, resource): """Returns the LabelBinding name for the LabelValue and resource if it exists. Args: label_value: String, numeric id of the LabelValue resource: String, full resource name of the resource Raises: InvalidInputError: if the specified LabelValue and resource are not bound. Returns: The LabelBinding name of the LabelValue bound to the resource. """ labelbindings_service = labelmanager.LabelBindingsService() labelmanager_messages = labelmanager.LabelManagerMessages() list_request = (labelmanager_messages.LabelmanagerLabelBindingsListRequest( filter='labelValue:' + label_value)) response = labelbindings_service.List(list_request) for binding in response.bindings: if (binding.labelValue == label_value and binding.resource == resource): return binding.name raise InvalidInputError( 'Invalid LabelBinding for LabelValue [{}] and resource [{}]'.format( label_value, resource))
def Run(self, args): labelbindings_service = labelmanager.LabelBindingsService() labelmanager_messages = labelmanager.LabelManagerMessages() label_value = utils.GetLabelValueIfArgsAreValid(args) binding = labelmanager_messages.LabelBinding(labelValue=label_value, resource=args.resource) return labelbindings_service.Create(binding)
def Run(self, args): labelbindings_service = labelmanager.LabelBindingsService() labelmanager_messages = labelmanager.LabelManagerMessages() label_value = utils.GetLabelValueIfArgsAreValid(args) label_binding_name = utils.GetLabelBindingNameFromLabelValueAndResource( label_value, args.resource) request = labelmanager_messages.LabelmanagerLabelBindingsDeleteRequest( name=label_binding_name) return labelbindings_service.Delete(request)
def Run(self, args): labelbindings_service = labelmanager.LabelBindingsService() labelmanager_messages = labelmanager.LabelManagerMessages() if args.IsSpecified('resource'): request = ( labelmanager_messages.LabelmanagerLabelBindingsListRequest( filter='resource:' + args.resource)) else: label_value = utils.GetLabelValueIfArgsAreValid(args) request = ( labelmanager_messages.LabelmanagerLabelBindingsListRequest( filter='labelValue:' + label_value)) return labelbindings_service.List(request)
def Run(self, args): labelbindings_service = labelmanager.LabelBindingsService() labelmanager_messages = labelmanager.LabelManagerMessages() label_value = utils.GetLabelValueIfArgsAreValid(args) label_value_id = utils.GetIdFromResourceName(label_value) request = labelmanager_messages.LabelmanagerLabelValuesLabelBindingsDeleteRequest( labelBinding_labelValue=label_value, labelBinding_resource=args.resource, labelValuesId=label_value_id, labelBindingsId=args.resource) return labelbindings_service.Delete(request)
def Run(self, args): labelbindings_service = labelmanager.LabelBindingsService() labelmanager_messages = labelmanager.LabelManagerMessages() label_value = utils.GetLabelValueIfArgsAreValid(args) label_value_id = utils.GetIdFromResourceName(label_value) binding = labelmanager_messages.LabelBinding(labelValue=label_value, resource=args.resource) create_request = labelmanager_messages.CreateLabelBindingRequest( labelBinding=binding) request = labelmanager_messages.LabelmanagerLabelValuesLabelBindingsCreateRequest( createLabelBindingRequest=create_request, labelValuesId=label_value_id) return labelbindings_service.Create(request)
def Run(self, args): labelbindings_service = labelmanager.LabelBindingsService() labelmanager_messages = labelmanager.LabelManagerMessages() label_value = utils.GetLabelValueIfArgsAreValid(args) label_binding_name = utils.GetLabelBindingNameFromLabelValueAndResource( label_value, args.resource) request = labelmanager_messages.LabelmanagerLabelBindingsDeleteRequest( name=label_binding_name) op = labelbindings_service.Delete(request) if op.response is not None: return {'response': op.response} else: raise operations.OperationError(op.error.message)
def Run(self, args): labelbindings_service = labelmanager.LabelBindingsService() labelmanager_messages = labelmanager.LabelManagerMessages() label_value = utils.GetLabelValueIfArgsAreValid(args) binding = labelmanager_messages.LabelBinding( labelValue=label_value, resource=args.resource) op = labelbindings_service.Create(binding) if op.response is not None: response_dict = encoding.MessageToPyValue(op.response) del response_dict['@type'] return response_dict else: raise operations.OperationError(op.error.message)
def Run(self, args): labelbindings_service = labelmanager.LabelBindingsService() labelmanager_messages = labelmanager.LabelManagerMessages() if args.IsSpecified('label_key'): label_key = args.label_key if args.IsSpecified('label_parent'): label_key = utils.GetLabelKeyFromDisplayName(args.label_key, args.label_parent) label_value = utils.GetLabelValueFromDisplayName(args.LABEL_VALUE_ID, label_key) else: label_value = args.LABEL_VALUE_ID binding = labelmanager_messages.LabelBinding( labelValue=label_value, resource=args.resource) create_request = labelmanager_messages.CreateLabelBindingRequest( labelBinding=binding) request = labelmanager_messages.LabelmanagerLabelValuesLabelBindingsCreateRequest( createLabelBindingRequest=create_request, labelValuesId=label_value) return labelbindings_service.Create(request)