Example #1
0
    def _GET(self, *param, **params):

        if self.input.has_key('job_id') is True:
            self.view.job_id = self.input.job_id
        else:
            self.view.job_id = None

        host_id =  param[0]
        host_id = self.chk_hostby1(param)
        if host_id is None:
            return web.notfound()

        uri_id =  param[1]
        if uri_id is None:
            return web.notfound()

        model = findbyhost1(self.orm, host_id)

        if self.is_mode_input() is False:
            if model.attribute == 2:
                info = {}
                segs = uri_split(model.hostname)
                uri = uri_join(segs, without_auth=True)
                creds = ''
                if segs["user"] is not None:
                    creds += segs["user"]
                    if segs["passwd"] is not None:
                        creds += ':' + segs["passwd"]
                self.kvc = KaresansuiVirtConnectionAuth(uri,creds)

                try:
                    host = MergeHost(self.kvc, model)
                    for guest in host.guests:
                        if not '__guest' in locals():
                            _virt = self.kvc.search_kvg_guests(guest.info["model"].name)
                            if 0 < len(_virt):
                                for _v in _virt:
                                    info = _v.get_info()
                                    if info["uuid"] == uri_id or (uri[0:5] == "test:"):
                                        __guest = MergeGuest(guest.info["model"],_v)
                                        autostart       = _v.autostart()
                                        status          = _v.status()
                                        is_creatable    = _v.is_creatable()
                                        is_shutdownable = _v.is_shutdownable()
                                        is_suspendable  = _v.is_suspendable()
                                        is_resumable    = _v.is_resumable()
                                        is_destroyable  = _v.is_destroyable()
                                        is_active       = _v.is_active()
                                        break

                    if self.is_json() is True:
                        json_host  = host.get_json(self.me.languages)
                        json_guest = __guest.get_json(self.me.languages)
                        self.view.data = json_dumps(
                            {
                                "parent_model": json_host["model"],
                                "parent_virt": json_host["virt"],
                                "model": json_guest["model"],
                                "virt": json_guest["virt"],
                                "info": info,
                                "autostart": autostart,
                                "status": status,
                                "is_creatable": is_creatable,
                                "is_shutdownable": is_shutdownable,
                                "is_suspendable": is_suspendable,
                                "is_resumable": is_resumable,
                                "is_destroyable": is_destroyable,
                                "is_active": is_active,
                            }
                        )
                    else:
                        self.view.parent_model = host.info["model"]
                        self.view.parent_virt = host.info["virt"]
                        self.view.model = __guest.info["model"]
                        self.view.virt = __guest.info["virt"]
                        self.view.info = info
                        self.view.autostart = autostart
                        self.view.status = status
                        self.view.is_creatable = is_creatable
                        self.view.is_shutdownable = is_shutdownable
                        self.view.is_suspendable = is_suspendable
                        self.view.is_resumable = is_resumable
                        self.view.is_destroyable = is_destroyable
                        self.view.is_active = is_active
                finally:
                    self.kvc.close()

        return True
Example #2
0
    def _GET(self, *param, **params):
        (host_id, guest_id) = self.chk_guestby1(param)

        if self.input.has_key('job_id') is True:
            self.view.job_id = self.input.job_id
        else:
            self.view.job_id = None

        if guest_id is None:
            return web.notfound()

        model = findbyguest1(self.orm, guest_id)

        self.kvc = KaresansuiVirtConnection()
        if self.is_mode_input() is True:
            try:
                domname = self.kvc.uuid_to_domname(model.uniq_key)
                if not domname:
                    return web.notfound()

                virt = self.kvc.search_kvg_guests(domname)[0]
                guest = MergeGuest(model, virt)
                self.view.model = guest.info["model"]
                return True
            except:
                self.kvc.close()
                raise
        else:
            try:
                domname = self.kvc.uuid_to_domname(model.uniq_key)
                if not domname:
                    return web.notfound()

                virt = self.kvc.search_kvg_guests(domname)[0]

                guest = MergeGuest(model, virt)

                guest_info = guest.info["virt"].get_info()
                info = {}
                info['memory'] = guest_info["memory"]
                info['cpu'] = guest_info["cpuTime"]
                info['os'] = guest_info["OSType"]
                info['hypervisor'] = guest_info["hypervisor"]
                info['type'] = guest_info["VMType"]
                info['hv_version'] = guest_info["hv_version"]

                disk_info = guest.info["virt"].get_disk_info()
                interface_info = guest.info["virt"].get_interface_info()
                net_info = guest.info["virt"].get_netinfo()
                graphics_info = guest.info["virt"].get_graphics_info()
                vcpu_info = guest.info["virt"].get_vcpus_info()

                pool_info = []
                pool_vols_info = []
                already_vols = []
                pools = self.kvc.get_storage_pool_name_bydomain(domname)
                if len(pools) > 0:
                    for pool in pools:
                        pool_obj = self.kvc.search_kvn_storage_pools(pool)[0]
                        if pool_obj.is_active() is True:
                            pool_info = pool_obj.get_info()

                            vols_obj = pool_obj.search_kvn_storage_volumes(
                                self.kvc)
                            vols_info = {}

                            for vol_obj in vols_obj:
                                vol_name = vol_obj.get_storage_volume_name()
                                vols_info[vol_name] = vol_obj.get_info()

                            pool_vols_info = vols_info

                if self.__template__["media"] == 'json':
                    json_guest = guest.get_json(self.me.languages)
                    self.view.data = json_dumps({
                        "model":
                        json_guest["model"],
                        "virt":
                        json_guest["virt"],
                        "autostart":
                        guest.info["virt"].autostart(),
                        "info":
                        info,
                        "disk_info":
                        disk_info,
                        "net_info":
                        net_info,
                        "interface_info":
                        interface_info,
                        "pool_info":
                        pool_info,
                        "pool_vols_info":
                        pool_vols_info,
                        "graphics_info":
                        graphics_info,
                        "vcpu_info":
                        vcpu_info,
                    })
                else:
                    self.view.model = guest.info["model"]
                    self.view.virt = guest.info["virt"]
                    self.view.autostart = guest.info["virt"].autostart()
                    self.view.info = info
                    self.view.disk_info = disk_info
                    self.view.net_info = net_info
                    self.view.interface_info = interface_info
                    self.view.pool_info = pool_info
                    self.view.pool_vols_info = pool_vols_info
                    self.view.graphics_info = graphics_info
                    self.view.vcpu_info = vcpu_info
            except:
                self.kvc.close()
                raise

            return True
Example #3
0
    def _GET(self, *param, **params):
        (host_id, guest_id) = self.chk_guestby1(param)

        if self.input.has_key('job_id') is True:
            self.view.job_id = self.input.job_id
        else:
            self.view.job_id = None

        if guest_id is None:
            return web.notfound()

        model = findbyguest1(self.orm, guest_id)

        self.kvc = KaresansuiVirtConnection()
        if self.is_mode_input() is True:
            try:
                domname = self.kvc.uuid_to_domname(model.uniq_key)
                if not domname:
                    return web.notfound()

                virt = self.kvc.search_kvg_guests(domname)[0]
                guest = MergeGuest(model, virt)
                self.view.model = guest.info["model"]
                return True
            except:
                self.kvc.close()
                raise
        else:
            try:
                domname = self.kvc.uuid_to_domname(model.uniq_key)
                if not domname:
                    return web.notfound()

                virt = self.kvc.search_kvg_guests(domname)[0]

                guest = MergeGuest(model, virt)

                guest_info = guest.info["virt"].get_info()
                info = {}
                info['memory'] = guest_info["memory"]
                info['cpu'] = guest_info["cpuTime"]
                info['os'] = guest_info["OSType"]
                info['hypervisor'] = guest_info["hypervisor"]
                info['type'] = guest_info["VMType"]
                info['hv_version'] = guest_info["hv_version"]

                disk_info = guest.info["virt"].get_disk_info()
                interface_info = guest.info["virt"].get_interface_info()
                net_info = guest.info["virt"].get_netinfo()
                graphics_info = guest.info["virt"].get_graphics_info()
                vcpu_info = guest.info["virt"].get_vcpus_info()

                pool_info = []
                pool_vols_info = []
                already_vols = []
                pools = self.kvc.get_storage_pool_name_bydomain(domname)
                if len(pools) > 0:
                    for pool in pools:
                        pool_obj = self.kvc.search_kvn_storage_pools(pool)[0]
                        if pool_obj.is_active() is True:
                            pool_info = pool_obj.get_info()

                            vols_obj = pool_obj.search_kvn_storage_volumes(self.kvc)
                            vols_info = {}

                            for vol_obj in vols_obj:
                                vol_name = vol_obj.get_storage_volume_name()
                                vols_info[vol_name] = vol_obj.get_info()

                            pool_vols_info = vols_info

                if self.__template__["media"] == 'json':
                    json_guest = guest.get_json(self.me.languages)
                    self.view.data = json_dumps(
                        {
                            "model": json_guest["model"],
                            "virt": json_guest["virt"],
                            "autostart": guest.info["virt"].autostart(),
                            "info": info,
                            "disk_info": disk_info,
                            "net_info": net_info,
                            "interface_info": interface_info,
                            "pool_info": pool_info,
                            "pool_vols_info": pool_vols_info,
                            "graphics_info": graphics_info,
                            "vcpu_info": vcpu_info,
                        }
                    )
                else:
                    self.view.model = guest.info["model"]
                    self.view.virt = guest.info["virt"]
                    self.view.autostart = guest.info["virt"].autostart()
                    self.view.info = info
                    self.view.disk_info = disk_info
                    self.view.net_info = net_info
                    self.view.interface_info = interface_info
                    self.view.pool_info = pool_info
                    self.view.pool_vols_info = pool_vols_info
                    self.view.graphics_info = graphics_info
                    self.view.vcpu_info = vcpu_info
            except:
                self.kvc.close()
                raise

            return True