def create(self, base=None, cpus=None, ram=None, name=None, ip=None, mac=None, vnc=None): self._store() if not name: debug("Missing name") return if self.store.exists("Vms", "active", name): debug("VM Already Exists") return # set defaults if not base: base = self.conf['vm_default_base'] if not cpus: cpus = self.conf['vm_default_cpus'] if not ram: ram = self.conf['vm_default_ram'] if not vnc: vnc = 5900+self.conf.incr('vnc') if not mac: mac = util.uniq_mac() images = Images('base') self.data['base'] = images[base] self.data['cpus'] = cpus self.data['ram'] = ram self.data['ip'] = ip self.data['mac'] = mac self.data['vnc'] = vnc self.data['state'] = 'off' self.data['name'] = name img = Volume() img.create(self.data['base']) self.data['image'] = img.key debug(self.data) domain = self.xml() debug(domain) self.update_xml() vms = Vms('active') vms[self.data['name']] = self.key self.hv.define(domain) self.save() img.save() vms.save()
def delete(self): self._load() try: self.hv.undefine(self.key) except: pass try: xmld = "%s/%s.xml" % (self.conf['domain_xml_path'], self.key) os.unlink(xmld) except: pass vms = Vms('active') debug(self.key) debug(self.data) vms.remove(self.data['name']) img = Volume(self.data['image']) img.delete() super(VM, self).delete()
return self.data['path'] = imgpath def mount(): ''' qemu-nbd -c /dev/nbd[0-9] <image-file> mkdir /data/vms/mnt/<uuid> mount /dev/mbd[0-9]p1 /data/vms/mnt/<uuid> ''' pass def umount(): ''' umount /data/vms/mnt/<uuid> rmdir /data/vms/mnt/<uuid> qemu-nbd -d /dev/nbd[0-9] ''' pass def delete(self): path = "%s/%s.img" % (self.conf['image_path'], self.key) try: os.unlink(path) except OSError: pass super(QCOW2Volume, self).delete() Volume.register(Volume, 'qcow2', QCOW2Volume)