mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
Close, commit and delete supported for projects in controller
This commit is contained in:
19 files changed
+560
-117
No files matched your search
@@ -15,6 +15,8 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import asyncio
|
||||
import aiohttp
|
||||
|
||||
from ..config import Config
|
||||
|
||||
@@ -24,6 +26,7 @@ class Controller:
|
||||
|
||||
def __init__(self):
|
||||
self._hypervisors = {}
|
||||
self._projects = {}
|
||||
|
||||
def isEnabled(self):
|
||||
"""
|
||||
@@ -36,7 +39,8 @@ class Controller:
|
||||
"""
|
||||
Add a server to the dictionnary of hypervisors controlled by GNS3
|
||||
"""
|
||||
self._hypervisors[hypervisor.id] = hypervisor
|
||||
if hypervisor.id not in self._hypervisors:
|
||||
self._hypervisors[hypervisor.id] = hypervisor
|
||||
|
||||
@property
|
||||
def hypervisors(self):
|
||||
@@ -45,6 +49,35 @@ class Controller:
|
||||
"""
|
||||
return self._hypervisors
|
||||
|
||||
@asyncio.coroutine
|
||||
def addProject(self, project):
|
||||
"""
|
||||
Add a server to the dictionnary of projects controlled by GNS3
|
||||
"""
|
||||
if project.id not in self._projects:
|
||||
self._projects[project.id] = project
|
||||
for hypervisor in self._hypervisors.values():
|
||||
yield from project.addHypervisor(hypervisor)
|
||||
|
||||
def getProject(self, project_id):
|
||||
"""
|
||||
Return a server or raise a 404
|
||||
"""
|
||||
try:
|
||||
return self._projects[project_id]
|
||||
except KeyError:
|
||||
raise aiohttp.web.HTTPNotFound(text="Project ID {} doesn't exist".format(project_id))
|
||||
|
||||
def removeProject(self, project):
|
||||
del self._projects[project.id]
|
||||
|
||||
@property
|
||||
def projects(self):
|
||||
"""
|
||||
:returns: The dictionnary of hypervisors managed by GNS3
|
||||
"""
|
||||
return self._projects
|
||||
|
||||
@staticmethod
|
||||
def instance():
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user