Skip to content

Commit a96ceef

Browse files
Organized uplink backup/restore and added example workbooks
The uplink prefs backup and restore notebooks are now in their own folder. Also added example workbooks created by the backup script.
1 parent b244134 commit a96ceef

7 files changed

Lines changed: 68 additions & 40 deletions

notebooks/merakiUplinkPreferenceBackup.ipynb renamed to notebooks/Uplink preference backup and restore/merakiUplinkPreferenceBackup.ipynb

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
},
3131
"outputs": [],
3232
"source": [
33-
"# Install the relevant modules. If you are using a local editor (e.g. VS Code, rather than Colab) you can run these commands, without the preceding %, via a terminal. NB: Run `pip install meraki==` to find the latest version of the Meraki SDK.\n",
34-
"%pip install meraki\n",
35-
"%pip install openpyxl\n",
33+
"# Install the relevant modules. If you are using a local editor (e.g. VS Code, rather than Colab) you can run these commands, without the preceding %, via a terminal. NB: Run `pip install meraki==` to find the latest version of the Meraki SDK. Uncomment these lines to run them in Google Colab.\n",
34+
"#%pip install meraki\n",
35+
"#%pip install openpyxl\n",
3636
"\n",
3737
"# If you are using Google Colab, please ensure you have set up your environment variables as linked above, then delete the two lines of ''' to activate the following code:\n",
3838
"'''\n",
@@ -207,6 +207,7 @@
207207
},
208208
"outputs": [],
209209
"source": [
210+
"# Make a list of all networks in the org\n",
210211
"user_choices['all_networks'] = dashboard.organizations.getOrganizationNetworks(organizationId=user_choices['organization'].id)\n",
211212
"\n",
212213
"# Find the networks with appliances\n",
@@ -543,9 +544,9 @@
543544
" if 'application' in rule_type:\n",
544545
" rule_protocol = rule['trafficFilters'][0]['value']['id']\n",
545546
" rule_source = rule['trafficFilters'][0]['value']['name']\n",
546-
" rule_src_port = NOT_APPLICABLE_STRING\n",
547-
" rule_destination = NOT_APPLICABLE_STRING\n",
548-
" rule_dst_port = NOT_APPLICABLE_STRING\n",
547+
" rule_src_port = string_constants['NOT_APPLICABLE']\n",
548+
" rule_destination = string_constants['NOT_APPLICABLE']\n",
549+
" rule_dst_port = string_constants['NOT_APPLICABLE']\n",
549550
" else: \n",
550551
" rule_protocol = rule['trafficFilters'][0]['value']['protocol']\n",
551552
" rule_source = rule['trafficFilters'][0]['value']['source']['cidr']\n",
@@ -557,8 +558,8 @@
557558
" rule_src_port = 'any'\n",
558559
" rule_dst_port = 'any'\n",
559560
" elif rule_protocol == 'icmp':\n",
560-
" rule_src_port = NOT_APPLICABLE_STRING\n",
561-
" rule_dst_port = NOT_APPLICABLE_STRING\n",
561+
" rule_src_port = string_constants['NOT_APPLICABLE']\n",
562+
" rule_dst_port = string_constants['NOT_APPLICABLE']\n",
562563
" else:\n",
563564
" rule_src_port = rule['trafficFilters'][0]['value']['source']['port']\n",
564565
" rule_dst_port = rule['trafficFilters'][0]['value']['destination']['port']\n",
@@ -568,15 +569,15 @@
568569
" if rule.get('failOverCriterion', False):\n",
569570
" rule_failover_criterion = rule['failOverCriterion']\n",
570571
" else: # No failOverCriterion set\n",
571-
" rule_failover_criterion = NOT_APPLICABLE_STRING\n",
572+
" rule_failover_criterion = string_constants['NOT_APPLICABLE']\n",
572573
"\n",
573574
" # Check if the rule has performanceClass set\n",
574575
" if rule.get('performanceClass', False):\n",
575576
" rule_performance_class_type = rule['performanceClass']['type']\n",
576577
"\n",
577578
" # If the performance class is set, and is 'builtin', then we use 'builtinPerformanceClassName'. If it's 'custom', then we use 'customPerformanceClassId' to identify it.\n",
578579
" if rule_performance_class_type == 'builtin':\n",
579-
" rule_performance_class_id = NOT_APPLICABLE_STRING\n",
580+
" rule_performance_class_id = string_constants['NOT_APPLICABLE']\n",
580581
" rule_performance_class_name = rule['performanceClass']['builtinPerformanceClassName']\n",
581582
" else:\n",
582583
" rule_performance_class_id = rule['performanceClass']['customPerformanceClassId']\n",
@@ -589,9 +590,9 @@
589590
" \n",
590591
" # Else, there's no performanceClass set, so we'll set these values accordingly.\n",
591592
" else:\n",
592-
" rule_performance_class_type = NOT_APPLICABLE_STRING\n",
593-
" rule_performance_class_name = NOT_APPLICABLE_STRING\n",
594-
" rule_performance_class_id = NOT_APPLICABLE_STRING\n",
593+
" rule_performance_class_type = string_constants['NOT_APPLICABLE']\n",
594+
" rule_performance_class_name = string_constants['NOT_APPLICABLE']\n",
595+
" rule_performance_class_id = string_constants['NOT_APPLICABLE']\n",
595596
"\n",
596597
" # We assemble the parameters into a tuple that will represent a row.\n",
597598
" rule_row = (\n",

notebooks/merakiUplinkPreferenceRestore.ipynb renamed to notebooks/Uplink preference backup and restore/merakiUplinkPreferenceRestore.ipynb

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
},
3535
"outputs": [],
3636
"source": [
37-
"# Install the relevant modules. If you are using a local editor (e.g. VS Code, rather than Colab) you can run these commands, without the preceding %, via a terminal. NB: Run `pip install meraki==` to find the latest version of the Meraki SDK.\n",
38-
"%pip install meraki\n",
39-
"%pip install openpyxl\n",
37+
"# Install the relevant modules. If you are using a local editor (e.g. VS Code, rather than Colab) you can run these commands, without the preceding %, via a terminal. NB: Run `pip install meraki==` to find the latest version of the Meraki SDK. Uncomment these lines if you're using Google Colab.\n",
38+
"#%pip install meraki\n",
39+
"#%pip install openpyxl\n",
4040
"\n",
4141
"# If you are using Google Colab, please ensure you have set up your environment variables as linked above, then delete the two lines of ''' to activate the following code:\n",
4242
"'''\n",
@@ -80,7 +80,7 @@
8080
"user_data = dict()\n",
8181
"\n",
8282
"# Set the filename to use for the backup workbook\n",
83-
"WORKBOOK_FILENAME = 'downloaded_rules_workbook_2020-11-24 after.xlsx'"
83+
"WORKBOOK_FILENAME = 'exampleBackups/downloaded_rules_workbook_2020-12-03 live demo workbook.xlsx'"
8484
]
8585
},
8686
{
@@ -306,6 +306,23 @@
306306
"\n",
307307
"\n",
308308
"\n",
309+
"\t\n",
310+
"\t\n",
311+
"\t\n",
312+
"\t\n",
313+
"\t\n",
314+
"\t\n",
315+
"\t\n",
316+
"\t\n",
317+
"\t\n",
318+
"\t\n",
319+
"\t\n",
320+
"\t\n",
321+
"\t\n",
322+
"\t\n",
323+
"\t\n",
324+
"\t\n",
325+
"\t\n",
309326
"\t## WAN PREFERENCES ##\n",
310327
"\t# We'll also count the number of rules to help the user know that it's working.\n",
311328
"\trule_count = 0\n",
@@ -324,24 +341,18 @@
324341
"\n",
325342
"\t\t# The first column is Protocol\n",
326343
"\t\trule_protocol = row[0].value.lower()\n",
327-
"\t\tif rule_protocol == 'any':\n",
328-
"\t\t\t# Since protocol is 'any' then src and dst ports are also 'any'\n",
329-
"\t\t\trule_src_port = 'any'\n",
330-
"\t\t\trule_dst_port = 'any'\n",
331-
"\t\telse:\t\t\t\n",
332-
"\t\t\t# Since protocol is not 'any', we pass these as-is\n",
333-
"\t\t\trule_src_port = row[1].value.lower()\n",
334-
"\t\t\trule_dst_port = row[4].value.lower()\n",
335344
"\t\t\n",
336-
"\t\t# Next column is Source [1]\n",
337-
"\t\trule_source = row[1].value.lower()\n",
345+
"\t\t# Source column is [1]\n",
346+
"\t\trule_source = row[1].value\n",
338347
"\n",
339-
"\t\t# Last column to fill is Destination [3]\n",
340-
"\t\trule_destination = row[3].value.lower()\n",
348+
"\t\t# Destination column is [3]\n",
349+
"\t\trule_destination = row[3].value.lower() \n",
341350
"\n",
342351
"\t\t# Assemble the rule into a single Python object that uses the syntax that the corresponding API call expects\n",
343-
"\t\t\n",
344352
"\t\tif rule_protocol == 'any':\n",
353+
"\t\t\t# Since protocol is 'any' then src and dst ports are also 'any'\n",
354+
"\t\t\trule_src_port = 'any'\n",
355+
"\t\t\trule_dst_port = 'any'\n",
345356
"\t\t\t# Protocol is any, so leave out the port numbers\n",
346357
"\t\t\trule_value = {\n",
347358
"\t\t\t\t'protocol': rule_protocol,\n",
@@ -352,8 +363,10 @@
352363
"\t\t\t\t\t'cidr': rule_destination\n",
353364
"\t\t\t\t}\n",
354365
"\t\t\t}\n",
355-
"\n",
356-
"\t\telse: \n",
366+
"\t\telse:\t\t\t\n",
367+
"\t\t\t# Since protocol is not 'any', we pass these as-is\n",
368+
"\t\t\trule_src_port = row[2].value\n",
369+
"\t\t\trule_dst_port = row[4].value\n",
357370
"\t\t\t# Rule isn't any, so we need the port numbers\n",
358371
"\t\t\trule_value = {\n",
359372
"\t\t\t\t'protocol': rule_protocol,\n",
@@ -367,6 +380,7 @@
367380
"\t\t\t\t}\n",
368381
"\t\t\t}\n",
369382
"\n",
383+
"\n",
370384
"\t\t# Append the trafficFilters param to the rule\n",
371385
"\t\trule['trafficFilters'] = [\n",
372386
"\t\t\t{\n",
@@ -385,6 +399,24 @@
385399
"\t\n",
386400
"\tprint(f'Loaded {rule_count} WAN uplink preferences.')\n",
387401
"\n",
402+
"\t\n",
403+
"\t\n",
404+
"\t\n",
405+
"\t\n",
406+
"\t\n",
407+
"\t\n",
408+
"\t\n",
409+
"\t\n",
410+
"\t\n",
411+
"\t\n",
412+
"\t\n",
413+
"\t\n",
414+
"\t\n",
415+
"\t\n",
416+
"\t\n",
417+
"\t\n",
418+
"\t\n",
419+
"\t\n",
388420
"\t## VPN PREFERENCES ##\n",
389421
"\t# For reference, the expected column order is\n",
390422
"\t# Type [0], Protocol or App ID [1], Source or App Name [2], Src port [3], Destination [4],\n",
@@ -441,8 +473,8 @@
441473
"\t\t\t\t}\n",
442474
"\t\t\telse:\n",
443475
"\t\t\t\t# Since protocol is not 'any', we pass these from the worksheet\n",
444-
"\t\t\t\trule_src_port = row[3].value.lower() # Always lowercase\n",
445-
"\t\t\t\trule_dst_port = row[5].value.lower() # Always lowercase\n",
476+
"\t\t\t\trule_src_port = row[3].value # Always lowercase\n",
477+
"\t\t\t\trule_dst_port = row[5].value # Always lowercase\n",
446478
"\t\t\t\trule_value = {\n",
447479
"\t\t\t\t\t'protocol': rule_protocol, \n",
448480
"\t\t\t\t\t'source': {\n",
@@ -531,7 +563,7 @@
531563
},
532564
"outputs": [],
533565
"source": [
534-
"printj(user_data['loaded_combined_uplink_prefs']['vpnPrefs'])\n",
566+
"printj(user_data['loaded_combined_uplink_prefs']['wanPrefs'])\n",
535567
"\n",
536568
"# How might we look at the other components of the loaded backup?"
537569
]
@@ -840,11 +872,6 @@
840872
")"
841873
]
842874
},
843-
{
844-
"cell_type": "markdown",
845-
"metadata": {},
846-
"source": []
847-
},
848875
{
849876
"cell_type": "markdown",
850877
"metadata": {},

0 commit comments

Comments
 (0)