-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
organize remotely executing functions in "cmdeploy.remote" sub package
- Loading branch information
Showing
11 changed files
with
132 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
""" | ||
The 'cmdeploy.remote' sub package contains modules with remotely executing functions. | ||
Its "_sshexec_bootstrap" module is executed remotely through `SSHExec` | ||
and its main() loop there stays connected via a command channel, | ||
ready to receive function invocations ("command") and return results. | ||
""" | ||
|
||
from . import rdns, rshell | ||
|
||
__all__ = ["rdns", "rshell"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import builtins | ||
import importlib | ||
import traceback | ||
|
||
## Function Execution server | ||
|
||
|
||
def _run_loop(cmd_channel): | ||
while 1: | ||
cmd = cmd_channel.receive() | ||
if cmd is None: | ||
break | ||
|
||
cmd_channel.send(_handle_one_request(cmd)) | ||
|
||
|
||
def _handle_one_request(cmd): | ||
pymod_path, func_name, kwargs = cmd | ||
try: | ||
mod = importlib.import_module(pymod_path) | ||
func = getattr(mod, func_name) | ||
res = func(**kwargs) | ||
return ("finish", res) | ||
except: | ||
data = traceback.format_exc() | ||
return ("error", data) | ||
|
||
|
||
def main(channel): | ||
# enable simple "print" logging | ||
|
||
builtins.print = lambda x="": channel.send(("log", x)) | ||
|
||
_run_loop(channel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from subprocess import CalledProcessError as ShellError | ||
from subprocess import check_output | ||
|
||
|
||
def shell(command, fail_ok=False): | ||
print(f"$ {command}") | ||
try: | ||
return check_output(command, shell=True).decode().rstrip() | ||
except ShellError: | ||
if not fail_ok: | ||
raise | ||
return "" | ||
|
||
|
||
def get_systemd_running(): | ||
lines = shell("systemctl --type=service --state=running").split("\n") | ||
return [line for line in lines if line.startswith(" ")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters