1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-01 04:38:12 +00:00
gns3-server/gns3server/modules/base_vm.py

129 lines
3.2 KiB
Python
Raw Normal View History

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/>.
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-20 11:46:15 +00:00
def __init__(self, name, uuid, project, manager):
2015-01-16 00:43:06 +00:00
2015-01-14 01:26:32 +00:00
self._name = name
self._uuid = uuid
2015-01-20 11:46:15 +00:00
self._project = project
2015-01-19 10:22:24 +00:00
self._manager = manager
2015-01-14 17:52:02 +00:00
log.debug("{module}: {name} [{uuid}] initialized".format(module=self.manager.module_name,
name=self.name,
uuid=self.uuid))
2015-01-21 22:21:15 +00:00
2015-01-22 10:49:22 +00:00
def __del__(self):
self.destroy()
2015-01-19 10:22:24 +00:00
2015-01-20 11:46:15 +00:00
@property
def project(self):
"""
Returns the VM current project.
:returns: Project instance.
"""
2015-01-20 11:46:15 +00:00
return self._project
2015-01-14 01:26:32 +00:00
@property
def name(self):
2015-01-14 01:26:32 +00:00
"""
Returns the name for this VM.
2015-01-14 01:26:32 +00:00
:returns: name
2015-01-14 01:26:32 +00:00
"""
return self._name
@name.setter
def name(self, new_name):
"""
Sets the name of this VM.
:param new_name: name
"""
log.info("{module}: {name} [{uuid}] renamed to {new_name}".format(module=self.manager.module_name,
name=self.name,
uuid=self.uuid,
new_name=new_name))
self._name = new_name
2015-01-14 01:26:32 +00:00
@property
def uuid(self):
2015-01-14 01:26:32 +00:00
"""
Returns the UUID for this VM.
2015-01-14 01:26:32 +00:00
:returns: uuid (string)
2015-01-14 01:26:32 +00:00
"""
return self._uuid
2015-01-14 01:26:32 +00:00
@property
def manager(self):
"""
Returns the manager for this VM.
:returns: instance of manager
"""
return self._manager
2015-01-14 01:26:32 +00:00
@property
def working_dir(self):
"""
Return VM working directory
"""
2015-01-21 22:21:15 +00:00
return self._project.vm_working_directory(self.manager.module_name.lower(), self._uuid)
def create(self):
"""
Creates the VM.
"""
2015-01-14 01:26:32 +00:00
log.info("{module}: {name} [{uuid}] created".format(module=self.manager.module_name,
name=self.name,
uuid=self.uuid))
2015-01-14 01:26:32 +00:00
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-14 17:52:02 +00:00
raise NotImplementedError
def stop(self):
"""
Starts the VM process.
2015-01-14 01:26:32 +00:00
"""
raise NotImplementedError
2015-01-22 10:49:22 +00:00
def destroy(self):
"""
Destroy the VM process.
"""
raise NotImplementedError