Guest User

Untitled

a guest
Aug 16th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. # We use tags to identify hosts - tag is Name: host_short_name.
  2. # Tags are also used for other aws objects - Load balancers, snapshots etc..
  3. tagger = ec2conn.get_all_tags()
  4. for i in tagger:
  5. # Iterate through all tags and pull out the one that matches a hostname
  6. # We're interested in res_id (instance id) and value (tag value)
  7. # We are only interested in instances
  8. if i.res_type == 'instance':
  9. # We only want the tags that contain the hostname
  10. if i.name == 'Name':
  11. # This dict statement prints the full attributes of each tag/instance combo - for debugging
  12. #pprint.pprint(i.__dict__)
  13. # We want to make sure that the value pulled matches the hostname of the host we're running this on
  14. if i.value == small_host:
  15. print "Hostname of the node we're running this on is:"
  16. print small_host
  17. lbees = awslbconn.get_all_load_balancers()
  18. print "This is our load balancer:"
  19. print lbees
  20. # Only do load balancing actions on an app Server node
  21. if small_host.startswith ( 'n6a1' ) == True:
  22. print "This is the node name:"
  23. print i.value
  24. print "This is the instance id:"
  25. print i.res_id
  26. # Put LB stuff here
  27. print "Trying to install into the load balancer:"
  28. varvar = i.res_id
  29. print varvar
  30. lbtoggle = awslbconn.register_instances('server-lb', 'i-ef154389')
  31. print "The result is:"
  32. print lbtoggle
Add Comment
Please, Sign In to add comment