Guest User

Untitled

a guest
Oct 18th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 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.  
  19. path='/tmp/'
  20. file_name=path+'mac-port'
  21. mac_port=open('%s.csv'%file_name, 'w')
  22.  
  23. task={}
  24. for obj in ManagedObject.objects.filter(administrative_domain=1):
  25. task[str(obj.id)] = ReduceTask.create_task([obj],
  26. "pyrule:get_single_result",
  27. {},
  28. "get_mac_address_table",
  29. {},
  30. 90
  31. )
  32.  
  33. for obj in ManagedObject.objects.filter(administrative_domain=1):
  34. mo_id=obj.id
  35. result = ReduceTask.get_result(task[str(obj.id)])
  36. if result <> None:
  37. ports={}
  38. black=[]
  39. for i in result:
  40. port=i["interfaces"]
  41. port=port[0]
  42. if port not in black and port <> 'CPU':
  43. if port not in ports:
  44. ports[port]=i["mac"]
  45. else:
  46. del ports[port]
  47. black.append(port)
  48. for i in ports:
  49. mac_port.write(obj.address+','+i+','+ports[i]+',\r\n')
  50.  
  51. mac_port.close()
Add Comment
Please, Sign In to add comment