From d5bf357c8010bb1219d04ede14ce699b409e93c5 Mon Sep 17 00:00:00 2001 From: Determinant Date: Sun, 30 Aug 2020 00:15:08 -0400 Subject: fix the connection issue with --notls flag on; WIP: deployment example --- scripts/deploy/app/hotstuff_cli.py | 97 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 scripts/deploy/app/hotstuff_cli.py (limited to 'scripts/deploy/app/hotstuff_cli.py') diff --git a/scripts/deploy/app/hotstuff_cli.py b/scripts/deploy/app/hotstuff_cli.py new file mode 100644 index 0000000..0d4b57a --- /dev/null +++ b/scripts/deploy/app/hotstuff_cli.py @@ -0,0 +1,97 @@ +#!/usr/bin/python3 + +import os +import subprocess + +ANSIBLE_METADATA = { + 'metadata_version': '0.1', + 'status': ['preview'], + 'supported_by': 'Ted Yin' +} + +DOCUMENTATION = ''' +--- +module: hotstuff_cli + +short_description: Ansible module for hotstuff-client + +author: + - Ted Yin (@Tederminant) +''' + +EXAMPLES = ''' +''' + +RETURN = ''' +''' + +from ansible.module_utils.basic import AnsibleModule + +def run_module(): + # define available arguments/parameters a user can pass to the module + module_args = dict( + bin=dict(type='str', required=True), + cwd=dict(type='str', required=True), + idx=dict(type='int', required=True), + cid=dict(type='int', required=True), + iter=dict(type='int', required=True), + max_async=dict(type='int', required=True), + log_dir=dict(type='str', required=True), + ) + + module = AnsibleModule( + argument_spec=module_args, + supports_check_mode=False + ) + + expanduser = [ + 'bin', + 'cwd', + 'log_dir', + ] + + for arg in expanduser: + module.params[arg] = os.path.expanduser(module.params[arg]) + + try: + cmd = [*(module.params['bin'].split())] + cmd += [ + '--idx', str(module.params['idx']), + '--cid', str(module.params['cid']), + '--iter', str(module.params['iter']), + '--max-async', str(module.params['max_async']), + ] + + logdir = module.params['log_dir'] + if not (logdir is None): + stdout = open(os.path.expanduser( + os.path.join(logdir, 'stdout')), "w") + stderr = open(os.path.expanduser( + os.path.join(logdir, 'stderr')), "w") + nullsrc = open("/dev/null", "r") + else: + (stdout, stderr) = None, None + + cwd = module.params['cwd'] + + pid = subprocess.Popen( + cmd, + cwd=cwd, + stdin=nullsrc, + stdout=stdout, stderr=stderr, + env=os.environ, + shell=False, + start_new_session=True).pid + module.exit_json( + changed=False, + status=0, pid=pid, cmd=" ".join(cmd), cwd=cwd) + except (OSError, subprocess.SubprocessError) as e: + module.fail_json(msg=str(e), changed=False, status=1) + + +def main(): + run_module() + + +if __name__ == '__main__': + main() -- cgit v1.2.3