2020-10-02 09:37:50 +03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright (C) 2020 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/>.
|
|
|
|
|
|
|
|
"""
|
2020-11-19 06:51:03 +02:00
|
|
|
API routes for managing the GNS3 VM.
|
2020-10-02 09:37:50 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
from fastapi import APIRouter
|
|
|
|
from fastapi.encoders import jsonable_encoder
|
|
|
|
|
|
|
|
from gns3server.controller import Controller
|
2020-10-31 07:32:21 +02:00
|
|
|
from gns3server import schemas
|
2020-10-02 09:37:50 +03:00
|
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
|
|
|
2020-10-14 03:19:29 +03:00
|
|
|
@router.get("/engines")
|
|
|
|
async def get_engines():
|
2020-10-02 09:37:50 +03:00
|
|
|
"""
|
|
|
|
Return the list of supported engines for the GNS3VM.
|
|
|
|
"""
|
|
|
|
|
|
|
|
gns3_vm = Controller().instance().gns3vm
|
|
|
|
return gns3_vm.engine_list()
|
|
|
|
|
|
|
|
|
2020-10-14 03:19:29 +03:00
|
|
|
@router.get("/engines/{engine}/vms")
|
2020-10-02 09:37:50 +03:00
|
|
|
async def get_vms(engine: str):
|
|
|
|
"""
|
2020-10-14 03:19:29 +03:00
|
|
|
Return all the available VMs for a specific virtualization engine.
|
2020-10-02 09:37:50 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
vms = await Controller.instance().gns3vm.list(engine)
|
|
|
|
return vms
|
|
|
|
|
|
|
|
|
2020-10-31 07:32:21 +02:00
|
|
|
@router.get("", response_model=schemas.GNS3VM)
|
2020-10-02 09:37:50 +03:00
|
|
|
async def get_gns3vm_settings():
|
2020-10-14 03:19:29 +03:00
|
|
|
"""
|
|
|
|
Return the GNS3 VM settings.
|
|
|
|
"""
|
2020-10-02 09:37:50 +03:00
|
|
|
|
|
|
|
return Controller.instance().gns3vm.__json__()
|
|
|
|
|
|
|
|
|
2020-10-31 07:32:21 +02:00
|
|
|
@router.put("", response_model=schemas.GNS3VM, response_model_exclude_unset=True)
|
|
|
|
async def update_gns3vm_settings(gns3vm_data: schemas.GNS3VM):
|
2020-10-14 03:19:29 +03:00
|
|
|
"""
|
|
|
|
Update the GNS3 VM settings.
|
|
|
|
"""
|
2020-10-02 09:37:50 +03:00
|
|
|
|
|
|
|
controller = Controller().instance()
|
|
|
|
gns3_vm = controller.gns3vm
|
|
|
|
await gns3_vm.update_settings(jsonable_encoder(gns3vm_data, exclude_unset=True))
|
|
|
|
controller.save()
|
|
|
|
return gns3_vm.__json__()
|