def get_switch(self, uuid): switch_data = self._service_instance("{}/{}".format( LenovoSwitch.API_PATH, uuid.lower())) if not switch_data: raise ItemNotFound("switch", uuid) switch = LenovoSwitch(switch_data, system=self) return switch
def _get_disk_attachment_service(self, disk_name): disk_attachments_service = self.api.disk_attachments_service() for disk_attachment_service in disk_attachments_service.list(): disk = self.system.api.follow_link(disk_attachment_service.disk) if disk.name == disk_name: return disk_attachments_service.service(disk.id) raise ItemNotFound(disk_name, 'disk')
def refresh(self): """ Re-pull the data for this entity and update this instance's attributes """ try: self._raw = self.api.get() except OVirtNotFoundError: raise ItemNotFound(self.uuid, self.__class__.__name__)
def _get_disk_service(self, disk_name): disks_service = self.api.system_service().disks_service() query_result = disks_service.list(search="name={}".format(disk_name)) if not query_result: raise ItemNotFound(disk_name, 'disk') else: disk = query_result[0] return disks_service.service(disk.id)
def _get_storage_domain_service(self, name): query = 'name={}'.format(name) query_result = self._storage_domains_service.list(search=query) if not query_result: raise ItemNotFound(name, 'storage domain') else: storage_domain = query_result[0] return self._storage_domains_service.storage_domain_service(storage_domain.id)
def _get_network(self, network_name): """retreive a network object by name""" networks = self.system.api.system_service().networks_service().list( search='name={}'.format(network_name)) try: return networks[0] except IndexError: raise ItemNotFound( 'No match for network by "name={}"'.format(network_name))
def refresh(self, **kwargs): """ Re-pull the data for this entity and update this instance's attributes Args: kwargs: passed to VmService or TemplateService get() call http://ovirt.github.io/ovirt-engine-sdk/master/services.m.html (next line for specifics) #ovirtsdk4.services.TemplateService.get """ try: self._raw = self.api.get(**kwargs) except OVirtNotFoundError: raise ItemNotFound(self.uuid, self.__class__.__name__)
def update_nic(self, network_name, nic_name='nic1', interface='VIRTIO'): nic_service = self._get_nic_service(nic_name) nic = nic_service.get() nic.network = self._get_network(network_name) try: nic.vnic_profile = [ v for v in self.system.api.system_service(). vnic_profiles_service().list() if v.name == network_name ][0] except IndexError: raise ItemNotFound( 'Unable to find vnic_profile matching network {}'.format( network_name)) nic.interface = getattr(types.NicInterface, interface) nic_service.update(nic)
def list_objects(self, container_name): """List of available object in container. Args: container_name: name of container Returns: list of existing objects """ try: _, objects = self.sapi.get_container(container_name) except SwiftException as e: if e.http_reason == "Not Found": raise ItemNotFound(name=container_name, item_type="Swift Container") else: raise return [obj.get("name") for obj in objects]
def delete_container(self, container_name): """Delete existing container Args: container_name: name of container Returns: bool """ try: self.sapi.delete_container(container_name) except SwiftException as e: if e.http_reason == "Not Found": raise ItemNotFound(name=container_name, item_type="Swift Container") else: raise return container_name not in self.list_containers()
def delete_object(self, container_name, object_name): """Delete object from container. Args: container_name: name of container object_name: name of object Returns: bool """ try: self.sapi.delete_object(container_name, object_name) except SwiftException as e: if e.http_reason == "Not Found": raise ItemNotFound(name=object_name, item_type="Swift Object") else: raise return object_name not in self.list_objects(container_name)
def download_object(self, container_name, object_name, path): """Download object from container. Args: container_name: name of container object_name: name of object path: local object path where like to save. Returns: None """ try: _, obj_contents = self.sapi.get_object(container_name, object_name) except SwiftException as e: if e.http_reason == "Not Found": raise ItemNotFound( name=object_name, item_type="Swift Object in Container {}".format( container_name)) else: raise with open(path, "wb") as obj: obj.write(obj_contents)
def _get_glance_server_service(self, name): for glance_server in self._glance_servers_service.list(): if glance_server.name == name: return self._glance_servers_service.provider_service( glance_server.id) raise ItemNotFound(name, 'glance server')