Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- ##----------------------------------------------------------------------
- ## Apply ignored_interfaces to given interface profile
- ##----------------------------------------------------------------------
- ## Copyright (C) 2007-2012 The NOC Project
- ## See LICENSE for details
- ##----------------------------------------------------------------------
- ## Bootstrap
- import set_env
- set_env.setup(use_django=True)
- from noc.inv.models import Interface, InterfaceProfile
- from noc.sa.models import ManagedObjectAttribute,ManagedObject
- def migrate(profile):
- print "Setting profile %s" % profile.name
- for a in ManagedObject.objects.filter(name__istartswith=sys.argv[1]):
- mo = a
- ignored = []
- for iface in Interface.objects.filter(managed_object=mo.id):
- if iface.name.startswith(sys.argv[3]):
- iface.profile = profile
- iface.save()
- ignored += [iface.name]
- if ignored:
- print "%s: %s" % (
- mo.name, ", ".join(ignored)
- )
- # a.delete()
- if __name__ == "__main__":
- import sys
- if len(sys.argv) != 3:
- print "Usage: (setting interface profile name to managed object)"
- print "%s <mo-obj-name-startswith> <interface profile name> <interface-name-startswith>" % sys.argv[0]
- sys.exit(1)
- profile = InterfaceProfile.objects.filter(name=sys.argv[2]).first()
- if not profile:
- print "Invalid interface profile. Existing profiles are:"
- for profile in InterfaceProfile.objects.all():
- print profile
- migrate(profile)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement