Skip to content

Commit 832067f

Browse files
Notebook optimizations.
Optimizations for uplink prefs backup and restore notebooks, and the SSID limits checker notebook. Tweaked readme.
1 parent 6f926a4 commit 832067f

4 files changed

Lines changed: 215 additions & 319 deletions

File tree

notebooks/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Jupyter notebooks are documents that take coding in Python (and potentially other languages) to a whole new level. They are technically just fancy JSON files with a `.ipynb` extension, but with a Jupyter notebook and a compatible IDE, you can:
66

7-
1. Write, run and re-run code in a block-by-block basis, while keeping all variables in an active and *interactive* kernel space. Those blocks are called "cells."
7+
1. Write, run and re-run code in a block-by-block basis, while keeping all variables in an active and *interactive* kernel space. Those blocks are called "cells." If you're unfamiliar with Python debugging, it may be easier to use notebooks than debuggers!
88
2. Combine executable code, rich text, HTML, and even images in a single document, going way beyond standard Python comments and inserting HTML- or Markdown-formatted documentation inline with code in a way that never interferes with the operation of your code.
99
3. Rearrange code and Markdown cells aribitrarily for verification, experimentation, or pure curiosity.
1010
4. Much more, if you are willing to learn!
@@ -196,4 +196,4 @@ Select the cell, then hold `Ctrl` or `⌘` and type `MY`.
196196

197197
### Using VS Code
198198

199-
Select the cell, then at the top of the cell click either `M` to convert to text, or `{}` to convert to code.
199+
Select the cell, then at the top of the cell click either `M` to convert to text, or `{}` to convert to code.

notebooks/merakiSSIDLimitsChecker.ipynb

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,25 @@
3232
"source": [
3333
"# 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",
3434
"%pip install meraki\n",
35-
"%pip install tablib\n",
3635
"\n",
3736
"# 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",
3837
"'''\n",
3938
"%pip install colab-env -qU\n",
4039
"import colab_env\n",
4140
"'''\n",
4241
"\n",
43-
"# Rely on meraki SDK, os, and tablib -- more on tablib later\n",
42+
"# Rely on meraki SDK and os\n",
4443
"import meraki\n",
4544
"import os\n",
46-
"import tablib\n",
47-
"\n",
4845
"# We're also going to import Python's built-in JSON module, but only to make the console output pretty. In production, you wouldn't need any of the printing calls at all, nor this import!\n",
4946
"import json\n",
5047
"\n",
51-
"# Setting API key this way, and storing it in the env variables, lets us keep the sensitive API key out of the script itself\n",
52-
"# The meraki.DashboardAPI() method does not require explicitly passing this value; it will check the environment for a variable\n",
53-
"# called 'MERAKI_DASHBOARD_API_KEY' on its own. In this case, API_KEY is shown simply as an reference to where that information is\n",
54-
"# stored.\n",
55-
"API_KEY = os.getenv('MERAKI_DASHBOARD_API_KEY')\n",
48+
"# Treat your API key like a password. Store it in your environment variables as 'MERAKI_DASHBOARD_API_KEY' and let the SDK call it for you.\n",
49+
"# Or, call it manually after importing Python's os module:\n",
50+
"# API_KEY = os.getenv('MERAKI_DASHBOARD_API_KEY')\n",
5651
"\n",
5752
"# Initialize the Dashboard connection.\n",
58-
"dashboard = meraki.DashboardAPI()"
53+
"dashboard = meraki.DashboardAPI(suppress_logging=True)"
5954
]
6055
},
6156
{
@@ -251,11 +246,13 @@
251246
" # SSIDs are always numbered 1-15 (0-14 in the API)\n",
252247
" for ssidNumber in range(15):\n",
253248
" # Disable rule-based traffic shaping for that network's SSID\n",
249+
" print(f'Modifying {network[\"name\"]} and SSID number {ssidNumber}...')\n",
254250
" dashboard.wireless.updateNetworkWirelessSsidTrafficShapingRules(\n",
255251
" network['id'],\n",
256252
" ssidNumber,\n",
257253
" rules=[]\n",
258-
" )"
254+
" )\n",
255+
" "
259256
]
260257
},
261258
{
@@ -276,24 +273,25 @@
276273
"outputs": [],
277274
"source": [
278275
"# Re-used strings\n",
279-
"CONFIRM_STRING = 'OK, are you sure you want to do this? This script does not have an \"undo\" feature.'\n",
280-
"CANCEL_STRING = 'OK. Operation canceled.'\n",
281-
"WORKING_STRING = 'Working...'\n",
282-
"COMPLETE_STRING = 'Operation complete.'\n",
276+
"string_constants = dict()\n",
277+
"string_constants['CONFIRM'] = 'OK, are you sure you want to do this? This script does not have an \"undo\" feature.'\n",
278+
"string_constants['CANCEL'] = 'OK. Operation canceled.'\n",
279+
"string_constants['WORKING'] = 'Working...'\n",
280+
"string_constants['COMPLETE'] = 'Operation complete.'\n",
283281
"\n",
284282
"# Let's give the user the option to clear those bandwidth limits\n",
285283
"if len(organization_ssids_with_limits):\n",
286284
" print('Would you like to remove all SSID-level bandwidth limits?')\n",
287285
" if input('([Y]es/[N]o):') in ['Y', 'y', 'Yes', 'yes', 'ye', 'Ye']:\n",
288-
" print(CONFIRM_STRING)\n",
286+
" print(string_constants['CONFIRM'])\n",
289287
" if input('([Y]es/[N]o):') in ['Y', 'y', 'Yes', 'yes', 'ye', 'Ye']:\n",
290-
" print(WORKING_STRING)\n",
288+
" print(string_constants['WORKING'])\n",
291289
" removeSsidLimits(organization_ssids_with_limits)\n",
292-
" print(COMPLETE_STRING)\n",
290+
" print(string_constants['COMPLETE'])\n",
293291
" else:\n",
294-
" print(CANCEL_STRING)\n",
292+
" print(string_constants['CANCEL'])\n",
295293
" else:\n",
296-
" print(CANCEL_STRING)"
294+
" print(string_constants['CANCEL'])"
297295
]
298296
},
299297
{
@@ -314,15 +312,15 @@
314312
"# Let's also check if the user wants to take the extra step to remove all rule-based limits\n",
315313
"print('There may also be client bandwidth limits on custom traffic shaping rules. Would you also like to remove any and all custom traffic shaping rules? This may take some time depending on the size and quantity of your networks. This will not clear default traffic shaping rules.')\n",
316314
"if input('([Y]es/[N]o):') in ['Y', 'y', 'Yes', 'yes', 'ye', 'Ye']:\n",
317-
" print(CONFIRM_STRING)\n",
315+
" print(string_constants['CONFIRM'])\n",
318316
" if input('([Y]es/[N]o):') in ['Y', 'y', 'Yes', 'yes', 'ye', 'Ye']:\n",
319-
" print(WORKING_STRING)\n",
317+
" print(string_constants['WORKING'])\n",
320318
" removeCustomTrafficShapingRules()\n",
321-
" print(COMPLETE_STRING)\n",
319+
" print(string_constants['COMPLETE'])\n",
322320
" else:\n",
323-
" print(CANCEL_STRING)\n",
321+
" print(string_constants['CANCEL'])\n",
324322
"else:\n",
325-
" print(CANCEL_STRING)\n",
323+
" print(string_constants['CANCEL'])\n",
326324
" "
327325
]
328326
},
@@ -336,17 +334,10 @@
336334
"\n",
337335
"[Meraki Interactive API Docs](https://developer.cisco.com/meraki/api-v1/#!overview): The official (and interactive!) Meraki API and SDK documentation repository on DevNet.\n",
338336
"\n",
339-
"[VS Code](https://code.visualstudio.com/): An excellent code editor with full support for Python and Python notebooks.\n",
337+
"[VS Code](https://code.visualstudio.com/): A code editor with full support for Python and some support for Python notebooks.\n",
340338
"\n",
341339
"[Automate the Boring Stuff with Python](https://automatetheboringstuff.com/): An excellent learning resource that puts the real-world problem first, then teaches you the Pythonic solution along the way."
342340
]
343-
},
344-
{
345-
"cell_type": "code",
346-
"execution_count": null,
347-
"metadata": {},
348-
"outputs": [],
349-
"source": []
350341
}
351342
],
352343
"metadata": {
@@ -365,7 +356,7 @@
365356
"name": "python",
366357
"nbconvert_exporter": "python",
367358
"pygments_lexer": "ipython3",
368-
"version": "3.8.4"
359+
"version": "3.8.4-final"
369360
}
370361
},
371362
"nbformat": 4,

0 commit comments

Comments
 (0)