Example #1
0
    async def stop_capture(request, response):

        vbox_manager = VirtualBox.instance()
        vm = vbox_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.stop_capture(adapter_number)
        response.set_status(204)
Example #2
0
    async def stream_pcap_file(request, response):

        virtualbox_manager = VirtualBox.instance()
        vm = virtualbox_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 virtualbox_manager.stream_pcap_file(nio, vm.project.id, request, response)
Example #3
0
    async def create(request, response):

        vbox_manager = VirtualBox.instance()
        vm = await vbox_manager.create_node(
            request.json.pop("name"),
            request.match_info["project_id"],
            request.json.get("node_id"),
            request.json.pop("vmname"),
            linked_clone=request.json.pop("linked_clone", False),
            console=request.json.get("console", None),
            console_type=request.json.get("console_type", "telnet"),
            adapters=request.json.get("adapters", 0))

        if "ram" in request.json:
            ram = request.json.pop("ram")
            if ram != vm.ram:
                await vm.set_ram(ram)

        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)
Example #4
0
    async def delete_nio(request, response):

        vbox_manager = VirtualBox.instance()
        vm = vbox_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)
Example #5
0
    def delete(request, response):

        # check the project_id exists
        ProjectManager.instance().get_project(request.match_info["project_id"])
        yield from VirtualBox.instance().delete_node(
            request.match_info["node_id"])
        response.set_status(204)
Example #6
0
    def reload(request, response):

        vbox_manager = VirtualBox.instance()
        vm = vbox_manager.get_node(request.match_info["node_id"],
                                   project_id=request.match_info["project_id"])
        yield from vm.reload()
        response.set_status(204)
Example #7
0
    async def console_ws(request, response):

        virtualbox_manager = VirtualBox.instance()
        vm = virtualbox_manager.get_node(
            request.match_info["node_id"],
            project_id=request.match_info["project_id"])
        return await vm.start_websocket_console(request)
Example #8
0
    async def resume(request, response):

        vbox_manager = VirtualBox.instance()
        vm = vbox_manager.get_node(request.match_info["node_id"],
                                   project_id=request.match_info["project_id"])
        await vm.resume()
        response.set_status(204)
Example #9
0
    def stop_capture(request, response):

        vbox_manager = VirtualBox.instance()
        vm = vbox_manager.get_node(request.match_info["node_id"],
                                   project_id=request.match_info["project_id"])
        vm.stop_capture(int(request.match_info["adapter_number"]))
        response.set_status(204)
Example #10
0
    def update(request, response):

        vbox_manager = VirtualBox.instance()
        vm = vbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])

        if "name" in request.json:
            name = request.json.pop("name")
            vmname = request.json.pop("vmname", None)
            if name != vm.name:
                oldname = vm.name
                vm.name = name
                if vm.linked_clone:
                    try:
                        yield from vm.set_vmname(vm.name)
                    except VirtualBoxError as e:  # In case of error we rollback (we can't change the name when running)
                        vm.name = oldname
                        vm.updated()
                        raise e

        if "adapters" in request.json:
            adapters = int(request.json.pop("adapters"))
            if adapters != vm.adapters:
                yield from vm.set_adapters(adapters)

        if "ram" in request.json:
            ram = request.json.pop("ram")
            if ram != vm.ram:
                yield from vm.set_ram(ram)

        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)
Example #11
0
    def update(request, response):

        vbox_manager = VirtualBox.instance()
        vm = vbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])

        if "name" in request.json:
            name = request.json.pop("name")
            vmname = request.json.pop("vmname", None)
            if name != vm.name:
                oldname = vm.name
                vm.name = name
                if vm.linked_clone:
                    try:
                        yield from vm.set_vmname(vm.name)
                    except VirtualBoxError as e:  # In case of error we rollback (we can't change the name when running)
                        vm.name = oldname
                        vm.updated()
                        raise e

        if "adapters" in request.json:
            adapters = int(request.json.pop("adapters"))
            if adapters != vm.adapters:
                yield from vm.set_adapters(adapters)

        if "ram" in request.json:
            ram = request.json.pop("ram")
            if ram != vm.ram:
                yield from vm.set_ram(ram)

        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)
Example #12
0
    def start_capture(request, response):

        vbox_manager = VirtualBox.instance()
        vm = vbox_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})
Example #13
0
    def delete_nio(request, response):

        vbox_manager = VirtualBox.instance()
        vm = vbox_manager.get_node(request.match_info["node_id"],
                                   project_id=request.match_info["project_id"])
        yield from vm.adapter_remove_nio_binding(
            int(request.match_info["adapter_number"]))
        response.set_status(204)
Example #14
0
    def start_capture(request, response):

        vbox_manager = VirtualBox.instance()
        vm = vbox_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})
Example #15
0
    async def stream_pcap_file(request, response):

        virtualbox_manager = VirtualBox.instance()
        vm = virtualbox_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 virtualbox_manager.stream_pcap_file(nio, vm.project.id, request,
                                                  response)
Example #16
0
    def start(request, response):

        vbox_manager = VirtualBox.instance()
        vm = vbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        if (yield from 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 VMware or KVM (on Linux)")
        yield from vm.start()
        response.set_status(204)
Example #17
0
    def update_nio(request, response):

        virtualbox_manager = VirtualBox.instance()
        vm = virtualbox_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)
Example #18
0
    def start(request, response):

        vbox_manager = VirtualBox.instance()
        vm = vbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        if (yield from 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 VMware or KVM (on Linux)")
        yield from vm.start()
        response.set_status(204)
Example #19
0
    def create_nio(request, response):

        vbox_manager = VirtualBox.instance()
        vm = vbox_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_nat"):
            raise HTTPConflict(text="NIO of type {} is not supported".format(nio_type))
        nio = vbox_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)
Example #20
0
    def create_nio(request, response):

        vbox_manager = VirtualBox.instance()
        vm = vbox_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_nat"):
            raise HTTPConflict(text="NIO of type {} is not supported".format(nio_type))
        nio = vbox_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)
Example #21
0
    def update_nio(request, response):

        virtualbox_manager = VirtualBox.instance()
        vm = virtualbox_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)
Example #22
0
    async def update_nio(request, response):

        virtualbox_manager = VirtualBox.instance()
        vm = virtualbox_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"]
        if "suspend" in request.json:
            nio.suspend = request.json["suspend"]
        await vm.adapter_update_nio_binding(adapter_number, nio)
        response.set_status(201)
        response.json(request.json)
Example #23
0
    async def update_nio(request, response):

        virtualbox_manager = VirtualBox.instance()
        vm = virtualbox_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"]
        if "suspend" in request.json:
            nio.suspend = request.json["suspend"]
        await vm.adapter_update_nio_binding(adapter_number, nio)
        response.set_status(201)
        response.json(request.json)
Example #24
0
    def create(request, response):

        vbox_manager = VirtualBox.instance()
        vm = yield from vbox_manager.create_node(request.json.pop("name"),
                                                 request.match_info["project_id"],
                                                 request.json.get("node_id"),
                                                 request.json.pop("vmname"),
                                                 linked_clone=request.json.pop("linked_clone", False),
                                                 console=request.json.get("console", None),
                                                 adapters=request.json.get("adapters", 0))

        if "ram" in request.json:
            ram = request.json.pop("ram")
            if ram != vm.ram:
                yield from vm.set_ram(ram)

        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)
Example #25
0
 async def get_vms(request, response):
     vbox_manager = VirtualBox.instance()
     vms = await vbox_manager.list_vms()
     response.json(vms)
Example #26
0
    async def resume(request, response):

        vbox_manager = VirtualBox.instance()
        vm = vbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        await vm.resume()
        response.set_status(204)
def manager(port_manager):
    m = VirtualBox.instance()
    m.port_manager = port_manager
    return m
Example #28
0
    def delete(request, response):

        # check the project_id exists
        ProjectManager.instance().get_project(request.match_info["project_id"])
        yield from VirtualBox.instance().delete_node(request.match_info["node_id"])
        response.set_status(204)
Example #29
0
    def show(request, response):

        vbox_manager = VirtualBox.instance()
        vm = vbox_manager.get_node(request.match_info["node_id"],
                                   project_id=request.match_info["project_id"])
        response.json(vm)
Example #30
0
 def get_vms(request, response):
     vbox_manager = VirtualBox.instance()
     vms = yield from vbox_manager.list_vms()
     response.json(vms)
Example #31
0
    def reload(request, response):

        vbox_manager = VirtualBox.instance()
        vm = vbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        yield from vm.reload()
        response.set_status(204)
Example #32
0
    def show(request, response):

        vbox_manager = VirtualBox.instance()
        vm = vbox_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
        response.json(vm)
Example #33
0
 def get_vms(request, response):
     vbox_manager = VirtualBox.instance()
     vms = yield from vbox_manager.list_vms()
     response.json(vms)
Example #34
0
async def manager(loop, port_manager):

    m = VirtualBox.instance()
    m.port_manager = port_manager
    return m
def manager(port_manager):
    m = VirtualBox.instance()
    m.port_manager = port_manager
    return m
Example #36
0
 async def get_vms(request, response):
     vbox_manager = VirtualBox.instance()
     vms = await vbox_manager.list_vms()
     response.json(vms)