Exemplo n.º 1
0
 def storagepool_lookup(self, name):
     pool = self._get_storagepool(name)
     info = pool.info()
     xml = pool.XMLDesc(0)
     path = xmlutils.xpath_get_text(xml, "/pool/target/path")[0]
     pool_type = xmlutils.xpath_get_text(xml, "/pool/@type")[0]
     return {'state': Model.pool_state_map[info[0]],
             'path': path,
             'type': pool_type,
             'capacity': info[1] >> 20,
             'allocated': info[2] >> 20,
             'available': info[3] >> 20}
Exemplo n.º 2
0
 def storagepool_lookup(self, name):
     pool = self._get_storagepool(name)
     info = pool.info()
     nr_volumes = self._get_storagepool_vols_num(pool)
     autostart = True if pool.autostart() else False
     xml = pool.XMLDesc(0)
     path = xmlutils.xpath_get_text(xml, "/pool/target/path")[0]
     pool_type = xmlutils.xpath_get_text(xml, "/pool/@type")[0]
     return {'state': Model.pool_state_map[info[0]],
             'path': path,
             'type': pool_type,
             'autostart': autostart,
             'capacity': info[1],
             'allocated': info[2],
             'available': info[3],
             'nr_volumes': nr_volumes}
Exemplo n.º 3
0
 def _vm_get_graphics(self, name):
     dom = self._get_vm(name)
     xml = dom.XMLDesc(0)
     expr = "/domain/devices/graphics/@type"
     res = xmlutils.xpath_get_text(xml, expr)
     graphics_type = res[0] if res else None
     port = None
     if graphics_type:
         expr = "/domain/devices/graphics[@type='%s']/@port" % graphics_type
         res = xmlutils.xpath_get_text(xml, expr)
         port = int(res[0]) if res else None
     # FIX ME
     # graphics_type should be 'vnc' or None.  'spice' should only be
     # returned if we support it in the future.
     graphics_type = None if graphics_type != "vnc" else graphics_type
     return graphics_type, port
Exemplo n.º 4
0
    def storagevolume_lookup(self, pool, name):
        vol = self._get_storagevolume(pool, name)
        path = vol.path()
        info = vol.info()
        xml = vol.XMLDesc(0)
        fmt = xmlutils.xpath_get_text(xml, "/volume/target/format/@type")[0]
        res = dict(type=Model.volume_type_map[info[0]],
                   capacity=info[1],
                   allocation=info[2],
                   path=path,
                   format=fmt)
        if fmt == 'iso':
            if os.path.islink(path):
                path = os.path.join(os.path.dirname(path), os.readlink(path))
            os_distro = os_version = 'unknown'
            try:
                os_distro, os_version = isoinfo.probe_one(path)
                bootable = True
            except isoinfo.IsoFormatError:
                bootable = False
            res.update(
                dict(os_distro=os_distro,
                     os_version=os_version,
                     path=path,
                     bootable=bootable))

        return res
Exemplo n.º 5
0
 def _vm_get_graphics(self, name):
     dom = self._get_vm(name)
     xml = dom.XMLDesc(0)
     expr = "/domain/devices/graphics/@type"
     res = xmlutils.xpath_get_text(xml, expr)
     graphics_type = res[0] if res else None
     port = None
     if graphics_type:
         expr = "/domain/devices/graphics[@type='%s']/@port" % graphics_type
         res = xmlutils.xpath_get_text(xml, expr)
         port = int(res[0]) if res else None
     # FIX ME
     # graphics_type should be 'vnc' or None.  'spice' should only be
     # returned if we support it in the future.
     graphics_type = None if graphics_type != "vnc" else graphics_type
     return graphics_type, port
Exemplo n.º 6
0
 def storagepool_lookup(self, name):
     pool = self._get_storagepool(name)
     info = pool.info()
     nr_volumes = self._get_storagepool_vols_num(pool)
     autostart = True if pool.autostart() else False
     xml = pool.XMLDesc(0)
     path = xmlutils.xpath_get_text(xml, "/pool/target/path")[0]
     pool_type = xmlutils.xpath_get_text(xml, "/pool/@type")[0]
     return {
         'state': Model.pool_state_map[info[0]],
         'path': path,
         'type': pool_type,
         'autostart': autostart,
         'capacity': info[1],
         'allocated': info[2],
         'available': info[3],
         'nr_volumes': nr_volumes
     }
Exemplo n.º 7
0
 def storagevolume_lookup(self, pool, name):
     vol = self._get_storagevolume(pool, name)
     path = vol.path()
     info = vol.info()
     xml = vol.XMLDesc(0)
     fmt = xmlutils.xpath_get_text(xml, "/volume/target/format/@type")[0]
     return {'type': Model.volume_type_map[info[0]],
             'capacity': info[1] >> 20,
             'allocation': info[2] >> 20,
             'path': path,
             'format': fmt}
Exemplo n.º 8
0
    def vm_connect(self, name):
        dom = self._get_vm(name)
        xml = dom.XMLDesc(0)
        expr = "/domain/devices/graphics[@type='vnc']/@port"
        res = xmlutils.xpath_get_text(xml, expr)

        if len(res) < 1:
            raise OperationFailed("Unable to find VNC port in %s" % name)

        vnc_port = int(res[0])
        vnc_port = vnc.new_ws_proxy(vnc_port)
        self.vnc_ports[name] = vnc_port
Exemplo n.º 9
0
    def storagevolume_lookup(self, pool, name):
        vol = self._get_storagevolume(pool, name)
        path = vol.path()
        info = vol.info()
        xml = vol.XMLDesc(0)
        fmt = xmlutils.xpath_get_text(xml, "/volume/target/format/@type")[0]
        res = dict(type=Model.volume_type_map[info[0]],
                   capacity=info[1],
                   allocation=info[2],
                   path=path,
                   format=fmt)
        if fmt == 'iso':
            if os.path.islink(path):
                path = os.path.join(os.path.dirname(path), os.readlink(path))
            os_distro = os_version = 'unknown'
            try:
                os_distro, os_version = isoinfo.probe_one(path)
                bootable = True
            except isoinfo.IsoFormatError:
                bootable = False
            res.update(
                dict(os_distro=os_distro, os_version=os_version, path=path, bootable=bootable))

        return res
Exemplo n.º 10
0
 def _vm_get_disk_paths(self, dom):
     xml = dom.XMLDesc(0)
     xpath = "/domain/devices/disk[@device='disk']/source/@file"
     return xmlutils.xpath_get_text(xml, xpath)
Exemplo n.º 11
0
        name = get_vm_name(params.get('name'), t_name, vm_list)
        # incoming text, from js json, is unicode, do not need decode
        if name in vm_list:
            raise InvalidOperation("VM already exists")
        t = self._get_template(t_name)

        if not self.qemu_stream and t.info.get('iso_stream', False):
            raise InvalidOperation("Remote ISO image is not supported by this server.")

        vm_uuid = str(uuid.uuid4())
        conn = self.conn.get()
        pool_uri = params.get('storagepool', t.info['storagepool'])
        pool_name = pool_name_from_uri(pool_uri)
        pool = conn.storagePoolLookupByName(pool_name)
        xml = pool.XMLDesc(0)
        storage_path = xmlutils.xpath_get_text(xml, "/pool/target/path")[0]

        # Provision storage:
        # TODO: Rebase on the storage API once upstream
        vol_list = t.to_volume_list(vm_uuid, storage_path)
        for v in vol_list:
            # outgoing text to libvirt, encode('utf-8')
            pool.createXML(v['xml'].encode('utf-8'), 0)

        # Store the icon for displaying later
        icon = t.info.get('icon')
        if icon:
            with self.objstore as session:
                session.store('vm', vm_uuid, {'icon': icon})

        libvirt_stream = False if len(self.libvirt_stream_protocols) == 0 else True
Exemplo n.º 12
0
 def _vm_get_disk_paths(self, dom):
     xml = dom.XMLDesc(0)
     xpath = "/domain/devices/disk[@device='disk']/source/@file"
     return xmlutils.xpath_get_text(xml, xpath)
Exemplo n.º 13
0
        # incoming text, from js json, is unicode, do not need decode
        if name in vm_list:
            raise InvalidOperation("VM already exists")
        t = self._get_template(t_name)

        if not self.qemu_stream and t.info.get('iso_stream', False):
            raise InvalidOperation(
                "Remote ISO image is not supported by this server.")

        vm_uuid = str(uuid.uuid4())
        conn = self.conn.get()
        pool_uri = params.get('storagepool', t.info['storagepool'])
        pool_name = pool_name_from_uri(pool_uri)
        pool = conn.storagePoolLookupByName(pool_name)
        xml = pool.XMLDesc(0)
        storage_path = xmlutils.xpath_get_text(xml, "/pool/target/path")[0]

        # Provision storage:
        # TODO: Rebase on the storage API once upstream
        vol_list = t.to_volume_list(vm_uuid, storage_path)
        for v in vol_list:
            # outgoing text to libvirt, encode('utf-8')
            pool.createXML(v['xml'].encode('utf-8'), 0)

        # Store the icon for displaying later
        icon = t.info.get('icon')
        if icon:
            with self.objstore as session:
                session.store('vm', vm_uuid, {'icon': icon})

        libvirt_stream = False if len(