forked from MirantisWorkloadMobility/CloudFerry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfglib.py
323 lines (262 loc) · 10.2 KB
/
cfglib.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
from oslo.config import cfg
import addons
src = cfg.OptGroup(name='src',
title='Credetionals and general config for source cloud')
src_opts = [
cfg.StrOpt('type', default='os',
help='os - OpenStack Cloud'),
cfg.StrOpt('host', default='-',
help='ip-address controller for cloud'),
cfg.StrOpt('user', default='-',
help='user for access to API'),
cfg.StrOpt('password', default='-',
help='password for access to API'),
cfg.StrOpt('tenant', default='-',
help='tenant for access to API'),
cfg.StrOpt('temp', default='-',
help='temporary directory on controller')
]
dst = cfg.OptGroup(name='dst',
title='Credetionals and general '
'config for destination cloud')
dst_opts = [
cfg.StrOpt('type', default='os',
help='os - OpenStack Cloud'),
cfg.StrOpt('host', default='-',
help='ip-address controller for cloud'),
cfg.StrOpt('user', default='-',
help='user for access to API'),
cfg.StrOpt('password', default='-',
help='password for access to API'),
cfg.StrOpt('tenant', default='-',
help='tenant for access to API'),
cfg.StrOpt('temp', default='-',
help='temporary directory on controller'),
]
migrate = cfg.OptGroup(name='migrate',
title='General config for migration process')
migrate_opts = [
cfg.BoolOpt('keep_user_passwords', default=True,
help='True - keep user passwords, '
'False - not keep user passwords'),
cfg.StrOpt('key_filename', default='id_rsa',
help='name pub key'),
cfg.StrOpt('keep_ip', default='no',
help='yes - keep ip, no - not keep ip'),
cfg.StrOpt('speed_limit', default='10MB',
help='speed limit for glance to glance'),
cfg.StrOpt('instances', default='key_name-qwerty',
help='filter instance by parametrs'),
cfg.StrOpt('file_compression', default='dd',
help='gzip - use GZIP when file tranfering via ssh, '
' - no compression, directly via dd'),
cfg.IntOpt('level_compression', default='7',
help='level compression for gzip'),
cfg.StrOpt('ssh_transfer_port', default='9990',
help='interval ports for ssh tunnel'),
cfg.StrOpt('port', default='9990',
help='interval ports for ssh tunnel'),
cfg.BoolOpt('overwrite_user_passwords', default=False,
help='Overwrite password for exists users on destination')
]
mail = cfg.OptGroup(name='mail',
title='Mail credentials for notifications')
mail_opts = [
cfg.StrOpt('server', default='-',
help='name mail server'),
cfg.StrOpt('username', default='-',
help='name username for mail'),
cfg.StrOpt('password', default='-',
help='password for mail'),
cfg.StrOpt('from_addr', default='-',
help='field FROM in letter')
]
src_mysql = cfg.OptGroup(name='src_mysql',
title='Config mysql for source cloud')
src_mysql_opts = [
cfg.StrOpt('user', default='-',
help='user for mysql'),
cfg.StrOpt('password', default='-',
help='password for mysql'),
cfg.StrOpt('host', default='-',
help='host of mysql'),
cfg.StrOpt('connection', default='mysql+mysqlconnector',
help='driver for connection'),
]
src_compute = cfg.OptGroup(name='src_compute',
title='Config service for compute')
src_compute_opts = [
cfg.StrOpt('service', default='nova',
help='name service for compute'),
cfg.StrOpt('backend', default='ceph',
help='backend for ephemeral drives'),
cfg.StrOpt('convert_diff_file', default='qcow2',
help='convert diff file to'),
cfg.StrOpt('convert_ephemeral_disk', default='qcow2',
help='convert ephemeral disk to'),
]
src_storage = cfg.OptGroup(name='src_storage',
title='Config service for storage')
src_storage_opts = [
cfg.StrOpt('service', default='cinder',
help='name service for storage'),
cfg.StrOpt('backend', default='iscsi',
help='backend for storage'),
cfg.StrOpt('protocol_transfer', default='GLANCE',
help='mode transporting volumes GLANCE or SSH'),
cfg.StrOpt('disk_format', default='qcow2',
help='convert volume'),
]
src_image = cfg.OptGroup(name='src_image',
title='Config service for images')
src_image_opts = [
cfg.StrOpt('service', default='glance',
help='name service for images')
]
src_identity = cfg.OptGroup(name='src_identity',
title='Config service for identity')
src_identity_opts = [
cfg.StrOpt('service', default='keystone',
help='name service for keystone')
]
src_network = cfg.OptGroup(name='src_network',
title='Config service for network')
src_network_opts = [
cfg.StrOpt('service', default='auto',
help='name service for network, '
'auto - detect avaiable service')
]
dst_mysql = cfg.OptGroup(name='dst_mysql',
title='Config mysql for destination cloud')
dst_mysql_opts = [
cfg.StrOpt('user', default='-',
help='user for mysql'),
cfg.StrOpt('password', default='-',
help='password for mysql'),
cfg.StrOpt('host', default='-',
help='host of mysql'),
cfg.StrOpt('connection', default='mysql+mysqlconnector',
help='driver for connection'),
]
dst_compute = cfg.OptGroup(name='dst_compute',
title='Config service for compute')
dst_compute_opts = [
cfg.StrOpt('service', default='nova',
help='name service for compute'),
cfg.StrOpt('backend', default='ceph',
help='backend for ephemeral drives'),
cfg.StrOpt('convert_diff_file', default='qcow2',
help='convert diff file to'),
cfg.StrOpt('convert_ephemeral_disk', default='qcow2',
help='convert ephemeral disk to'),
]
dst_storage = cfg.OptGroup(name='dst_storage',
title='Config service for storage')
dst_storage_opts = [
cfg.StrOpt('service', default='cinder',
help='name service for storage'),
cfg.StrOpt('backend', default='iscsi',
help='backend for storage'),
cfg.StrOpt('protocol_transfer', default='GLANCE',
help='mode transporting volumes GLANCE or SSH'),
cfg.StrOpt('disk_format', default='qcow2',
help='convert volume'),
]
dst_image = cfg.OptGroup(name='dst_image',
title='Config service for images')
dst_image_opts = [
cfg.StrOpt('service', default='glance',
help='name service for images'),
cfg.BoolOpt('convert_to_raw', default='True',
help='convert to raw images')
]
dst_identity = cfg.OptGroup(name='dst_identity',
title='Config service for identity')
dst_identity_opts = [
cfg.StrOpt('service', default='keystone',
help='name service for keystone')
]
dst_network = cfg.OptGroup(name='dst_network',
title='Config service for network')
dst_network_opts = [
cfg.StrOpt('service', default='auto',
help='name service for network, '
'auto - detect avaiable service'),
cfg.ListOpt('interfaces_for_instance', default='net04',
help='list interfaces for connection to instance')
]
import_rules = cfg.OptGroup(name='import_rules',
title='Import Rules for '
'overwrite something fields')
import_rules_opts = [
cfg.StrOpt('key', default='',
help=''),
]
cfg_for_reg = [
(src, src_opts),
(dst, dst_opts),
(migrate, migrate_opts),
(mail, mail_opts),
(src_mysql, src_mysql_opts),
(src_compute, src_compute_opts),
(src_storage, src_storage_opts),
(src_identity, src_identity_opts),
(src_image, src_image_opts),
(src_network, src_network_opts),
(dst_mysql, dst_mysql_opts),
(dst_compute, dst_compute_opts),
(dst_storage, dst_storage_opts),
(dst_identity, dst_identity_opts),
(dst_image, dst_image_opts),
(dst_network, dst_network_opts),
(import_rules, import_rules_opts)
]
CONF = cfg.CONF
name_configs = ['configs/config.ini']
def init_config(name_config=None):
for i in cfg_for_reg:
CONF.register_group(i[0])
CONF.register_opts(i[1], i[0])
if name_config:
name_configs[0] = name_config
CONF(default_config_files=name_configs, args="")
def get_plugins():
plugins = addons
dir_plugins = dir(plugins)
exclude_field = ['__author__', '__builtins__', '__doc__', '__file__',
'__name__', '__package__', '__path__']
plugins = [(item, plugins.__dict__[item])
for item in dir_plugins if item not in exclude_field]
return plugins
def find_group(group):
for g in xrange(len(cfg_for_reg)):
if group.name == cfg_for_reg[g][0].name:
return g
return -1
def find_field(field, fields):
for g in xrange(len(fields)):
if field.name == fields[g].name:
return g
return -1
def merge_fields(index_pair, fields):
for field in fields:
index_field = find_field(field, cfg_for_reg[index_pair][1])
if index_field >= 0:
cfg_for_reg[index_pair][1][index_field] = field
else:
cfg_for_reg[index_pair][1].append(field)
def merge_cfg(cfg):
for pair in cfg:
index_pair = find_group(pair[0])
if index_pair == -1:
cfg_for_reg.append(pair)
else:
merge_fields(index_pair, pair[1])
def collector_configs_plugins():
plugins = get_plugins()
for plugin in plugins:
merge_cfg(plugin[1].cfg_for_reg)
name_configs.append('addons/%s/configs/config.ini' % plugin[0])
if __name__ == '__main__':
collector_configs_plugins()
init_config()