Guest User

Untitled

a guest
Oct 18th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ##----------------------------------------------------------------------
  4. ## Make .dot from links data base
  5. ##----------------------------------------------------------------------
  6. ## Copyright (C) 2007-2011 The NOC Project
  7. ## See LICENSE for details
  8. ##----------------------------------------------------------------------
  9.  
  10. # Python modules
  11. import os
  12. from django.utils.encoding import smart_str, smart_unicode
  13. # NOC modules
  14. import set_staticvlan_env
  15. import set_env
  16. set_env.setup(use_django=True)
  17. from noc.sa.models import *
  18. from noc.staticvlan.models import graph_vlan_map_dot
  19.  
  20. path='/tmp/'
  21. file_name=path+'mac-port'
  22. mac_port=open('%s.csv'%file_name, 'w')
  23.  
  24. task={}
  25. for obj in ManagedObject.objects.filter(administrative_domain=1):
  26. task[str(obj.id)] = ReduceTask.create_task([obj],
  27. "pyrule:get_single_result",
  28. {},
  29. "get_mac_address_table",
  30. {},
  31. 90
  32. )
  33.  
  34. for obj in ManagedObject.objects.filter(administrative_domain=1):
  35. mo_id=obj.id
  36. result = ReduceTask.get_result(task[str(obj.id)])
  37. if result <> None:
  38. ports={}
  39. black=[]
  40. for i in result:
  41. port=i["interfaces"]
  42. port=port[0]
  43. if port not in black and port <> 'CPU':
  44. if port not in ports:
  45. ports[port]=i["mac"]
  46. else:
  47. del ports[port]
  48. black.append(port)
  49. for i in ports:
  50. mac_port.write(obj.address+','+i+','+ports[i]+',\r\n')
  51.  
  52. mac_port.close()
Add Comment
Please, Sign In to add comment