-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparser.py
83 lines (78 loc) · 4.29 KB
/
parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#
# Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
#
"""
Default options for any debug vertex
"""
import argparse
import ConfigParser
import os
class ArgumentParser(argparse.ArgumentParser):
def __init__(self, **kwargs):
super(ArgumentParser, self).__init__(**kwargs)
self._parser_add_std_args()
@staticmethod
def read_config_option(config, section, option, default_option):
''' Read the config file. If the option/section is not present, return the default_option
'''
try:
val = config.get(section, option)
if val.lower() == 'true':
val = True
elif val.lower() == 'false' or val.lower() == 'none':
val = False
elif not val:
val = default_option
return val
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
return default_option
def _parser_add_std_args(self):
self.add_argument("-c", "--config", help="Specify conf file", metavar="FILE", default='debug.ini')
self.add_argument("-v", "--verbose", help="Enable verbose output", action="store_true")
self.add_argument("-d", "--discard", help="Disable dump of json output to file", action="store_true")
self.add_argument("-D", "--depth", type=int, default=-1, help="Depth of the dependent vertexes to process")
self.add_argument("-V", "--verify", help="Verify objects", action="store_true")
self.add_argument("--token", help="Auth Token to use to talk to Config/Analytics Rest API Services")
self.add_argument("--username", help="stack username")
self.add_argument("--password", help="stack password")
self.add_argument("--tenant", help="stack tenant")
self.add_argument("--fqname", help="fqname of the object")
self.add_argument("--uuid", help="uuid of the object")
self.add_argument("--obj-type", help="type of the object")
def parse_args(self, args):
pargs = super(ArgumentParser, self).parse_args(args)
pargs = dict(pargs._get_kwargs())
if os.path.exists(pargs['config']):
config = ConfigParser.SafeConfigParser()
config.read(pargs['config'])
pargs['auth_ip'] = self.read_config_option(config, 'auth',
'AUTHN_SERVER', '127.0.0.1')
pargs['auth_port'] = self.read_config_option(config, 'auth',
'AUTHN_PORT', '35357')
pargs['auth_url_path'] = self.read_config_option(config, 'auth',
'AUTHN_URL', '/v2.0/tokens')
pargs['username'] = pargs['username'] or os.getenv('OS_USERNAME') or \
self.read_config_option(config, 'auth', 'AUTHN_USER', 'admin')
pargs['password'] = pargs['password'] or os.getenv('OS_PASSWORD') or \
self.read_config_option(config, 'auth', 'AUTHN_PASSWORD', 'contrail123')
pargs['tenant'] = pargs['tenant'] or os.getenv('OS_TENANT_NAME') or \
self.read_config_option(config, 'auth', 'AUTHN_TENANT_NAME', 'admin')
pargs['token'] = pargs['token'] or os.getenv('OS_TOKEN') or \
self.read_config_option(config, 'auth', 'AUTHN_TOKEN', None)
pargs['config_ip'] = self.read_config_option(config, 'contrail',
'CONFIG_IP', '127.0.0.1')
pargs['config_port'] = self.read_config_option(config, 'contrail',
'CONFIG_PORT', '8082')
pargs['analytics_ip'] = self.read_config_option(config, 'contrail',
'ANALYTICS_IP', '')
pargs['analytics_port'] = self.read_config_option(config, 'contrail',
'ANALYTICS_PORT', '8081')
pargs['control_port'] = self.read_config_option(config, 'contrail',
'CONTROL_PORT', '8083')
pargs['agent_port'] = self.read_config_option(config, 'contrail',
'AGENT_PORT', '8085')
pargs['schema_transformer_port'] = self.read_config_option(config, 'contrail',
'SCHEMA_TRANSFORMER_PORT', '8087')
else:
raise Exception('Unable to read the ini file %s'%pargs['config'])
return pargs