def test_update(self): imgs = oca.ImagePool(self.c) imgs.info() for img in imgs: if img.name.startswith('inttest'): img.update('<TEMPLATE><NAME>inttest_img_6</NAME>\ <TYPE>DATABLOCK</TYPE><SIZE>382</SIZE></TEMPLATE>')
def test_info(self): self.xml = self.xml.replace('\n', '') self.xml = self.xml.replace(' ', '') self.client.call = Mock(return_value=self.xml) pool = oca.ImagePool(self.client) pool.info() assert len(pool) == 3
def tearDown(self): print("teardown") imgs = oca.ImagePool(self.c) imgs.info() for img in imgs: if img.name.startswith('inttest_img_'): img.delete()
def get_image(module, client, predicate): pool = oca.ImagePool(client) # Filter -2 means fetch all images user can Use pool.info(filter=-2) for image in pool: if predicate(image): return image return None
def __init__(self, secret=None, address=None, proxy=None): if (secret[0] == '/'): secretfile = secret if os.path.isfile(secretfile): try: f = open(secretfile, 'r') secret = f.readlines()[0].strip('\n') f.close() except (IOError, OSError) as e: raise exception.SecretFileError(secretfile, e) else: e = 'secret file does not exist' raise exception.SecretFileError(secretfile, e) self._oca = oca.Client(secret=secret, address=address, proxy=proxy) self._vm_pool = oca.VirtualMachinePool(self._oca) self._image_pool = oca.ImagePool(self._oca)
def get_image_list(self, filter_dict={}): """Obtain tenant images from VIM Filter_dict can be: name: image name id: image uuid checksum: image checksum location: image path Returns the image list of dictionaries: [{<the fields at Filter_dict plus some VIM specific>}, ...] List can be empty """ # IMPORTANT!!!!! Modify python oca library path pool.py line 102 try: client = oca.Client(self.user + ':' + self.passwd, self.url) image_pool = oca.ImagePool(client) image_pool.info() images = [] if "name" in filter_dict.keys(): image_name_filter = filter_dict["name"] else: image_name_filter = None if "id" in filter_dict.keys(): image_id_filter = filter_dict["id"] else: image_id_filter = None for image in image_pool: match = False if str(image_name_filter) == str(image.name) and str(image.id) == str(image_id_filter): match = True if image_name_filter is None and str(image.id) == str(image_id_filter): match = True if image_id_filter is None and str(image_name_filter) == str(image.name): match = True if match: images_dict = {"name": image.name, "id": str(image.id)} images.append(images_dict) return images except Exception as e: self.logger.error("Get image list error: " + str(e)) raise vimconn.vimconnException(e)
def get_all_images(client): pool = oca.ImagePool(client) # Filter -2 means fetch all images user can Use pool.info(filter=-2) return pool
def test_publish(self): imgs = oca.ImagePool(self.c) imgs.info() for img in imgs: if img.name.startswith('inttest'): img.publish()
def test_set_persistent(self): imgs = oca.ImagePool(self.c) imgs.info() for img in imgs: if img.name.startswith('inttest'): img.set_persistent()
def test_chown(self): imgs = oca.ImagePool(self.c) imgs.info() for img in imgs: if img.name.startswith('inttest'): img.chown(0, -1)
def test_delete(self): imgs = oca.ImagePool(self.c) imgs.info() for img in imgs: if img.name.startswith('inttest'): img.delete()