def GetLabelValueFromDisplayName(display_name, label_key): """Returns the LabelValue with display_name under label_key if it exists. Args: display_name: String, display name of the LabelValue label_key: String, resource name of the parent of the LabelKey Raises: InvalidInputError: if the specified display_name does not exist under the label_key Returns: The resource name of the LabelValue associated with the display_name """ labelvalues_service = labelmanager.LabelValuesService() labelmanager_messages = labelmanager.LabelManagerMessages() list_request = labelmanager_messages.LabelmanagerLabelValuesListRequest( parent=label_key) response = labelvalues_service.List(list_request) for value in response.values: if value.displayName == display_name: return value.name raise InvalidInputError( 'Invalid display_name for LabelValue [{}] in parent [{}]'.format( display_name, label_key))
def Run(self, args): labelvalues_service = labelmanager.LabelValuesService() labelmanager_messages = labelmanager.LabelManagerMessages() label_value = utils.GetLabelValueIfArgsAreValid(args) get_request = labelmanager_messages.LabelmanagerLabelValuesGetRequest( name=label_value) return labelvalues_service.Get(get_request)
def Run(self, args): labelvalues_service = labelmanager.LabelValuesService() labelmanager_messages = labelmanager.LabelManagerMessages() label_value = utils.GetLabelValueIfArgsAreValid(args) delete_request = labelmanager_messages.LabelmanagerLabelValuesDeleteRequest( name=label_value) op = labelvalues_service.Delete(delete_request) 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): labelvalues_service = labelmanager.LabelValuesService() labelmanager_messages = labelmanager.LabelManagerMessages() label_key_id = args.label_key if args.IsSpecified('label_parent'): label_key = utils.GetLabelKeyFromDisplayName( label_key_id, args.label_parent) else: label_key = label_key_id list_request = labelmanager_messages.LabelmanagerLabelValuesListRequest( parent=label_key) response = labelvalues_service.List(list_request) return response.values
def Run(self, args): labelvalues_service = labelmanager.LabelValuesService() labelmanager_messages = labelmanager.LabelManagerMessages() label_value = utils.GetLabelValueIfArgsAreValid(args) delete_request = labelmanager_messages.LabelmanagerLabelValuesDeleteRequest( name=label_value) op = labelvalues_service.Delete(delete_request) if args.async_: return op else: return operations.WaitForOperation( op, 'Waiting for LabelValue [{}] to be deleted with [{}]'.format( args.LABEL_VALUE_ID, op.name), labelvalues_service)
def Run(self, args): labelvalues_service = labelmanager.LabelValuesService() labelmanager_messages = labelmanager.LabelManagerMessages() if args.IsSpecified('label_parent'): label_key = utils.GetLabelKeyFromDisplayName( args.label_key, args.label_parent) else: label_key = args.label_key create_request = labelmanager_messages.LabelValue( displayName=args.DISPLAY_NAME, parent=label_key, description=args.description) op = labelvalues_service.Create(create_request) if args.async_: return op else: return operations.WaitForOperation( op, 'Waiting for label value [{}] to be created with [{}]'.format( args.DISPLAY_NAME, op.name), service=labelvalues_service)