diff options
author | Harry Huang <huangxiangyu5@huawei.com> | 2017-03-01 12:49:09 +0800 |
---|---|---|
committer | Harry Huang <huangxiangyu5@huawei.com> | 2017-03-01 14:35:26 +0800 |
commit | bd9c1aff4191019efe05cd0fabbade624bb2229d (patch) | |
tree | 80bd6d9f4905ae9b04ec8ed6a7ee43e8577fe8b9 /juju/openo_connect.py | |
parent | 51451b626187ae1b6db3015174792fadc3428968 (diff) |
juju connect fix
use argparse to explicitly pass args
Change-Id: Id729d6897be6511c8bd2de8aa31cf37dfada1caf
Signed-off-by: Harry Huang <huangxiangyu5@huawei.com>
Diffstat (limited to 'juju/openo_connect.py')
-rw-r--r-- | juju/openo_connect.py | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/juju/openo_connect.py b/juju/openo_connect.py index 782c7cb..7792082 100644 --- a/juju/openo_connect.py +++ b/juju/openo_connect.py @@ -8,6 +8,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import argparse import sys import os import requests @@ -40,13 +41,9 @@ def add_common_tosca_aria(msb_ip, tosca_aria_ip): except Exception: raise -def add_openo_vim(msb_ip): +def add_openo_vim(msb_ip, auth_url): url = 'http://' + msb_ip + '/openoapi/extsys/v1/vims/' headers = {'Content-Type': 'application/json'} - if os.getenv('OS_AUTH_URL') is None: - raise RaiseError('env OS_AUTH_URL not found') - else: - auth_url = os.getenv('OS_AUTH_URL') data = {"name":"openstack", "url":auth_url, "userName":"admin", @@ -65,14 +62,10 @@ def add_openo_vim(msb_ip): except Exception: raise -def add_openo_vnfm(msb_ip): +def add_openo_vnfm(msb_ip, juju_client_ip): vnfm_url = 'http://' + msb_ip + '/openoapi/extsys/v1/vnfms' vim_url = 'http://' + msb_ip + '/openoapi/extsys/v1/vims' headers = {'Content-Type': 'application/json'} - if os.getenv('floating_ip_client') is None: - raise RaiseError('env floating_ip_client not found') - else: - juju_client_ip = os.getenv('floating_ip_client') try: resp = requests.get(vim_url) if resp.status_code not in (200,201): @@ -99,10 +92,25 @@ def add_openo_vnfm(msb_ip): if __name__ == "__main__": - if len(sys.argv) != 3: - raise RaiseError('input open-o ip error') + parser = argparse.ArgumentParser() + parser.add_argument("--msb_ip", action='store', help="common_services_msb ip") + parser.add_argument("--tosca_aria_ip", action='store', help="common_tosca_aria ip") + parser.add_argument("--juju_client_ip", action='store', help="juju client ip") + parser.add_argument("--auth_url", action='store', help="openstack auth url") + + args = parser.parse_args() + msb_ip = args.msb_ip + tosca_aria_ip = args.tosca_aria_ip + juju_client_ip = args.juju_client_ip + auth_url = args.auth_url + + if None in (msb_ip, tosca_aria_ip, juju_client_ip, auth_url): + missing = [] + for i in (msb_ip, tosca_aria_ip, juju_client_ip, auth_url): + if i is None: + missing.append(i) + raise RaiseError('missing parameter: %s' % missing) - _, msb_ip, tosca_aria_ip = sys.argv add_common_tosca_aria(msb_ip, tosca_aria_ip) - add_openo_vim(msb_ip) - add_openo_vnfm(msb_ip) + add_openo_vim(msb_ip, auth_url) + add_openo_vnfm(msb_ip, juju_client_ip) |