def set_meta(self): response = dict() response['changed'] = False vapp_name = self.params.get('vapp_name') metadata = self.params.get('metadata') domain = self.params.get("metadata_domain") visibility = self.params.get("metadata_visibility") metadata_type = self.params.get("metadata_type") metadata_type = "Metadata{0}Value".format(metadata_type) try: vapp = self.get_vapp() domain = MetadataDomain(domain) visibility = MetadataVisibility(visibility) metadata_type = MetadataValueType(metadata_type) set_meta_task = vapp.set_multiple_metadata(metadata, domain=domain, visibility=visibility, metadata_value_type=metadata_type) self.execute_task(set_meta_task) msg = "Metadata {0} have been set to vApp {1}" response["msg"] = msg.format(list(metadata.keys()), vapp_name) except EntityNotFoundException as ex: response['warnings'] = str(ex) return response
def set_multiple_metadata(self, key_value_dict, domain=MetadataDomain.GENERAL, visibility=MetadataVisibility.READ_WRITE, metadata_value_type=MetadataValueType.STRING): """Add multiple new metadata entries to the vApp. If an entry with the same key exists, it will be updated with the new value. All entries must have the same value type and will be written to the same domain with identical visibility. :param dict key_value_dict: a dict containing key-value pairs to be added/updated. :param client.MetadataDomain domain: domain where the new entries would be put. :param client.MetadataVisibility visibility: visibility of the metadata entries. :param client.MetadataValueType metadata_value_type: :return: an object of type EntityType.TASK XML which represents the asynchronous task that is updating the metadata on the vApp. """ metadata = Metadata(client=self.client, resource=self.get_metadata()) return metadata.set_multiple_metadata( key_value_dict=key_value_dict, domain=MetadataDomain(domain), visibility=MetadataVisibility(visibility), metadata_value_type=MetadataValueType(metadata_value_type), use_admin_endpoint=False)
def set_metadata(self, domain, visibility, key, value, metadata_type=MetadataValueType.STRING.value): """Add a new metadata entry to the vApp. If an entry with the same key exists, it will be updated with the new value. :param str domain: a value of SYSTEM places this MetadataEntry in the SYSTEM domain. Omit or leave empty to place this MetadataEntry in the GENERAL domain. :param str visibility: must be one of the values specified in MetadataVisibility enum. :param str key: an arbitrary key name. Length cannot exceed 256 UTF-8 characters. :param str value: value of the metadata entry. :param str metadata_type: one of the types specified in client.MetadataValueType enum. :return: an object of type EntityType.TASK XML which represents the asynchronous task that is updating the metadata on the vApp. """ metadata = Metadata(client=self.client, resource=self.get_metadata()) return metadata.set_metadata( key=key, value=value, domain=MetadataDomain(domain), visibility=MetadataVisibility(visibility), metadata_value_type=MetadataValueType(metadata_type), use_admin_endpoint=False)
def remove_meta(self): response = dict() response['changed'] = False vm_name = self.params.get('target_vm_name') domain = self.params.get("metadata_domain") vm = self.get_vm() metadata = self.params.get('metadata') domain = MetadataDomain(domain) response['msg'] = list() for key in metadata: remove_meta_task = vm.remove_metadata(key, domain=domain) self.execute_task(remove_meta_task) msg = "Metadata {0} have been removed from vm {1}" response["msg"] = msg.format(list(metadata.keys()), vm_name) return response
def remove_meta(self): response = dict() response['changed'] = False vapp_name = self.params.get('vapp_name') domain = self.params.get("metadata_domain") metadata = self.params.get('metadata') domain = MetadataDomain(domain) response['msg'] = list() try: vapp = self.get_vapp() for key in metadata: remove_meta_task = vapp.remove_metadata(key, domain=domain) self.execute_task(remove_meta_task) msg = "Metadata {0} have been removed from vApp {1}" response["msg"] = msg.format(list(metadata.keys()), vapp_name) except EntityNotFoundException as ex: response['warnings'] = str(ex) return response
def set_meta(self): response = dict() response['changed'] = False vm_name = self.params.get('target_vm_name') metadata = self.params.get('metadata') domain = self.params.get("metadata_domain") visibility = self.params.get("metadata_visibility") metadata_type = self.params.get("metadata_type") metadata_type = "Metadata{0}Value".format(metadata_type) domain = MetadataDomain(domain) visibility = MetadataVisibility(visibility) metadata_type = MetadataValueType(metadata_type) vm = self.get_vm() set_meta_task = vm.set_multiple_metadata( metadata, domain=domain, visibility=visibility, metadata_value_type=metadata_type) self.execute_task(set_meta_task) msg = "Metadata {0} have been set to vm {1}" response["msg"] = msg.format(list(metadata.keys()), vm_name) return response