Class: Sortinghat::Banquet
- Inherits:
-
Object
- Object
- Sortinghat::Banquet
- Defined in:
- lib/sortinghat/banquet.rb
Instance Method Summary collapse
-
#dejavu? ⇒ Boolean
Method to figure out if we’ve been here before.
-
#finish! ⇒ Object
Last method of Sortinghat.
-
#initialize(options = {}) ⇒ Banquet
constructor
Creation method.
-
#start! ⇒ Object
Main method of Sortinghat.
Constructor Details
#initialize(options = {}) ⇒ Banquet
Creation method
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sortinghat/banquet.rb', line 8 def initialize( = {}) # Check that we have write premissions () # Create a syslog for us to use as an instance variable @log = Syslog::Logger.new 'sortinghat' # Append a trailing dot to the zone, if there isn't one if [:zone][-1, 1] != '.' [:zone] << '.' end # Save the options as instance variable = # Create an instance varible to contain our AWS calls @aws = Sortinghat::AWS.new([:region]) end |
Instance Method Details
#dejavu? ⇒ Boolean
Method to figure out if we’ve been here before
28 29 30 31 32 33 34 35 |
# File 'lib/sortinghat/banquet.rb', line 28 def dejavu? # Check for sentinel file if File.exists?('/etc/.sorted') # We found it, log error and exit successfully @log.info('Found /etc/.sorted, refusing to sort.') exit 0 end end |
#finish! ⇒ Object
Last method of Sortinghat
87 88 89 90 |
# File 'lib/sortinghat/banquet.rb', line 87 def finish! # Create our sentinel file FileUtils.touch('/etc/.sorted') end |
#start! ⇒ Object
Main method of Sortinghat
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/sortinghat/banquet.rb', line 38 def start! # Best thing to avoid run conditions are to wait sleep rand(10) # Find out who is who, instances alive # If discover() returns an Array full of nil(s), alive will become an empty Array alive = cleanup(@aws.discover()) # Given the alive instances, find our prefix # If alive an empty array, selection will return the number '1' @prefix = ensurezero(selection(alive)) # Put together hostname/fqdn construction() # Set the Name tag on this instance @aws.settag!(@hostname) # Find out who is who, instances alive # If discover() returns an Array full of nil(s), alive will become an empty Array alive = cleanup(@aws.discover()) # Only enter recursion if the uniq() length of the alive array does not equal the actual length # On AutoScalingGroup initalization, the cleanup() should ensure the alive array is empty not nil so uniq() works unless alive.uniq.length == alive.length # There are duplicates, remove tag, wait, restart @aws.removetag!() sleep rand(10) start!() end # Register in DNS @aws.setroute53([:zone], @fqdn) # Set the localhost hostname setlocal() # Set /etc/hosts sethostsfile() # Throw the hostname in /etc/sysconfig/httpd (if exists) givetohttpd() # All done finish!() end |