Class: Beaker::Blimper

Inherits:
Hypervisor show all
Defined in:
lib/beaker/hypervisor/blimper.rb

Instance Method Summary collapse

Methods inherited from Hypervisor

#configure, create

Constructor Details

#initialize(blimpy_hosts, options) ⇒ Blimper

Returns a new instance of Blimper.



27
28
29
30
31
32
# File 'lib/beaker/hypervisor/blimper.rb', line 27

def initialize(blimpy_hosts, options)
  @options = options
  @logger = options[:logger]
  @blimpy_hosts = blimpy_hosts
  @blimpy = Blimpy
end

Instance Method Details

#amiports(host) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/beaker/hypervisor/blimper.rb', line 7

def amiports(host)
  roles = host['roles']
  ports = [22]

  if roles.include? 'database'
    ports << 8080
    ports << 8081
  end

  if roles.include? 'master'
    ports << 8140
  end

  if roles.include? 'dashboard'
    ports << 443
  end

  ports
end

#cleanupObject

revert_blimpy



108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/beaker/hypervisor/blimper.rb', line 108

def cleanup
  fleet = @blimpy.fleet do |fleet|
    @blimpy_hosts.each do |host|
      fleet.add(:aws) do |ship|
        ship.name = host.name
      end
    end
  end

  @logger.notify "Destroying Blimpy boxes"
  fleet.destroy
end

#provisionObject



34
35
36
37
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/beaker/hypervisor/blimper.rb', line 34

def provision
  ami_spec= YAML.load_file(@options[:ec2_yaml])["AMI"]

  fleet = @blimpy.fleet do |fleet|
    @blimpy_hosts.each do |host|
      amitype = host['vmname'] || host['platform']
      amisize = host['amisize'] || 'm1.small'
      #use snapshot provided for this host 
      image_type = host['snapshot'] 
      if not image_type
        raise "No snapshot/image_type provided for blimpy provisioning"
      end
      ami = ami_spec[amitype]
      fleet.add(:aws) do |ship|
        ship.name = host.name
        ship.ports = amiports(host)
        ship.image_id = ami[:image][image_type.to_sym]
        if not ship.image_id
          raise "No image_id found for host #{ship.name} (#{amitype}:#{amisize}) using snapshot/image_type #{image_type}"
        end
        ship.flavor = amisize
        ship.region = ami[:region]
        ship.username = 'root'
      end
      @logger.debug "Added #{host.name} (#{amitype}:#{amisize}) using snapshot/image_type #{image_type} to blimpy fleet"
    end
  end

  # Attempt to start the fleet, we wrap it with some error handling that deals
  # with generic Fog errors and retrying in case these errors are transient.
  fleet_retries = 0
  begin
    fleet.start
  rescue Fog::Errors::Error => ex
    fleet_retries += 1
    if fleet_retries <= 3
      sleep_time = rand(10) + 10
      @logger.notify("Calling fleet.destroy, sleeping #{sleep_time} seconds and retrying fleet.start due to Fog::Errors::Error (#{
  ex.message}), retry attempt #{fleet_retries}.")
      begin
        timeout(30) do
          fleet.destroy
        end
      rescue
      end
      sleep sleep_time
      retry
    else
      @logger.error("Retried Fog #{fleet_retries} times, giving up and throwing the exception")
      raise ex
    end
  end

  # Configure our nodes to match the blimp fleet
  # Also generate hosts entries for the fleet, since we're iterating
  etc_hosts = "127.0.0.1\tlocalhost localhost.localdomain\n"
  fleet.ships.each do |ship|
    ship.wait_for_sshd
    name = ship.name
    host = @blimpy_hosts.select { |host| host.name == name }[0]
    host['ip'] = ship.dns
    host.exec(Command.new("hostname #{name}"))
    ip = get_ip(host) 
    domain = get_domain_name(host)
    etc_hosts += "#{ip}\t#{name}\t#{name}.#{domain}\n"
  end

  # Send our hosts information to the nodes
  @blimpy_hosts.each do |host|
    set_etc_hosts(host, etc_hosts)
  end

end