IOU integration.

Improvements on module management.
File upload support.
Config file for the server.
This commit is contained in:
grossmj committed 2014-03-11 15:45:04 -06:00
1 parent 89888ae7bf
commit 0f75dbc68a
27 files changed
+2509 -59

No files matched your search

+6 -31
View File
@@ -97,8 +97,9 @@ class Dynamips(IModule):
:param kwargs: named arguments for the module
"""
def __init__(self, name=None, args=(), kwargs={}):
IModule.__init__(self, name=name, args=args, kwargs=kwargs)
def __init__(self, name, *args, **kwargs):
IModule.__init__(self, name, *args, **kwargs)
self._hypervisor_manager = None
self._remote_server = False
@@ -107,6 +108,8 @@ class Dynamips(IModule):
self._frame_relay_switches = {}
self._atm_switches = {}
self._ethernet_hubs = {}
self._projects_dir = kwargs["projects_dir"]
self._tempdir = kwargs["temp_dir"]
#self._callback = self.add_periodic_callback(self.test, 1000)
#self._callback.start()
@@ -189,13 +192,7 @@ class Dynamips(IModule):
else:
self._remote_server = True
log.info("this server is remote")
try:
working_dir = tempfile.mkdtemp(prefix="gns3-remote-server-")
working_dir = os.path.join(working_dir, "dynamips")
os.makedirs(working_dir)
log.info("temporary working directory created: {}".format(working_dir))
except EnvironmentError as e:
raise DynamipsError("Could not create temporary working directory: {}".format(e))
working_dir = self._projects_dir
#TODO: check if executable
if not os.path.exists(dynamips_path):
@@ -342,28 +339,6 @@ class Dynamips(IModule):
router.ghost_status = 2
router.ghost_file = ghost_instance
# def get_base64_config(self, config_path, router):
# """
# Get the base64 encoded config from a file.
# Replaces %h by the router name.
#
# :param config_path: path to the configuration file.
# :param router: Router instance.
#
# :returns: base64 encoded string
# """
#
# try:
# with open(config_path, "r") as f:
# log.info("opening configuration file: {}".format(config_path))
# config = f.read()
# config = '!\n' + config.replace('\r', "")
# config = config.replace('%h', router.name)
# encoded = ("").join(base64.encodestring(config.encode("utf-8")).decode("utf-8").split())
# return encoded
# except EnvironmentError as e:
# raise DynamipsError("Cannot parse {}: {}".format(config_path, e))
@IModule.route("dynamips.nio.get_interfaces")
def nio_get_interfaces(self, request):
"""
@@ -84,6 +84,7 @@ class ATMSW(object):
try:
atmsw.delete()
self._hypervisor_manager.unallocate_hypervisor_for_simulated_device(atmsw)
del self._atm_switches[atmsw_id]
except DynamipsError as e:
self.send_custom_error(str(e))
return
@@ -83,6 +83,7 @@ class ETHHUB(object):
try:
ethhub.delete()
self._hypervisor_manager.unallocate_hypervisor_for_simulated_device(ethhub)
del self._ethernet_hubs[ethhub_id]
except DynamipsError as e:
self.send_custom_error(str(e))
return
@@ -83,6 +83,7 @@ class ETHSW(object):
try:
ethsw.delete()
self._hypervisor_manager.unallocate_hypervisor_for_simulated_device(ethsw)
del self._ethernet_switches[ethsw_id]
except DynamipsError as e:
self.send_custom_error(str(e))
return
@@ -83,6 +83,7 @@ class FRSW(object):
try:
frsw.delete()
self._hypervisor_manager.unallocate_hypervisor_for_simulated_device(frsw)
del self._frame_relay_switches[frsw_id]
except DynamipsError as e:
self.send_custom_error(str(e))
return
@@ -206,6 +206,7 @@ class VM(object):
try:
router.delete()
self._hypervisor_manager.unallocate_hypervisor_for_router(router)
del self._routers[router_id]
except DynamipsError as e:
self.send_custom_error(str(e))
return
+10 -5
View File
@@ -211,11 +211,16 @@ class Hypervisor(DynamipsHypervisor):
if self.is_running():
DynamipsHypervisor.stop(self)
log.info("stopping Dynamips PID={}".format(self._process.pid))
# give some time for the hypervisor to properly stop.
# time to delete UNIX NIOs for instance.
time.sleep(0.01)
self._process.kill()
self._process.wait()
try:
# give some time for the hypervisor to properly stop.
# time to delete UNIX NIOs for instance.
time.sleep(0.01)
self._process.terminate()
self._process.wait(1)
except subprocess.TimeoutExpired:
self._process.kill()
if self._process.poll() == None:
log.warn("Dynamips process {} is still running".format(self._process.pid))
def read_stdout(self):
"""
@@ -20,7 +20,6 @@ Manages Dynamips hypervisors (load-balancing etc.)
"""
from .hypervisor import Hypervisor
from .dynamips_error import DynamipsError
import socket
import time
import logging