2015-02-11 13:31:21 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Copyright (C) 2015 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/>.
|
|
|
|
|
|
|
|
"""
|
|
|
|
IOU server module.
|
|
|
|
"""
|
|
|
|
|
2015-02-26 01:55:35 +00:00
|
|
|
import os
|
2015-02-11 13:31:21 +00:00
|
|
|
import asyncio
|
|
|
|
|
|
|
|
from ..base_manager import BaseManager
|
|
|
|
from .iou_error import IOUError
|
|
|
|
from .iou_vm import IOUVM
|
2018-03-12 06:38:50 +00:00
|
|
|
from .utils.application_id import get_next_application_id
|
2015-02-11 13:31:21 +00:00
|
|
|
|
2015-06-08 17:32:00 +00:00
|
|
|
import logging
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2015-02-11 13:31:21 +00:00
|
|
|
|
|
|
|
class IOU(BaseManager):
|
2015-04-08 17:17:34 +00:00
|
|
|
|
2016-05-11 17:35:36 +00:00
|
|
|
_NODE_CLASS = IOUVM
|
2016-06-07 17:38:01 +00:00
|
|
|
_NODE_TYPE = "iou"
|
2015-02-11 13:31:21 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
2015-04-08 17:17:34 +00:00
|
|
|
|
2015-02-11 13:31:21 +00:00
|
|
|
super().__init__()
|
2018-03-12 06:38:50 +00:00
|
|
|
self._iou_id_lock = asyncio.Lock()
|
2015-02-11 13:31:21 +00:00
|
|
|
|
2018-10-15 10:05:49 +00:00
|
|
|
async def create_node(self, *args, **kwargs):
|
2015-04-08 17:17:34 +00:00
|
|
|
"""
|
|
|
|
Creates a new IOU VM.
|
|
|
|
|
|
|
|
:returns: IOUVM instance
|
|
|
|
"""
|
2015-02-11 13:31:21 +00:00
|
|
|
|
2018-10-15 10:05:49 +00:00
|
|
|
async with self._iou_id_lock:
|
2018-03-12 06:38:50 +00:00
|
|
|
# wait for a node to be completely created before adding a new one
|
|
|
|
# this is important otherwise we allocate the same application ID
|
|
|
|
# when creating multiple IOU node at the same time
|
|
|
|
application_id = get_next_application_id(self.nodes)
|
2018-10-15 10:05:49 +00:00
|
|
|
node = await super().create_node(*args, application_id=application_id, **kwargs)
|
2016-05-11 17:35:36 +00:00
|
|
|
return node
|
2015-02-11 13:31:21 +00:00
|
|
|
|
2015-02-26 01:55:35 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_legacy_vm_workdir(legacy_vm_id, name):
|
2015-02-25 15:35:13 +00:00
|
|
|
"""
|
2016-05-11 17:35:36 +00:00
|
|
|
Returns the name of the legacy working directory (pre 1.3) name for a node.
|
2015-02-25 15:35:13 +00:00
|
|
|
|
2016-05-11 17:35:36 +00:00
|
|
|
:param legacy_vm_id: legacy node identifier (integer)
|
|
|
|
:param name: Node name (not used)
|
2015-02-26 01:55:35 +00:00
|
|
|
|
2015-02-25 15:35:13 +00:00
|
|
|
:returns: working directory name
|
|
|
|
"""
|
|
|
|
|
2015-02-26 01:55:35 +00:00
|
|
|
return os.path.join("iou", "device-{}".format(legacy_vm_id))
|