Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- ##----------------------------------------------------------------------
- ## Make .dot from links data base
- ##----------------------------------------------------------------------
- ## Copyright (C) 2007-2011 The NOC Project
- ## See LICENSE for details
- ##----------------------------------------------------------------------
- # Python modules
- import os
- from django.utils.encoding import smart_str, smart_unicode
- # NOC modules
- import set_staticvlan_env
- import set_env
- set_env.setup(use_django=True)
- from noc.sa.models import *
- path='/tmp/'
- file_name=path+'mac-port'
- mac_port=open('%s.csv'%file_name, 'w')
- task={}
- for obj in ManagedObject.objects.filter(administrative_domain=1):
- task[str(obj.id)] = ReduceTask.create_task([obj],
- "pyrule:get_single_result",
- {},
- "get_mac_address_table",
- {},
- 90
- )
- for obj in ManagedObject.objects.filter(administrative_domain=1):
- mo_id=obj.id
- result = ReduceTask.get_result(task[str(obj.id)])
- if result <> None:
- ports={}
- black=[]
- for i in result:
- port=i["interfaces"]
- port=port[0]
- if port not in black and port <> 'CPU':
- if port not in ports:
- ports[port]=i["mac"]
- else:
- del ports[port]
- black.append(port)
- for i in ports:
- mac_port.write(obj.address+','+i+','+ports[i]+',\r\n')
- mac_port.close()
Add Comment
Please, Sign In to add comment