Skip to content

Commit

Permalink
daemon: updated docker nodes to use docker exec by default for comman…
Browse files Browse the repository at this point in the history
…ds, leaving an nsenter approach when needed as a new function
  • Loading branch information
bharnden committed May 13, 2024
1 parent 7252c04 commit d803478
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions daemon/core/nodes/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,11 @@ def create_cmd(self, args: str, shell: bool = False) -> str:
"""
if shell:
args = f"{BASH} -c {shlex.quote(args)}"
return f"nsenter -t {self.pid} -m -u -i -p -n -- {args}"
return f"{DOCKER} exec {self.name} {args}"

def cmd(self, args: str, wait: bool = True, shell: bool = False) -> str:
"""
Runs a command that is used to configure and setup the network within a
node.
Runs a command within the context of the Docker node.
:param args: command to run
:param wait: True to wait for status, False otherwise
Expand All @@ -134,6 +133,25 @@ def cmd(self, args: str, wait: bool = True, shell: bool = False) -> str:
else:
return self.server.remote_cmd(args, wait=wait, env=self.env)

def cmd_perf(self, args: str, wait: bool = True, shell: bool = False) -> str:
"""
Runs a command within the Docker node using nsenter to avoid
client/server overhead.
:param args: command to run
:param wait: True to wait for status, False otherwise
:param shell: True to use shell, False otherwise
:return: combined stdout and stderr
:raises CoreCommandError: when a non-zero exit status occurs
"""
if shell:
args = f"{BASH} -c {shlex.quote(args)}"
args = f"nsenter -t {self.pid} -m -u -i -p -n -- {args}"
if self.server is None:
return utils.cmd(args, wait=wait, shell=shell, env=self.env)
else:
return self.server.remote_cmd(args, wait=wait, env=self.env)

def create_net_cmd(self, args: str, shell: bool = False) -> str:
"""
Create command used to run network commands within the context of a node.
Expand Down

0 comments on commit d803478

Please sign in to comment.