1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-12 19:38:57 +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
log.debug("received request {}".format(request))
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]
try:
atmsw.delete()
self._hypervisor_manager.unallocate_hypervisor_for_simulated_device(atmsw)
@ -117,6 +121,9 @@ class ATMSW(object):
#TODO: JSON schema validation for the request
log.debug("received request {}".format(request))
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]
# rename the switch if requested
@ -153,6 +160,9 @@ class ATMSW(object):
#TODO: JSON schema validation for the request
log.debug("received request {}".format(request))
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]
try:
@ -207,6 +217,9 @@ class ATMSW(object):
#TODO: JSON schema validation for the request
log.debug("received request {}".format(request))
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]
port = request["port"]
@ -273,6 +286,9 @@ class ATMSW(object):
#TODO: JSON schema validation for the request
log.debug("received request {}".format(request))
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]
port = request["port"]

View File

@ -82,7 +82,11 @@ class ETHHUB(object):
#TODO: JSON schema validation for the request
log.debug("received request {}".format(request))
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]
try:
ethhub.delete()
self._hypervisor_manager.unallocate_hypervisor_for_simulated_device(ethhub)
@ -116,6 +120,9 @@ class ETHHUB(object):
#TODO: JSON schema validation for the request
log.debug("received request {}".format(request))
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]
# rename the hub if requested
@ -152,6 +159,9 @@ class ETHHUB(object):
#TODO: JSON schema validation for the request
log.debug("received request {}".format(request))
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]
try:
@ -205,6 +215,9 @@ class ETHHUB(object):
#TODO: JSON schema validation for the request
log.debug("received request {}".format(request))
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]
port = request["port"]
@ -247,6 +260,9 @@ class ETHHUB(object):
#TODO: JSON schema validation for the request
log.debug("received request {}".format(request))
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]
port = request["port"]

View File

@ -82,7 +82,11 @@ class ETHSW(object):
#TODO: JSON schema validation for the request
log.debug("received request {}".format(request))
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]
try:
ethsw.delete()
self._hypervisor_manager.unallocate_hypervisor_for_simulated_device(ethsw)
@ -117,6 +121,9 @@ class ETHSW(object):
#TODO: JSON schema validation for the request
log.debug("received request {}".format(request))
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]
if "ports" in request:
@ -171,6 +178,9 @@ class ETHSW(object):
#TODO: JSON schema validation for the request
log.debug("received request {}".format(request))
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]
try:
@ -226,6 +236,9 @@ class ETHSW(object):
#TODO: JSON schema validation for the request
log.debug("received request {}".format(request))
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]
port = request["port"]
@ -276,6 +289,9 @@ class ETHSW(object):
#TODO: JSON schema validation for the request
log.debug("received request {}".format(request))
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]
port = request["port"]

View File

@ -82,7 +82,11 @@ class FRSW(object):
#TODO: JSON schema validation for the request
log.debug("received request {}".format(request))
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]
try:
frsw.delete()
self._hypervisor_manager.unallocate_hypervisor_for_simulated_device(frsw)
@ -116,6 +120,9 @@ class FRSW(object):
#TODO: JSON schema validation for the request
log.debug("received request {}".format(request))
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]
# rename the switch if requested
@ -151,6 +158,9 @@ class FRSW(object):
#TODO: JSON schema validation for the request
log.debug("received request {}".format(request))
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]
try:
@ -205,6 +215,9 @@ class FRSW(object):
#TODO: JSON schema validation for the request
log.debug("received request {}".format(request))
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]
port = request["port"]
@ -258,6 +271,9 @@ class FRSW(object):
#TODO: JSON schema validation for the request
log.debug("received request {}".format(request))
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]
port = request["port"]

View File

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

View File

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

View File

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

View File

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