當前位置: 首頁>>代碼示例>>Python>>正文


Python vmware.VMware類代碼示例

本文整理匯總了Python中gns3server.compute.vmware.VMware的典型用法代碼示例。如果您正苦於以下問題:Python VMware類的具體用法?Python VMware怎麽用?Python VMware使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了VMware類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _set_vcpus_ram

    async def _set_vcpus_ram(self, vcpus, ram):
        """
        Set the number of vCPU cores and amount of RAM for the GNS3 VM.

        :param vcpus: number of vCPU cores
        :param ram: amount of RAM
        """

        # memory must be a multiple of 4 (VMware requirement)
        if ram % 4 != 0:
            raise GNS3VMError("Allocated memory {} for the GNS3 VM must be a multiple of 4".format(ram))

        available_vcpus = psutil.cpu_count(logical=True)
        if vcpus > available_vcpus:
            raise GNS3VMError("You have allocated too many vCPUs for the GNS3 VM! (max available is {} vCPUs)".format(available_vcpus))

        try:
            pairs = VMware.parse_vmware_file(self._vmx_path)
            if vcpus > 1:
                pairs["numvcpus"] = str(vcpus)
                cores_per_sockets = int(vcpus / psutil.cpu_count(logical=False))
                if cores_per_sockets > 1:
                    pairs["cpuid.corespersocket"] = str(cores_per_sockets)
                pairs["memsize"] = str(ram)
                VMware.write_vmx_file(self._vmx_path, pairs)
            log.info("GNS3 VM vCPU count set to {} and RAM amount set to {}".format(vcpus, ram))
        except OSError as e:
            raise GNS3VMError('Could not read/write VMware VMX file "{}": {}'.format(self._vmx_path, e))
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:28,代碼來源:vmware_gns3_vm.py

示例2: stream_pcap_file

    async def stream_pcap_file(request, response):

        vmware_manager = VMware.instance()
        vm = vmware_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        adapter_number = int(request.match_info["adapter_number"])
        nio = vm.get_nio(adapter_number)
        await vmware_manager.stream_pcap_file(nio, vm.project.id, request, response)
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:7,代碼來源:vmware_handler.py

示例3: stop_capture

    def stop_capture(request, response):

        vmware_manager = VMware.instance()
        vm = vmware_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        adapter_number = int(request.match_info["adapter_number"])
        yield from vm.stop_capture(adapter_number)
        response.set_status(204)
開發者ID:athmane,項目名稱:gns3-server,代碼行數:7,代碼來源:vmware_handler.py

示例4: delete_nio

    async def delete_nio(request, response):

        vmware_manager = VMware.instance()
        vm = vmware_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        adapter_number = int(request.match_info["adapter_number"])
        await vm.adapter_remove_nio_binding(adapter_number)
        response.set_status(204)
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:7,代碼來源:vmware_handler.py

示例5: start_capture

    def start_capture(request, response):

        vmware_manager = VMware.instance()
        vm = vmware_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        adapter_number = int(request.match_info["adapter_number"])
        pcap_file_path = os.path.join(vm.project.capture_working_directory(), request.json["capture_file_name"])
        yield from vm.start_capture(adapter_number, pcap_file_path)
        response.json({"pcap_file_path": pcap_file_path})
開發者ID:athmane,項目名稱:gns3-server,代碼行數:8,代碼來源:vmware_handler.py

示例6: test_parse_vmware_file

def test_parse_vmware_file(manager, tmpdir):
    path = str(tmpdir / "test.vmx")
    with open(path, "w+") as f:
        f.write('displayname = "GNS3 VM"\nguestOS = "ubuntu-64"')

    vmx = VMware.parse_vmware_file(path)
    assert vmx["displayname"] == "GNS3 VM"
    assert vmx["guestos"] == "ubuntu-64"
開發者ID:AJNOURI,項目名稱:gns3-server,代碼行數:8,代碼來源:test_vmware_manager.py

示例7: allocate_vmnet

    def allocate_vmnet(request, response):

        vmware_manager = VMware.instance()
        vm = vmware_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        vmware_manager.refresh_vmnet_list(ubridge=False)
        vmnet = vmware_manager.allocate_vmnet()
        vm.vmnets.append(vmnet)
        response.set_status(201)
        response.json({"vmnet": vmnet})
開發者ID:athmane,項目名稱:gns3-server,代碼行數:9,代碼來源:vmware_handler.py

示例8: start

    def start(request, response):

        vmware_manager = VMware.instance()
        vm = vmware_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        if vm.check_hw_virtualization():
            pm = ProjectManager.instance()
            if pm.check_hardware_virtualization(vm) is False:
                raise HTTPConflict(text="Cannot start VM because hardware virtualization (VT-x/AMD-V) is already used by another software like VirtualBox or KVM (on Linux)")
        yield from vm.start()
        response.set_status(204)
開發者ID:athmane,項目名稱:gns3-server,代碼行數:10,代碼來源:vmware_handler.py

示例9: update_nio

    def update_nio(request, response):

        vmware_manager = VMware.instance()
        vm = vmware_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        nio = vm.ethernet_adapters[int(request.match_info["adapter_number"])]
        if "filters" in request.json and nio:
            nio.filters = request.json["filters"]
            yield from vm.adapter_update_nio_binding(int(request.match_info["adapter_number"]), nio)
            response.set_status(201)
            response.json(request.json)
開發者ID:athmane,項目名稱:gns3-server,代碼行數:10,代碼來源:vmware_handler.py

示例10: update

    def update(request, response):

        vmware_manager = VMware.instance()
        vm = vmware_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])

        for name, value in request.json.items():
            if hasattr(vm, name) and getattr(vm, name) != value:
                setattr(vm, name, value)

        vm.updated()
        response.json(vm)
開發者ID:athmane,項目名稱:gns3-server,代碼行數:11,代碼來源:vmware_handler.py

示例11: create_nio

    def create_nio(request, response):

        vmware_manager = VMware.instance()
        vm = vmware_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        nio_type = request.json["type"]
        if nio_type not in ("nio_udp", "nio_vmnet", "nio_nat", "nio_tap"):
            raise HTTPConflict(text="NIO of type {} is not supported".format(nio_type))
        nio = vmware_manager.create_nio(request.json)
        yield from vm.adapter_add_nio_binding(int(request.match_info["adapter_number"]), nio)
        response.set_status(201)
        response.json(nio)
開發者ID:athmane,項目名稱:gns3-server,代碼行數:11,代碼來源:vmware_handler.py

示例12: update_nio

    async def update_nio(request, response):

        vmware_manager = VMware.instance()
        vm = vmware_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        adapter_number = int(request.match_info["adapter_number"])
        nio = vm.get_nio(adapter_number)
        if "filters" in request.json:
            nio.filters = request.json["filters"]
        await vm.adapter_update_nio_binding(adapter_number, nio)
        response.set_status(201)
        response.json(request.json)
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:11,代碼來源:vmware_handler.py

示例13: update

    def update(request, response):

        vmware_manager = VMware.instance()
        vm = vmware_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        # update the console first to avoid issue if updating console type
        vm.console = request.json.pop("console", vm.console)
        for name, value in request.json.items():
            if hasattr(vm, name) and getattr(vm, name) != value:
                setattr(vm, name, value)

        vm.updated()
        response.json(vm)
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:12,代碼來源:vmware_handler.py

示例14: _set_extra_options

    async def _set_extra_options(self):
        try:
            """
            Due to bug/change in VMWare 14 we're not able to pass Hardware Virtualization in GNS3VM.
            We only enable this when it's not present in current configuration and user hasn't deactivated that.
            """
            extra_config = (
                ("vhv.enable", "TRUE"),
            )
            pairs = VMware.parse_vmware_file(self._vmx_path)
            updated = False
            for key, value in extra_config:
                if key not in pairs.keys():
                    pairs[key] = value
                    updated = True
                    log.info("GNS3 VM VMX `{}` set to `{}`".format(key, value))

            if updated:
                VMware.write_vmx_file(self._vmx_path, pairs)
                log.info("GNS3 VM VMX has been updated.")
        except OSError as e:
            raise GNS3VMError('Could not read/write VMware VMX file "{}": {}'.format(self._vmx_path, e))
開發者ID:GNS3,項目名稱:gns3-server,代碼行數:22,代碼來源:vmware_gns3_vm.py

示例15: create

    def create(request, response):

        vmware_manager = VMware.instance()
        vm = yield from vmware_manager.create_node(request.json.pop("name"),
                                                   request.match_info["project_id"],
                                                   request.json.get("node_id"),
                                                   request.json.pop("vmx_path"),
                                                   linked_clone=request.json.pop("linked_clone"),
                                                   console=request.json.get("console", None))

        for name, value in request.json.items():
            if name != "node_id":
                if hasattr(vm, name) and getattr(vm, name) != value:
                    setattr(vm, name, value)

        response.set_status(201)
        response.json(vm)
開發者ID:athmane,項目名稱:gns3-server,代碼行數:17,代碼來源:vmware_handler.py


注:本文中的gns3server.compute.vmware.VMware類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。