2015-01-14 01:26:32 +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/>.
|
|
|
|
|
|
|
|
|
|
|
|
import asyncio
|
2015-01-15 23:50:36 +00:00
|
|
|
from .vm_error import VMError
|
2015-01-16 19:23:43 +00:00
|
|
|
from ..config import Config
|
2015-01-14 01:26:32 +00:00
|
|
|
|
2015-01-14 17:52:02 +00:00
|
|
|
import logging
|
|
|
|
log = logging.getLogger(__name__)
|
2015-01-14 01:26:32 +00:00
|
|
|
|
2015-01-15 23:50:36 +00:00
|
|
|
|
2015-01-14 01:26:32 +00:00
|
|
|
class BaseVM:
|
2015-01-18 22:41:53 +00:00
|
|
|
|
2015-01-19 10:22:24 +00:00
|
|
|
def __init__(self, name, identifier, manager):
|
2015-01-16 00:43:06 +00:00
|
|
|
|
2015-01-14 01:26:32 +00:00
|
|
|
self._name = name
|
|
|
|
self._id = identifier
|
|
|
|
self._created = asyncio.Future()
|
2015-01-19 10:22:24 +00:00
|
|
|
self._manager = manager
|
2015-01-16 19:23:43 +00:00
|
|
|
self._config = Config.instance()
|
2015-01-19 12:47:20 +00:00
|
|
|
asyncio.async(self._create())
|
2015-01-18 22:41:53 +00:00
|
|
|
log.info("{type} device {name} [id={id}] has been created".format(type=self.__class__.__name__,
|
|
|
|
name=self._name,
|
|
|
|
id=self._id))
|
2015-01-14 17:52:02 +00:00
|
|
|
|
2015-01-19 10:22:24 +00:00
|
|
|
#TODO: When delete release console ports
|
|
|
|
|
|
|
|
|
2015-01-14 01:26:32 +00:00
|
|
|
@property
|
|
|
|
def id(self):
|
|
|
|
"""
|
|
|
|
Returns the unique ID for this VM.
|
|
|
|
|
|
|
|
:returns: id (integer)
|
|
|
|
"""
|
|
|
|
|
|
|
|
return self._id
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""
|
|
|
|
Returns the name for this VM.
|
|
|
|
|
|
|
|
:returns: name (string)
|
|
|
|
"""
|
|
|
|
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2015-01-18 22:41:53 +00:00
|
|
|
def _execute(self, command):
|
|
|
|
"""
|
|
|
|
Called when we receive an event.
|
|
|
|
"""
|
|
|
|
|
2015-01-14 01:26:32 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
|
|
|
def _create(self):
|
2015-01-18 22:41:53 +00:00
|
|
|
"""
|
2015-01-19 12:47:20 +00:00
|
|
|
Called when the run module is created and ready to receive
|
|
|
|
commands. It's asynchronous.
|
2015-01-18 22:41:53 +00:00
|
|
|
"""
|
2015-01-19 12:47:20 +00:00
|
|
|
self._created.set_result(True)
|
|
|
|
log.info("{type} device {name} [id={id}] has been created".format(type=self.__class__.__name__,
|
|
|
|
name=self._name,
|
|
|
|
id=self._id))
|
2015-01-14 01:26:32 +00:00
|
|
|
|
|
|
|
def wait_for_creation(self):
|
|
|
|
return self._created
|
|
|
|
|
2015-01-14 17:52:02 +00:00
|
|
|
@asyncio.coroutine
|
2015-01-15 23:50:36 +00:00
|
|
|
def start(self):
|
2015-01-14 17:52:02 +00:00
|
|
|
"""
|
|
|
|
Starts the VM process.
|
|
|
|
"""
|
2015-01-18 22:41:53 +00:00
|
|
|
|
2015-01-14 17:52:02 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2015-01-14 01:26:32 +00:00
|
|
|
|
2015-01-19 12:47:20 +00:00
|
|
|
@asyncio.coroutine
|
|
|
|
def stop(self):
|
|
|
|
"""
|
|
|
|
Starts the VM process.
|
2015-01-14 01:26:32 +00:00
|
|
|
"""
|
|
|
|
|
2015-01-19 12:47:20 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|