From 3f0cf41e1e082783eb638b4a36b1219daf4909b8 Mon Sep 17 00:00:00 2001 From: Odin-byte Date: Fri, 14 Jun 2024 14:37:38 +0200 Subject: [PATCH 1/5] Added prefix argument which is used for session names and set as a env variable within the new session i.e. for docker names --- robmuxinator/robmuxinator.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/robmuxinator/robmuxinator.py b/robmuxinator/robmuxinator.py index 4bf0791..0f73723 100755 --- a/robmuxinator/robmuxinator.py +++ b/robmuxinator/robmuxinator.py @@ -773,6 +773,12 @@ def main(): help="the path to the yaml config file", default="/etc/ros/upstart_robot.yaml", ) + parser.add_argument( + "-p", + "--prefix", + help="the prefix to append to each session name within the config file", + default="", + ) parser.add_argument( "-s", "--sessions", @@ -800,6 +806,7 @@ def main(): args = parser.parse_args() # parse arguments yaml_file = args.config + prefix = args.prefix command = args.command # set logging level @@ -880,6 +887,10 @@ def main(): else: envs = None + # check if prefix was given by the user + if prefix != "": + envs.append(("PREFIX", prefix)) + # get sessions from yaml yaml_sessions = None if "sessions" in yaml_content: @@ -911,7 +922,7 @@ def main(): sessions.append( Session( SSHClient(user=user, hostname=hosts[host].get_hostname(), port=hosts[host].get_ssh_port()), - key, + prefix + key, yaml_sessions[key], envs ) @@ -920,7 +931,7 @@ def main(): sessions.append( Session( SSHClient(user=user, hostname=hosts[host].get_hostname(), port=hosts[host].get_ssh_port()), - key, + prefix + key, yaml_sessions[key], envs ) From 30779a3d6f2fe7a3b62d688159dfb65a84eb78c2 Mon Sep 17 00:00:00 2001 From: Odin-byte Date: Fri, 28 Jun 2024 14:13:22 +0200 Subject: [PATCH 2/5] Renamed PREFIX to NUMBER and also automatically export it as a ROS_DOMAIN_ID --- robmuxinator/robmuxinator.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/robmuxinator/robmuxinator.py b/robmuxinator/robmuxinator.py index 0f73723..30aaadb 100755 --- a/robmuxinator/robmuxinator.py +++ b/robmuxinator/robmuxinator.py @@ -774,9 +774,9 @@ def main(): default="/etc/ros/upstart_robot.yaml", ) parser.add_argument( - "-p", - "--prefix", - help="the prefix to append to each session name within the config file", + "-n", + "--number", + help="the number to append to each session name within the config file. used for multi robot setups. Can also be used within sessions as a env_variable. this is used as a unique ros domain id", default="", ) parser.add_argument( @@ -806,7 +806,7 @@ def main(): args = parser.parse_args() # parse arguments yaml_file = args.config - prefix = args.prefix + number = args.number command = args.command # set logging level @@ -887,9 +887,10 @@ def main(): else: envs = None - # check if prefix was given by the user - if prefix != "": - envs.append(("PREFIX", prefix)) + # check if number was given by the user. This indicates the use of a multi robot setup. Therefore we export a unique ROS_DOMAIN_ID + if number != "": + envs.append(("NUMBER", number)) + envs.append(("ROS_DOMAIN_ID", number)) # get sessions from yaml yaml_sessions = None @@ -922,7 +923,7 @@ def main(): sessions.append( Session( SSHClient(user=user, hostname=hosts[host].get_hostname(), port=hosts[host].get_ssh_port()), - prefix + key, + number + key, yaml_sessions[key], envs ) @@ -931,7 +932,7 @@ def main(): sessions.append( Session( SSHClient(user=user, hostname=hosts[host].get_hostname(), port=hosts[host].get_ssh_port()), - prefix + key, + number + key, yaml_sessions[key], envs ) From a395156d319860a34ecbbc0b24afbd2e00c658f9 Mon Sep 17 00:00:00 2001 From: Odin-byte Date: Tue, 2 Jul 2024 15:34:42 +0200 Subject: [PATCH 3/5] Added for env export to ensure the functionality of longer strings with special chars. --- robmuxinator/robmuxinator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/robmuxinator/robmuxinator.py b/robmuxinator/robmuxinator.py index 30aaadb..6562a95 100755 --- a/robmuxinator/robmuxinator.py +++ b/robmuxinator/robmuxinator.py @@ -472,7 +472,7 @@ def __init__(self, ssh_client, session_name, yaml_session, envs=None) -> None: command_env_prefix = "" if self._envs is not None: for env in self._envs: - command_env_prefix += "export {}={} && ".format(env[0], env[1]) + command_env_prefix += "export {}='{}' && ".format(env[0], env[1]) if "command" in yaml_session: self._command = command_env_prefix + yaml_session["command"] From 35169df248216f9a51848f3f7fffc6bfec2c4cf1 Mon Sep 17 00:00:00 2001 From: fmessmer Date: Wed, 21 Aug 2024 15:54:11 +0200 Subject: [PATCH 4/5] use instance_id --- README.md | 2 ++ robmuxinator/robmuxinator.py | 28 +++++++++++++++------------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 0351157..11032fe 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,8 @@ sessions: - `-c` or `--config`: Specify the path to the YAML configuration file that defines the hosts, sessions, and other settings. The default configuration file path is "/etc/ros/upstart_robot.yaml." - `-s` or `--sessions`: Optionally, specify which sessions should be started or stopped. You can provide multiple session names as arguments. - `-f` or `--force`: Use this flag to force the closure of sessions, even if they are locked. +- `-l ` or `--logging_level `: Use this flag to set the logging level, ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] +- `--instance_id `: An unique id used to prepend to each session name and used within multi-robot setups. ### YAML Configuration diff --git a/robmuxinator/robmuxinator.py b/robmuxinator/robmuxinator.py index 6562a95..473b721 100755 --- a/robmuxinator/robmuxinator.py +++ b/robmuxinator/robmuxinator.py @@ -773,12 +773,6 @@ def main(): help="the path to the yaml config file", default="/etc/ros/upstart_robot.yaml", ) - parser.add_argument( - "-n", - "--number", - help="the number to append to each session name within the config file. used for multi robot setups. Can also be used within sessions as a env_variable. this is used as a unique ros domain id", - default="", - ) parser.add_argument( "-s", "--sessions", @@ -801,13 +795,19 @@ def main(): default="INFO", help="logging level", ) + parser.add_argument( + "--instance_id", + type=int, + help="an unique id used to prepend to each session name within the config file. used for multi-robot emulation. the instance_id is also exported to the env used within the sessions as well as to guarantee a unique ROS_DOMAIN_ID", + default=0, + ) argcomplete.autocomplete(parser) args = parser.parse_args() # parse arguments yaml_file = args.config - number = args.number command = args.command + instance_id = args.instance_id # set logging level logger.setLevel(level=args.logging_level) @@ -887,10 +887,12 @@ def main(): else: envs = None - # check if number was given by the user. This indicates the use of a multi robot setup. Therefore we export a unique ROS_DOMAIN_ID - if number != "": - envs.append(("NUMBER", number)) - envs.append(("ROS_DOMAIN_ID", number)) + # Check if 'instance_id' was given by the user. + # This indicates the a multi-instance setup, e.g. for multi-robot emulation. + # Therefore we export the INSTANCE_ID and use it for to guarantee a unique ROS_DOMAIN_ID + if instance_id != 0: + envs.append(("INSTANCE_ID", instance_id)) + envs.append(("ROS_DOMAIN_ID", instance_id)) # get sessions from yaml yaml_sessions = None @@ -923,7 +925,7 @@ def main(): sessions.append( Session( SSHClient(user=user, hostname=hosts[host].get_hostname(), port=hosts[host].get_ssh_port()), - number + key, + str(instance_id) + "_" + key if instance_id != 0 else key, yaml_sessions[key], envs ) @@ -932,7 +934,7 @@ def main(): sessions.append( Session( SSHClient(user=user, hostname=hosts[host].get_hostname(), port=hosts[host].get_ssh_port()), - number + key, + str(instance_id) + "_" + key if instance_id != 0 else key, yaml_sessions[key], envs ) From 1191e0da20198355804d47ebdfefd1df33dc0e18 Mon Sep 17 00:00:00 2001 From: fmessmer Date: Thu, 19 Sep 2024 08:58:10 +0200 Subject: [PATCH 5/5] fixup command_env_prefix --- robmuxinator/robmuxinator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/robmuxinator/robmuxinator.py b/robmuxinator/robmuxinator.py index 473b721..36b73fa 100755 --- a/robmuxinator/robmuxinator.py +++ b/robmuxinator/robmuxinator.py @@ -472,7 +472,7 @@ def __init__(self, ssh_client, session_name, yaml_session, envs=None) -> None: command_env_prefix = "" if self._envs is not None: for env in self._envs: - command_env_prefix += "export {}='{}' && ".format(env[0], env[1]) + command_env_prefix += "export {}={} && ".format(env[0], env[1]) if "command" in yaml_session: self._command = command_env_prefix + yaml_session["command"]