|
34 | 34 | }, |
35 | 35 | "outputs": [], |
36 | 36 | "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", |
40 | 40 | "\n", |
41 | 41 | "# 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", |
42 | 42 | "'''\n", |
|
80 | 80 | "user_data = dict()\n", |
81 | 81 | "\n", |
82 | 82 | "# 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'" |
84 | 84 | ] |
85 | 85 | }, |
86 | 86 | { |
|
306 | 306 | "\n", |
307 | 307 | "\n", |
308 | 308 | "\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", |
309 | 326 | "\t## WAN PREFERENCES ##\n", |
310 | 327 | "\t# We'll also count the number of rules to help the user know that it's working.\n", |
311 | 328 | "\trule_count = 0\n", |
|
324 | 341 | "\n", |
325 | 342 | "\t\t# The first column is Protocol\n", |
326 | 343 | "\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", |
335 | 344 | "\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", |
338 | 347 | "\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", |
341 | 350 | "\n", |
342 | 351 | "\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", |
344 | 352 | "\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", |
345 | 356 | "\t\t\t# Protocol is any, so leave out the port numbers\n", |
346 | 357 | "\t\t\trule_value = {\n", |
347 | 358 | "\t\t\t\t'protocol': rule_protocol,\n", |
|
352 | 363 | "\t\t\t\t\t'cidr': rule_destination\n", |
353 | 364 | "\t\t\t\t}\n", |
354 | 365 | "\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", |
357 | 370 | "\t\t\t# Rule isn't any, so we need the port numbers\n", |
358 | 371 | "\t\t\trule_value = {\n", |
359 | 372 | "\t\t\t\t'protocol': rule_protocol,\n", |
|
367 | 380 | "\t\t\t\t}\n", |
368 | 381 | "\t\t\t}\n", |
369 | 382 | "\n", |
| 383 | + "\n", |
370 | 384 | "\t\t# Append the trafficFilters param to the rule\n", |
371 | 385 | "\t\trule['trafficFilters'] = [\n", |
372 | 386 | "\t\t\t{\n", |
|
385 | 399 | "\t\n", |
386 | 400 | "\tprint(f'Loaded {rule_count} WAN uplink preferences.')\n", |
387 | 401 | "\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", |
388 | 420 | "\t## VPN PREFERENCES ##\n", |
389 | 421 | "\t# For reference, the expected column order is\n", |
390 | 422 | "\t# Type [0], Protocol or App ID [1], Source or App Name [2], Src port [3], Destination [4],\n", |
|
441 | 473 | "\t\t\t\t}\n", |
442 | 474 | "\t\t\telse:\n", |
443 | 475 | "\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", |
446 | 478 | "\t\t\t\trule_value = {\n", |
447 | 479 | "\t\t\t\t\t'protocol': rule_protocol, \n", |
448 | 480 | "\t\t\t\t\t'source': {\n", |
|
531 | 563 | }, |
532 | 564 | "outputs": [], |
533 | 565 | "source": [ |
534 | | - "printj(user_data['loaded_combined_uplink_prefs']['vpnPrefs'])\n", |
| 566 | + "printj(user_data['loaded_combined_uplink_prefs']['wanPrefs'])\n", |
535 | 567 | "\n", |
536 | 568 | "# How might we look at the other components of the loaded backup?" |
537 | 569 | ] |
|
840 | 872 | ")" |
841 | 873 | ] |
842 | 874 | }, |
843 | | - { |
844 | | - "cell_type": "markdown", |
845 | | - "metadata": {}, |
846 | | - "source": [] |
847 | | - }, |
848 | 875 | { |
849 | 876 | "cell_type": "markdown", |
850 | 877 | "metadata": {}, |
|
0 commit comments