|
32 | 32 | "source": [ |
33 | 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 | 34 | "%pip install meraki\n", |
35 | | - "%pip install tablib\n", |
36 | 35 | "\n", |
37 | 36 | "# 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", |
38 | 37 | "'''\n", |
39 | 38 | "%pip install colab-env -qU\n", |
40 | 39 | "import colab_env\n", |
41 | 40 | "'''\n", |
42 | 41 | "\n", |
43 | | - "# Rely on meraki SDK, os, and tablib -- more on tablib later\n", |
| 42 | + "# Rely on meraki SDK and os\n", |
44 | 43 | "import meraki\n", |
45 | 44 | "import os\n", |
46 | | - "import tablib\n", |
47 | | - "\n", |
48 | 45 | "# 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", |
49 | 46 | "import json\n", |
50 | 47 | "\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", |
56 | 51 | "\n", |
57 | 52 | "# Initialize the Dashboard connection.\n", |
58 | | - "dashboard = meraki.DashboardAPI()" |
| 53 | + "dashboard = meraki.DashboardAPI(suppress_logging=True)" |
59 | 54 | ] |
60 | 55 | }, |
61 | 56 | { |
|
251 | 246 | " # SSIDs are always numbered 1-15 (0-14 in the API)\n", |
252 | 247 | " for ssidNumber in range(15):\n", |
253 | 248 | " # Disable rule-based traffic shaping for that network's SSID\n", |
| 249 | + " print(f'Modifying {network[\"name\"]} and SSID number {ssidNumber}...')\n", |
254 | 250 | " dashboard.wireless.updateNetworkWirelessSsidTrafficShapingRules(\n", |
255 | 251 | " network['id'],\n", |
256 | 252 | " ssidNumber,\n", |
257 | 253 | " rules=[]\n", |
258 | | - " )" |
| 254 | + " )\n", |
| 255 | + " " |
259 | 256 | ] |
260 | 257 | }, |
261 | 258 | { |
|
276 | 273 | "outputs": [], |
277 | 274 | "source": [ |
278 | 275 | "# 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", |
283 | 281 | "\n", |
284 | 282 | "# Let's give the user the option to clear those bandwidth limits\n", |
285 | 283 | "if len(organization_ssids_with_limits):\n", |
286 | 284 | " print('Would you like to remove all SSID-level bandwidth limits?')\n", |
287 | 285 | " 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", |
289 | 287 | " 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", |
291 | 289 | " removeSsidLimits(organization_ssids_with_limits)\n", |
292 | | - " print(COMPLETE_STRING)\n", |
| 290 | + " print(string_constants['COMPLETE'])\n", |
293 | 291 | " else:\n", |
294 | | - " print(CANCEL_STRING)\n", |
| 292 | + " print(string_constants['CANCEL'])\n", |
295 | 293 | " else:\n", |
296 | | - " print(CANCEL_STRING)" |
| 294 | + " print(string_constants['CANCEL'])" |
297 | 295 | ] |
298 | 296 | }, |
299 | 297 | { |
|
314 | 312 | "# Let's also check if the user wants to take the extra step to remove all rule-based limits\n", |
315 | 313 | "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", |
316 | 314 | "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", |
318 | 316 | " 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", |
320 | 318 | " removeCustomTrafficShapingRules()\n", |
321 | | - " print(COMPLETE_STRING)\n", |
| 319 | + " print(string_constants['COMPLETE'])\n", |
322 | 320 | " else:\n", |
323 | | - " print(CANCEL_STRING)\n", |
| 321 | + " print(string_constants['CANCEL'])\n", |
324 | 322 | "else:\n", |
325 | | - " print(CANCEL_STRING)\n", |
| 323 | + " print(string_constants['CANCEL'])\n", |
326 | 324 | " " |
327 | 325 | ] |
328 | 326 | }, |
|
336 | 334 | "\n", |
337 | 335 | "[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", |
338 | 336 | "\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", |
340 | 338 | "\n", |
341 | 339 | "[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." |
342 | 340 | ] |
343 | | - }, |
344 | | - { |
345 | | - "cell_type": "code", |
346 | | - "execution_count": null, |
347 | | - "metadata": {}, |
348 | | - "outputs": [], |
349 | | - "source": [] |
350 | 341 | } |
351 | 342 | ], |
352 | 343 | "metadata": { |
|
365 | 356 | "name": "python", |
366 | 357 | "nbconvert_exporter": "python", |
367 | 358 | "pygments_lexer": "ipython3", |
368 | | - "version": "3.8.4" |
| 359 | + "version": "3.8.4-final" |
369 | 360 | } |
370 | 361 | }, |
371 | 362 | "nbformat": 4, |
|
0 commit comments