1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 03:08:14 +00:00

Change rename command to a name property setter for all Dynamips

devices. Adjust the tests and upload the new dynamips that supports the
rename command for VMs.
This commit is contained in:
grossmj 2014-02-05 15:45:33 -07:00
parent cef29e53aa
commit 5560e81f9a
17 changed files with 117 additions and 109 deletions

View File

@ -118,7 +118,8 @@ class Dynamips(IModule):
""" """
# stop all Dynamips hypervisors # stop all Dynamips hypervisors
self._hypervisor_manager.stop_all_hypervisors() if self._hypervisor_manager:
self._hypervisor_manager.stop_all_hypervisors()
# resets the instance counters # resets the instance counters
Router.reset() Router.reset()

View File

@ -472,7 +472,7 @@ class HypervisorManager(object):
hypervisor.port, hypervisor.port,
current_memory_load, current_memory_load,
router_ram)) router_ram))
return hypervisor return hypervisor
hypervisor = self.start_new_hypervisor() hypervisor = self.start_new_hypervisor()
hypervisor.image_ref = router_ios_image hypervisor.image_ref = router_ios_image

View File

@ -51,6 +51,19 @@ class ATMBridge(object):
return self._name[1:-1] # remove quotes return self._name[1:-1] # remove quotes
@name.setter
def name(self, new_name):
"""
Renames this ATM bridge.
:param new_name: New name for this bridge
"""
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
self._hypervisor.send("atm_bridge rename {name} {new_name}".format(name=self._name,
new_name=new_name))
self._name = new_name
@property @property
def hypervisor(self): def hypervisor(self):
""" """
@ -90,18 +103,6 @@ class ATMBridge(object):
return self._mapping return self._mapping
def rename(self, new_name):
"""
Renames this ATM bridge.
:param new_name: New name for this bridge
"""
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
self._hypervisor.send("atm_bridge rename {name} {new_name}".format(name=self._name,
new_name=new_name))
self._name = new_name
def delete(self): def delete(self):
""" """
Deletes this ATM bridge. Deletes this ATM bridge.

View File

@ -86,6 +86,24 @@ class ATMSwitch(object):
return self._name[1:-1] # remove quotes return self._name[1:-1] # remove quotes
@name.setter
def name(self, new_name):
"""
Renames this ATM switch.
:param new_name: New name for this switch
"""
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
self._hypervisor.send("atmsw rename {name} {new_name}".format(name=self._name,
new_name=new_name))
log.info("ATM switch {name} [id={id}]: renamed to {new_name}".format(name=self._name,
id=self._id,
new_name=new_name))
self._name = new_name
@property @property
def hypervisor(self): def hypervisor(self):
""" """
@ -125,23 +143,6 @@ class ATMSwitch(object):
return self._mapping return self._mapping
def rename(self, new_name):
"""
Renames this ATM switch.
:param new_name: New name for this switch
"""
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
self._hypervisor.send("atmsw rename {name} {new_name}".format(name=self._name,
new_name=new_name))
log.info("ATM switch {name} [id={id}]: renamed to {new_name}".format(name=self._name,
id=self._id,
new_name=new_name))
self._name = new_name
def delete(self): def delete(self):
""" """
Deletes this ATM switch. Deletes this ATM switch.

View File

@ -49,6 +49,20 @@ class Bridge(object):
return self._name[1:-1] # remove quotes return self._name[1:-1] # remove quotes
@name.setter
def name(self, new_name):
"""
Renames this bridge.
:param new_name: New name for this bridge
"""
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
self._hypervisor.send("nio_bridge rename {name} {new_name}".format(name=self._name,
new_name=new_name))
self._name = new_name
@property @property
def hypervisor(self): def hypervisor(self):
""" """
@ -78,19 +92,6 @@ class Bridge(object):
return self._nios return self._nios
def rename(self, new_name):
"""
Renames this bridge.
:param new_name: New name for this bridge
"""
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
self._hypervisor.send("nio_bridge rename {name} {new_name}".format(name=self._name,
new_name=new_name))
self._name = new_name
def delete(self): def delete(self):
""" """
Deletes this bridge. Deletes this bridge.

View File

@ -87,6 +87,24 @@ class EthernetSwitch(object):
return self._name[1:-1] # remove quotes return self._name[1:-1] # remove quotes
@name.setter
def name(self, new_name):
"""
Renames this Ethernet switch.
:param new_name: New name for this switch
"""
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
self._hypervisor.send("ethsw rename {name} {new_name}".format(name=self._name,
new_name=new_name))
log.info("Ethernet switch {name} [id={id}]: renamed to {new_name}".format(name=self._name,
id=self._id,
new_name=new_name))
self._name = new_name
@property @property
def hypervisor(self): def hypervisor(self):
""" """
@ -126,23 +144,6 @@ class EthernetSwitch(object):
return self._mapping return self._mapping
def rename(self, new_name):
"""
Renames this Ethernet switch.
:param new_name: New name for this switch
"""
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
self._hypervisor.send("ethsw rename {name} {new_name}".format(name=self._name,
new_name=new_name))
log.info("Ethernet switch {name} [id={id}]: renamed to {new_name}".format(name=self._name,
id=self._id,
new_name=new_name))
self._name = new_name
def delete(self): def delete(self):
""" """
Deletes this Ethernet switch. Deletes this Ethernet switch.

View File

@ -86,6 +86,24 @@ class FrameRelaySwitch(object):
return self._name[1:-1] # remove quotes return self._name[1:-1] # remove quotes
@name.setter
def name(self, new_name):
"""
Renames this Frame Relay switch.
:param new_name: New name for this switch
"""
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
self._hypervisor.send("frsw rename {name} {new_name}".format(name=self._name,
new_name=new_name))
log.info("Frame Relay switch {name} [id={id}]: renamed to {new_name}".format(name=self._name,
id=self._id,
new_name=new_name))
self._name = new_name
@property @property
def hypervisor(self): def hypervisor(self):
""" """
@ -125,23 +143,6 @@ class FrameRelaySwitch(object):
return self._mapping return self._mapping
def rename(self, new_name):
"""
Renames this Frame Relay switch.
:param new_name: New name for this switch
"""
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
self._hypervisor.send("frsw rename {name} {new_name}".format(name=self._name,
new_name=new_name))
log.info("Frame Relay switch {name} [id={id}]: renamed to {new_name}".format(name=self._name,
id=self._id,
new_name=new_name))
self._name = new_name
def delete(self): def delete(self):
""" """
Deletes this Frame Relay switch. Deletes this Frame Relay switch.

View File

@ -163,6 +163,24 @@ class Router(object):
return self._name[1:-1] # remove quotes return self._name[1:-1] # remove quotes
@name.setter
def name(self, new_name):
"""
Renames this router.
:param new_name: new name string
"""
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
self._hypervisor.send("vm rename {name} {new_name}".format(name=self._name,
new_name=new_name))
log.info("router {name} [id={id}]: renamed to {new_name}".format(name=self._name,
id=self._id,
new_name=new_name))
self._name = new_name
@property @property
def platform(self): def platform(self):
""" """
@ -202,23 +220,6 @@ class Router(object):
return self._hypervisor.send("vm list_con_ports") return self._hypervisor.send("vm list_con_ports")
def rename(self, new_name):
"""
Renames this router.
:param new_name: new name string
"""
new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces
self._hypervisor.send("vm rename {name} {new_name}".format(name=self._name,
new_name=new_name))
log.info("router {name} [id={id}]: renamed to {new_name}".format(name=self._name,
id=self._id,
new_name=new_name))
self._name = new_name
def delete(self): def delete(self):
""" """
Deletes this router. Deletes this router.

View File

@ -9,7 +9,7 @@ def hypervisor(request):
cwd = os.path.dirname(os.path.abspath(__file__)) cwd = os.path.dirname(os.path.abspath(__file__))
dynamips_path = os.path.join(cwd, "dynamips.stable") dynamips_path = os.path.join(cwd, "dynamips.stable")
print("\nStarting Dynamips Hypervisor: {}".format(dynamips_path)) print("\nStarting Dynamips Hypervisor: {}".format(dynamips_path))
manager = HypervisorManager(dynamips_path, "/tmp", base_port=9000) manager = HypervisorManager(dynamips_path, "/tmp", "127.0.0.1", 9000)
hypervisor = manager.start_new_hypervisor() hypervisor = manager.start_new_hypervisor()
def stop(): def stop():

Binary file not shown.

View File

@ -19,7 +19,7 @@ def test_atm_bridge_exists(atm_bridge):
def test_rename_atm_bridge(atm_bridge): def test_rename_atm_bridge(atm_bridge):
atm_bridge.rename("new ATM bridge") atm_bridge.name = "new ATM bridge"
assert atm_bridge.name == "new ATM bridge" assert atm_bridge.name == "new ATM bridge"

View File

@ -19,7 +19,7 @@ def test_atmsw_exists(atmsw):
def test_rename_atmsw(atmsw): def test_rename_atmsw(atmsw):
atmsw.rename("new ATM switch") atmsw.name = "new ATM switch"
assert atmsw.name == "new ATM switch" assert atmsw.name == "new ATM switch"

View File

@ -18,7 +18,7 @@ def test_bridge_exists(bridge):
def test_rename_bridge(bridge): def test_rename_bridge(bridge):
bridge.rename("new bridge") bridge.name = "new bridge"
assert bridge.name == "new bridge" assert bridge.name == "new bridge"

View File

@ -19,7 +19,7 @@ def test_ethsw_exists(ethsw):
def test_rename_ethsw(ethsw): def test_rename_ethsw(ethsw):
ethsw.rename("new Ethernet switch") ethsw.name = "new Ethernet switch"
assert ethsw.name == "new Ethernet switch" assert ethsw.name == "new Ethernet switch"

View File

@ -19,7 +19,7 @@ def test_frsw_exists(frsw):
def test_rename_frsw(frsw): def test_rename_frsw(frsw):
frsw.rename("new Frame Relay switch") frsw.name = "new Frame Relay switch"
assert frsw.name == "new Frame Relay switch" assert frsw.name == "new Frame Relay switch"

View File

@ -11,6 +11,7 @@ def hypervisor_manager(request):
dynamips_path = os.path.join(cwd, "dynamips.stable") dynamips_path = os.path.join(cwd, "dynamips.stable")
print("\nStarting Dynamips Hypervisor: {}".format(dynamips_path)) print("\nStarting Dynamips Hypervisor: {}".format(dynamips_path))
manager = HypervisorManager(dynamips_path, "/tmp", "127.0.0.1", 9000) manager = HypervisorManager(dynamips_path, "/tmp", "127.0.0.1", 9000)
#manager.start_new_hypervisor() #manager.start_new_hypervisor()
def stop(): def stop():
@ -23,6 +24,7 @@ def hypervisor_manager(request):
def test_allocate_hypervisor_for_router(hypervisor_manager): def test_allocate_hypervisor_for_router(hypervisor_manager):
hypervisor_manager.allocate_hypervisor_per_device = False
# default of 1GB of RAM per hypervisor instance # default of 1GB of RAM per hypervisor instance
assert hypervisor_manager.memory_usage_limit_per_hypervisor == 1024 assert hypervisor_manager.memory_usage_limit_per_hypervisor == 1024
hypervisor = hypervisor_manager.allocate_hypervisor_for_router("c3725.image", 512) hypervisor = hypervisor_manager.allocate_hypervisor_for_router("c3725.image", 512)

View File

@ -30,14 +30,13 @@ def test_create_and_delete_router(hypervisor):
router.get_status() router.get_status()
# def test_rename_router(router): def test_rename_router(hypervisor):
#
# assert router.name == "router" router = Router(hypervisor, "my router to rename")
# router.rename("my_router") assert router.name == "my router to rename"
# assert router.name == "my_router" router.name = "my_router"
# router.rename("router") assert router.name == "my_router"
# assert router.name == "router" router.delete()
#router.delete() # FIXME: fails with current Dynamips version
def test_image(router): def test_image(router):