예제 #1
0
    def close_port(self, req):
        body = jsonobject.loads(req[http.REQUEST_BODY])
        rsp = models.AgentResponse()

        with CiscoSwitch(body.username, body.password, body.host) as client:
            try:
                result = client.shutdown_port(body.ports)
            except Exception as ex:
                raise exceptions.SwitchTaskError(error=str(ex))
            if "Copy complete." in result:
                for port in body.ports:
                    logger.debug("close port %s successfully." % port)
        return jsonobject.dumps(rsp)
예제 #2
0
 def clean_all_config(self, req):
     body = jsonobject.loads(req[http.REQUEST_BODY])
     rsp = models.AgentResponse()
     for switch in body.switches:
         with CiscoSwitch(switch.username, switch.password,
                          switch.host) as client:
             try:
                 time.sleep(random.randint(1, 3))
                 result = client.clean_all_config(switch,
                                                  body.template_name)
             except Exception as ex:
                 raise exceptions.SwitchTaskError(error=str(ex))
             if "Copy complete." in result:
                 logger.debug(
                     "clean switch %s port %s config successfully." %
                     (switch.host, switch.ports))
     return jsonobject.dumps(rsp)
예제 #3
0
 def open_port(self, req):
     body = jsonobject.loads(req[http.REQUEST_BODY])
     rsp = models.AgentResponse()
     device_cfg = {
         "device_type": "cisco_nxos",
         "ip": body.host,
         "username": body.username,
         "password": body.password
     }
     with CiscoSwitch(device_cfg) as client:
         try:
             result = client.open_port(body.ports)
         except Exception as ex:
             raise exceptions.SwitchTaskError(error=str(ex))
         if "Copy complete." in result:
             for port in body.ports:
                 logger.debug("open port %s successfully." % port)
     return jsonobject.dumps(rsp)
예제 #4
0
 def init_all_config(self, req):
     body = jsonobject.loads(req[http.REQUEST_BODY])
     rsp = models.AgentResponse()
     for switch in body.switches:
         device_cfg = {
             "device_type": "cisco_nxos",
             "ip": switch.host,
             "username": switch.username,
             "password": switch.password
         }
         with CiscoSwitch(device_cfg) as client:
             try:
                 time.sleep(random.randint(1, 3))
                 result = client.init_all_config(switch, body.template_name, body.is_dhclient)
             except Exception as ex:
                 raise exceptions.SwitchTaskError(error=str(ex))
             if "Copy complete." in result:
                 logger.debug("init switch %s port %s config successfully." %
                              (switch.host, switch.ports))
             else:
                 logger.error("init switch %s port %s config result: %s." %
                              (switch.host, switch.ports, result))
     return jsonobject.dumps(rsp)