Skip to content

Commit

Permalink
add exec command
Browse files Browse the repository at this point in the history
  • Loading branch information
dadevel committed Apr 10, 2024
1 parent 150a052 commit 121288f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "wgnetns"
version = "2.3.2"
version = "2.3.4"
description = "wg-quick for network namespaces"
authors = ["dadevel <[email protected]>"]
license = "MIT"
Expand Down
6 changes: 6 additions & 0 deletions wgnetns/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def cli(args):
parser = subparsers.add_parser('switch', help='open shell in namespace')
parser.add_argument('netns', metavar='NETNS', help='network namespace name')

parser = subparsers.add_parser('exec', help='run command in namespace')
parser.add_argument('netns', metavar='NETNS', help='network namespace name')
parser.add_argument('command', nargs='+', help='command')

opts = entrypoint.parse_args(args)

try:
Expand Down Expand Up @@ -97,6 +101,8 @@ def cli(args):
print('\n'.join(item['name'] for item in data))
elif opts.action == 'switch':
os.execvp('sudo', ['ip', 'ip', 'netns', 'exec', opts.netns, 'sudo', '-u', getpass.getuser(), '-D', Path.cwd().as_posix(), os.environ['SHELL'], '-i'])
elif opts.action == 'exec':
os.execvp('sudo', ['ip', 'ip', 'netns', 'exec', opts.netns, 'sudo', '-u', getpass.getuser(), '-D', Path.cwd().as_posix(), *opts.command])
else:
raise RuntimeError('congratulations, you reached unreachable code')

Expand Down

0 comments on commit 121288f

Please sign in to comment.