1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-25 15:45:23 +00:00

convert strings to python3 f-Strings

This commit is contained in:
catborise 2020-05-21 16:17:25 +03:00 committed by catborise
parent 0461df7685
commit a93f8b3321
5 changed files with 121 additions and 124 deletions

View file

@ -651,27 +651,27 @@ class wvmInstance(wvmConnect):
additionals = '' additionals = ''
if cache_mode is not None and cache_mode != 'default' and disk_device != 'cdrom': if cache_mode is not None and cache_mode != 'default' and disk_device != 'cdrom':
additionals += "cache='%s' " % cache_mode additionals += f"cache='{cache_mode}' "
if io_mode is not None and io_mode != 'default': if io_mode is not None and io_mode != 'default':
additionals += "io='%s' " % io_mode additionals += f"io='{io_mode}' "
if discard_mode is not None and discard_mode != 'default': if discard_mode is not None and discard_mode != 'default':
additionals += "discard='%s' " % discard_mode additionals += f"discard='{discard_mode}' "
if detect_zeroes_mode is not None and detect_zeroes_mode != 'default': if detect_zeroes_mode is not None and detect_zeroes_mode != 'default':
additionals += "detect_zeroes='%s' " % detect_zeroes_mode additionals += f"detect_zeroes='{detect_zeroes_mode}' "
xml_disk = "<disk type='%s' device='%s'>" % (disk_type, disk_device) xml_disk = f"<disk type='{disk_type}' device='{disk_device}'>"
if disk_device == 'cdrom': if disk_device == 'cdrom':
xml_disk += "<driver name='%s' type='%s'/>" % (driver_name, driver_type) xml_disk += f"<driver name='{driver_name}' type='{driver_type}'/>"
elif disk_device == 'disk': elif disk_device == 'disk':
xml_disk += "<driver name='%s' type='%s' %s/>" % (driver_name, driver_type, additionals) xml_disk += f"<driver name='{driver_name}' type='{driver_type}' {additionals}/>"
xml_disk += """<source file='%s'/> xml_disk += f"""<source file='{source}'/>
<target dev='%s' bus='%s'/>""" % (source, target_dev, target_bus) <target dev='{target_dev}' bus='{target_bus}'/>"""
if readonly or disk_device == 'cdrom': if readonly or disk_device == 'cdrom':
xml_disk += """<readonly/>""" xml_disk += """<readonly/>"""
if shareable: if shareable:
xml_disk += """<shareable/>""" xml_disk += """<shareable/>"""
if serial is not None and serial != 'None' and serial != '': if serial is not None and serial != 'None' and serial != '':
xml_disk += """<serial>%s</serial>""" % serial xml_disk += f"""<serial>{serial}</serial>"""
xml_disk += """</disk>""" xml_disk += """</disk>"""
if self.get_status() == 1: if self.get_status() == 1:
self.instance.attachDeviceFlags(xml_disk, VIR_DOMAIN_AFFECT_LIVE) self.instance.attachDeviceFlags(xml_disk, VIR_DOMAIN_AFFECT_LIVE)
@ -703,28 +703,28 @@ class wvmInstance(wvmConnect):
additionals = '' additionals = ''
if cache_mode is not None and cache_mode != 'default': if cache_mode is not None and cache_mode != 'default':
additionals += "cache='%s' " % cache_mode additionals += f"cache='{cache_mode}' "
if io_mode is not None and io_mode != 'default': if io_mode is not None and io_mode != 'default':
additionals += "io='%s' " % io_mode additionals += f"io='{io_mode}' "
if discard_mode is not None and discard_mode != 'default': if discard_mode is not None and discard_mode != 'default':
additionals += "discard='%s' " % discard_mode additionals += f"discard='{discard_mode}' "
if detect_zeroes_mode is not None and detect_zeroes_mode != 'default': if detect_zeroes_mode is not None and detect_zeroes_mode != 'default':
additionals += "detect_zeroes='%s' " % detect_zeroes_mode additionals += f"detect_zeroes='{detect_zeroes_mode}' "
xml_disk = "<disk type='%s' device='%s'>" % (old_disk_type, old_disk_device) xml_disk = f"<disk type='{old_disk_type}' device='{old_disk_device}'>"
if old_disk_device == 'cdrom': if old_disk_device == 'cdrom':
xml_disk += "<driver name='%s' type='%s'/>" % (old_driver_name, format) xml_disk += f"<driver name='{old_driver_name}' type='{format}'/>"
elif old_disk_device == 'disk': elif old_disk_device == 'disk':
xml_disk += "<driver name='%s' type='%s' %s/>" % (old_driver_name, format, additionals) xml_disk += f"<driver name='{old_driver_name}' type='{format}' {additionals}/>"
xml_disk += """<source file='%s'/> xml_disk += f"""<source file='{source}'/>
<target dev='%s' bus='%s'/>""" % (source, target_dev, target_bus) <target dev='{target_dev}' bus='{target_bus}'/>"""
if readonly: if readonly:
xml_disk += """<readonly/>""" xml_disk += """<readonly/>"""
if shareable: if shareable:
xml_disk += """<shareable/>""" xml_disk += """<shareable/>"""
if serial is not None and serial != 'None' and serial != '': if serial is not None and serial != 'None' and serial != '':
xml_disk += """<serial>%s</serial>""" % serial xml_disk += f"""<serial>{serial}</serial>"""
xml_disk += """</disk>""" xml_disk += """</disk>"""
self.instance.updateDeviceFlags(xml_disk, VIR_DOMAIN_AFFECT_CONFIG) self.instance.updateDeviceFlags(xml_disk, VIR_DOMAIN_AFFECT_CONFIG)
@ -753,7 +753,7 @@ class wvmInstance(wvmConnect):
xml = """ <vcpus>""" xml = """ <vcpus>"""
xml += """<vcpu id='0' enabled='yes' hotpluggable='no' order='1'/>""" xml += """<vcpu id='0' enabled='yes' hotpluggable='no' order='1'/>"""
for i in range(1, vcpus_hotplug): for i in range(1, vcpus_hotplug):
xml += """<vcpu id='{}' enabled='yes' hotpluggable='yes' order='{}'/>""".format(i, i+1) xml += f"""<vcpu id='{i}' enabled='yes' hotpluggable='yes' order='{i+1}'/>"""
xml += """</vcpus>""" xml += """</vcpus>"""
tree = etree.fromstring(self._XMLDesc(0)) tree = etree.fromstring(self._XMLDesc(0))
@ -914,7 +914,7 @@ class wvmInstance(wvmConnect):
xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE) xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE)
root = ElementTree.fromstring(xml) root = ElementTree.fromstring(xml)
try: try:
graphic = root.find("devices/graphics[@type='%s']" % current_type) graphic = root.find(f"devices/graphics[@type='{current_type}']")
except SyntaxError: except SyntaxError:
# Little fix for old version ElementTree # Little fix for old version ElementTree
graphic = root.find("devices/graphics") graphic = root.find("devices/graphics")
@ -942,7 +942,7 @@ class wvmInstance(wvmConnect):
root = ElementTree.fromstring(xml) root = ElementTree.fromstring(xml)
console_type = self.get_console_type() console_type = self.get_console_type()
try: try:
graphic = root.find("devices/graphics[@type='%s']" % console_type) graphic = root.find(f"devices/graphics[@type='{console_type}']")
except SyntaxError: except SyntaxError:
# Little fix for old version ElementTree # Little fix for old version ElementTree
graphic = root.find("devices/graphics") graphic = root.find("devices/graphics")
@ -1161,7 +1161,7 @@ class wvmInstance(wvmConnect):
stg_conn = self.get_wvmStorages() stg_conn = self.get_wvmStorages()
stg_conn.create_storage('dir', nvram_pool_name, None, nvram_dir) stg_conn.create_storage('dir', nvram_pool_name, None, nvram_dir)
new_nvram_name = "%s_VARS" % clone_data['name'] new_nvram_name = f"{clone_data['name']}_VARS"
nvram_stg = self.get_wvmStorage(nvram_pool_name) nvram_stg = self.get_wvmStorage(nvram_pool_name)
nvram_stg.clone_volume(src_nvram_name, new_nvram_name, file_suffix='fd') nvram_stg.clone_volume(src_nvram_name, new_nvram_name, file_suffix='fd')
@ -1195,16 +1195,16 @@ class wvmInstance(wvmConnect):
if vol_format == 'qcow2' and meta_prealloc: if vol_format == 'qcow2' and meta_prealloc:
meta_prealloc = True meta_prealloc = True
vol_clone_xml = """ vol_clone_xml = f"""
<volume> <volume>
<name>%s</name> <name>{target_file}</name>
<capacity>0</capacity> <capacity>0</capacity>
<allocation>0</allocation> <allocation>0</allocation>
<target> <target>
<format type='%s'/> <format type='{vol_format}'/>
<permissions> <permissions>
<owner>%s</owner> <owner>{OWNER['uid']}</owner>
<group>%s</group> <group>{OWNER['guid']}</group>
<mode>0644</mode> <mode>0644</mode>
<label>virt_image_t</label> <label>virt_image_t</label>
</permissions> </permissions>
@ -1213,7 +1213,7 @@ class wvmInstance(wvmConnect):
<lazy_refcounts/> <lazy_refcounts/>
</features> </features>
</target> </target>
</volume>""" % (target_file, vol_format, OWNER['uid'], OWNER['guid']) </volume>"""
stg = vol.storagePoolLookupByVolume() stg = vol.storagePoolLookupByVolume()
stg.createXMLFrom(vol_clone_xml, vol, meta_prealloc) stg.createXMLFrom(vol_clone_xml, vol, meta_prealloc)
@ -1227,15 +1227,15 @@ class wvmInstance(wvmConnect):
vol = self.get_volume_by_path(source_name) vol = self.get_volume_by_path(source_name)
vol_format = util.get_xml_path(vol.XMLDesc(0), "/volume/target/format/@type") vol_format = util.get_xml_path(vol.XMLDesc(0), "/volume/target/format/@type")
vol_clone_xml = """ vol_clone_xml = f"""
<volume type='network'> <volume type='network'>
<name>%s</name> <name>{target_file}</name>
<capacity>0</capacity> <capacity>0</capacity>
<allocation>0</allocation> <allocation>0</allocation>
<target> <target>
<format type='%s'/> <format type='{vol_format}'/>
</target> </target>
</volume>""" % (target_file, vol_format) </volume>"""
stg = vol.storagePoolLookupByVolume() stg = vol.storagePoolLookupByVolume()
stg.createXMLFrom(vol_clone_xml, vol, meta_prealloc) stg.createXMLFrom(vol_clone_xml, vol, meta_prealloc)
@ -1275,18 +1275,16 @@ class wvmInstance(wvmConnect):
else: else:
interface_type = 'bridge' interface_type = 'bridge'
xml_iface = """ xml_iface = f"""
<interface type='%s'> <interface type='{interface_type}'>
<mac address='%s'/>""" % (interface_type, mac_address) <mac address='{mac_address}'/>"""
if interface_type == 'network': if interface_type == 'network':
xml_iface += """<source network='%s'/>""" % source xml_iface += f"""<source network='{source}'/>"""
else: else:
xml_iface += """<source bridge='%s'/>""" % bridge_name xml_iface += f"""<source bridge='{bridge_name}'/>"""
xml_iface += """<model type='%s'/>""" % model xml_iface += f"""<model type='{model}'/>"""
if nwfilter: if nwfilter:
xml_iface += """ xml_iface += f"""<filterref filter='{nwfilter}'/>"""
<filterref filter='%s'/>
""" % nwfilter
xml_iface += """</interface>""" xml_iface += """</interface>"""
if self.get_status() == 1: if self.get_status() == 1:
@ -1438,9 +1436,9 @@ class wvmInstance(wvmConnect):
def set_qos(self, mac, direction, average, peak, burst): def set_qos(self, mac, direction, average, peak, burst):
if direction == "inbound": if direction == "inbound":
xml = "<inbound average='{}' peak='{}' burst='{}'/>".format(average, peak, burst) xml = f"<inbound average='{average}' peak='{peak}' burst='{burst}'/>"
elif direction == "outbound": elif direction == "outbound":
xml = "<outbound average='{}' peak='{}' burst='{}'/>".format(average, peak, burst) xml = f"<outbound average='{average}' peak='{peak}' burst='{burst}'/>"
else: else:
raise Exception('Direction must be inbound or outbound') raise Exception('Direction must be inbound or outbound')

View file

@ -19,32 +19,32 @@ class wvmInterfaces(wvmConnect):
def create_iface(self, name, itype, mode, netdev, ipv4_type, ipv4_addr, ipv4_gw, def create_iface(self, name, itype, mode, netdev, ipv4_type, ipv4_addr, ipv4_gw,
ipv6_type, ipv6_addr, ipv6_gw, stp, delay): ipv6_type, ipv6_addr, ipv6_gw, stp, delay):
xml = """<interface type='%s' name='%s'> xml = f"""<interface type='{itype}' name='{name}'>
<start mode='%s'/>""" % (itype, name, mode) <start mode='{mode}'/>"""
if ipv4_type == 'dhcp': if ipv4_type == 'dhcp':
xml += """<protocol family='ipv4'> xml += """<protocol family='ipv4'>
<dhcp/> <dhcp/>
</protocol>""" </protocol>"""
if ipv4_type == 'static': if ipv4_type == 'static':
address, prefix = ipv4_addr.split('/') address, prefix = ipv4_addr.split('/')
xml += """<protocol family='ipv4'> xml += f"""<protocol family='ipv4'>
<ip address='%s' prefix='%s'/> <ip address='{address}' prefix='{prefix}'/>
<route gateway='%s'/> <route gateway='{ipv4_gw}'/>
</protocol>""" % (address, prefix, ipv4_gw) </protocol>"""
if ipv6_type == 'dhcp': if ipv6_type == 'dhcp':
xml += """<protocol family='ipv6'> xml += """<protocol family='ipv6'>
<dhcp/> <dhcp/>
</protocol>""" </protocol>"""
if ipv6_type == 'static': if ipv6_type == 'static':
address, prefix = ipv6_addr.split('/') address, prefix = ipv6_addr.split('/')
xml += """<protocol family='ipv6'> xml += f"""<protocol family='ipv6'>
<ip address='%s' prefix='%s'/> <ip address='{address}' prefix='{prefix}'/>
<route gateway='%s'/> <route gateway='{ipv6_gw}'/>
</protocol>""" % (address, prefix, ipv6_gw) </protocol>"""
if itype == 'bridge': if itype == 'bridge':
xml += """<bridge stp='%s' delay='%s'> xml += f"""<bridge stp='{stp}' delay='{delay}'>
<interface name='%s' type='ethernet'/> <interface name='{netdev}' type='ethernet'/>
</bridge>""" % (stp, delay, netdev) </bridge>"""
xml += """</interface>""" xml += """</interface>"""
self.define_iface(xml) self.define_iface(xml)
iface = self.get_iface(name) iface = self.get_iface(name)

View file

@ -45,37 +45,37 @@ class wvmNetworks(wvmConnect):
ipv4, gateway, mask, dhcp4, ipv4, gateway, mask, dhcp4,
ipv6, gateway6, prefix6, dhcp6, ipv6, gateway6, prefix6, dhcp6,
bridge, openvswitch, fixed=False): bridge, openvswitch, fixed=False):
xml = """ xml = f"""
<network> <network>
<name>%s</name>""" % name <name>{name}</name>"""
if forward in ['nat', 'route', 'bridge']: if forward in ['nat', 'route', 'bridge']:
xml += """<forward mode='%s'/>""" % forward xml += f"""<forward mode='{forward}'/>"""
xml += """<bridge """ xml += """<bridge """
if forward in ['nat', 'route', 'none']: if forward in ['nat', 'route', 'none']:
xml += """stp='on' delay='0'""" xml += """stp='on' delay='0'"""
if forward == 'bridge': if forward == 'bridge':
xml += """name='%s'""" % bridge xml += f"""name='{bridge}'"""
xml += """/>""" xml += """/>"""
if openvswitch is True: if openvswitch is True:
xml += """<virtualport type='openvswitch'/>""" xml += """<virtualport type='openvswitch'/>"""
if forward != 'bridge': if forward != 'bridge':
if ipv4: if ipv4:
xml += """<ip address='%s' netmask='%s'>""" % (gateway, mask) xml += f"""<ip address='{gateway}' netmask='{mask}'>"""
if dhcp4: if dhcp4:
xml += """<dhcp> xml += f"""<dhcp>
<range start='%s' end='%s' />""" % (dhcp4[0], dhcp4[1]) <range start='{dhcp4[0]}' end='{dhcp4[1]}' />"""
if fixed: if fixed:
fist_oct = int(dhcp4[0].strip().split('.')[3]) fist_oct = int(dhcp4[0].strip().split('.')[3])
last_oct = int(dhcp4[1].strip().split('.')[3]) last_oct = int(dhcp4[1].strip().split('.')[3])
for ip in range(fist_oct, last_oct + 1): for ip in range(fist_oct, last_oct + 1):
xml += """<host mac='%s' ip='%s.%s' />""" % (util.randomMAC(), gateway[:-2], ip) xml += f"""<host mac='{util.randomMAC()}' ip='{gateway[:-2]}.{ip}' />"""
xml += """</dhcp>""" xml += """</dhcp>"""
xml += """</ip>""" xml += """</ip>"""
if ipv6: if ipv6:
xml += """<ip family='ipv6' address='%s' prefix='%s'>""" % (gateway6, prefix6) xml += f"""<ip family='ipv6' address='{gateway6}' prefix='{prefix6}'>"""
if dhcp6: if dhcp6:
xml += """<dhcp> xml += f"""<dhcp>
<range start='%s' end='%s' />""" % (dhcp6[0], dhcp6[1]) <range start='{dhcp6[0]}' end='{dhcp6[1]}' />"""
xml += """</dhcp>""" xml += """</dhcp>"""
xml += """</ip>""" xml += """</ip>"""
xml += """</network>""" xml += """</network>"""
@ -314,9 +314,9 @@ class wvmNetwork(wvmConnect):
def set_qos(self, direction, average, peak, burst): def set_qos(self, direction, average, peak, burst):
if direction == "inbound": if direction == "inbound":
xml = "<inbound average='{}' peak='{}' burst='{}'/>".format(average, peak, burst) xml = f"<inbound average='{average}' peak='{peak}' burst='{burst}'/>"
elif direction == "outbound": elif direction == "outbound":
xml = "<outbound average='{}' peak='{}' burst='{}'/>".format(average, peak, burst) xml = f"<outbound average='{average}' peak='{peak}' burst='{burst}'/>"
else: else:
raise Exception('Direction must be inbound or outbound') raise Exception('Direction must be inbound or outbound')
@ -324,7 +324,7 @@ class wvmNetwork(wvmConnect):
band = tree.xpath("/network/bandwidth") band = tree.xpath("/network/bandwidth")
if len(band) == 0: if len(band) == 0:
xml = "<bandwidth>" + xml + "</bandwidth>" xml = f"<bandwidth>{xml}</bandwidth>"
tree.append(etree.fromstring(xml)) tree.append(etree.fromstring(xml))
else: else:
direct = band[0].find(direction) direct = band[0].find(direction)
@ -339,7 +339,7 @@ class wvmNetwork(wvmConnect):
def unset_qos(self, direction): def unset_qos(self, direction):
tree = etree.fromstring(self._XMLDesc(0)) tree = etree.fromstring(self._XMLDesc(0))
for direct in tree.xpath("/network/bandwidth/{}".format(direction)): for direct in tree.xpath(f"/network/bandwidth/{direction}"):
parent = direct.getparent() parent = direct.getparent()
parent.remove(direct) parent.remove(direct)
@ -353,7 +353,7 @@ class wvmNetwork(wvmConnect):
self.leases = self.net.DHCPLeases() self.leases = self.net.DHCPLeases()
except Exception as e: except Exception as e:
self.leases = [] self.leases = []
raise "Error getting %s DHCP leases: %s" % (self, e) raise f"Error getting {self} DHCP leases: {e}"
def get_dhcp_leases(self): def get_dhcp_leases(self):
if self.leases is None: if self.leases is None:

View file

@ -4,14 +4,14 @@ from vrtManager.connection import wvmConnect
class wvmSecrets(wvmConnect): class wvmSecrets(wvmConnect):
def create_secret(self, ephemeral, private, secret_type, data): def create_secret(self, ephemeral, private, secret_type, data):
xml = """<secret ephemeral='%s' private='%s'> xml = f"""<secret ephemeral='{ephemeral}' private='{private}'>
<usage type='%s'>""" % (ephemeral, private, secret_type) <usage type='{secret_type}'>"""
if secret_type == 'ceph': if secret_type == 'ceph':
xml += """<name>%s</name>""" % data xml += f"""<name>{data}</name>"""
if secret_type == 'volume': if secret_type == 'volume':
xml += """<volume>%s</volume>""" % data xml += f"""<volume>{data}</volume>"""
if secret_type == 'iscsi': if secret_type == 'iscsi':
xml += """<target>%s</target>""" % data xml += f"""<target>{data}</target>"""
xml += """</usage> xml += """</usage>
</secret>""" </secret>"""
self.wvm.secretDefineXML(xml) self.wvm.secretDefineXML(xml)

View file

@ -25,23 +25,21 @@ class wvmStorages(wvmConnect):
self.wvm.storagePoolDefineXML(xml, flag) self.wvm.storagePoolDefineXML(xml, flag)
def create_storage(self, stg_type, name, source, target): def create_storage(self, stg_type, name, source, target):
xml = """ xml = f"""<pool type='{stg_type}'>
<pool type='%s'> <name>{name}</name>"""
<name>%s</name>""" % (stg_type, name)
if stg_type == 'logical': if stg_type == 'logical':
xml += """ xml += f"""<source>
<source> <device path='{source}'/>
<device path='%s'/> <name>{name}</name>
<name>%s</name> <format type='lvm2'/>
<format type='lvm2'/> </source>"""
</source>""" % (source, name)
if stg_type == 'logical': if stg_type == 'logical':
target = '/dev/' + name target = '/dev/' + name
xml += """ xml += f"""
<target> <target>
<path>%s</path> <path>{target}</path>
</target> </target>
</pool>""" % target </pool>"""
self.define_storage(xml, 0) self.define_storage(xml, 0)
stg = self.get_storage(name) stg = self.get_storage(name)
if stg_type == 'logical': if stg_type == 'logical':
@ -52,35 +50,37 @@ class wvmStorages(wvmConnect):
return stg return stg
def create_storage_ceph(self, stg_type, name, ceph_pool, ceph_host, ceph_user, secret): def create_storage_ceph(self, stg_type, name, ceph_pool, ceph_host, ceph_user, secret):
xml = """ xml = f"""
<pool type='%s'> <pool type='{stg_type}'>
<name>%s</name> <name>{name}</name>
<source> <source>
<name>%s</name> <name>{ceph_pool}</name>
<host name='%s' port='6789'/> <host name='{ceph_host}' port='6789'/>
<auth username='%s' type='ceph'> <auth username='{ceph_user}' type='ceph'>
<secret uuid='%s'/> <secret uuid='{secret}'/>
</auth> </auth>
</source> </source>
</pool>""" % (stg_type, name, ceph_pool, ceph_host, ceph_user, secret) </pool>
"""
self.define_storage(xml, 0) self.define_storage(xml, 0)
stg = self.get_storage(name) stg = self.get_storage(name)
stg.create(0) stg.create(0)
stg.setAutostart(1) stg.setAutostart(1)
def create_storage_netfs(self, stg_type, name, netfs_host, source, source_format, target): def create_storage_netfs(self, stg_type, name, netfs_host, source, source_format, target):
xml = """ xml = f"""
<pool type='%s'> <pool type='{stg_type}'>
<name>%s</name> <name>{name}</name>
<source> <source>
<host name='%s'/> <host name='{netfs_host}'/>
<dir path='%s'/> <dir path='{source}'/>
<format type='%s'/> <format type='{source_format}'/>
</source> </source>
<target> <target>
<path>%s</path> <path>{target}</path>
</target> </target>
</pool>""" % (stg_type, name, netfs_host, source, source_format, target) </pool>
"""
self.define_storage(xml, 0) self.define_storage(xml, 0)
stg = self.get_storage(name) stg = self.get_storage(name)
stg.create(0) stg.create(0)
@ -222,27 +222,26 @@ class wvmStorage(wvmConnect):
else: else:
name += '.img' name += '.img'
alloc = 0 alloc = 0
xml = """ xml = f"""
<volume> <volume>
<name>%s</name> <name>{name}</name>
<capacity>%s</capacity> <capacity>{size}</capacity>
<allocation>%s</allocation> <allocation>{alloc}</allocation>
<target> <target>
<format type='%s'/> <format type='{vol_fmt}'/>
<permissions> <permissions>
<owner>%s</owner> <owner>{owner['uid']}</owner>
<group>%s</group> <group>{owner['guid']}</group>
<mode>0644</mode> <mode>0644</mode>
<label>virt_image_t</label> <label>virt_image_t</label>
</permissions>""" % (name, size, alloc, vol_fmt, owner['uid'], owner['guid']) </permissions>"""
if vol_fmt == 'qcow2': if vol_fmt == 'qcow2':
xml += """ xml += """
<compat>1.1</compat> <compat>1.1</compat>
<features> <features>
<lazy_refcounts/> <lazy_refcounts/>
</features>""" </features>"""
xml += """ xml += """</target>
</target>
</volume>""" </volume>"""
self._createXML(xml, metadata) self._createXML(xml, metadata)
return name return name
@ -260,19 +259,19 @@ class wvmStorage(wvmConnect):
suffix = '.' + file_suffix suffix = '.' + file_suffix
target_file += suffix if len(suffix) > 1 else '' target_file += suffix if len(suffix) > 1 else ''
xml = """ xml = f"""
<volume> <volume>
<name>%s</name> <name>{target_file}</name>
<capacity>0</capacity> <capacity>0</capacity>
<allocation>0</allocation> <allocation>0</allocation>
<target> <target>
<format type='%s'/> <format type='{vol_fmt}'/>
<permissions> <permissions>
<owner>%s</owner> <owner>{owner['uid']}</owner>
<group>%s</group> <group>{owner['guid']}</group>
<mode>%s</mode> <mode>{mode}</mode>
<label>virt_image_t</label> <label>virt_image_t</label>
</permissions>""" % (target_file, vol_fmt, owner['uid'], owner['guid'], mode) </permissions>"""
if vol_fmt == 'qcow2': if vol_fmt == 'qcow2':
xml += """ xml += """
<compat>1.1</compat> <compat>1.1</compat>