def unset_limit(self, req): body = jsonobject.loads(req[http.REQUEST_BODY]) rsp = models.SetSwitchResponse() with CiscoSwitch(body.username, body.password, body.host) as client: try: result = client.unset_limit(body.limit_infos) except Exception as ex: raise exceptions.SwitchTaskError(error=str(ex)) if "Copy complete." in result: for info in body.limit_infos: logger.debug("unset limit for port %s successfully." % info.inbound_port) return jsonobject.dumps(rsp)
def delete_limit_template(self, req): body = jsonobject.loads(req[http.REQUEST_BODY]) rsp = models.SetSwitchResponse() with CiscoSwitch(body.username, body.password, body.host) as client: try: result = client.delete_limit_template(body.templates) except Exception as ex: raise exceptions.SwitchTaskError(error=str(ex)) if "Copy complete." in result: for template in body.templates: logger.debug("delete limit template %s successfully." % template) return jsonobject.dumps(rsp)
def unset_vlan(self, req): body = jsonobject.loads(req[http.REQUEST_BODY]) rsp = models.SetSwitchResponse() with CiscoSwitch(body.username, body.password, body.host) as client: try: result = client.unset_vlan(body.ports) except Exception as ex: raise exceptions.SwitchTaskError(error=str(ex)) if "Copy complete." in result: for port in body.ports: logger.debug("unset vlan for port %s successfully." % ("Eth-Trunk %s" % port)) return jsonobject.dumps(rsp)
def set_limit(self, req): body = jsonobject.loads(req[http.REQUEST_BODY]) rsp = models.SetSwitchResponse() device_cfg = { "device_type": "cisco_nxos", "ip": body.host, "username": body.username, "password": body.password } with CiscoSwitch(device_cfg) as client: try: result = client.set_limit(body.limit_infos) except Exception as ex: raise exceptions.SwitchTaskError(error=str(ex)) if "Copy complete." in result: for info in body.limit_infos: logger.debug("set limit for port %s successfully." % info.inbound_port) return jsonobject.dumps(rsp)
def create_limit_template(self, req): body = jsonobject.loads(req[http.REQUEST_BODY]) rsp = models.SetSwitchResponse() device_cfg = { "device_type": "cisco_nxos", "ip": body.host, "username": body.username, "password": body.password } with CiscoSwitch(device_cfg) as client: try: result = client.create_limit_template(body.templates) except Exception as ex: raise exceptions.SwitchTaskError(error=str(ex)) if "Copy complete." in result: for template in body.templates: logger.debug("create limit template %s successfully." % template.name) return jsonobject.dumps(rsp)