Skip to content

Commit 8e657d2

Browse files
committed
feat: can specify pusher and puller name with the cli
1 parent 4ca2811 commit 8e657d2

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

powerapi/cli/tools.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ def __init__(self):
6767

6868
subparser_mongo_input = ComponentSubParser('mongodb')
6969
subparser_mongo_input.add_argument('u', 'uri', help='sepcify MongoDB uri')
70-
subparser_mongo_input.add_argument('d', 'db', help='specify MongoDB database name')
71-
subparser_mongo_input.add_argument('c', 'collection', help='specify MongoDB database collection')
70+
subparser_mongo_input.add_argument('d', 'db', help='specify MongoDB database name', )
71+
subparser_mongo_input.add_argument('c', 'collection', help='specify MongoDB database collection',
72+
default='sensor')
73+
subparser_mongo_input.add_argument('n', 'name', help='specify puller name', default='puller_mongodb')
7274
subparser_mongo_input.add_argument('m', 'model', help='specify data type that will be storen in the database',
7375
default='hwpc_report')
7476
self.add_component_subparser('input', subparser_mongo_input,
@@ -81,15 +83,18 @@ def __init__(self):
8183
check_msg='one or more csv files couldn\'t be read')
8284
subparser_csv_input.add_argument('m', 'model', help='specify data type that will be storen in the database',
8385
default='hwpc_report')
86+
subparser_csv_input.add_argument('n', 'name', help='specify puller name', default='puller_csv')
8487
self.add_component_subparser('input', subparser_csv_input,
8588
help_str='specify a database input : --db_output database_name ARG1 ARG2 ... ')
8689

8790
subparser_mongo_output = ComponentSubParser('mongodb')
8891
subparser_mongo_output.add_argument('u', 'uri', help='sepcify MongoDB uri')
8992
subparser_mongo_output.add_argument('d', 'db', help='specify MongoDB database name')
90-
subparser_mongo_output.add_argument('c', 'collection', help='specify MongoDB database collection')
93+
subparser_mongo_output.add_argument('c', 'collection', help='specify MongoDB database collection',
94+
default='powermeter')
9195
subparser_mongo_output.add_argument('m', 'model', help='specify data type that will be storen in the database',
9296
default='power_report')
97+
subparser_mongo_output.add_argument('n', 'name', help='specify puller name', default='pusher_mongodb')
9398
self.add_component_subparser('output', subparser_mongo_output,
9499
help_str='specify a database output : --db_output database_name ARG1 ARG2 ...')
95100

@@ -98,6 +103,7 @@ def __init__(self):
98103
help='specify directory where where output csv files will be writen')
99104
subparser_csv_output.add_argument('m', 'model', help='specify data type that will be storen in the database',
100105
default='power_report')
106+
subparser_csv_output.add_argument('n', 'name', help='specify puller name', default='pusher_csv')
101107
self.add_component_subparser('output', subparser_csv_output,
102108
help_str='specify a database input : --db_output database_name ARG1 ARG2 ... ')
103109

@@ -107,6 +113,7 @@ def __init__(self):
107113
subparser_influx_output.add_argument('p', 'port', help='specify InfluxDB connection port', type=int)
108114
subparser_influx_output.add_argument('m', 'model', help='specify data type that will be storen in the database',
109115
default='power_report')
116+
subparser_influx_output.add_argument('n', 'name', help='specify puller name', default='pusher_influxdb')
110117
self.add_component_subparser('output', subparser_influx_output,
111118
help_str='specify a database input : --db_output database_name ARG1 ARG2 ... ')
112119

@@ -117,6 +124,7 @@ def __init__(self):
117124

118125
subparser_opentsdb_output.add_argument('m', 'model', help='specify data type that will be storen in the database',
119126
default='power_report')
127+
subparser_opentsdb_output.add_argument('n', 'name', help='specify puller name', default='pusher_opentsdb')
120128
self.add_component_subparser('output', subparser_opentsdb_output,
121129
help_str='specify a database input : --db_output database_name ARG1 ARG2 ... ')
122130

@@ -182,7 +190,7 @@ def generate_pullers(config, report_filter):
182190
try:
183191
factory = DB_FACTORY[db_config['type']]
184192
model = MODEL_FACTORY[db_config['model']]
185-
name = 'puller_' + db_config['type']
193+
name = db_config[name]
186194
puller = PullerActor(name, factory(db_config), report_filter, model, stream_mode=config['stream'],
187195
level_logger=config['verbose'])
188196
pullers[name] = puller
@@ -210,7 +218,7 @@ def generate_pushers(config):
210218
try:
211219
factory = DB_FACTORY[db_config['type']]
212220
model = MODEL_FACTORY[db_config['model']]
213-
name = 'pusher_' + db_config['type']
221+
name = db_config[name]
214222
pusher = PusherActor(name, model, factory(db_config), level_logger=config['verbose'])
215223

216224
pushers[name] = pusher

0 commit comments

Comments
 (0)