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

Checks for valid device IDs.

This commit is contained in:
grossmj 2014-04-12 14:43:30 -06:00
parent 3edbdbe0b5
commit a874b63e40
8 changed files with 132 additions and 1 deletions

View File

@ -83,7 +83,11 @@ class ATMSW(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
atmsw_id = request["id"] atmsw_id = request["id"]
if atmsw_id not in self._atm_switches:
self.send_custom_error("ATM switch id {} doesn't exist".format(atmsw_id))
return
atmsw = self._atm_switches[atmsw_id] atmsw = self._atm_switches[atmsw_id]
try: try:
atmsw.delete() atmsw.delete()
self._hypervisor_manager.unallocate_hypervisor_for_simulated_device(atmsw) self._hypervisor_manager.unallocate_hypervisor_for_simulated_device(atmsw)
@ -117,6 +121,9 @@ class ATMSW(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
atmsw_id = request["id"] atmsw_id = request["id"]
if atmsw_id not in self._atm_switches:
self.send_custom_error("ATM switch id {} doesn't exist".format(atmsw_id))
return
atmsw = self._atm_switches[atmsw_id] atmsw = self._atm_switches[atmsw_id]
# rename the switch if requested # rename the switch if requested
@ -153,6 +160,9 @@ class ATMSW(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
atmsw_id = request["id"] atmsw_id = request["id"]
if atmsw_id not in self._atm_switches:
self.send_custom_error("ATM switch id {} doesn't exist".format(atmsw_id))
return
atmsw = self._atm_switches[atmsw_id] atmsw = self._atm_switches[atmsw_id]
try: try:
@ -207,6 +217,9 @@ class ATMSW(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
atmsw_id = request["id"] atmsw_id = request["id"]
if atmsw_id not in self._atm_switches:
self.send_custom_error("ATM switch id {} doesn't exist".format(atmsw_id))
return
atmsw = self._atm_switches[atmsw_id] atmsw = self._atm_switches[atmsw_id]
port = request["port"] port = request["port"]
@ -273,6 +286,9 @@ class ATMSW(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
atmsw_id = request["id"] atmsw_id = request["id"]
if atmsw_id not in self._atm_switches:
self.send_custom_error("ATM switch id {} doesn't exist".format(atmsw_id))
return
atmsw = self._atm_switches[atmsw_id] atmsw = self._atm_switches[atmsw_id]
port = request["port"] port = request["port"]

View File

@ -82,7 +82,11 @@ class ETHHUB(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
ethhub_id = request["id"] ethhub_id = request["id"]
if ethhub_id not in self._ethernet_hubs:
self.send_custom_error("Ethernet hub id {} doesn't exist".format(ethhub_id))
return
ethhub = self._ethernet_hubs[ethhub_id] ethhub = self._ethernet_hubs[ethhub_id]
try: try:
ethhub.delete() ethhub.delete()
self._hypervisor_manager.unallocate_hypervisor_for_simulated_device(ethhub) self._hypervisor_manager.unallocate_hypervisor_for_simulated_device(ethhub)
@ -116,6 +120,9 @@ class ETHHUB(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
ethhub_id = request["id"] ethhub_id = request["id"]
if ethhub_id not in self._ethernet_hubs:
self.send_custom_error("Ethernet hub id {} doesn't exist".format(ethhub_id))
return
ethhub = self._ethernet_hubs[ethhub_id] ethhub = self._ethernet_hubs[ethhub_id]
# rename the hub if requested # rename the hub if requested
@ -152,6 +159,9 @@ class ETHHUB(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
ethhub_id = request["id"] ethhub_id = request["id"]
if ethhub_id not in self._ethernet_hubs:
self.send_custom_error("Ethernet hub id {} doesn't exist".format(ethhub_id))
return
ethhub = self._ethernet_hubs[ethhub_id] ethhub = self._ethernet_hubs[ethhub_id]
try: try:
@ -205,6 +215,9 @@ class ETHHUB(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
ethhub_id = request["id"] ethhub_id = request["id"]
if ethhub_id not in self._ethernet_hubs:
self.send_custom_error("Ethernet hub id {} doesn't exist".format(ethhub_id))
return
ethhub = self._ethernet_hubs[ethhub_id] ethhub = self._ethernet_hubs[ethhub_id]
port = request["port"] port = request["port"]
@ -247,6 +260,9 @@ class ETHHUB(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
ethhub_id = request["id"] ethhub_id = request["id"]
if ethhub_id not in self._ethernet_hubs:
self.send_custom_error("Ethernet hub id {} doesn't exist".format(ethhub_id))
return
ethhub = self._ethernet_hubs[ethhub_id] ethhub = self._ethernet_hubs[ethhub_id]
port = request["port"] port = request["port"]

View File

@ -82,7 +82,11 @@ class ETHSW(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
ethsw_id = request["id"] ethsw_id = request["id"]
if ethsw_id not in self._ethernet_switches:
self.send_custom_error("Ethernet switch id {} doesn't exist".format(ethsw_id))
return
ethsw = self._ethernet_switches[ethsw_id] ethsw = self._ethernet_switches[ethsw_id]
try: try:
ethsw.delete() ethsw.delete()
self._hypervisor_manager.unallocate_hypervisor_for_simulated_device(ethsw) self._hypervisor_manager.unallocate_hypervisor_for_simulated_device(ethsw)
@ -117,6 +121,9 @@ class ETHSW(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
ethsw_id = request["id"] ethsw_id = request["id"]
if ethsw_id not in self._ethernet_switches:
self.send_custom_error("Ethernet switch id {} doesn't exist".format(ethsw_id))
return
ethsw = self._ethernet_switches[ethsw_id] ethsw = self._ethernet_switches[ethsw_id]
if "ports" in request: if "ports" in request:
@ -171,6 +178,9 @@ class ETHSW(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
ethsw_id = request["id"] ethsw_id = request["id"]
if ethsw_id not in self._ethernet_switches:
self.send_custom_error("Ethernet switch id {} doesn't exist".format(ethsw_id))
return
ethsw = self._ethernet_switches[ethsw_id] ethsw = self._ethernet_switches[ethsw_id]
try: try:
@ -226,6 +236,9 @@ class ETHSW(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
ethsw_id = request["id"] ethsw_id = request["id"]
if ethsw_id not in self._ethernet_switches:
self.send_custom_error("Ethernet switch id {} doesn't exist".format(ethsw_id))
return
ethsw = self._ethernet_switches[ethsw_id] ethsw = self._ethernet_switches[ethsw_id]
port = request["port"] port = request["port"]
@ -276,6 +289,9 @@ class ETHSW(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
ethsw_id = request["id"] ethsw_id = request["id"]
if ethsw_id not in self._ethernet_switches:
self.send_custom_error("Ethernet switch id {} doesn't exist".format(ethsw_id))
return
ethsw = self._ethernet_switches[ethsw_id] ethsw = self._ethernet_switches[ethsw_id]
port = request["port"] port = request["port"]

View File

@ -82,7 +82,11 @@ class FRSW(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
frsw_id = request["id"] frsw_id = request["id"]
if frsw_id not in self._frame_relay_switches:
self.send_custom_error("Frame relay switch id {} doesn't exist".format(frsw_id))
return
frsw = self._frame_relay_switches[frsw_id] frsw = self._frame_relay_switches[frsw_id]
try: try:
frsw.delete() frsw.delete()
self._hypervisor_manager.unallocate_hypervisor_for_simulated_device(frsw) self._hypervisor_manager.unallocate_hypervisor_for_simulated_device(frsw)
@ -116,6 +120,9 @@ class FRSW(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
frsw_id = request["id"] frsw_id = request["id"]
if frsw_id not in self._frame_relay_switches:
self.send_custom_error("Frame relay switch id {} doesn't exist".format(frsw_id))
return
frsw = self._frame_relay_switches[frsw_id] frsw = self._frame_relay_switches[frsw_id]
# rename the switch if requested # rename the switch if requested
@ -151,6 +158,9 @@ class FRSW(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
frsw_id = request["id"] frsw_id = request["id"]
if frsw_id not in self._frame_relay_switches:
self.send_custom_error("Frame relay switch id {} doesn't exist".format(frsw_id))
return
frsw = self._frame_relay_switches[frsw_id] frsw = self._frame_relay_switches[frsw_id]
try: try:
@ -205,6 +215,9 @@ class FRSW(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
frsw_id = request["id"] frsw_id = request["id"]
if frsw_id not in self._frame_relay_switches:
self.send_custom_error("Frame relay switch id {} doesn't exist".format(frsw_id))
return
frsw = self._frame_relay_switches[frsw_id] frsw = self._frame_relay_switches[frsw_id]
port = request["port"] port = request["port"]
@ -258,6 +271,9 @@ class FRSW(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
frsw_id = request["id"] frsw_id = request["id"]
if frsw_id not in self._frame_relay_switches:
self.send_custom_error("Frame relay switch id {} doesn't exist".format(frsw_id))
return
frsw = self._frame_relay_switches[frsw_id] frsw = self._frame_relay_switches[frsw_id]
port = request["port"] port = request["port"]

View File

@ -209,7 +209,11 @@ class VM(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
router_id = request["id"] router_id = request["id"]
if router_id not in self._routers:
self.send_custom_error("IOS router id {} doesn't exist".format(router_id))
return
router = self._routers[router_id] router = self._routers[router_id]
try: try:
router.delete() router.delete()
self._hypervisor_manager.unallocate_hypervisor_for_router(router) self._hypervisor_manager.unallocate_hypervisor_for_router(router)
@ -240,7 +244,11 @@ class VM(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
router_id = request["id"] router_id = request["id"]
if router_id not in self._routers:
self.send_custom_error("IOS router id {} doesn't exist".format(router_id))
return
router = self._routers[router_id] router = self._routers[router_id]
try: try:
router.start() router.start()
except DynamipsError as e: except DynamipsError as e:
@ -269,7 +277,11 @@ class VM(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
router_id = request["id"] router_id = request["id"]
if router_id not in self._routers:
self.send_custom_error("IOS router id {} doesn't exist".format(router_id))
return
router = self._routers[router_id] router = self._routers[router_id]
try: try:
router.stop() router.stop()
except DynamipsError as e: except DynamipsError as e:
@ -298,7 +310,11 @@ class VM(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
router_id = request["id"] router_id = request["id"]
if router_id not in self._routers:
self.send_custom_error("IOS router id {} doesn't exist".format(router_id))
return
router = self._routers[router_id] router = self._routers[router_id]
try: try:
router.suspend() router.suspend()
except DynamipsError as e: except DynamipsError as e:
@ -327,6 +343,9 @@ class VM(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
router_id = request["id"] router_id = request["id"]
if router_id not in self._routers:
self.send_custom_error("IOS router id {} doesn't exist".format(router_id))
return
router = self._routers[router_id] router = self._routers[router_id]
try: try:
if router.get_status() != "inactive": if router.get_status() != "inactive":
@ -363,6 +382,9 @@ class VM(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
router_id = request["id"] router_id = request["id"]
if router_id not in self._routers:
self.send_custom_error("IOS router id {} doesn't exist".format(router_id))
return
router = self._routers[router_id] router = self._routers[router_id]
try: try:
@ -454,7 +476,11 @@ class VM(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
router_id = request["id"] router_id = request["id"]
if router_id not in self._routers:
self.send_custom_error("IOS router id {} doesn't exist".format(router_id))
return
router = self._routers[router_id] router = self._routers[router_id]
try: try:
if router.startup_config or router.private_config: if router.startup_config or router.private_config:
@ -509,6 +535,9 @@ class VM(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
router_id = request["id"] router_id = request["id"]
if router_id not in self._routers:
self.send_custom_error("IOS router id {} doesn't exist".format(router_id))
return
router = self._routers[router_id] router = self._routers[router_id]
try: try:
@ -549,6 +578,9 @@ class VM(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
router_id = request["id"] router_id = request["id"]
if router_id not in self._routers:
self.send_custom_error("IOS router id {} doesn't exist".format(router_id))
return
router = self._routers[router_id] router = self._routers[router_id]
try: try:
@ -603,6 +635,9 @@ class VM(object):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
router_id = request["id"] router_id = request["id"]
if router_id not in self._routers:
self.send_custom_error("IOS router id {} doesn't exist".format(router_id))
return
router = self._routers[router_id] router = self._routers[router_id]
slot = request["slot"] slot = request["slot"]
@ -649,6 +684,9 @@ class VM(object):
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
router_id = request["id"] router_id = request["id"]
router = self._routers[router_id] router = self._routers[router_id]
if router_id not in self._routers:
self.send_custom_error("IOS router id {} doesn't exist".format(router_id))
return
slot = request["slot"] slot = request["slot"]
port = request["port"] port = request["port"]

View File

@ -291,7 +291,11 @@ class IOU(IModule):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
iou_id = request["id"] iou_id = request["id"]
if iou_id not in self._iou_instances:
self.send_custom_error("IOU device id {} doesn't exist".format(iou_id))
return
iou_instance = self._iou_instances[iou_id] iou_instance = self._iou_instances[iou_id]
try: try:
iou_instance.delete() iou_instance.delete()
del self._iou_instances[iou_id] del self._iou_instances[iou_id]
@ -325,6 +329,9 @@ class IOU(IModule):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
iou_id = request["id"] iou_id = request["id"]
if iou_id not in self._iou_instances:
self.send_custom_error("IOU device id {} doesn't exist".format(iou_id))
return
iou_instance = self._iou_instances[iou_id] iou_instance = self._iou_instances[iou_id]
try: try:
@ -378,7 +385,11 @@ class IOU(IModule):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
iou_id = request["id"] iou_id = request["id"]
if iou_id not in self._iou_instances:
self.send_custom_error("IOU device id {} doesn't exist".format(iou_id))
return
iou_instance = self._iou_instances[iou_id] iou_instance = self._iou_instances[iou_id]
try: try:
log.debug("starting IOU with command: {}".format(iou_instance.command())) log.debug("starting IOU with command: {}".format(iou_instance.command()))
iou_instance.iouyap = self._iouyap iou_instance.iouyap = self._iouyap
@ -410,7 +421,11 @@ class IOU(IModule):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
iou_id = request["id"] iou_id = request["id"]
if iou_id not in self._iou_instances:
self.send_custom_error("IOU device id {} doesn't exist".format(iou_id))
return
iou_instance = self._iou_instances[iou_id] iou_instance = self._iou_instances[iou_id]
try: try:
iou_instance.stop() iou_instance.stop()
except IOUError as e: except IOUError as e:
@ -439,7 +454,11 @@ class IOU(IModule):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
iou_id = request["id"] iou_id = request["id"]
if iou_id not in self._iou_instances:
self.send_custom_error("IOU device id {} doesn't exist".format(iou_id))
return
iou_instance = self._iou_instances[iou_id] iou_instance = self._iou_instances[iou_id]
try: try:
if iou_instance.is_running(): if iou_instance.is_running():
iou_instance.stop() iou_instance.stop()
@ -472,6 +491,9 @@ class IOU(IModule):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
iou_id = request["id"] iou_id = request["id"]
if iou_id not in self._iou_instances:
self.send_custom_error("IOU device id {} doesn't exist".format(iou_id))
return
iou_instance = self._iou_instances[iou_id] iou_instance = self._iou_instances[iou_id]
try: try:
@ -528,6 +550,9 @@ class IOU(IModule):
#TODO: JSON schema validation for the request #TODO: JSON schema validation for the request
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
iou_id = request["id"] iou_id = request["id"]
if iou_id not in self._iou_instances:
self.send_custom_error("IOU device id {} doesn't exist".format(iou_id))
return
iou_instance = self._iou_instances[iou_id] iou_instance = self._iou_instances[iou_id]
slot = request["slot"] slot = request["slot"]
@ -608,6 +633,9 @@ class IOU(IModule):
log.debug("received request {}".format(request)) log.debug("received request {}".format(request))
iou_id = request["id"] iou_id = request["id"]
iou_instance = self._iou_instances[iou_id] iou_instance = self._iou_instances[iou_id]
if iou_id not in self._iou_instances:
self.send_custom_error("IOU device id {} doesn't exist".format(iou_id))
return
slot = request["slot"] slot = request["slot"]
port = request["port"] port = request["port"]

View File

@ -68,6 +68,7 @@ setup(
"Programming Language :: Python", "Programming Language :: Python",
"Programming Language :: Python :: 3", "Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: CPython",
], ],
) )

View File

@ -1,5 +1,5 @@
[tox] [tox]
envlist = py33 envlist = py33, py34
[testenv] [testenv]
commands = py.test [] -s tests commands = py.test [] -s tests