2015-02-14 03:01:18 +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-02-15 19:18:12 +00:00
|
|
|
class Device:
|
2015-02-23 16:21:39 +00:00
|
|
|
|
2015-02-14 03:01:18 +00:00
|
|
|
"""
|
|
|
|
Base device for switches and hubs
|
|
|
|
|
2015-02-15 19:18:12 +00:00
|
|
|
:param name: name for this device
|
2016-05-20 23:59:59 +00:00
|
|
|
:param node_id: Node instance identifier
|
2015-02-14 03:01:18 +00:00
|
|
|
:param project: Project instance
|
2015-02-15 19:18:12 +00:00
|
|
|
:param manager: Parent manager
|
2015-02-14 03:01:18 +00:00
|
|
|
:param hypervisor: Dynamips hypervisor instance
|
|
|
|
"""
|
|
|
|
|
2016-05-20 04:45:04 +00:00
|
|
|
def __init__(self, name, node_id, project, manager, hypervisor=None):
|
2015-02-14 03:01:18 +00:00
|
|
|
|
2015-02-15 19:18:12 +00:00
|
|
|
self._name = name
|
2016-05-20 04:45:04 +00:00
|
|
|
self._id = node_id
|
2015-02-15 19:18:12 +00:00
|
|
|
self._project = project
|
|
|
|
self._manager = manager
|
2015-02-14 03:01:18 +00:00
|
|
|
self._hypervisor = hypervisor
|
|
|
|
|
|
|
|
@property
|
|
|
|
def hypervisor(self):
|
|
|
|
"""
|
|
|
|
Returns the current hypervisor.
|
|
|
|
|
|
|
|
:returns: hypervisor instance
|
|
|
|
"""
|
|
|
|
|
|
|
|
return self._hypervisor
|
|
|
|
|
2015-02-15 19:18:12 +00:00
|
|
|
@property
|
|
|
|
def project(self):
|
|
|
|
"""
|
|
|
|
Returns the device current project.
|
|
|
|
|
|
|
|
:returns: Project instance.
|
|
|
|
"""
|
|
|
|
|
|
|
|
return self._project
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""
|
|
|
|
Returns the name for this device.
|
|
|
|
|
|
|
|
:returns: name
|
|
|
|
"""
|
2015-02-14 03:01:18 +00:00
|
|
|
|
2015-02-15 19:18:12 +00:00
|
|
|
return self._name
|
|
|
|
|
|
|
|
@name.setter
|
|
|
|
def name(self, new_name):
|
|
|
|
"""
|
2016-05-11 17:35:36 +00:00
|
|
|
Sets the name of this device.
|
2015-02-15 19:18:12 +00:00
|
|
|
|
|
|
|
:param new_name: name
|
|
|
|
"""
|
2015-02-14 03:01:18 +00:00
|
|
|
|
2015-02-15 19:18:12 +00:00
|
|
|
self._name = new_name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def id(self):
|
|
|
|
"""
|
|
|
|
Returns the ID for this device.
|
|
|
|
|
|
|
|
:returns: device identifier (string)
|
|
|
|
"""
|
|
|
|
|
|
|
|
return self._id
|
|
|
|
|
|
|
|
@property
|
|
|
|
def manager(self):
|
|
|
|
"""
|
|
|
|
Returns the manager for this device.
|
|
|
|
|
|
|
|
:returns: instance of manager
|
|
|
|
"""
|
|
|
|
|
|
|
|
return self._manager
|
|
|
|
|
2016-05-20 04:45:04 +00:00
|
|
|
def updated(self):
|
|
|
|
"""
|
|
|
|
Send a updated event
|
|
|
|
"""
|
|
|
|
self.project.emit("node.updated", self)
|
|
|
|
|
2015-02-15 19:18:12 +00:00
|
|
|
def create(self):
|
|
|
|
"""
|
|
|
|
Creates the device.
|
|
|
|
"""
|
2015-02-14 03:01:18 +00:00
|
|
|
|
2015-02-15 19:18:12 +00:00
|
|
|
raise NotImplementedError
|