Commit 4a81e0381dd5862766ba96760784afa5d2da3adb

Authored by Alexis Koralewski
1 parent 01ef8ec6
Exists in dev

Add get_specifics_cmd in agent, and add option to simulate computer hostname for agentSST

pyros.py
... ... @@ -1116,9 +1116,9 @@ def new_start(configfile: str, observatory: str, unit: str, computer_hostname: s
1116 1116 if verbose_mode():
1117 1117 cmd += " -v"
1118 1118 if configfile:
1119   - cmd += " {configfile}"
  1119 + cmd += f" {configfile}"
1120 1120 if computer_hostname:
1121   - cmd += " -c {computer_hostname}"
  1121 + cmd += f" --computer {computer_hostname}"
1122 1122  
1123 1123 # if not test_mode(): current_processes.append( [execProcessFromVenvAsync(cmd), agent_name, -1] )
1124 1124 # Append this process ( [process id, agent_name, result=failure] )
... ...
src/core/pyros_django/agent/Agent.py
... ... @@ -1419,6 +1419,14 @@ class Agent:
1419 1419 def show_mode_and_status(self):
1420 1420 log.info(f"CURRENT MODE is {self.mode} (status is {self.status})")
1421 1421  
  1422 + def get_specifics_cmd(self):
  1423 + specific_commands = ""
  1424 + for index, command_tuple in enumerate(self.AGENT_SPECIFIC_COMMANDS):
  1425 + specific_commands += f"{command_tuple[0]}"
  1426 + if index != len(self.AGENT_SPECIFIC_COMMANDS)-1:
  1427 + specific_commands += ";"
  1428 + return specific_commands
  1429 +
1422 1430 def get_mode(self):
1423 1431 return self.mode
1424 1432  
... ... @@ -1641,7 +1649,8 @@ class Agent:
1641 1649 ex: send_command(“AgentX”,"EVAL”,“3+4”)
1642 1650 """
1643 1651 #return AgentCmd.send_cmd_from_to(self.name, self._get_real_agent_name_for_alias(to_agent), cmd_name, cmd_args)
1644   - cmd = self.create_cmd_for(to_agent, cmd_name, cmd_args, validity, timeout).send()
  1652 + #cmd = self.create_cmd_for(to_agent, cmd_name, cmd_args, validity, timeout).send()
  1653 + cmd = self.create_cmd_for(to_agent, cmd_name, cmd_args, validity).send()
1645 1654 #cmd.send()
1646 1655 return cmd
1647 1656  
... ... @@ -1934,6 +1943,8 @@ class Agent:
1934 1943 #cmd.set_result(eval(cmd_args))
1935 1944 #result = eval(cmd_args)
1936 1945 result = self.do_eval(cmd_args[0])
  1946 + elif cmd_name == "get_specifics_cmd":
  1947 + result = self.get_specifics_cmd()
1937 1948  
1938 1949 cmd.set_as_processed(result)
1939 1950 log.info("...Agent level GENERAL cmd has been executed")
... ... @@ -2056,6 +2067,7 @@ class Agent:
2056 2067 return cmd.is_agent_general_cmd()
2057 2068  
2058 2069  
  2070 +
2059 2071 '''
2060 2072 def _exec_agent_cmd(self, cmd:Command):
2061 2073 # AGENT "GENERAL LEVEL" command
... ... @@ -2544,10 +2556,12 @@ class Agent:
2544 2556 =================================================================
2545 2557 """
2546 2558  
  2559 +import argparse
2547 2560 def extract_parameters():
2548 2561 """ Usage: Agent.py [-t] [configfile] """
2549 2562 # arg 1 : -t
2550 2563 # arg 2 : configfile
  2564 +
2551 2565 DEBUG_MODE = False
2552 2566 TEST_MODE = False
2553 2567 WITH_SIM = False
... ... @@ -2580,11 +2594,25 @@ def build_agent(Agent_type:Agent) -> Agent :
2580 2594 log.debug("debug mode is" + os.getenv("PYROS_DEBUG"))
2581 2595  
2582 2596 #print(logger)
2583   -
  2597 + parser = argparse.ArgumentParser(description='Start an agent.')
  2598 + parser.add_argument("--test",help='Launch agent in test mode',action="store_true")
  2599 + parser.add_argument("--debug",help='Launch agent in debug mode',action="store_true")
  2600 + parser.add_argument("--computer",dest="computer",help='Launch agent with simulated computer hostname',action="store")
  2601 + parser.add_argument("{configfile}")
  2602 + args = parser.parse_args()
  2603 + if args.test:
  2604 + TEST_MODE = True
  2605 + if args.debug:
  2606 + DEBUG_MODE = True
  2607 +
2584 2608 #agent = Agent("GenericAgent", configfile, RUN_IN_THREAD=True)
2585 2609 #agent = Agent_type(configfile, RUN_IN_THREAD, DEBUG_MODE=DEBUG_MODE)
2586 2610 #agent = Agent_type(RUN_IN_THREAD)
  2611 +
2587 2612 agent = Agent_type()
  2613 + if agent.name == "AgentSST":
  2614 + if args.computer:
  2615 + agent.set_computer(args.computer)
2588 2616 # AgentSP isn't in a config, so to avoid that WITH_SIM returns an error it's a special case
2589 2617 if agent.name == "AgentSP":
2590 2618 agent._set_with_simulator(False)
... ...
src/core/pyros_django/agent/AgentSST.py
... ... @@ -39,7 +39,7 @@ class AgentSST(Agent):
39 39 self.PROJECT_ROOT_PATH = os.environ["PROJECT_ROOT_PATH"]
40 40 if name is None:
41 41 name = self.__class__.__name__
42   - # self.computer = socket.gethostname()
  42 + self.computer = socket.gethostname()
43 43 WITH_DOCKER = False
44 44 if os.environ.get("WITH_DOCKER"):
45 45 WITH_DOCKER = True
... ... @@ -59,16 +59,19 @@ class AgentSST(Agent):
59 59 + os.sep
60 60 )
61 61 self.VENV_PYTHON = VENV_BIN + "python3"
62   - log.info(f"PC hostname is {self.computer}")
  62 + #log.info(f"PC hostname is {self.computer}")
63 63 #name_from_config = self.get_config().get_agent_sst_of_current_computer()
64 64  
65 65 def init(self):
66 66 super().init()
  67 + log.info(f"PC hostname is {self.computer}")
67 68 self.start_agents()
68 69 self.TEST_MODE = False
69 70 time.sleep(10)
70 71 self.set_delay(3)
71 72  
  73 + def set_computer(self,computer):
  74 + self.computer = computer
72 75 def start_agents(self,agent_name=None):
73 76 """
74 77 Start all agents or one agent of obs_config
... ...