⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xendapi.py

📁 xen 3.2.2 源码
💻 PY
📖 第 1 页 / 共 5 页
字号:
        return xen_api_success(domid is None and -1 or domid)    def VM_get_is_control_domain(self, session, vm_ref):        xd = XendDomain.instance()        return xen_api_success(            xd.get_vm_by_uuid(vm_ref) == xd.privilegedDomain())    def VM_set_name_label(self, session, vm_ref, label):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        dom.setName(label)        return self._VM_save(dom)        def VM_set_name_description(self, session, vm_ref, desc):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        return xen_api_todo()        def VM_set_user_version(self, session, vm_ref, ver):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        return xen_api_todo()        def VM_set_is_a_template(self, session, vm_ref, is_template):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        return xen_api_todo()        def VM_set_memory_dynamic_max(self, session, vm_ref, mem):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        dom.set_memory_dynamic_max(int(mem))        return self._VM_save(dom)    def VM_set_memory_dynamic_min(self, session, vm_ref, mem):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        dom.set_memory_dynamic_min(int(mem))        return self._VM_save(dom)    def VM_set_memory_static_max(self, session, vm_ref, mem):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        dom.set_memory_static_max(int(mem))        return self._VM_save(dom)        def VM_set_memory_static_min(self, session, vm_ref, mem):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        dom.set_memory_static_min(int(mem))        return self._VM_save(dom)    def VM_set_memory_dynamic_max_live(self, session, vm_ref, mem):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        dom.set_memory_dynamic_max(int(mem))        # need to pass target as MiB        dom.setMemoryTarget(int(mem)/1024/1024)        return xen_api_success_void()    def VM_set_memory_dynamic_min_live(self, session, vm_ref, mem):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        dom.set_memory_dynamic_min(int(mem))        # need to pass target as MiB        dom.setMemoryTarget(int(mem)/1024/1024)        return xen_api_success_void()    def VM_set_VCPUs_params(self, session, vm_ref, value):        return self.VM_set('vcpus_params', session, vm_ref, value)    def VM_add_to_VCPUs_params(self, session, vm_ref, key, value):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        if 'vcpus_params' not in dom.info:            dom.info['vcpus_params'] = {}        dom.info['vcpus_params'][key] = value        return self._VM_save(dom)    def VM_add_to_VCPUs_params_live(self, session, vm_ref, key, value):        self.VM_add_to_VCPUs_params(session, vm_ref, key, value)        self._VM_VCPUs_params_refresh(vm_ref)        return xen_api_success_void()    def _VM_VCPUs_params_refresh(self, vm_ref):        xendom  = XendDomain.instance()        xeninfo = xendom.get_vm_by_uuid(vm_ref)        #update the cpumaps        for key, value in xeninfo.info['vcpus_params'].items():            if key.startswith("cpumap"):                vcpu = int(key[6:])                try:                    cpus = map(int, value.split(","))                    xendom.domain_pincpu(xeninfo.getDomid(), vcpu, cpus)                except Exception, ex:                    log.exception(ex)        #need to update sched params aswell        if 'weight' in xeninfo.info['vcpus_params'] \           and 'cap' in xeninfo.info['vcpus_params']:            weight = xeninfo.info['vcpus_params']['weight']            cap = xeninfo.info['vcpus_params']['cap']            xendom.domain_sched_credit_set(xeninfo.getDomid(), weight, cap)    def VM_set_VCPUs_number_live(self, _, vm_ref, num):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        dom.setVCpuCount(int(num))        return xen_api_success_void()         def VM_remove_from_VCPUs_params(self, session, vm_ref, key):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        if 'vcpus_params' in dom.info \               and key in dom.info['vcpus_params']:            del dom.info['vcpus_params'][key]            return self._VM_save(dom)        else:            return xen_api_success_void()        def VM_set_VCPUs_at_startup(self, session, vm_ref, num):        return self.VM_set('VCPUs_at_startup', session, vm_ref, num)    def VM_set_VCPUs_max(self, session, vm_ref, num):        return self.VM_set('VCPUs_max', session, vm_ref, num)    def VM_set_actions_after_shutdown(self, session, vm_ref, action):        if action not in XEN_API_ON_NORMAL_EXIT:            return xen_api_error(['VM_ON_NORMAL_EXIT_INVALID', vm_ref])        return self.VM_set('actions_after_shutdown', session, vm_ref, action)        def VM_set_actions_after_reboot(self, session, vm_ref, action):        if action not in XEN_API_ON_NORMAL_EXIT:            return xen_api_error(['VM_ON_NORMAL_EXIT_INVALID', vm_ref])        return self.VM_set('actions_after_reboot', session, vm_ref, action)        def VM_set_actions_after_suspend(self, session, vm_ref, action):        if action not in XEN_API_ON_NORMAL_EXIT:            return xen_api_error(['VM_ON_NORMAL_EXIT_INVALID', vm_ref])        return self.VM_set('actions_after_suspend', session, vm_ref, action)        def VM_set_actions_after_crash(self, session, vm_ref, action):        if action not in XEN_API_ON_CRASH_BEHAVIOUR:            return xen_api_error(['VM_ON_CRASH_BEHAVIOUR_INVALID', vm_ref])        return self.VM_set('actions_after_crash', session, vm_ref, action)    def VM_set_HVM_boot_policy(self, session, vm_ref, value):        if value != "" and value != "BIOS order":            return xen_api_error(                ['VALUE_NOT_SUPPORTED', 'VM.HVM_boot_policy', value,                 'Xend supports only the "BIOS order" boot policy.'])        else:            return self.VM_set('HVM_boot_policy', session, vm_ref, value)    def VM_set_HVM_boot_params(self, session, vm_ref, value):        return self.VM_set('HVM_boot_params', session, vm_ref, value)    def VM_add_to_HVM_boot_params(self, session, vm_ref, key, value):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        if 'HVM_boot_params' not in dom.info:            dom.info['HVM_boot_params'] = {}        dom.info['HVM_boot_params'][key] = value        return self._VM_save(dom)    def VM_remove_from_HVM_boot_params(self, session, vm_ref, key):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        if 'HVM_boot_params' in dom.info \               and key in dom.info['HVM_boot_params']:            del dom.info['HVM_boot_params'][key]            return self._VM_save(dom)        else:            return xen_api_success_void()    def VM_set_PV_bootloader(self, session, vm_ref, value):        return self.VM_set('PV_bootloader', session, vm_ref, value)    def VM_set_PV_kernel(self, session, vm_ref, value):        return self.VM_set('PV_kernel', session, vm_ref, value)    def VM_set_PV_ramdisk(self, session, vm_ref, value):        return self.VM_set('PV_ramdisk', session, vm_ref, value)    def VM_set_PV_args(self, session, vm_ref, value):        return self.VM_set('PV_args', session, vm_ref, value)    def VM_set_PV_bootloader_args(self, session, vm_ref, value):        return self.VM_set('PV_bootloader_args', session, vm_ref, value)    def VM_set_platform(self, session, vm_ref, value):        return self.VM_set('platform', session, vm_ref, value)        def VM_add_to_platform(self, session, vm_ref, key, value):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        plat = dom.get_platform()        plat[key] = value        return self.VM_set_platform(session, vm_ref, plat)    def VM_remove_from_platform(self, session, vm_ref, key):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        plat = dom.get_platform()        if key in plat:            del plat[key]            return self.VM_set_platform(session, vm_ref, plat)        else:            return xen_api_success_void()    def VM_set_other_config(self, session, vm_ref, value):        return self.VM_set('other_config', session, vm_ref, value)    def VM_add_to_other_config(self, session, vm_ref, key, value):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        if dom and 'other_config' in dom.info:            dom.info['other_config'][key] = value        return self._VM_save(dom)    def VM_remove_from_other_config(self, session, vm_ref, key):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        if dom and 'other_config' in dom.info \               and key in dom.info['other_config']:            del dom.info['other_config'][key]            return self._VM_save(dom)        else:            return xen_api_success_void()    def VM_get_crash_dumps(self, _, vm_ref):        return xen_api_todo()    # class methods    def VM_get_all(self, session):        refs = [d.get_uuid() for d in XendDomain.instance().list('all')]        return xen_api_success(refs)        def VM_get_by_name_label(self, session, label):        xendom = XendDomain.instance()        dom = xendom.domain_lookup_nr(label)        if dom:            return xen_api_success([dom.get_uuid()])        return xen_api_success([])    def VM_get_security_label(self, session, vm_ref):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        label = dom.get_security_label()        return xen_api_success(label)    def VM_set_security_label(self, session, vm_ref, sec_label, old_label):        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)        (rc, errors, oldlabel, new_ssidref) = \                                 dom.set_security_label(sec_label, old_label)        if rc != xsconstants.XSERR_SUCCESS:            return xen_api_error(['SECURITY_ERROR', rc,                                 xsconstants.xserr2string(-rc)])        if rc == 0:            rc = new_ssidref        return xen_api_success(rc)    def VM_create(self, session, vm_struct):        xendom = XendDomain.instance()        domuuid = XendTask.log_progress(0, 100,                                        xendom.create_domain, vm_struct)        return xen_api_success(domuuid)        # object methods    def VM_get_record(self, session, vm_ref):        xendom = XendDomain.instance()        xeninfo = xendom.get_vm_by_uuid(vm_ref)        if not xeninfo:            return xen_api_error(['HANDLE_INVALID', 'VM', vm_ref])        domid = xeninfo.getDomid()        record = {            'uuid': xeninfo.get_uuid(),            'power_state': xeninfo.get_power_state(),            'name_label': xeninfo.getName(),            'name_description': xeninfo.getName(),            'user_version': 1,            'is_a_template': xeninfo.info['is_a_template'],            'auto_power_on': False,            'resident_on': XendNode.instance().uuid,            'memory_static_min': xeninfo.get_memory_static_min(),            'memory_static_max': xeninfo.get_memory_static_max(),            'memory_dynamic_min': xeninfo.get_memory_dynamic_min(),            'memory_dynamic_max': xeninfo.get_memory_dynamic_max(),            'VCPUs_params': xeninfo.get_vcpus_params(),            'VCPUs_at_startup': xeninfo.getVCpuCount(),            'VCPUs_max': xeninfo.getVCpuCount(),            'actions_after_shutdown': xeninfo.get_on_shutdown(),            'actions_after_reboot': xeninfo.get_on_reboot(),            'actions_after_suspend': xeninfo.get_on_suspend(),            'actions_after_crash': xeninfo.get_on_crash(),            'consoles': xeninfo.get_consoles(),            'VIFs': xeninfo.get_vifs(),            'VBDs': xeninfo.get_vbds(),            'VTPMs': xeninfo.get_vtpms(),            'PV_bootloader': xeninfo.info.get('PV_bootloader'),            'PV_kernel': xeninfo.info.get('PV_kernel'),            'PV_ramdisk': xeninfo.info.get('PV_ramdisk'),            'PV_args': xeninfo.info.get('PV_args'),            'PV_bootloader_args': xeninfo.info.get('PV_bootloader_args'),            'HVM_boot_policy': xeninfo.info.get('HVM_boot_policy'),            'HVM_boot_params': xeninfo.info.get('HVM_boot_params'),            'platform': xeninfo.get_platform(),            'PCI_bus': xeninfo.get_pci_bus(),            'tools_version': xeninfo.get_tools_version(),            'other_config': xeninfo.info.get('other_config', {}),            'domid': domid is None and -1 or domid,            'is_control_domain': xeninfo.info['is_control_domain'],            'metrics': xeninfo.get_metrics(),            'security_label': xeninfo.get_security_label(),            'crash_dumps': []        }        return xen_api_success(record)    def VM_clean_reboot(self, session, vm_ref):        xendom = XendDomain.instance()        xeninfo = xendom.get_vm_by_uuid(vm_ref)        XendTask.log_progress(0, 100, xeninfo.shutdown, "reboot")        return xen_api_success_void()        def VM_clean_shutdown(self, session, vm_ref):        xendom = XendDomain.instance()        xeninfo = xendom.get_vm_by_uuid(vm_ref)        XendTask.log_progress(0, 100, xeninfo.shutdown, "poweroff")                return xen_api_success_void()        def VM_clone(self, session, vm_ref):        return xen_api_error(XEND_ERROR_UNSUPPORTED)        def VM_destroy(self, session, vm_ref):        return XendTask.log_progress(0, 100, do_vm_func,                                     "domain_delete", vm_ref)        def VM_hard_reboot(self, session, vm_ref):        return xen_api_error(XEND_ERROR_UNSUPPORTED)        def VM_hard_shutdown(self, session, vm_ref):        return XendTask.log_progress(0, 100, do_vm_func,                                     "domain_destroy", vm_ref)        def VM_pause(self, session, vm_ref):        return XendTask.log_progress(0, 100, do_vm_func,                                     "domain_pause", vm_ref)        def VM_resume(self, session, vm_ref, start_paused):        return XendTask.log_progress(0, 100, do_vm_func,                                     "domain_resume", vm_ref,                                     start_paused = start_paused)        def VM_start(self, session, vm_ref, start_paused):        try:            return XendTask.log_progress(0, 100, do_vm_func,                                         "domain_start", vm_ref,                                         start_paused = start_paused)        except HVMRequired, exn:            return xen_api_error(['VM_HVM_REQUIRED', vm_ref])    def VM_suspend(s

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -