def define(self): name = underscored( deepgetattr(self, 'node.group.environment.name'), deepgetattr(self, 'node.name'), self.name, ) backing_store_path = None backing_store_format = None if self.backing_store is not None: backing_store_path = self.backing_store.get_path() backing_store_format = self.backing_store.format if self.source_image is not None: capacity = get_file_size(self.source_image) else: capacity = int(self.capacity * 1024 ** 3) pool_name = self.driver.storage_pool_name pool = self.driver.conn.storagePoolLookupByName(pool_name) xml = LibvirtXMLBuilder.build_volume_xml( name=name, capacity=capacity, vol_format=self.format, backing_store_path=backing_store_path, backing_store_format=backing_store_format, ) libvirt_volume = pool.createXML(xml, 0) self.uuid = libvirt_volume.key() super(LibvirtVolume, self).define() # Upload predefined image to the volume if self.source_image is not None: self.upload(self.source_image)
def define(self): name = underscored( deepgetattr(self, 'node.group.environment.name'), deepgetattr(self, 'node.name'), self.name, ) backing_store_path = None backing_store_format = None if self.backing_store is not None: backing_store_path = self.backing_store.get_path() backing_store_format = self.backing_store.format if self.source_image is not None: capacity = get_file_size(self.source_image) else: capacity = int(self.capacity * 1024**3) pool_name = self.driver.storage_pool_name pool = self.driver.conn.storagePoolLookupByName(pool_name) xml = LibvirtXMLBuilder.build_volume_xml( name=name, capacity=capacity, vol_format=self.format, backing_store_path=backing_store_path, backing_store_format=backing_store_format, ) libvirt_volume = pool.createXML(xml, 0) self.uuid = libvirt_volume.key() super(LibvirtVolume, self).define() # Upload predefined image to the volume if self.source_image is not None: self.upload(self.source_image)
def upload(self, path): size = get_file_size(path) with open(path, 'rb') as fd: stream = self.driver.conn.newStream(0) self._libvirt_volume.upload( stream=stream, offset=0, length=size, flags=0) stream.sendAll(self.chunk_render, fd) stream.finish()
def upload(self, path): size = get_file_size(path) with open(path, 'rb') as fd: stream = self.driver.conn.newStream(0) self._libvirt_volume.upload(stream=stream, offset=0, length=size, flags=0) stream.sendAll(self.chunk_render, fd) stream.finish()
def test_volumes_for_pptesting(self): images_for_upload = { 'ubuntu-12.04.3-desktop-amd64.iso': '%s' % ( '/tmp/ubuntu-12.04.3-desktop-amd64.iso'), 'centos6.4-base.qcow2': '/tmp/centos6.4-base.qcow2', } for name, vol in images_for_upload.items(): v = Volume.volume_create(name, get_file_size(vol)) if not self.driver.volume_exists(v): self.driver.volume_define(v) self.driver.volume_upload(v, vol)
def test_volumes_for_pptesting(self): images_for_upload = { 'ubuntu-12.04.3-desktop-amd64.iso': '%s' % ('/tmp/ubuntu-12.04.3-desktop-amd64.iso'), 'centos6.4-base.qcow2': '/tmp/centos6.4-base.qcow2', } for name, vol in images_for_upload.items(): v = Volume.volume_create(name, get_file_size(vol)) if not self.driver.volume_exists(v): self.driver.volume_define(v) self.driver.volume_upload(v, vol)