| 13 | |
| 14 | |
| 15 | class wvmCreate(wvmConnect): |
| 16 | def get_storages_images(self): |
| 17 | """ |
| 18 | Function return all images on all storages |
| 19 | """ |
| 20 | images = [] |
| 21 | storages = self.get_storages() |
| 22 | for storage in storages: |
| 23 | stg = self.get_storage(storage) |
| 24 | try: |
| 25 | stg.refresh(0) |
| 26 | except: |
| 27 | pass |
| 28 | for img in stg.listVolumes(): |
| 29 | if img.endswith('.iso'): |
| 30 | pass |
| 31 | else: |
| 32 | images.append(img) |
| 33 | return images |
| 34 | |
| 35 | def get_os_type(self): |
| 36 | """Get guest capabilities""" |
| 37 | return util.get_xml_path(self.get_cap_xml(), "/capabilities/guest/os_type") |
| 38 | |
| 39 | def get_host_arch(self): |
| 40 | """Get guest capabilities""" |
| 41 | return util.get_xml_path(self.get_cap_xml(), "/capabilities/host/cpu/arch") |
| 42 | |
| 43 | def create_volume(self, storage, name, size, format='qcow2', metadata=False): |
| 44 | size = int(size) * 1073741824 |
| 45 | stg = self.get_storage(storage) |
| 46 | storage_type = util.get_xml_path(stg.XMLDesc(0), "/pool/@type") |
| 47 | if storage_type == 'dir': |
| 48 | name += '.img' |
| 49 | alloc = 0 |
| 50 | else: |
| 51 | alloc = size |
| 52 | metadata = False |
| 53 | xml = """ |
| 54 | <volume> |
| 55 | <name>%s</name> |
| 56 | <capacity>%s</capacity> |
| 57 | <allocation>%s</allocation> |
| 58 | <target> |
| 59 | <format type='%s'/> |
| 60 | </target> |
| 61 | </volume>""" % (name, size, alloc, format) |
| 62 | stg.createXML(xml, metadata) |
| 63 | try: |
| 64 | stg.refresh(0) |
| 65 | except: |
| 66 | pass |
| 67 | vol = stg.storageVolLookupByName(name) |
| 68 | return vol.path() |
| 69 | |
| 70 | def get_volume_type(self, path): |
| 71 | vol = self.get_volume_by_path(path) |
| 72 | vol_type = util.get_xml_path(vol.XMLDesc(0), "/volume/target/format/@type") |