parameters: (request)
docstring: execute cli command on all linux instances in topology
docstring_summary: execute cli command on all linux instances in topology
docstring_tokens: execute cli command on all linux instances in topology
function: def execute_linux_automation(request):
      """
         execute cli command on all linux instances in topology
  
      """
      if 'topologyId' not in request.POST:
          return render(request, 'ajax/ajaxError.html', {'error': "No Topology Id in request"})
  
      topology_id = request.POST['topologyId']
      cli = request.POST['cli']
  
      try:
          topo = Topology.objects.get(pk=topology_id)
          # let's parse the json and convert to simple lists and dicts
          config = wistarUtils.load_config_from_topology_json(topo.json, topology_id)
          logger.debug("Running automation cli: " + cli)
          result_string = "Automation Command: " + cli + "\n\n"
          result_string += "==================================="
  
          for device in config["devices"]:
              if device["type"] == "linux" or "ubuntu" in device["type"]:
                  logger.debug("running automation cmd on " + device["ip"])
                  # host, username, password, cli
                  try:
                      output = linuxUtils.execute_cli(device["ip"], device["user"], device["password"], cli)
                  except Exception as e:
                      logger.info("Could not execute linux cli on host: %s" % device["ip"])
                      output = str(e)
  
                  logger.debug("got output: " + output)
                  result_string += "\n\n"
                  result_string += "Instance: " + device["label"] + "\n"
                  result_string += output
                  result_string += "\n"
                  result_string += "----------------------------"
  
          context = {'result': result_string}
  
          logger.debug("returning")
          return HttpResponse(json.dumps(context), content_type="application/json")
      except Exception as ex:
          logger.debug(ex)
          return render(request, 'ajax/ajaxError.html', {'error': "Topology not found!"})
function_tokens: def execute_linux_automation ( request ) : if 'topologyId' not in request . POST : return render ( request , 'ajax/ajaxError.html' , { 'error' : "No Topology Id in request" } ) topology_id = request . POST [ 'topologyId' ] cli = request . POST [ 'cli' ] try : topo = Topology . objects . get ( pk = topology_id ) # let's parse the json and convert to simple lists and dicts config = wistarUtils . load_config_from_topology_json ( topo . json , topology_id ) logger . debug ( "Running automation cli: " + cli ) result_string = "Automation Command: " + cli + "\n\n" result_string += "===================================" for device in config [ "devices" ] : if device [ "type" ] == "linux" or "ubuntu" in device [ "type" ] : logger . debug ( "running automation cmd on " + device [ "ip" ] ) # host, username, password, cli try : output = linuxUtils . execute_cli ( device [ "ip" ] , device [ "user" ] , device [ "password" ] , cli ) except Exception as e : logger . info ( "Could not execute linux cli on host: %s" % device [ "ip" ] ) output = str ( e ) logger . debug ( "got output: " + output ) result_string += "\n\n" result_string += "Instance: " + device [ "label" ] + "\n" result_string += output result_string += "\n" result_string += "----------------------------" context = { 'result' : result_string } logger . debug ( "returning" ) return HttpResponse ( json . dumps ( context ) , content_type = "application/json" ) except Exception as ex : logger . debug ( ex ) return render ( request , 'ajax/ajaxError.html' , { 'error' : "Topology not found!" } )