Add wrcp aio client test with real ocloud
[pti/o2.git] / o2ims / config.py
1 # Copyright (C) 2021 Wind River Systems, Inc.
2 #
3 #  Licensed under the Apache License, Version 2.0 (the "License");
4 #  you may not use this file except in compliance with the License.
5 #  You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 #  Unless required by applicable law or agreed to in writing, software
10 #  distributed under the License is distributed on an "AS IS" BASIS,
11 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 #  See the License for the specific language governing permissions and
13 #  limitations under the License.
14
15 import os
16 import sys
17 import logging
18
19
20 def get_postgres_uri():
21     host = os.environ.get("DB_HOST", "localhost")
22     port = 54321 if host == "localhost" else 5432
23     password = os.environ.get("DB_PASSWORD", "o2ims123")
24     user, db_name = "o2ims", "o2ims"
25     return f"postgresql://{user}:{password}@{host}:{port}/{db_name}"
26
27
28 def get_api_url():
29     host = os.environ.get("API_HOST", "localhost")
30     port = 5005 if host == "localhost" else 80
31     return f"http://{host}:{port}"
32
33
34 def get_o2ims_api_base():
35     return '/o2ims_infrastructureInventory/v1'
36
37
38 def get_redis_host_and_port():
39     host = os.environ.get("REDIS_HOST", "localhost")
40     port = 63791 if host == "localhost" else 6379
41     return dict(host=host, port=port)
42
43
44 def get_smo_o2endpoint():
45     smo_o2endpoint = os.environ.get(
46         "SMO_O2_ENDPOINT", "http://localhost/smo_sim")
47     return smo_o2endpoint
48
49
50 def get_stx_access_info():
51     # authurl = os.environ.get("STX_AUTH_URL", "http://192.168.204.1:5000/v3")
52     # username = os.environ.get("STX_USERNAME", "admin")
53     # pswd = os.environ.get("STX_PASSWORD", "passwd1")
54     # stx_access_info = (authurl, username, pswd)
55     try:
56         client_args = dict(
57             auth_url=os.environ.get('OS_AUTH_URL',
58                                     "http://192.168.204.1:5000/v3"),
59             username=os.environ.get('OS_USERNAME', "admin"),
60             api_key=os.environ.get('OS_PASSWORD', "fakepasswd1"),
61             project_name=os.environ.get('OS_PROJECT_NAME', "admin"),
62         )
63         # dc_client_args = dict(
64         #     auth_url=os.environ['OS_AUTH_URL'],
65         #     username=os.environ['OS_USERNAME'],
66         #     api_key=os.environ['OS_PASSWORD'],
67         #     project_name=os.environ['OS_PROJECT_NAME'],
68         #     user_domain_name=os.environ['OS_USER_DOMAIN_NAME'],
69         #     project_domain_name=os.environ['OS_PROJECT_NAME'],
70         #     project_domain_id=os.environ['OS_PROJECT_DOMAIN_ID']
71         # )
72     except KeyError:
73         logging.error('Please source your RC file before execution, '
74                       'e.g.: `source ~/downloads/admin-rc.sh`')
75         sys.exit(1)
76
77     os_client_args = {}
78     for key, val in client_args.items():
79         os_client_args['os_{key}'.format(key=key)] = val
80     os_client_args['os_password'] = os_client_args.pop('os_api_key')
81     os_client_args['os_region_name'] = 'RegionOne'
82     os_client_args['api_version'] = 1
83     return os_client_args