illumio-pylo 0.3.0__py3-none-any.whl → 0.3.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- illumio_pylo/API/APIConnector.py +12 -8
- illumio_pylo/API/CredentialsManager.py +9 -8
- illumio_pylo/Helpers/exports.py +77 -63
- illumio_pylo/IPMap.py +9 -0
- illumio_pylo/LabeledObject.py +1 -1
- illumio_pylo/Organization.py +4 -1
- illumio_pylo/Rule.py +27 -1
- illumio_pylo/Ruleset.py +15 -27
- illumio_pylo/Service.py +49 -52
- illumio_pylo/__init__.py +1 -1
- illumio_pylo/cli/__init__.py +19 -6
- illumio_pylo/cli/commands/credential_manager.py +91 -26
- illumio_pylo/cli/commands/ruleset_export.py +44 -37
- illumio_pylo/cli/commands/utils/misc.py +4 -0
- illumio_pylo/cli/commands/ven_compatibility_report_export.py +14 -8
- illumio_pylo/cli/commands/ven_duplicate_remover.py +18 -15
- illumio_pylo/cli/commands/ven_upgrader.py +10 -78
- illumio_pylo/cli/commands/workload_export.py +16 -12
- illumio_pylo/cli/commands/workload_import.py +50 -17
- illumio_pylo/cli/commands/workload_update.py +3 -2
- illumio_pylo/tmp.py +8 -4
- {illumio_pylo-0.3.0.dist-info → illumio_pylo-0.3.2.dist-info}/METADATA +1 -1
- {illumio_pylo-0.3.0.dist-info → illumio_pylo-0.3.2.dist-info}/RECORD +26 -30
- illumio_pylo/utilities/explorer_report_exporter.py +0 -86
- illumio_pylo/utilities/iplists_stats_duplicates_unused_finder.py +0 -75
- illumio_pylo/utilities/ven_idle_to_illumination.py +0 -344
- illumio_pylo/utilities/ven_reassign_pce.py +0 -183
- {illumio_pylo-0.3.0.dist-info → illumio_pylo-0.3.2.dist-info}/LICENSE +0 -0
- {illumio_pylo-0.3.0.dist-info → illumio_pylo-0.3.2.dist-info}/WHEEL +0 -0
- {illumio_pylo-0.3.0.dist-info → illumio_pylo-0.3.2.dist-info}/top_level.txt +0 -0
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import sys
|
|
3
|
-
import argparse
|
|
4
|
-
from datetime import datetime
|
|
5
|
-
from typing import Union,Dict,List
|
|
6
|
-
|
|
7
|
-
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))
|
|
8
|
-
import illumio_pylo as pylo
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
parser = argparse.ArgumentParser(description='TODO LATER')
|
|
12
|
-
parser.add_argument('--pce', type=str, required=True,
|
|
13
|
-
help='hostname of the PCE')
|
|
14
|
-
|
|
15
|
-
parser.add_argument('--dev-use-cache', type=bool, nargs='?', required=False, default=False, const=True,
|
|
16
|
-
help='For developers only')
|
|
17
|
-
|
|
18
|
-
parser.add_argument('--filter-env-label', type=str, required=False, default=None,
|
|
19
|
-
help='Filter agents by environment labels (separated by commas)')
|
|
20
|
-
parser.add_argument('--filter-loc-label', type=str, required=False, default=None,
|
|
21
|
-
help='Filter agents by environment labels (separated by commas)')
|
|
22
|
-
parser.add_argument('--filter-app-label', type=str, required=False, default=None,
|
|
23
|
-
help='Filter agents by role labels (separated by commas)')
|
|
24
|
-
parser.add_argument('--filter-role-label', type=str, required=False, default=None,
|
|
25
|
-
help='Filter agents by role labels (separated by commas)')
|
|
26
|
-
|
|
27
|
-
parser.add_argument('--filter-on-href-from-file', type=str, required=False, default=None,
|
|
28
|
-
help='Filter agents on workload href found in specific csv file')
|
|
29
|
-
|
|
30
|
-
parser.add_argument('--ignore-incompatibilities', type=str, nargs='+', required=False, default=None,
|
|
31
|
-
help="Ignore specific incompatibilities and force mode switch!")
|
|
32
|
-
|
|
33
|
-
parser.add_argument('--ignore-all-incompatibilities', action='store_true',
|
|
34
|
-
help="Don't check compatibility report and just do the change!")
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
parser.add_argument('--confirm', action='store_true',
|
|
38
|
-
help='Request upgrade of the Agents')
|
|
39
|
-
|
|
40
|
-
parser.add_argument('--debug', type=bool, nargs='?', required=False, default=False, const=True,
|
|
41
|
-
help='extra debugging messages')
|
|
42
|
-
|
|
43
|
-
parser.add_argument('--mode', type=str.lower, required=True, choices=['build', 'test'],
|
|
44
|
-
help='Select if you want to switch from IDLE to BUILD or TEST')
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
args = vars(parser.parse_args())
|
|
48
|
-
|
|
49
|
-
if args['debug']:
|
|
50
|
-
pylo.log_set_debug()
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
hostname = args['pce']
|
|
54
|
-
print(args)
|
|
55
|
-
use_cached_config = args['dev_use_cache']
|
|
56
|
-
request_upgrades = args['confirm']
|
|
57
|
-
switch_to_mode = args['mode']
|
|
58
|
-
href_filter_file = args['filter_on_href_from_file']
|
|
59
|
-
options_ignore_all_incompatibilities = args['ignore_all_incompatibilities']
|
|
60
|
-
option_ignore_incompatibilities: Union[None, Dict[str, bool]] = None
|
|
61
|
-
if args['ignore_incompatibilities'] is not None:
|
|
62
|
-
option_ignore_incompatibilities = {}
|
|
63
|
-
for entry in args['ignore_incompatibilities']:
|
|
64
|
-
option_ignore_incompatibilities[entry] = True
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
minimum_supported_version = pylo.SoftwareVersion("18.2.0-0")
|
|
68
|
-
|
|
69
|
-
org = pylo.Organization(1)
|
|
70
|
-
fake_config = pylo.Organization.create_fake_empty_config()
|
|
71
|
-
|
|
72
|
-
now = datetime.now()
|
|
73
|
-
report_file = 'ven-idle-to-illumination-results_{}.csv'.format(now.strftime("%Y%m%d-%H%M%S"))
|
|
74
|
-
report_file_excel = 'ven-idle-to-illumination-results_{}.xlsx'.format(now.strftime("%Y%m%d-%H%M%S"))
|
|
75
|
-
|
|
76
|
-
csv_report_headers = ['name', 'hostname', 'role', 'app', 'env', 'loc', 'changed_mode', 'details', 'href']
|
|
77
|
-
csv_report = pylo.ArrayToExport(csv_report_headers)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
def add_workload_to_report(wkl: pylo.Workload, changed_mode: str, details: str):
|
|
81
|
-
labels = workload.get_labels_str_list()
|
|
82
|
-
new_row = {
|
|
83
|
-
'hostname': wkl.hostname,
|
|
84
|
-
'role': labels[0],
|
|
85
|
-
'app': labels[1],
|
|
86
|
-
'env': labels[2],
|
|
87
|
-
'loc': labels[3],
|
|
88
|
-
'href': wkl.href,
|
|
89
|
-
'status': wkl.get_status_string(),
|
|
90
|
-
'changed_mode': changed_mode,
|
|
91
|
-
'details': details
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
csv_report.add_line_from_object(new_row)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if use_cached_config:
|
|
98
|
-
org.load_from_cache_or_saved_credentials(hostname)
|
|
99
|
-
else:
|
|
100
|
-
print(" * Looking for credentials for PCE '{}'... ".format(hostname), end="", flush=True)
|
|
101
|
-
connector = pylo.APIConnector.create_from_credentials_in_file(hostname, request_if_missing=True)
|
|
102
|
-
print("OK!")
|
|
103
|
-
|
|
104
|
-
print(" * Downloading Workloads/Agents listing from the PCE... ", end="", flush=True)
|
|
105
|
-
fake_config['workloads'] = connector.objects_workload_get()
|
|
106
|
-
print("OK!")
|
|
107
|
-
|
|
108
|
-
print(" * Downloading Labels listing from the PCE... ", end="", flush=True)
|
|
109
|
-
fake_config['labels'] = connector.objects_label_get()
|
|
110
|
-
print("OK!")
|
|
111
|
-
|
|
112
|
-
print(" * Parsing PCE data ... ", end="", flush=True)
|
|
113
|
-
org.pce_version = connector.version
|
|
114
|
-
org.load_from_json(fake_config)
|
|
115
|
-
print("OK!")
|
|
116
|
-
|
|
117
|
-
print(" * PCE data statistics:\n{}".format(org.stats_to_str(padding=' ')))
|
|
118
|
-
|
|
119
|
-
href_filter_data = None
|
|
120
|
-
if href_filter_file is not None:
|
|
121
|
-
print(" * Loading CSV input file '{}'...".format(href_filter_file), flush=True, end='')
|
|
122
|
-
href_filter_data = pylo.CsvExcelToObject(href_filter_file, expected_headers=[{'name': 'href', 'optional': False}])
|
|
123
|
-
print('OK')
|
|
124
|
-
print(" - CSV has {} columns and {} lines (headers don't count)".format(href_filter_data.count_columns(), href_filter_data.count_lines()), flush=True)
|
|
125
|
-
|
|
126
|
-
agents = {}
|
|
127
|
-
for agent in org.AgentStore.items_by_href.values():
|
|
128
|
-
if agent.mode == 'idle':
|
|
129
|
-
agents[agent.href] = agent
|
|
130
|
-
print(" * Found {} IDLE Agents".format(len(agents)))
|
|
131
|
-
count_idle_agents_total = len(agents)
|
|
132
|
-
|
|
133
|
-
print(" * Parsing filters")
|
|
134
|
-
|
|
135
|
-
env_label_list = {}
|
|
136
|
-
if args['filter_env_label'] is not None:
|
|
137
|
-
print(" * Environment Labels specified")
|
|
138
|
-
for raw_label_name in args['filter_env_label'].split(','):
|
|
139
|
-
print(" - label named '{}'".format(raw_label_name), end='', flush=True)
|
|
140
|
-
label = org.LabelStore.find_label_by_name_and_type(raw_label_name, pylo.label_type_env)
|
|
141
|
-
if label is None:
|
|
142
|
-
print("NOT FOUND!")
|
|
143
|
-
raise pylo.PyloEx("Cannot find label named '{}'".format(raw_label_name))
|
|
144
|
-
else:
|
|
145
|
-
print(" found")
|
|
146
|
-
env_label_list[label] = label
|
|
147
|
-
|
|
148
|
-
loc_label_list = {}
|
|
149
|
-
if args['filter_loc_label'] is not None:
|
|
150
|
-
print(" * Location Labels specified")
|
|
151
|
-
for raw_label_name in args['filter_loc_label'].split(','):
|
|
152
|
-
print(" - label named '{}' ".format(raw_label_name), end='', flush=True)
|
|
153
|
-
label = org.LabelStore.find_label_by_name_and_type(raw_label_name, pylo.label_type_loc)
|
|
154
|
-
if label is None:
|
|
155
|
-
print("NOT FOUND!")
|
|
156
|
-
raise pylo.PyloEx("Cannot find label named '{}'".format(raw_label_name))
|
|
157
|
-
else:
|
|
158
|
-
print(" found")
|
|
159
|
-
loc_label_list[label] = label
|
|
160
|
-
|
|
161
|
-
app_label_list = {}
|
|
162
|
-
if args['filter_app_label'] is not None:
|
|
163
|
-
print(" * Application Labels specified")
|
|
164
|
-
for raw_label_name in args['filter_app_label'].split(','):
|
|
165
|
-
print(" - label named '{}' ".format(raw_label_name), end='', flush=True)
|
|
166
|
-
label = org.LabelStore.find_label_by_name_and_type(raw_label_name, pylo.label_type_app)
|
|
167
|
-
if label is None:
|
|
168
|
-
print(" NOT FOUND!")
|
|
169
|
-
raise pylo.PyloEx("Cannot find label named '{}'".format(raw_label_name))
|
|
170
|
-
else:
|
|
171
|
-
print(" found")
|
|
172
|
-
app_label_list[label] = label
|
|
173
|
-
|
|
174
|
-
role_label_list = {}
|
|
175
|
-
if args['filter_role_label'] is not None:
|
|
176
|
-
print(" * Role Labels specified")
|
|
177
|
-
for raw_label_name in args['filter_role_label'].split(','):
|
|
178
|
-
print(" - label named '{}' ".format(raw_label_name), end='', flush=True)
|
|
179
|
-
label = org.LabelStore.find_label_by_name_and_type(raw_label_name, pylo.label_type_role)
|
|
180
|
-
if label is None:
|
|
181
|
-
print("NOT FOUND!")
|
|
182
|
-
raise pylo.PyloEx("Cannot find label named '{}'".format(raw_label_name))
|
|
183
|
-
else:
|
|
184
|
-
print("found")
|
|
185
|
-
role_label_list[label] = label
|
|
186
|
-
print(" * DONE")
|
|
187
|
-
|
|
188
|
-
print(" * Applying filters to the list of Agents...", flush=True, end='')
|
|
189
|
-
|
|
190
|
-
for agent_href in list(agents.keys()):
|
|
191
|
-
agent = agents[agent_href]
|
|
192
|
-
workload = agent.workload
|
|
193
|
-
|
|
194
|
-
if len(env_label_list) > 0 and (workload.env_label is None or workload.env_label not in env_label_list):
|
|
195
|
-
del agents[agent_href]
|
|
196
|
-
continue
|
|
197
|
-
if len(loc_label_list) > 0 and (workload.loc_label is None or workload.loc_label not in loc_label_list):
|
|
198
|
-
del agents[agent_href]
|
|
199
|
-
continue
|
|
200
|
-
if len(app_label_list) > 0 and (workload.app_label is None or workload.app_label not in app_label_list):
|
|
201
|
-
del agents[agent_href]
|
|
202
|
-
continue
|
|
203
|
-
if len(role_label_list) > 0 and (workload.role_label is None or workload.role_label not in role_label_list):
|
|
204
|
-
del agents[agent_href]
|
|
205
|
-
continue
|
|
206
|
-
|
|
207
|
-
if href_filter_data is not None:
|
|
208
|
-
workload_href_found = False
|
|
209
|
-
for href_entry in href_filter_data.objects():
|
|
210
|
-
workload_href = href_entry['href']
|
|
211
|
-
if workload_href is not None and workload_href == workload.href:
|
|
212
|
-
workload_href_found = True
|
|
213
|
-
break
|
|
214
|
-
if not workload_href_found:
|
|
215
|
-
del agents[agent_href]
|
|
216
|
-
continue
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
print("OK! {} VENs are matching filters (from initial list of {} IDLE VENs).".format(len(agents), count_idle_agents_total))
|
|
220
|
-
|
|
221
|
-
print()
|
|
222
|
-
print(" ** Request Compatibility Report for each Agent in IDLE mode **")
|
|
223
|
-
|
|
224
|
-
agent_count = 0
|
|
225
|
-
agent_green_count = 0
|
|
226
|
-
agent_mode_changed_count = 0
|
|
227
|
-
agent_skipped_not_online = 0
|
|
228
|
-
agent_has_no_report_count = 0
|
|
229
|
-
agent_report_failed_count = 0
|
|
230
|
-
|
|
231
|
-
try:
|
|
232
|
-
for agent in agents.values():
|
|
233
|
-
agent_count += 1
|
|
234
|
-
print(" - Agent #{}/{}: wkl NAME:'{}' HREF:{} Labels:{}".format(agent_count, len(agents), agent.workload.get_name(),
|
|
235
|
-
agent.workload.href,
|
|
236
|
-
agent.workload.get_labels_str())
|
|
237
|
-
)
|
|
238
|
-
if not agent.workload.online:
|
|
239
|
-
print(" - Agent is not ONLINE so we're skipping it")
|
|
240
|
-
agent_skipped_not_online += 1
|
|
241
|
-
add_workload_to_report(agent.workload, 'no', 'VEN is not online')
|
|
242
|
-
continue
|
|
243
|
-
|
|
244
|
-
if options_ignore_all_incompatibilities:
|
|
245
|
-
if not request_upgrades:
|
|
246
|
-
print(" - ** SKIPPING Agent mode change process as option '--confirm' was not used")
|
|
247
|
-
add_workload_to_report(agent.workload, 'no', '--confirm option was not used')
|
|
248
|
-
continue
|
|
249
|
-
print(" - Request Agent mode switch to BUILD/TEST...", end='', flush=True)
|
|
250
|
-
connector.objects_agent_change_mode(agent.workload.href, switch_to_mode)
|
|
251
|
-
print("OK")
|
|
252
|
-
agent_mode_changed_count += 1
|
|
253
|
-
add_workload_to_report(agent.workload, 'yes', '')
|
|
254
|
-
continue
|
|
255
|
-
|
|
256
|
-
print(" - Downloading report...", flush=True, end='')
|
|
257
|
-
report = connector.agent_get_compatibility_report(agent_href=agent.href, return_raw_json=False)
|
|
258
|
-
print('OK')
|
|
259
|
-
if report.empty:
|
|
260
|
-
print(" - ** SKIPPING : Report does not exist")
|
|
261
|
-
agent_has_no_report_count += 1
|
|
262
|
-
add_workload_to_report(agent.workload, 'no', 'Compatibility report does not exist')
|
|
263
|
-
continue
|
|
264
|
-
print(" - Report status is '{}'".format(report.global_status))
|
|
265
|
-
if report.global_status == 'green':
|
|
266
|
-
agent_green_count += 1
|
|
267
|
-
if not request_upgrades:
|
|
268
|
-
print(" - ** SKIPPING Agent mode change process as option '--confirm' was not used")
|
|
269
|
-
add_workload_to_report(agent.workload, 'no', '--confirm option was not used')
|
|
270
|
-
continue
|
|
271
|
-
print(" - Request Agent mode switch to BUILD/TEST...", end='', flush=True)
|
|
272
|
-
connector.objects_agent_change_mode(agent.workload.href, switch_to_mode)
|
|
273
|
-
print("OK")
|
|
274
|
-
agent_mode_changed_count += 1
|
|
275
|
-
add_workload_to_report(agent.workload, 'yes', '')
|
|
276
|
-
else:
|
|
277
|
-
print(" - the following issues were found in the report:", flush=True)
|
|
278
|
-
failed_items = report.get_failed_items()
|
|
279
|
-
issues_remaining = False
|
|
280
|
-
for failed_item in failed_items:
|
|
281
|
-
if option_ignore_incompatibilities is not None and failed_item in option_ignore_incompatibilities:
|
|
282
|
-
print(" -{} (ignored because it's part of --ignore-incompatibilities list)".format(failed_item))
|
|
283
|
-
else:
|
|
284
|
-
print(" -{}".format(failed_item))
|
|
285
|
-
issues_remaining = True
|
|
286
|
-
|
|
287
|
-
if not issues_remaining:
|
|
288
|
-
agent_green_count += 1
|
|
289
|
-
if not request_upgrades:
|
|
290
|
-
print(" - ** SKIPPING Agent mode change process as option '--confirm' was not used")
|
|
291
|
-
add_workload_to_report(agent.workload, 'no', '--confirm option was not used')
|
|
292
|
-
continue
|
|
293
|
-
print(" - Request Agent mode switch to BUILD/TEST...", end='', flush=True)
|
|
294
|
-
connector.objects_agent_change_mode(agent.workload.href, switch_to_mode)
|
|
295
|
-
print("OK")
|
|
296
|
-
agent_mode_changed_count += 1
|
|
297
|
-
add_workload_to_report(agent.workload, 'yes', '')
|
|
298
|
-
continue
|
|
299
|
-
|
|
300
|
-
add_workload_to_report(agent.workload, 'no',
|
|
301
|
-
'compatibility report has reported issues: {}'.format(pylo.string_list_to_text(failed_items.keys()))
|
|
302
|
-
)
|
|
303
|
-
agent_report_failed_count += 1
|
|
304
|
-
|
|
305
|
-
except:
|
|
306
|
-
pylo.log.error("An unexpected error happened, an intermediate report will be written and original traceback displayed")
|
|
307
|
-
pylo.log.error(" * Writing report file '{}' ... ".format(report_file))
|
|
308
|
-
csv_report.write_to_csv(report_file)
|
|
309
|
-
pylo.log.error("DONE")
|
|
310
|
-
pylo.log.error(" * Writing report file '{}' ... ".format(report_file_excel))
|
|
311
|
-
csv_report.write_to_excel(report_file_excel)
|
|
312
|
-
pylo.log.error("DONE")
|
|
313
|
-
|
|
314
|
-
raise
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
def myformat(name, value):
|
|
318
|
-
return "{:<42} {:>6}".format(name, value)
|
|
319
|
-
# return "{:<18} {:>6}".format(name, "${:.2f}".format(value))
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
print("\n\n*** Statistics ***")
|
|
323
|
-
print(myformat(" - IDLE Agents count (after filters):", agent_count))
|
|
324
|
-
if request_upgrades:
|
|
325
|
-
print(myformat(" - Agents mode changed count:", agent_mode_changed_count))
|
|
326
|
-
else:
|
|
327
|
-
print(myformat(" - Agents with successful report count:", agent_green_count))
|
|
328
|
-
print(myformat(" - SKIPPED because not online count:", agent_skipped_not_online))
|
|
329
|
-
print(myformat(" - SKIPPED because report was not found:", agent_has_no_report_count))
|
|
330
|
-
print(myformat(" - Agents with failed reports:", agent_report_failed_count ))
|
|
331
|
-
|
|
332
|
-
print()
|
|
333
|
-
print(" * Writing report file '{}' ... ".format(report_file), end='', flush=True)
|
|
334
|
-
csv_report.write_to_csv(report_file)
|
|
335
|
-
print("DONE")
|
|
336
|
-
print(" * Writing report file '{}' ... ".format(report_file_excel), end='', flush=True)
|
|
337
|
-
csv_report.write_to_excel(report_file_excel)
|
|
338
|
-
print("DONE")
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
if not request_upgrades:
|
|
342
|
-
print()
|
|
343
|
-
print(" ***** No Agent was switched to Illumination because --confirm option was not used *****")
|
|
344
|
-
print()
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import sys
|
|
3
|
-
import argparse
|
|
4
|
-
|
|
5
|
-
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))
|
|
6
|
-
import illumio_pylo as pylo
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
# <editor-fold desc="Argparse stuff">
|
|
10
|
-
parser = argparse.ArgumentParser(description='TODO LATER')
|
|
11
|
-
parser.add_argument('--pce', type=str, required=True,
|
|
12
|
-
help='hostname of the PCE')
|
|
13
|
-
|
|
14
|
-
parser.add_argument('--dev-use-cache', type=bool, nargs='?', required=False, default=False, const=True,
|
|
15
|
-
help='For developers only')
|
|
16
|
-
parser.add_argument('--debug', '-d', type=bool, nargs='?', required=False, default=False, const=True,
|
|
17
|
-
help='extra debugging messages for developers')
|
|
18
|
-
|
|
19
|
-
parser.add_argument('--filter-env-label', type=str, required=False, default=None,
|
|
20
|
-
help='Filter agents by environment labels (separated by commas)')
|
|
21
|
-
parser.add_argument('--filter-loc-label', type=str, required=False, default=None,
|
|
22
|
-
help='Filter agents by environment labels (separated by commas)')
|
|
23
|
-
parser.add_argument('--filter-app-label', type=str, required=False, default=None,
|
|
24
|
-
help='Filter agents by role labels (separated by commas)')
|
|
25
|
-
parser.add_argument('--filter-role-label', type=str, required=False, default=None,
|
|
26
|
-
help='Filter agents by role labels (separated by commas)')
|
|
27
|
-
|
|
28
|
-
parser.add_argument('--confirm', action='store_true',
|
|
29
|
-
help='Confirm reassignment request')
|
|
30
|
-
parser.add_argument('--stop-after', type=int, nargs='?', required=False, default=False, const=True,
|
|
31
|
-
help='Stop reassigning agents after X number of agents have already been processed')
|
|
32
|
-
|
|
33
|
-
parser.add_argument('--target-pce', type=str, required=True,
|
|
34
|
-
help='the new PCE these VENs should report to')
|
|
35
|
-
|
|
36
|
-
args = vars(parser.parse_args())
|
|
37
|
-
# </editor-fold>
|
|
38
|
-
|
|
39
|
-
if args['debug']:
|
|
40
|
-
pylo.log_set_debug()
|
|
41
|
-
|
|
42
|
-
hostname = args['pce']
|
|
43
|
-
use_cached_config = args['dev_use_cache']
|
|
44
|
-
request_upgrades = args['confirm']
|
|
45
|
-
target_pce_string = args['target_pce']
|
|
46
|
-
stop_after_x_agents = args['stop_after']
|
|
47
|
-
|
|
48
|
-
org = pylo.Organization(1)
|
|
49
|
-
fake_config = pylo.Organization.create_fake_empty_config()
|
|
50
|
-
|
|
51
|
-
if use_cached_config:
|
|
52
|
-
org.load_from_cache_or_saved_credentials(hostname)
|
|
53
|
-
else:
|
|
54
|
-
print(" * Looking for credentials for PCE '{}'... ".format(hostname), end="", flush=True)
|
|
55
|
-
connector = pylo.APIConnector.create_from_credentials_in_file(hostname, request_if_missing=True)
|
|
56
|
-
print("OK!")
|
|
57
|
-
|
|
58
|
-
print(" * Downloading Workloads/Agents listing from the PCE... ", end="", flush=True)
|
|
59
|
-
fake_config['workloads'] = connector.objects_workload_get()
|
|
60
|
-
print("OK!")
|
|
61
|
-
|
|
62
|
-
print(" * Downloading Labels listing from the PCE... ", end="", flush=True)
|
|
63
|
-
fake_config['labels'] = connector.objects_label_get()
|
|
64
|
-
print("OK!")
|
|
65
|
-
|
|
66
|
-
print(" * Parsing PCE data ... ", end="", flush=True)
|
|
67
|
-
org.pce_version = connector.version
|
|
68
|
-
org.connector = connector
|
|
69
|
-
org.load_from_json(fake_config)
|
|
70
|
-
print("OK!")
|
|
71
|
-
|
|
72
|
-
print(" * PCE data statistics:\n{}".format(org.stats_to_str(padding=' ')))
|
|
73
|
-
|
|
74
|
-
print(" * Parsing filters")
|
|
75
|
-
|
|
76
|
-
env_label_list = {}
|
|
77
|
-
if args['filter_env_label'] is not None:
|
|
78
|
-
print(" * Environment Labels specified")
|
|
79
|
-
for raw_label_name in args['filter_env_label'].split(','):
|
|
80
|
-
print(" - label named '{}'".format(raw_label_name), end='', flush=True)
|
|
81
|
-
label = org.LabelStore.find_label_by_name_and_type(raw_label_name, pylo.label_type_env)
|
|
82
|
-
if label is None:
|
|
83
|
-
print("NOT FOUND!")
|
|
84
|
-
raise pylo.PyloEx("Cannot find label named '{}'".format(raw_label_name))
|
|
85
|
-
else:
|
|
86
|
-
print(" FOUND")
|
|
87
|
-
env_label_list[label] = label
|
|
88
|
-
|
|
89
|
-
loc_label_list = {}
|
|
90
|
-
if args['filter_loc_label'] is not None:
|
|
91
|
-
print(" * Location Labels specified")
|
|
92
|
-
for raw_label_name in args['filter_loc_label'].split(','):
|
|
93
|
-
print(" - label named '{}' ".format(raw_label_name), end='', flush=True)
|
|
94
|
-
label = org.LabelStore.find_label_by_name_and_type(raw_label_name, pylo.label_type_loc)
|
|
95
|
-
if label is None:
|
|
96
|
-
print("NOT FOUND!")
|
|
97
|
-
raise pylo.PyloEx("Cannot find label named '{}'".format(raw_label_name))
|
|
98
|
-
else:
|
|
99
|
-
print("FOUND")
|
|
100
|
-
loc_label_list[label] = label
|
|
101
|
-
|
|
102
|
-
app_label_list = {}
|
|
103
|
-
if args['filter_app_label'] is not None:
|
|
104
|
-
print(" * Application Labels specified")
|
|
105
|
-
for raw_label_name in args['filter_app_label'].split(','):
|
|
106
|
-
print(" - label named '{}' ".format(raw_label_name), end='', flush=True)
|
|
107
|
-
label = org.LabelStore.find_label_by_name_and_type(raw_label_name, pylo.label_type_app)
|
|
108
|
-
if label is None:
|
|
109
|
-
print("NOT FOUND!")
|
|
110
|
-
raise pylo.PyloEx("Cannot find label named '{}'".format(raw_label_name))
|
|
111
|
-
else:
|
|
112
|
-
print("FOUND")
|
|
113
|
-
app_label_list[label] = label
|
|
114
|
-
|
|
115
|
-
role_label_list = {}
|
|
116
|
-
if args['filter_role_label'] is not None:
|
|
117
|
-
print(" * Role Labels specified")
|
|
118
|
-
for raw_label_name in args['filter_role_label'].split(','):
|
|
119
|
-
print(" - label named '{}' ".format(raw_label_name), end='', flush=True)
|
|
120
|
-
label = org.LabelStore.find_label_by_name_and_type(raw_label_name, pylo.label_type_role)
|
|
121
|
-
if label is None:
|
|
122
|
-
print("NOT FOUND!")
|
|
123
|
-
raise pylo.PyloEx("Cannot find label named '{}'".format(raw_label_name))
|
|
124
|
-
else:
|
|
125
|
-
print("FOUND")
|
|
126
|
-
role_label_list[label] = label
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
agents = org.AgentStore.items_by_href.copy()
|
|
130
|
-
|
|
131
|
-
for agent_href in list(agents.keys()):
|
|
132
|
-
agent = agents[agent_href]
|
|
133
|
-
workload = agent.workload
|
|
134
|
-
|
|
135
|
-
if len(env_label_list) > 0 and (workload.env_label is None or workload.env_label not in env_label_list):
|
|
136
|
-
del agents[agent_href]
|
|
137
|
-
continue
|
|
138
|
-
if len(loc_label_list) > 0 and (workload.loc_label is None or workload.loc_label not in loc_label_list):
|
|
139
|
-
del agents[agent_href]
|
|
140
|
-
continue
|
|
141
|
-
if len(app_label_list) > 0 and (workload.app_label is None or workload.app_label not in app_label_list):
|
|
142
|
-
del agents[agent_href]
|
|
143
|
-
continue
|
|
144
|
-
|
|
145
|
-
if len(role_label_list) > 0 and (workload.role_label is None or workload.role_label not in role_label_list):
|
|
146
|
-
del agents[agent_href]
|
|
147
|
-
continue
|
|
148
|
-
|
|
149
|
-
if 'active_pce_fqdn' in agent.raw_json and agent.raw_json['active_pce_fqdn'] == target_pce_string:
|
|
150
|
-
del agents[agent_href]
|
|
151
|
-
continue
|
|
152
|
-
|
|
153
|
-
print("")
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
print("\n *** Now Requesting Agents Reassignment to the new PCE '{}' ***".format(target_pce_string))
|
|
157
|
-
processed_agent_count = 0
|
|
158
|
-
for agent in agents.values():
|
|
159
|
-
if stop_after_x_agents is not False and processed_agent_count >= stop_after_x_agents:
|
|
160
|
-
print("\n ** Reassignment Processed stopped after {} agents as requested while there is {} more to process **".format(stop_after_x_agents, len(agents)-stop_after_x_agents))
|
|
161
|
-
break
|
|
162
|
-
|
|
163
|
-
print(" - Agent #{}/{}: wkl NAME:'{}' HREF:{} Labels:{}".format(processed_agent_count, len(agents), agent.workload.get_name(),
|
|
164
|
-
agent.workload.href,
|
|
165
|
-
agent.workload.get_labels_str())
|
|
166
|
-
)
|
|
167
|
-
if agent.workload.online is not True:
|
|
168
|
-
print(" * SKIPPED because Workload is not online")
|
|
169
|
-
continue
|
|
170
|
-
if not request_upgrades:
|
|
171
|
-
print(" * SKIPPED Reassign Request process as option '--confirm' was not used")
|
|
172
|
-
continue
|
|
173
|
-
if use_cached_config:
|
|
174
|
-
print(" * SKIPPED Upgrade process as --dev-use-cache option was used!")
|
|
175
|
-
continue
|
|
176
|
-
|
|
177
|
-
connector.objects_agent_reassign_pce(agent.href, target_pce_string)
|
|
178
|
-
processed_agent_count += 1
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
print("\n ** {} Agents were reassigned to PCE '{}' **".format(processed_agent_count, target_pce_string))
|
|
182
|
-
|
|
183
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|