diff options
author | k.kedron <k.kedron@partner.samsung.com> | 2020-03-05 13:12:27 +0100 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2020-06-24 06:01:11 +0000 |
commit | cb30f3a566b73c78c3ea666acfcd3f288098684a (patch) | |
tree | 38cd1acb83ddde2b927485611d130bbeec3c1a4b /catalog-be/src/main/resources/scripts/sdcBePy/tosca/main.py | |
parent | bdbfc2e460ccb561c3e174260b2908b974996d4f (diff) |
Refactoring the sdc-BE-init python scripts
Deeper refactoring of python script:
- create the python package with init script
- support for python 3.x
- reuse code
- new design
- support for .json conf file
- update the docker chef script
Issue-ID: SDC-2784
Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com>
Change-Id: I02169eb7d0e3e90851ba1811536d1712c3b4145f
Diffstat (limited to 'catalog-be/src/main/resources/scripts/sdcBePy/tosca/main.py')
-rw-r--r-- | catalog-be/src/main/resources/scripts/sdcBePy/tosca/main.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/main.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/main.py new file mode 100644 index 0000000000..2535ba6d77 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/main.py @@ -0,0 +1,56 @@ +import json +import os +import sys +from argparse import ArgumentParser + + +def usage(): + print(sys.argv[0], + '[-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | ' + '--port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | ' + '--debug=<true|false>] [-v <true|false> | --updateVersion=<true|false>]') + + +def load_be_config(conf_path): + with open(conf_path, 'r') as f: + return json.load(f) + + +def parse_param(): + parser = ArgumentParser() + + path = os.path.dirname(__file__) + parser.add_argument('--conf', default=os.path.join(path, 'data', 'beConfig.json')) + + parser.add_argument('--ip', "-i") + parser.add_argument('--port', "-p") + parser.add_argument('--adminUser', "-a") + parser.add_argument('--https', action='store_true') + parser.add_argument('--updateVersion', action='store_false') + parser.add_argument('--debug', action='store_true') + + args, _ = parser.parse_known_args() + + return [args.conf, 'https' if args.https else 'http', + args.ip, args.port, args.adminUser, args.updateVersion, + args.debug] + + +def get_args(): + print('Number of arguments:', len(sys.argv), 'arguments.') + + conf_path, scheme, be_host, be_port, admin_user, update_version, debug = parse_param() + defaults = load_be_config(conf_path) + + # Use defaults if param not provided by the user + if be_host is None: + be_host = defaults["beHost"] + if be_port is None: + be_port = defaults["bePort"] + if admin_user is None: + admin_user = defaults["adminUser"] + + print('scheme =', scheme, ',be host =', be_host, ', be port =', be_port, ', user =', admin_user, + ', debug =', debug, ', update_version =', update_version) + + return scheme, be_host, be_port, admin_user, update_version, debug |