Advertisement
Guest User

allowed_ports.py

a guest
Jun 10th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. #/usr/bin/python
  2. #set system login class server permissions configure
  3. #set system login class server permissions view
  4. #set system login class server permissions view-configuration
  5. #set system login class server allow-configuration "interfaces xe-5/1/2 unit .* vlan-id .*"
  6.  
  7. #Get a list of all the interfaces on the box that match ge/xe/et.
  8. #Delete the exception interfaces from the list
  9. #Generate allow-configuration for box
  10.  
  11. import sys
  12. import time
  13. import datetime
  14. from pprint import pprint
  15. from jnpr.junos import Device
  16. from jnpr.junos.op.phyport import *
  17.  
  18. dev = Device(host = 'router', user='user', password='pass')
  19. dev.open()
  20.  
  21. #grab all interfaces
  22. ports = PhyPortTable(dev).get()
  23. port_names = []
  24. for port in ports:
  25. port_names.append(port.key)
  26.  
  27. #build exclusion list
  28. port_exclude = ['xe-5/1/2', 'xe-0/3/1']
  29.  
  30. #remove port-exclude entries from port_names list put them in whitelist_ports
  31. whitelist_ports = [x for x in port_names if x not in port_exclude]
  32.  
  33. #generate config
  34. config_whitelist_ports = []
  35. for item in whitelist_ports:
  36. config_whitelist_ports.append('set system login class server allow-configuration "interfaces ' + item + ' unit .* vlan-id .*"')
  37.  
  38. for item in config_whitelist_ports:
  39. print item
  40.  
  41. #Example output
  42. #set system login class server allow-configuration "interfaces xe-0/0/0 unit .* vlan-id .*"
  43. #set system login class server allow-configuration "interfaces xe-0/0/1 unit .* vlan-id .*"
  44. #set system login class server allow-configuration "interfaces xe-0/0/2 unit .* vlan-id .*"
  45. #set system login class server allow-configuration "interfaces xe-0/0/3 unit .* vlan-id .*"
  46. #set system login class server allow-configuration "interfaces xe-0/1/0 unit .* vlan-id .*"
  47. #set system login class server allow-configuration "interfaces xe-0/1/1 unit .* vlan-id .*"
  48. #set system login class server allow-configuration "interfaces xe-0/1/2 unit .* vlan-id .*"
  49. #set system login class server allow-configuration "interfaces xe-0/1/3 unit .* vlan-id .*"
  50. #set system login class server allow-configuration "interfaces xe-0/2/0 unit .* vlan-id .*"
  51. #set system login class server allow-configuration "interfaces xe-0/2/1 unit .* vlan-id .*"
  52. #set system login class server allow-configuration "interfaces xe-0/2/2 unit .* vlan-id .*"
  53.  
  54. dev.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement