1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-27 09:18:09 +00:00
gns3-server/gns3server/compute/dynamips/nodes/c7200.py

245 lines
9.2 KiB
Python
Raw Normal View History

2013-12-22 00:42:33 +00:00
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013 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/>.
"""
Interface for Dynamips virtual Cisco 7200 instances module ("c7200")
http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L294
"""
2015-02-11 04:50:02 +00:00
import asyncio
2013-12-22 00:42:33 +00:00
from .router import Router
from ..adapters.c7200_io_fe import C7200_IO_FE
2013-12-22 00:42:33 +00:00
from ..adapters.c7200_io_ge_e import C7200_IO_GE_E
from ..dynamips_error import DynamipsError
2013-12-22 00:42:33 +00:00
import logging
log = logging.getLogger(__name__)
2013-12-22 00:42:33 +00:00
class C7200(Router):
2015-02-13 13:43:28 +00:00
2013-12-22 00:42:33 +00:00
"""
Dynamips c7200 router (model is 7206).
2015-02-11 04:50:02 +00:00
:param name: The name of this router
:param node_id: Node identifier
2015-02-11 04:50:02 +00:00
:param project: Project instance
:param manager: Parent VM Manager
2015-02-12 02:21:34 +00:00
:param dynamips_id: ID to use with Dynamips
:param console: console port
:param aux: auxiliary console port
2015-02-11 04:50:02 +00:00
:param npe: Default NPE
2013-12-22 00:42:33 +00:00
"""
def __init__(self, name, node_id, project, manager, dynamips_id, console=None, aux=None, npe="npe-400", chassis=None):
2015-04-08 17:17:34 +00:00
super().__init__(name, node_id, project, manager, dynamips_id, console, aux, platform="c7200")
2013-12-22 00:42:33 +00:00
# Set default values for this platform (must be the same as Dynamips)
self._ram = 256
2013-12-22 00:42:33 +00:00
self._nvram = 128
self._disk0 = 64
self._disk1 = 0
self._npe = npe
self._midplane = "vxr"
self._clock_divisor = 4
2015-02-11 04:50:02 +00:00
self._npe = npe
2013-12-22 00:42:33 +00:00
# 4 sensors with a default temperature of 22C:
# sensor 1 = I/0 controller inlet
# sensor 2 = I/0 controller outlet
# sensor 3 = NPE inlet
# sensor 4 = NPE outlet
self._sensors = [22, 22, 22, 22]
# 2 power supplies powered on
self._power_supplies = [1, 1]
self._create_slots(7)
if chassis is not None:
raise DynamipsError("c7200 routers do not have chassis")
2015-02-11 04:50:02 +00:00
def __json__(self):
2015-02-11 04:50:02 +00:00
c7200_router_info = {"npe": self._npe,
"midplane": self._midplane,
2014-03-19 00:14:30 +00:00
"sensors": self._sensors,
"power_supplies": self._power_supplies}
2015-02-11 04:50:02 +00:00
router_info = Router.__json__(self)
router_info.update(c7200_router_info)
return router_info
2015-02-11 04:50:02 +00:00
@asyncio.coroutine
def create(self):
2013-12-22 00:42:33 +00:00
2015-02-11 04:50:02 +00:00
yield from Router.create(self)
2013-12-22 00:42:33 +00:00
2015-02-11 04:50:02 +00:00
if self._npe != "npe-400":
yield from self.set_npe(self._npe)
# first slot is a mandatory Input/Output controller (based on NPE type)
if self.npe == "npe-g2":
yield from self.slot_add_binding(0, C7200_IO_GE_E())
else:
yield from self.slot_add_binding(0, C7200_IO_FE())
2013-12-22 00:42:33 +00:00
@property
def npe(self):
"""
Returns the NPE model.
:returns: NPE model string (e.g. "npe-200")
"""
return self._npe
2015-02-11 04:50:02 +00:00
@asyncio.coroutine
def set_npe(self, npe):
2013-12-22 00:42:33 +00:00
"""
Sets the NPE model.
2013-12-22 00:42:33 +00:00
:params npe: NPE model string (e.g. "npe-200")
NPE models are npe-100, npe-150, npe-175, npe-200,
npe-225, npe-300, npe-400 and npe-g2 (PowerPC c7200 only)
"""
2015-04-27 00:35:12 +00:00
if (yield from self.is_running()):
2013-12-22 00:42:33 +00:00
raise DynamipsError("Cannot change NPE on running router")
2015-02-11 04:50:02 +00:00
yield from self._hypervisor.send('c7200 set_npe "{name}" {npe}'.format(name=self._name, npe=npe))
2015-02-11 04:50:02 +00:00
log.info('Router "{name}" [{id}]: NPE updated from {old_npe} to {new_npe}'.format(name=self._name,
id=self._id,
old_npe=self._npe,
new_npe=npe))
2013-12-22 00:42:33 +00:00
self._npe = npe
@property
def midplane(self):
"""
Returns the midplane model.
:returns: midplane model string (e.g. "vxr" or "std")
"""
return self._midplane
2015-02-11 04:50:02 +00:00
@asyncio.coroutine
def set_midplane(self, midplane):
2013-12-22 00:42:33 +00:00
"""
Sets the midplane model.
2013-12-22 00:42:33 +00:00
:returns: midplane model string (e.g. "vxr" or "std")
"""
2015-02-11 04:50:02 +00:00
yield from self._hypervisor.send('c7200 set_midplane "{name}" {midplane}'.format(name=self._name, midplane=midplane))
2015-02-11 04:50:02 +00:00
log.info('Router "{name}" [{id}]: midplane updated from {old_midplane} to {new_midplane}'.format(name=self._name,
id=self._id,
old_midplane=self._midplane,
new_midplane=midplane))
2013-12-22 00:42:33 +00:00
self._midplane = midplane
@property
def sensors(self):
"""
Returns the 4 sensors with temperature in degree Celcius.
:returns: list of 4 sensor temperatures
"""
return self._sensors
2015-02-11 04:50:02 +00:00
@asyncio.coroutine
def set_sensors(self, sensors):
2013-12-22 00:42:33 +00:00
"""
Sets the 4 sensors with temperature in degree Celcius.
2013-12-22 00:42:33 +00:00
:param sensors: list of 4 sensor temperatures corresponding to
sensor 1 = I/0 controller inlet
sensor 2 = I/0 controller outlet
sensor 3 = NPE inlet
sensor 4 = NPE outlet
Example: [22, 22, 22, 22]
"""
sensor_id = 0
for sensor in sensors:
2015-02-11 04:50:02 +00:00
yield from self._hypervisor.send('c7200 set_temp_sensor "{name}" {sensor_id} {temp}'.format(name=self._name,
sensor_id=sensor_id,
temp=sensor))
2015-02-11 04:50:02 +00:00
log.info('Router "{name}" [{id}]: sensor {sensor_id} temperature updated from {old_temp}C to {new_temp}C'.format(name=self._name,
id=self._id,
sensor_id=sensor_id,
old_temp=self._sensors[sensor_id],
new_temp=sensors[sensor_id]))
2013-12-22 00:42:33 +00:00
sensor_id += 1
self._sensors = sensors
@property
def power_supplies(self):
"""
Returns the 2 power supplies with 0 = off, 1 = on.
:returns: list of 2 power supplies.
"""
return self._power_supplies
2015-02-11 04:50:02 +00:00
@asyncio.coroutine
def set_power_supplies(self, power_supplies):
2013-12-22 00:42:33 +00:00
"""
Sets the 2 power supplies with 0 = off, 1 = on.
2013-12-22 00:42:33 +00:00
:param power_supplies: list of 2 power supplies.
Example: [1, 0] = first power supply is on, second is off.
"""
power_supply_id = 0
for power_supply in power_supplies:
2015-02-11 04:50:02 +00:00
yield from self._hypervisor.send('c7200 set_power_supply "{name}" {power_supply_id} {powered_on}'.format(name=self._name,
power_supply_id=power_supply_id,
powered_on=power_supply))
log.info('Router "{name}" [{id}]: power supply {power_supply_id} state updated to {powered_on}'.format(name=self._name,
id=self._id,
power_supply_id=power_supply_id,
powered_on=power_supply))
2013-12-22 00:42:33 +00:00
power_supply_id += 1
2013-12-22 00:42:33 +00:00
self._power_supplies = power_supplies
2014-03-19 00:14:30 +00:00
2015-02-11 04:50:02 +00:00
@asyncio.coroutine
2014-03-19 00:14:30 +00:00
def start(self):
"""
Starts this router.
At least the IOS image must be set before starting it.
"""
# trick: we must send sensors and power supplies info after starting the router
# otherwise they are not taken into account (Dynamips bug?)
2015-02-11 04:50:02 +00:00
yield from Router.start(self)
2014-03-19 00:14:30 +00:00
if self._sensors != [22, 22, 22, 22]:
2015-02-11 04:50:02 +00:00
yield from self.set_sensors(self._sensors)
2014-03-19 00:14:30 +00:00
if self._power_supplies != [1, 1]:
2015-02-11 04:50:02 +00:00
yield from self.set_power_supplies(self._power_supplies)