Advertisement
Guest User

Untitled

a guest
Oct 19th, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ##----------------------------------------------------------------------
  4. ## Apply ignored_interfaces to given interface profile
  5. ##----------------------------------------------------------------------
  6. ## Copyright (C) 2007-2012 The NOC Project
  7. ## See LICENSE for details
  8. ##----------------------------------------------------------------------
  9.  
  10. ## Bootstrap
  11. import set_env
  12. set_env.setup(use_django=True)
  13.  
  14. from noc.inv.models import Interface, InterfaceProfile
  15. from noc.sa.models import ManagedObjectAttribute,ManagedObject
  16.  
  17. def migrate(profile):
  18. print "Setting profile %s" % profile.name
  19. for a in ManagedObject.objects.filter(name__istartswith=sys.argv[1]):
  20. mo = a
  21. ignored = []
  22. for iface in Interface.objects.filter(managed_object=mo.id):
  23. if iface.name.startswith(sys.argv[3]):
  24. iface.profile = profile
  25. iface.save()
  26. ignored += [iface.name]
  27. if ignored:
  28. print "%s: %s" % (
  29. mo.name, ", ".join(ignored)
  30. )
  31. # a.delete()
  32.  
  33. if __name__ == "__main__":
  34. import sys
  35.  
  36. if len(sys.argv) != 3:
  37. print "Usage: (setting interface profile name to managed object)"
  38. print "%s <mo-obj-name-startswith> <interface profile name> <interface-name-startswith>" % sys.argv[0]
  39. sys.exit(1)
  40.  
  41. profile = InterfaceProfile.objects.filter(name=sys.argv[2]).first()
  42. if not profile:
  43. print "Invalid interface profile. Existing profiles are:"
  44. for profile in InterfaceProfile.objects.all():
  45. print profile
  46.  
  47. migrate(profile)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement