catocli 3.0.0__py3-none-any.whl → 3.0.1__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.

Potentially problematic release.


This version of catocli might be problematic. Click here for more details.

catocli/__init__.py CHANGED
@@ -1,2 +1,2 @@
1
- __version__ = "3.0.0"
1
+ __version__ = "3.0.1"
2
2
  __cato_host__ = "https://api.catonetworks.com/api/v1/graphql2"
@@ -18,6 +18,10 @@ def export_sites_parse(subparsers):
18
18
  socket_sites_parser.add_argument('-f', '--format', dest='export_format', choices=['json', 'csv'], default='json',
19
19
  help='Export format: json (default) or csv')
20
20
 
21
+ # Template generation option
22
+ socket_sites_parser.add_argument('--generate-template', '-gt', dest='generate_template', action='store_true',
23
+ help='Generate template files instead of exporting data (use -f to specify format: csv or json)')
24
+
21
25
  # Filename arguments (updated for both formats)
22
26
  socket_sites_parser.add_argument('--json-filename', dest='json_filename', help='Override JSON file name (default: socket_sites_{account_id}.json)')
23
27
  socket_sites_parser.add_argument('--csv-filename', dest='csv_filename', help='Override CSV file name (default: socket_sites_{account_id}.csv)')
@@ -4,6 +4,7 @@ import traceback
4
4
  import sys
5
5
  import ipaddress
6
6
  import csv
7
+ import shutil
7
8
  from datetime import datetime
8
9
  from graphql_client.api.call_api import ApiClient, CallApi
9
10
  from graphql_client.api_client import ApiException
@@ -41,10 +42,78 @@ def calculateLocalIp(subnet):
41
42
  # Invalid subnet format
42
43
  return None
43
44
 
45
+ def generate_template(args):
46
+ """
47
+ Generate template files from embedded templates directory
48
+ """
49
+ try:
50
+ # Get the directory of this script to locate templates
51
+ script_dir = os.path.dirname(os.path.abspath(__file__))
52
+ templates_dir = os.path.join(script_dir, '..', '..', '..', '..', 'templates')
53
+
54
+ # Get the template format from export_format argument (defaults to json)
55
+ template_format = getattr(args, 'export_format', 'json')
56
+
57
+ # Determine output directory
58
+ output_dir = getattr(args, 'output_directory', None)
59
+ if output_dir is None:
60
+ output_dir = '.'
61
+ if not os.path.isabs(output_dir):
62
+ output_dir = os.path.join(os.getcwd(), output_dir)
63
+
64
+ os.makedirs(output_dir, exist_ok=True)
65
+
66
+ copied_files = []
67
+
68
+ if template_format == 'csv':
69
+ # Copy CSV template files
70
+ template_files = ['socket_sites.csv', 'Test_network_ranges.csv']
71
+ for template_file in template_files:
72
+ src_path = os.path.join(templates_dir, template_file)
73
+ dst_path = os.path.join(output_dir, template_file)
74
+
75
+ if os.path.exists(src_path):
76
+ shutil.copy2(src_path, dst_path)
77
+ copied_files.append(dst_path)
78
+ if hasattr(args, 'verbose') and args.verbose:
79
+ print(f"Copied template: {src_path} -> {dst_path}")
80
+ else:
81
+ print(f"Warning: Template file not found: {src_path}")
82
+
83
+ elif template_format == 'json':
84
+ # Copy JSON template file
85
+ template_file = 'socket_sites.json'
86
+ src_path = os.path.join(templates_dir, template_file)
87
+ dst_path = os.path.join(output_dir, template_file)
88
+
89
+ if os.path.exists(src_path):
90
+ shutil.copy2(src_path, dst_path)
91
+ copied_files.append(dst_path)
92
+ if hasattr(args, 'verbose') and args.verbose:
93
+ print(f"Copied template: {src_path} -> {dst_path}")
94
+ else:
95
+ print(f"Warning: Template file not found: {src_path}")
96
+
97
+ if copied_files:
98
+ print(f"Successfully generated {template_format.upper()} template files:")
99
+ for file_path in copied_files:
100
+ print(f" {file_path}")
101
+ return [{"success": True, "template_format": template_format, "copied_files": copied_files}]
102
+ else:
103
+ return [{"success": False, "error": f"No template files found for format: {template_format}"}]
104
+
105
+ except Exception as e:
106
+ print(f"Error generating template: {str(e)}")
107
+ return [{"success": False, "error": str(e)}]
108
+
44
109
  def export_socket_sites_dispatcher(args, configuration):
45
110
  """
46
111
  Dispatcher function that routes to JSON or CSV export based on format argument
47
112
  """
113
+ # Check if template generation is requested
114
+ if hasattr(args, 'generate_template') and args.generate_template:
115
+ return generate_template(args)
116
+
48
117
  export_format = getattr(args, 'export_format', 'json')
49
118
 
50
119
  if export_format == 'csv':
@@ -1098,9 +1098,13 @@ def load_site_network_ranges_csv(site, ranges_csv_file):
1098
1098
  if default_interface_index and lan_interface_index == default_interface_index:
1099
1099
  is_default_interface = True
1100
1100
 
1101
+ # Check if this is a LAN_LAG_MEMBER interface (special case)
1102
+ is_lan_lag_member = row.get('lan_interface_dest_type', '').strip() == 'LAN_LAG_MEMBER'
1103
+
1101
1104
  # If this row has a LAN interface ID, create/update the interface
1102
1105
  # OR if this is a default interface, get details from parent CSV
1103
- if (has_lan_interface_id or is_default_interface) and lan_interface_index:
1106
+ # OR if this is a LAN_LAG_MEMBER interface
1107
+ if (has_lan_interface_id or is_default_interface or is_lan_lag_member) and lan_interface_index:
1104
1108
 
1105
1109
  # Create or get the interface data
1106
1110
  if lan_interface_index not in interfaces:
@@ -1115,6 +1119,17 @@ def load_site_network_ranges_csv(site, ranges_csv_file):
1115
1119
  'default_lan': True, # Mark as default interface
1116
1120
  'network_ranges': []
1117
1121
  }
1122
+ elif is_lan_lag_member:
1123
+ # For LAN_LAG_MEMBER interfaces, they don't have interface_id but need to be tracked for import
1124
+ interfaces[lan_interface_index] = {
1125
+ 'id': None, # LAN LAG members don't have interface_id in CSV
1126
+ 'name': row.get('lan_interface_name', ''),
1127
+ 'index': lan_interface_index,
1128
+ 'dest_type': row.get('lan_interface_dest_type', 'LAN_LAG_MEMBER'),
1129
+ 'default_lan': False,
1130
+ 'network_ranges': [],
1131
+ 'is_lag_member': True # Special flag for LAN LAG members
1132
+ }
1118
1133
  else:
1119
1134
  # For regular interfaces, get details from CSV row
1120
1135
  interfaces[lan_interface_index] = {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: catocli
3
- Version: 3.0.0
3
+ Version: 3.0.1
4
4
  Summary: Cato Networks cli wrapper for the GraphQL API.
5
5
  Home-page: https://github.com/Cato-Networks/cato-cli
6
6
  Author: Cato Networks
@@ -1,4 +1,4 @@
1
- catocli/__init__.py,sha256=tEYo5ddj_Kr89T42Ax8XEnHSmLaIjMxDrMGGsdRZQ8Y,84
1
+ catocli/__init__.py,sha256=ggP6bSf8rSvqJC-7CtGguzNcK1OCyPUI7aBVQezDjNw,84
2
2
  catocli/__main__.py,sha256=6Z0ns_k_kUcz1Qtrn1u7UyUnqB-3e85jM_nppOwFsv4,217
3
3
  catocli/clisettings.json,sha256=s0NENqEgRtSzX8eJGASfOygI6cueF6mcPWSxj_oWMV4,964
4
4
  catocli/Utils/clidriver.py,sha256=lzVs1nYAiStwQjNxioxktwaKmfOF69Mmp5-9aWwsNOY,15972
@@ -15,12 +15,12 @@ catocli/parsers/custom/customLib.py,sha256=Nv-agL_ewpe1x6GbwWCRb_Ey-NVW_w9L6qWwE
15
15
  catocli/parsers/custom/eventsFeedEnhanced.py,sha256=t5vPVWBSl57CO6a3UVRyx4292YaXYVK0MEWH6qH8k_c,10736
16
16
  catocli/parsers/custom/export_rules/__init__.py,sha256=vst8auriTCLwy5AT2_ySM2puq3PIg920ZWa5yy03K_8,1813
17
17
  catocli/parsers/custom/export_rules/export_rules.py,sha256=gXig4NC29yC5nW48ri-j0FEnaTz_kxKiuLF5y-5fZ_4,15646
18
- catocli/parsers/custom/export_sites/__init__.py,sha256=z8K5IIq2N-muOTuDfEEE4pUiOaITEvhfKCLzB9e5Rok,2140
19
- catocli/parsers/custom/export_sites/export_sites.py,sha256=QumTMCrytgakNis6T38VzMcu-URKeOS7_IHnNhSQ9fc,77984
18
+ catocli/parsers/custom/export_sites/__init__.py,sha256=WAiaVzSGG8tsfWjl-FcUY2JyhfjE1sA265rtIsbmeVI,2427
19
+ catocli/parsers/custom/export_sites/export_sites.py,sha256=abHr_jBJLWl2keP-pPqqmIQCI8xvK--2iPxSqB6Fhic,80964
20
20
  catocli/parsers/custom/import_rules_to_tf/__init__.py,sha256=jFCFceFv8zDW7nGLZOXkFE6NXAMPYRwKQwTbhSawYdM,3908
21
21
  catocli/parsers/custom/import_rules_to_tf/import_rules_to_tf.py,sha256=WlyTDxUtWchu9CDs73ILHDfNXCAh7jFARBEKk5WWhwM,18714
22
22
  catocli/parsers/custom/import_sites_to_tf/__init__.py,sha256=1ayoaaKIxWf5JBN62CO9F7-yaP9MqizTBCedqCyEc4k,4339
23
- catocli/parsers/custom/import_sites_to_tf/import_sites_to_tf.py,sha256=3d1PAWviAZet-mNBzUy04XhMbTI8jRDHNQL-cqiUSqU,77059
23
+ catocli/parsers/custom/import_sites_to_tf/import_sites_to_tf.py,sha256=scZ8Pecu6b279jG-72eF4eCw-BWNSHFK7cl9JvBGT0E,78130
24
24
  catocli/parsers/custom/query_eventsFeed/__init__.py,sha256=awOFdkByn0ycDjZFYhySd9Z5zJ-vNq2-orX16B6NlYM,4405
25
25
  catocli/parsers/custom/scim/__init__.py,sha256=filQvWGXeJ-EppAzEHKJjXY12QPiT69weT6mav9TPXo,10410
26
26
  catocli/parsers/custom/scim/scim_client.py,sha256=dkObWVtWh331hoeU4Npx4xRzqAYM51MKxNx01WvVW5o,19560
@@ -395,7 +395,7 @@ catocli/parsers/query_xdr_stories/README.md,sha256=rRW1pTmVMr9-j21-_MWNlozTTQnhi
395
395
  catocli/parsers/query_xdr_story/README.md,sha256=Fl2HutndHVobrj73Wh5NlTLq56tvVN3W0iib6BuO-b0,925
396
396
  catocli/parsers/raw/README.md,sha256=qvDLcg7U12yqacIQStOPtkqTsTLltJ06SSVmbqvlZhY,739
397
397
  catocli/parsers/raw/__init__.py,sha256=fiSzQzNSG3vje-eEXuOcdhuL8pyavkufocOJumjdFXs,1356
398
- catocli-3.0.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
398
+ catocli-3.0.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
399
399
  graphql_client/__init__.py,sha256=2nxD4YsWoOnALXi5cXbmtIN_i0NL_eyDTQRTxs52mkI,315
400
400
  graphql_client/api_client.py,sha256=2Rc1Zo1xH9Jnk1AO68kLSofTShkZwSVF-WkVtczfIc4,5786
401
401
  graphql_client/api_client_types.py,sha256=dM3zl6FA5SSp6nR6KmLfTL1BKaXX9uPMCZAm4v_FiUs,11569
@@ -743,8 +743,8 @@ vendor/urllib3/util/timeout.py,sha256=4eT1FVeZZU7h7mYD1Jq2OXNe4fxekdNvhoWUkZusRp
743
743
  vendor/urllib3/util/url.py,sha256=wHORhp80RAXyTlAIkTqLFzSrkU7J34ZDxX-tN65MBZk,15213
744
744
  vendor/urllib3/util/util.py,sha256=j3lbZK1jPyiwD34T8IgJzdWEZVT-4E-0vYIJi9UjeNA,1146
745
745
  vendor/urllib3/util/wait.py,sha256=_ph8IrUR3sqPqi0OopQgJUlH4wzkGeM5CiyA7XGGtmI,4423
746
- catocli-3.0.0.dist-info/METADATA,sha256=4KHv5578jBbbXhRK0lMUHJ6UoXq_TRWJTnjyJ9IjXA0,1286
747
- catocli-3.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
748
- catocli-3.0.0.dist-info/entry_points.txt,sha256=p4k9Orre6aWcqVrNmBbckmCs39h-1naMxRo2AjWmWZ4,50
749
- catocli-3.0.0.dist-info/top_level.txt,sha256=F4qSgcjcW5wR9EFrO8Ud06F7ZQGFr04a9qALNQDyVxU,52
750
- catocli-3.0.0.dist-info/RECORD,,
746
+ catocli-3.0.1.dist-info/METADATA,sha256=vtZrZQc_EQnc-eAvOxhRjhRvCEPMKVjR2FZRhsuTbYk,1286
747
+ catocli-3.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
748
+ catocli-3.0.1.dist-info/entry_points.txt,sha256=p4k9Orre6aWcqVrNmBbckmCs39h-1naMxRo2AjWmWZ4,50
749
+ catocli-3.0.1.dist-info/top_level.txt,sha256=F4qSgcjcW5wR9EFrO8Ud06F7ZQGFr04a9qALNQDyVxU,52
750
+ catocli-3.0.1.dist-info/RECORD,,