mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
API for creating a VM
This commit is contained in:
14 files changed
+405
-48
No files matched your search
@@ -18,3 +18,5 @@
|
||||
from .hypervisor_handler import HypervisorHandler
|
||||
from .project_handler import ProjectHandler
|
||||
from .version_handler import VersionHandler
|
||||
from .vm_handler import VMHandler
|
||||
|
||||
@@ -44,9 +44,7 @@ class HypervisorHandler:
|
||||
output=HYPERVISOR_OBJECT_SCHEMA)
|
||||
def create(request, response):
|
||||
|
||||
hypervisor = Hypervisor(request.json.pop("hypervisor_id"), **request.json)
|
||||
Controller.instance().addHypervisor(hypervisor)
|
||||
|
||||
hypervisor = yield from Controller.instance().addHypervisor(**request.json)
|
||||
response.set_status(201)
|
||||
response.json(hypervisor)
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import asyncio
|
||||
from ....web.route import Route
|
||||
from ....schemas.project import PROJECT_OBJECT_SCHEMA, PROJECT_CREATE_SCHEMA
|
||||
from ....controller import Controller
|
||||
from ....controller.project import Project
|
||||
|
||||
|
||||
import logging
|
||||
@@ -44,11 +43,11 @@ class ProjectHandler:
|
||||
def create_project(request, response):
|
||||
|
||||
controller = Controller.instance()
|
||||
project = Project(name=request.json.get("name"),
|
||||
path=request.json.get("path"),
|
||||
project_id=request.json.get("project_id"),
|
||||
temporary=request.json.get("temporary", False))
|
||||
yield from controller.addProject(project)
|
||||
project = yield from controller.addProject(
|
||||
name=request.json.get("name"),
|
||||
path=request.json.get("path"),
|
||||
project_id=request.json.get("project_id"),
|
||||
temporary=request.json.get("temporary", False))
|
||||
response.set_status(201)
|
||||
response.json(project)
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2016 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from ....web.route import Route
|
||||
from ....schemas.vm import VM_OBJECT_SCHEMA
|
||||
from ....controller.project import Project
|
||||
from ....controller import Controller
|
||||
|
||||
|
||||
class VMHandler:
|
||||
"""
|
||||
API entry point for VM
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
@Route.post(
|
||||
r"/projects/{project_id}/vms",
|
||||
parameters={
|
||||
"project_id": "UUID for the project"
|
||||
},
|
||||
status_codes={
|
||||
201: "Instance created",
|
||||
400: "Invalid request"
|
||||
},
|
||||
description="Create a new VM instance",
|
||||
input=VM_OBJECT_SCHEMA,
|
||||
output=VM_OBJECT_SCHEMA)
|
||||
def create(request, response):
|
||||
|
||||
controller = Controller.instance()
|
||||
hypervisor = controller.getHypervisor(request.json.pop("hypervisor_id"))
|
||||
project = controller.getProject(request.match_info["project_id"])
|
||||
vm = yield from project.addVM(hypervisor, request.json.pop("vm_id", None), **request.json)
|
||||
response.set_status(201)
|
||||
response.json(vm)
|
||||
|
||||
Reference in new issue
Block a user