MCPcopy
hub / github.com/retspen/webvirtcloud / clone_instance

Method clone_instance

vrtManager/instance.py:601–653  ·  view source on GitHub ↗
(self, clone_data)

Source from the content-addressed store, hash-verified

599 return self.instance.hasManagedSaveImage(0)
600
601 def clone_instance(self, clone_data):
602 clone_dev_path = []
603
604 xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE)
605 tree = ElementTree.fromstring(xml)
606 name = tree.find('name')
607 name.text = clone_data['name']
608 uuid = tree.find('uuid')
609 tree.remove(uuid)
610
611 for num, net in enumerate(tree.findall('devices/interface')):
612 elm = net.find('mac')
613 elm.set('address', clone_data['net-' + str(num)])
614
615 for disk in tree.findall('devices/disk'):
616 if disk.get('device') == 'disk':
617 elm = disk.find('target')
618 device_name = elm.get('dev')
619 if device_name:
620 target_file = clone_data['disk-' + device_name]
621 try:
622 meta_prealloc = clone_data['meta-' + device_name]
623 except:
624 meta_prealloc = False
625 elm.set('dev', device_name)
626
627 elm = disk.find('source')
628 source_file = elm.get('file')
629 if source_file:
630 clone_dev_path.append(source_file)
631 clone_path = os.path.join(os.path.dirname(source_file),
632 target_file)
633 elm.set('file', clone_path)
634
635 vol = self.get_volume_by_path(source_file)
636 vol_format = util.get_xml_path(vol.XMLDesc(0),
637 "/volume/target/format/@type")
638
639 if vol_format == 'qcow2' and meta_prealloc:
640 meta_prealloc = True
641 vol_clone_xml = """
642 <volume>
643 <name>%s</name>
644 <capacity>0</capacity>
645 <allocation>0</allocation>
646 <target>
647 <format type='%s'/>
648 </target>
649 </volume>""" % (target_file, vol_format)
650 stg = vol.storagePoolLookupByVolume()
651 stg.createXMLFrom(vol_clone_xml, vol, meta_prealloc)
652
653 self._defineXML(ElementTree.tostring(tree))

Callers 1

instanceFunction · 0.80

Calls 3

_XMLDescMethod · 0.95
_defineXMLMethod · 0.95
get_volume_by_pathMethod · 0.80

Tested by

no test coverage detected