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

Method create_instance

vrtManager/create.py:124–214  ·  view source on GitHub ↗

Create VM function

(self, name, memory, vcpu, host_model, uuid, images, networks, virtio, mac=None)

Source from the content-addressed store, hash-verified

122 vol.delete()
123
124 def create_instance(self, name, memory, vcpu, host_model, uuid, images, networks, virtio, mac=None):
125 """
126 Create VM function
127 """
128 memory = int(memory) * 1024
129
130 if self.is_kvm_supported():
131 hypervisor_type = 'kvm'
132 else:
133 hypervisor_type = 'qemu'
134
135 xml = """
136 <domain type='%s'>
137 <name>%s</name>
138 <description>None</description>
139 <uuid>%s</uuid>
140 <memory unit='KiB'>%s</memory>
141 <vcpu>%s</vcpu>""" % (hypervisor_type, name, uuid, memory, vcpu)
142 if host_model:
143 xml += """<cpu mode='host-model'/>"""
144 xml += """<os>
145 <type arch='%s'>%s</type>
146 <boot dev='hd'/>
147 <boot dev='cdrom'/>
148 <bootmenu enable='yes'/>
149 </os>""" % (self.get_host_arch(), self.get_os_type())
150 xml += """<features>
151 <acpi/><apic/><pae/>
152 </features>
153 <clock offset="utc"/>
154 <on_poweroff>destroy</on_poweroff>
155 <on_reboot>restart</on_reboot>
156 <on_crash>restart</on_crash>
157 <devices>"""
158
159 disk_letters = list(string.lowercase)
160 for image, img_type in images.items():
161 stg = self.get_storage_by_vol_path(image)
162 stg_type = util.get_xml_path(stg.XMLDesc(0), "/pool/@type")
163
164 if stg_type == 'rbd':
165 ceph_user, secrt_uuid, ceph_host = get_rbd_storage_data(stg)
166 xml += """<disk type='network' device='disk'>
167 <driver name='qemu' type='%s'/>
168 <auth username='%s'>
169 <secret type='ceph' uuid='%s'/>
170 </auth>
171 <source protocol='rbd' name='%s'>
172 <host name='%s' port='6789'/>
173 </source>""" % (img_type, ceph_user, secrt_uuid, image, ceph_host)
174 else:
175 xml += """<disk type='file' device='disk'>
176 <driver name='qemu' type='%s'/>
177 <source file='%s'/>""" % (img_type, image)
178
179 if virtio:
180 xml += """<target dev='vd%s' bus='virtio'/>""" % (disk_letters.pop(0),)
181 else:

Callers 1

create_instanceFunction · 0.80

Calls 6

get_host_archMethod · 0.95
get_os_typeMethod · 0.95
_defineXMLMethod · 0.95
get_rbd_storage_dataFunction · 0.85
is_kvm_supportedMethod · 0.80

Tested by

no test coverage detected