illumio-pylo 0.3.7__py3-none-any.whl → 0.3.8__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/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "0.3.7"
1
+ __version__ = "0.3.8"
2
2
 
3
3
  from typing import Callable
4
4
 
@@ -1,8 +1,12 @@
1
+ from typing import List
2
+
1
3
  import illumio_pylo as pylo
2
4
  import argparse
3
5
  import sys
6
+ import click
4
7
  from .utils.misc import make_filename_with_timestamp
5
8
  from . import Command
9
+ from ...API.JsonPayloadTypes import IPListObjectCreationJsonStructure
6
10
 
7
11
  command_name = 'iplist-import'
8
12
  objects_load_filter = ['iplists']
@@ -14,20 +18,32 @@ def fill_parser(parser: argparse.ArgumentParser):
14
18
  parser.add_argument('--input-file-delimiter', type=str, required=False, default=',',
15
19
  help='CSV field delimiter')
16
20
 
21
+ parser.add_argument('--output-dir', '-o', type=str, required=False, default='output',
22
+ help='Directory where the output files will be saved')
23
+
17
24
  parser.add_argument('--ignore-if-iplist-exists', action='store_true',
18
25
  help='If an IPList with same same exists, ignore CSV entry')
19
26
 
20
27
  parser.add_argument('--network-delimiter', type=str, required=False, default=',', nargs='?', const=True,
21
28
  help='If an IPList with same same exists, ignore CSV entry')
22
29
 
30
+ parser.add_argument('--proceed', '-p', action='store_true',
31
+ help='If set, the script will proceed with the creation of iplists')
23
32
 
24
- def __main(args, org: pylo.Organization, **kwargs):
25
- input_file = args['input_file']
26
- input_file_delimiter = args['input_file_delimiter']
27
- ignore_if_iplist_exists = args['ignore_if_iplist_exists']
28
- network_delimiter = args['network_delimiter']
33
+ parser.add_argument('--no-confirmation-required', '-n', action='store_true',
34
+ help='If set, the script will proceed with the creation of iplists without asking for confirmation')
29
35
 
30
- output_file_prefix = make_filename_with_timestamp('import-iplists-results_')
36
+
37
+ def __main(args, org: pylo.Organization, **kwargs):
38
+ setting_input_file = args['input_file']
39
+ settings_input_file_delimiter = args['input_file_delimiter']
40
+ settings_ignore_if_iplist_exists = args['ignore_if_iplist_exists']
41
+ settings_network_delimiter = args['network_delimiter']
42
+ settings_proceed = args['proceed']
43
+ settings_no_confirmation_required = args['no_confirmation_required']
44
+ settings_output_dir: str = args['output_dir']
45
+
46
+ output_file_prefix = make_filename_with_timestamp('import-iplists-results_', settings_output_dir)
31
47
  output_file_csv = output_file_prefix + '.csv'
32
48
  output_file_excel = output_file_prefix + '.xlsx'
33
49
 
@@ -44,8 +60,8 @@ def __main(args, org: pylo.Organization, **kwargs):
44
60
  pylo.file_clean(output_file_csv)
45
61
  pylo.file_clean(output_file_excel)
46
62
 
47
- print(" * Loading CSV input file '{}'...".format(input_file), flush=True, end='')
48
- csv_data = pylo.CsvExcelToObject(input_file, expected_headers=csv_expected_fields, csv_delimiter=input_file_delimiter)
63
+ print(" * Loading CSV input file '{}'...".format(setting_input_file), flush=True, end='')
64
+ csv_data = pylo.CsvExcelToObject(setting_input_file, expected_headers=csv_expected_fields, csv_delimiter=settings_input_file_delimiter)
49
65
  print('OK')
50
66
  print(" - CSV has {} columns and {} lines (headers don't count)".format(csv_data.count_columns(), csv_data.count_lines()))
51
67
  # print(pylo.nice_json(csv_data._objects))
@@ -71,7 +87,7 @@ def __main(args, org: pylo.Organization, **kwargs):
71
87
  sys.exit(1)
72
88
  else:
73
89
  csv_object['**not_created_reason**'] = 'Found duplicated name in PCE'
74
- if not ignore_if_iplist_exists:
90
+ if not settings_ignore_if_iplist_exists:
75
91
  pylo.log.error("PCE contains iplists with duplicates name from CSV: '{}' at line #{}. Please fix CSV or look for --options to ignore it".format(lower_name, csv_object['*line*']))
76
92
  sys.exit(1)
77
93
  print(" - WARNING: CSV has an entry for iplist name '{}' at line #{} but it exists already in the PCE. It will be ignored.".format(lower_name, csv_object['*line*']))
@@ -89,28 +105,28 @@ def __main(args, org: pylo.Organization, **kwargs):
89
105
  ignored_objects_count += 1
90
106
 
91
107
  print(' * Preparing Iplist JSON data...')
92
- iplists_json_data = []
108
+ iplists_json_data: List[IPListObjectCreationJsonStructure] = []
93
109
  for data in csv_objects_to_create:
94
- new_iplist = {}
110
+ new_iplist: IPListObjectCreationJsonStructure = {}
95
111
  iplists_json_data.append(new_iplist)
96
112
 
97
113
  if len(data['name']) < 1:
98
114
  raise pylo.PyloEx('Iplist at line #{} is missing a name in CSV'.format(data['*line*']))
99
- else:
100
- new_iplist['name'] = data['name']
115
+
116
+ new_iplist['name'] = str(data['name'])
101
117
 
102
118
  if len(data['description']) > 0:
103
- new_iplist['description'] = data['description']
119
+ new_iplist['description'] = str(data['description'])
104
120
 
105
121
  if len(data['networks']) < 1:
106
122
  print('Iplist at line #{} has empty networks list'.format(data['*line*']))
107
123
  sys.exit(1)
108
124
 
109
- network_delimiter = network_delimiter.replace("\\n", "\n")
125
+ settings_network_delimiter = settings_network_delimiter.replace("\\n", "\n")
110
126
  ip_ranges = []
111
127
  new_iplist['ip_ranges'] = ip_ranges
112
128
 
113
- for network_string in data['networks'].rsplit(network_delimiter):
129
+ for network_string in data['networks'].rsplit(settings_network_delimiter):
114
130
  network_string = network_string.strip(" \r\n") # cleanup trailing characters
115
131
 
116
132
  exclusion = False
@@ -155,30 +171,38 @@ def __main(args, org: pylo.Organization, **kwargs):
155
171
 
156
172
  print(" * DONE")
157
173
 
158
- print(" * Creating {} IPLists".format(len(iplists_json_data)))
159
- total_created_count = 0
160
- total_failed_count = 0
174
+ if settings_proceed is False:
175
+ print(" * Dry-run mode, no changes will be made to the PCE. Use --proceed to actually create the iplists")
176
+
177
+ else:
178
+ if not settings_no_confirmation_required:
179
+ print(" * WARNING: You are about to create {} IPLists in the PCE. Are you sure you want to proceed?".format(len(iplists_json_data)))
180
+ click.confirm("Do you want to proceed with the creation of these labels?", abort=True)
181
+
182
+ print(" * Creating {} IPLists".format(len(iplists_json_data)))
183
+ total_created_count = 0
184
+ total_failed_count = 0
161
185
 
162
- for index in range(0, len(iplists_json_data)):
163
- json_blob = iplists_json_data[index]
164
- print(" - Pushing new iplist '{}' to PCE (#{} of {})... ".format(json_blob['name'], index+1, len(iplists_json_data)), end='', flush=True)
165
- result = org.connector.objects_iplist_create(json_blob)
166
- print("OK")
186
+ for index in range(0, len(iplists_json_data)):
187
+ json_blob: IPListObjectCreationJsonStructure = iplists_json_data[index]
188
+ print(" - Pushing new iplist '{}' to PCE (#{} of {})... ".format(json_blob['name'], index+1, len(iplists_json_data)), end='', flush=True)
189
+ result = org.connector.objects_iplist_create(json_blob)
190
+ print("OK")
167
191
 
168
- href = result.get('href')
169
- if href is None:
170
- raise pylo.PyloEx('API returned unexpected response which is missing a HREF:', result)
192
+ href = result.get('href')
193
+ if href is None:
194
+ raise pylo.PyloEx('API returned unexpected response which is missing a HREF:', result)
171
195
 
172
- total_created_count += 1
173
- csv_objects_to_create[index]['href'] = href
196
+ total_created_count += 1
197
+ csv_objects_to_create[index]['href'] = href
198
+
199
+ csv_data.save_to_csv(output_file_csv, csv_created_fields)
200
+ csv_data.save_to_excel(output_file_excel, csv_created_fields)
174
201
 
175
202
  csv_data.save_to_csv(output_file_csv, csv_created_fields)
176
203
  csv_data.save_to_excel(output_file_excel, csv_created_fields)
177
204
 
178
- csv_data.save_to_csv(output_file_csv, csv_created_fields)
179
- csv_data.save_to_excel(output_file_excel, csv_created_fields)
180
-
181
- print(" * DONE - {} created with success, {} failures and {} ignored. A report was created in {} and {}".format(total_created_count, total_failed_count, ignored_objects_count, output_file_csv, output_file_excel))
205
+ print(" * DONE - {} created with success, {} failures and {} ignored. A report was created in {} and {}".format(total_created_count, total_failed_count, ignored_objects_count, output_file_csv, output_file_excel))
182
206
 
183
207
 
184
208
  command_object = Command(command_name, __main, fill_parser, load_specific_objects_only=objects_load_filter)
@@ -2,6 +2,8 @@ import os
2
2
  from datetime import datetime
3
3
  import illumio_pylo as pylo
4
4
 
5
+ default_label_columns_prefix = 'label:'
6
+
5
7
 
6
8
  def make_filename_with_timestamp(prefix: str, output_directory: str = './') -> str:
7
9
  # if output directory starts with a dot, we assume it's a relative path. Same if not it's not starting with a slash
@@ -8,7 +8,7 @@ import click
8
8
  import illumio_pylo as pylo
9
9
  from illumio_pylo import ArraysToExcel, ExcelHeaderSet, ExcelHeader
10
10
  from .utils.LabelCreation import generate_list_of_labels_to_create, create_labels
11
- from .utils.misc import make_filename_with_timestamp
11
+ from .utils.misc import make_filename_with_timestamp, default_label_columns_prefix
12
12
  from . import Command
13
13
 
14
14
  command_name = 'workload-import'
@@ -27,7 +27,7 @@ def fill_parser(parser: argparse.ArgumentParser):
27
27
  parser.add_argument('--ignore-missing-headers', action='store_true',
28
28
  help='Ignore missing headers in the CSV/Excel file for label types')
29
29
 
30
- parser.add_argument('--label-type-header-prefix', type=str, required=False, default='label_',
30
+ parser.add_argument('--label-type-header-prefix', type=str, required=False, default=default_label_columns_prefix,
31
31
  help='Prefix for the label type headers in the CSV/Excel file')
32
32
 
33
33
  parser.add_argument('--ignore-hostname-collision', action='store_true',
@@ -89,7 +89,7 @@ def __main(args, org: pylo.Organization, **kwargs):
89
89
 
90
90
  csv_report_headers = ExcelHeaderSet(['name', 'hostname', 'ip', 'description'])
91
91
  for label_type in org.LabelStore.label_types:
92
- csv_report_headers.append(f'label_{label_type}')
92
+ csv_report_headers.append(f'{settings_header_label_prefix}{label_type}')
93
93
 
94
94
  csv_report_headers.append(ExcelHeader(name='**not_created_reason**'))
95
95
  csv_report_headers.append(ExcelHeader(name='href', max_width=15))
@@ -124,7 +124,7 @@ def __main(args, org: pylo.Organization, **kwargs):
124
124
  if len(labels_to_be_created) > 0:
125
125
  print(" * {} Labels need to created before Workloads can be imported, listing:".format(len(labels_to_be_created)))
126
126
  for label in labels_to_be_created:
127
- print(" - Label: {} (type={})".format(label.name, label.type))
127
+ print(" - Label: {} (type={})".format(label['name'], label['type']))
128
128
  if not settings_no_confirmation_required:
129
129
  click.confirm("Do you want to proceed with the creation of these labels?", abort=True)
130
130
 
@@ -6,7 +6,7 @@ import sys
6
6
  import illumio_pylo as pylo
7
7
  from illumio_pylo import ArraysToExcel, ExcelHeader, ExcelHeaderSet
8
8
  from .utils.LabelCreation import generate_list_of_labels_to_create, create_labels
9
- from .utils.misc import make_filename_with_timestamp
9
+ from .utils.misc import make_filename_with_timestamp, default_label_columns_prefix
10
10
  from . import Command
11
11
 
12
12
 
@@ -25,7 +25,7 @@ def fill_parser(parser: argparse.ArgumentParser):
25
25
  parser.add_argument('--input-file-delimiter', type=str, required=False, default=',',
26
26
  help='CSV field delimiter')
27
27
 
28
- parser.add_argument('--label-type-header-prefix', type=str, required=False, default='label_',
28
+ parser.add_argument('--label-type-header-prefix', type=str, required=False, default=default_label_columns_prefix,
29
29
  help='Prefix for the label type headers in the CSV/Excel file')
30
30
 
31
31
  parser.add_argument('--output-dir', '-o', type=str, required=False, default='output',
@@ -49,6 +49,7 @@ def fill_parser(parser: argparse.ArgumentParser):
49
49
  parser.add_argument('--batch-size', type=int, required=False, default=500,
50
50
  help='Number of Workloads to update per API call')
51
51
 
52
+
52
53
  class ContextSingleton:
53
54
 
54
55
  def __init__(self, org: pylo.Organization):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: illumio_pylo
3
- Version: 0.3.7
3
+ Version: 0.3.8
4
4
  Summary: A set of tools and library for working with Illumio PCE
5
5
  Home-page: https://github.com/cpainchaud/pylo
6
6
  Author: Christophe Painchaud
@@ -187,11 +187,11 @@ Requires-Python: >=3.11
187
187
  License-File: LICENSE
188
188
  Requires-Dist: click ==8.1.7
189
189
  Requires-Dist: colorama ~=0.4.4
190
- Requires-Dist: cryptography ~=42.0.5
191
- Requires-Dist: openpyxl ~=3.1.2
190
+ Requires-Dist: cryptography ==42.0.7
191
+ Requires-Dist: openpyxl ~=3.1.3
192
192
  Requires-Dist: paramiko ~=3.4.0
193
193
  Requires-Dist: prettytable ~=3.10.0
194
- Requires-Dist: requests ~=2.31.0
194
+ Requires-Dist: requests ~=2.32.0
195
195
  Requires-Dist: xlsxwriter ~=3.2.0
196
196
 
197
197
  README.md
@@ -21,7 +21,7 @@ illumio_pylo/VirtualServiceStore.py,sha256=MNTwo1cvteUuID6JniWUk5oRHQHGY4OwrWvFa
21
21
  illumio_pylo/Workload.py,sha256=9kZHawayQQ_L-OBzyuuDcViWSa7HzDKEfPtcSHMsInw,19910
22
22
  illumio_pylo/WorkloadStore.py,sha256=3C6SMU0wRlet6C6UVbjkYNsTY7vkyK_ZwqM1dlCBpsQ,10989
23
23
  illumio_pylo/WorkloadStoreSubClasses.py,sha256=4GBb5sXan38Y5OE7O6aAR-IZrZJar0mYE44FbCSb3_k,6093
24
- illumio_pylo/__init__.py,sha256=NfjWb-G4N-kqGKvsr_N-zQZFy1bGNrUmZNfIIC21P2I,4172
24
+ illumio_pylo/__init__.py,sha256=LOKwOb9r5Shqau4F43ZbOE8TV43Svk-TwNNBnV_9Cbs,4172
25
25
  illumio_pylo/tmp.py,sha256=DYlm07YEP6Nm5qScByfTloGi7TGaN9WtklSqeVROPik,3913
26
26
  illumio_pylo/API/APIConnector.py,sha256=pxHuaRvUU_sX_DWgE_TVMR5ktRURVMOVGhkBbuV--Sc,60725
27
27
  illumio_pylo/API/AuditLog.py,sha256=p0mfjrE5S8qoJgA5LIP_XGFBP3iL86Nl6BQEmhMVrPA,1533
@@ -40,7 +40,7 @@ illumio_pylo/cli/__main__.py,sha256=ll1gK8k1YL_kPsImI7WVlw2sCyNyhocnuCqko6mGaYI,
40
40
  illumio_pylo/cli/commands/__init__.py,sha256=yoVkXy-qBGiAAziWiayJdjcclx1WTayShXSPqHelcWA,1489
41
41
  illumio_pylo/cli/commands/credential_manager.py,sha256=sAPEvFjxHuxUexfTigy2CR5evU_j9W7rAbalsoSWrLk,9421
42
42
  illumio_pylo/cli/commands/iplist_analyzer.py,sha256=vOl6fNd0HrUKnKXtY1sj7jeyx2GtuDZENV7mF79O7yU,3714
43
- illumio_pylo/cli/commands/iplist_import_from_file.py,sha256=XvC-GlJyjA4dDPzfvGoBFtwelI9g_rQqGzgKgqMYcsI,8284
43
+ illumio_pylo/cli/commands/iplist_import_from_file.py,sha256=k_EkJbjEhZqJJdWN6vG_zHu7jmnodHj8TVPKQA1R7d4,9836
44
44
  illumio_pylo/cli/commands/ruleset_export.py,sha256=KC9ifZx8gcAzti6EnTMfS075K00-ovRbLxeKMUg3w8E,5893
45
45
  illumio_pylo/cli/commands/update_pce_objects_cache.py,sha256=kNBAmPIbJyw97FRcNREy059A5FLOGm_poKJYGdTWqr4,1256
46
46
  illumio_pylo/cli/commands/ven_compatibility_report_export.py,sha256=8ZpgGQfn5zmOslgeE1imwx4-gDHfukdgoXJGZUh9q3o,8120
@@ -48,13 +48,13 @@ illumio_pylo/cli/commands/ven_duplicate_remover.py,sha256=fr9EzLlJb_cizdxTC5yOOf
48
48
  illumio_pylo/cli/commands/ven_idle_to_visibility.py,sha256=OMcQSB82Pn50TS7OL1_TPOvvN9XFR3jUxVYYizUQinI,13387
49
49
  illumio_pylo/cli/commands/ven_upgrader.py,sha256=4cLUA7HSpskJpPOtEkQh41lE4gMGJJiQiKGCd0CKYJk,7222
50
50
  illumio_pylo/cli/commands/workload_export.py,sha256=EcQR8AacJVe7rOqYH-HFxyTchwHHQ9ZTc-ALSMt9gDY,11421
51
- illumio_pylo/cli/commands/workload_import.py,sha256=FuUeLkauqYvKvWgWcS_xfQIxwTScp90ZdUMbUIFSadE,18923
51
+ illumio_pylo/cli/commands/workload_import.py,sha256=LcyFQm92mnkueh6Hq2dTMgUva_Gmwla87S7H2s3pltE,19003
52
52
  illumio_pylo/cli/commands/workload_reset_names_to_null.py,sha256=GaO2Th1rx8i7_7yqb9WkGpDz3sdbYNod5fABQnhogig,3383
53
- illumio_pylo/cli/commands/workload_update.py,sha256=tmzTV8uh4zmJf_F5rhBChuYjfnY_JtcDjSUKhvGK3rM,28543
53
+ illumio_pylo/cli/commands/workload_update.py,sha256=3NtFNVSL7OvYBfhX5BincwLKvYLhLHKnIRR0nL29tuY,28594
54
54
  illumio_pylo/cli/commands/workload_used_in_rule_finder.py,sha256=2MO9jjYh-mkY6rkfvDyW0Ok6El_AqDWGXiFDYq5YgTk,3361
55
55
  illumio_pylo/cli/commands/utils/LabelCreation.py,sha256=qaU7BeP4et2GJxHwgbDNRoQLCA-xWp_y1nJ-m8ANUwA,4883
56
56
  illumio_pylo/cli/commands/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
57
- illumio_pylo/cli/commands/utils/misc.py,sha256=iV5CEEccfQ08eO0wSpTOxS9-32_GXSekShic6auuGPE,761
57
+ illumio_pylo/cli/commands/utils/misc.py,sha256=Oy-s4n6k7uHsYWqHZ32MJiaSSft2tOOxOGZ8Jwbaa_U,802
58
58
  illumio_pylo/docs/Doxygen,sha256=AVvSIRYLHFWJ15YLGahhzhsW0ZUUFO5lVxd2-F3iWz8,74257
59
59
  illumio_pylo/utilities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
60
60
  illumio_pylo/utilities/cli.py,sha256=7Wv7qhdc91-vsaxiu4j8k7LY7V9dcwWHnHV7PLpOBAI,320
@@ -65,8 +65,8 @@ illumio_pylo/utilities/resources/iplists-import-example.xlsx,sha256=VW-7CRr8NA2V
65
65
  illumio_pylo/utilities/resources/workload-exporter-filter-example.csv,sha256=cn5IA8AGEPjvS-EsPXA_GJ-LFsdF9t_44rSzFTCmAzE,36
66
66
  illumio_pylo/utilities/resources/workloads-import-example.csv,sha256=DEOGVikFjxQpMFFI0l0jb3hrxEEeZCpTGkmWkz6GUcY,91
67
67
  illumio_pylo/utilities/resources/workloads-import-example.xlsx,sha256=U8Ac2BZidA6NlvBFAVPHqeY5zmg3rjmIAXp5b3b1P5w,17101
68
- illumio_pylo-0.3.7.dist-info/LICENSE,sha256=WYmcYJG1QFgu1hfo7qrEkZ3Jhcz8NUWe6XUraZvlIFs,10172
69
- illumio_pylo-0.3.7.dist-info/METADATA,sha256=wydOUCStSL8nqGPvpBlvDa-xfIjGAqKy2N_OXcQozGk,12224
70
- illumio_pylo-0.3.7.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
71
- illumio_pylo-0.3.7.dist-info/top_level.txt,sha256=c5cu_ZMuSuxjq48ih58Kc0Tr8-JdQtV8GrKJicvWNFE,13
72
- illumio_pylo-0.3.7.dist-info/RECORD,,
68
+ illumio_pylo-0.3.8.dist-info/LICENSE,sha256=WYmcYJG1QFgu1hfo7qrEkZ3Jhcz8NUWe6XUraZvlIFs,10172
69
+ illumio_pylo-0.3.8.dist-info/METADATA,sha256=TJ4GTpwJhhvBtDV6XDIsk3bfFw7DYvcTJ7QgCr4Ots4,12224
70
+ illumio_pylo-0.3.8.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
71
+ illumio_pylo-0.3.8.dist-info/top_level.txt,sha256=c5cu_ZMuSuxjq48ih58Kc0Tr8-JdQtV8GrKJicvWNFE,13
72
+ illumio_pylo-0.3.8.dist-info/RECORD,,