Exemplo n.º 1
0
 def destroy(self, uuid):
     debug("destroying %s" % uuid)
     dom = self.conn.lookupByUUIDString(uuid)
     try:
         dom.destroy()
     except:
         pass
Exemplo n.º 2
0
 def check_pid(self):
     try:
         self.lock.acquire(timeout=0)
     except lockfile.AlreadyLocked:
         debug("Unable to lock pid file.")
         return False
     return True
Exemplo n.º 3
0
 def undefine(self, uuid):
     debug("undefining %s" % uuid)
     try:
         self.destroy(uuid)
     except libvirt.libvirtError:
         pass
     dom = self.conn.lookupByUUIDString(uuid)
     dom.undefine()
Exemplo n.º 4
0
 def start(self, vm):
     debug("starting %s" % vm.key)
     try:
         dom = self.conn.lookupByUUIDString(vm.key)
     except:
         self.define(vm.xml())
         dom = self.conn.lookupByUUIDString(vm.key)
     dom.create()
Exemplo n.º 5
0
Arquivo: vm.py Projeto: cloudcache/omg
 def xml(self):
     if not self.data:
         self._load()
     t = {}
     t.update(self.data)
     t['key'] = self.key
     t['path'] = self.conf['image_path']
     debug(t)
     domain = DOMAIN_TPL % t
     return domain
Exemplo n.º 6
0
    def create(self, base=None):
        # basepath should be pulled from the base image Volume() object
        basepath = "%s/%s.img" % (self.conf['base_path'], base)
        imgpath = "%s/%s.img" % (self.conf['image_path'], self.key)

        imgcmd = ['qemu-img', 'create', '-b', basepath, '-f', 'qcow2', imgpath]
        retcode = subprocess.call(imgcmd)
        if retcode != 0:
            debug("Unable to create image")
            return
        self.data['path'] = imgpath
Exemplo n.º 7
0
 def run(self):
     debug("Starting ZMQ Listener")
     self._setup()
     while not self.shutdown.is_set():
         resp = {}
         resp['exception'] = False
         try:
             msg = json.loads(self.sock.recv(flags=zmq.NOBLOCK))
         except zmq.ZMQError:
             time.sleep(0.001)
             continue
         debug("received: " + str(msg))
         if not self.handlers.has_key(msg['method']):
             debug("no handler for request type")
             resp['return'] = 'unknown method'
             resp['exception'] = True
         else:
             try:
                 resp['return'] = self.handlers[msg['method']](msg['args'])
             except Exception:
                 debug("unhandled exception while processing request")
                 resp['return'] = traceback.format_exc()
                 resp['exception'] = True
 
         resp['method'] = msg['method']
         
         self.sock.send(json.dumps(resp))
     self.done.set()
Exemplo n.º 8
0
Arquivo: vm.py Projeto: cloudcache/omg
 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()
Exemplo n.º 9
0
Arquivo: vm.py Projeto: cloudcache/omg
    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()
Exemplo n.º 10
0
 def __exit__(self, t, v, tb):
     debug("Exiting daemon Context")
     self.lock.release()
     super(Daemon, self).__exit__(t, v, tb)
Exemplo n.º 11
0
 def __enter__(self):
     debug("Entering daemon Context")
     self.files_preserve = open_files()
     super(Daemon, self).__enter__()
Exemplo n.º 12
0
 def stop(self, uuid):
     debug("stopping %s" % uuid)
     dom = self.conn.lookupByUUIDString(uuid)
     dom.shutdown()
Exemplo n.º 13
0
Arquivo: vm.py Projeto: cloudcache/omg
 def update_xml(self):
     xmld = "%s/%s.xml" % (self.conf['domain_xml_path'], self.key)
     with open(xmld, 'w') as fp:
         fp.write(self.xml())
         os.chmod(xmld, 0744)
     debug(self.data)
Exemplo n.º 14
0
 def shut(self, a, b):
     debug("Shutting down")
     self.shutdown.set()
Exemplo n.º 15
0
 def add_class(self, cls):
     debug("Registered API Class: %r" % cls)
     for m in dir(cls):
         a = getattr(cls, m)
         if callable(a):
             self.handlers[m] = a