Class: Ironfan::Provider::Rds::Machine

Inherits:
IaasProvider::Machine show all
Defined in:
lib/ironfan/headers.rb,
lib/ironfan/provider/rds/machine.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from IaasProvider::Machine

cloud_init_user_data

Class Method Details

.create!(computer) ⇒ Object

Manipulation


124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/ironfan/provider/rds/machine.rb', line 124

def self.create!(computer)
  return if computer.machine? and computer.machine.created?
  Ironfan.step(computer.name,"creating RDS machine... go grab some a beer or two.", :green)  #

  errors = lint(computer)
  if errors.present? then raise ArgumentError, "Failed validation: #{errors.inspect}" ; end  #

  launch_desc = launch_description(computer)
  launch_desc[:id] = computer.name
  Chef::Log.debug(JSON.pretty_generate(launch_desc))

  Ironfan.safely do
    fog_server = Rds.connection.servers.create(launch_desc)
    machine = Machine.new(:adaptee => fog_server)
    computer.machine = machine
    remember machine, :id => computer.name

    Ironfan.step(fog_server.id,"waiting for machine to be ready", :gray)
    Ironfan.tell_you_thrice     :name           => fog_server.id,
                                :problem        => "server unavailable",
                                :error_class    => Fog::Errors::Error do
      fog_server.wait_for { ready? }
    end
  end

  # tag the computer correctly
  tags = {
    'cluster' =>      computer.server.cluster_name,
    'facet' =>        computer.server.facet_name,
    'index' =>        computer.server.index,
    'name' =>         computer.name,
    'Name' =>         computer.name,
  }
  Rds.ensure_tags(tags, computer.machine)
  
  # Because chef will never run on these, we fake announcements after launch.  
  Ironfan.step(computer.name, "Adding enpoint and port announcements", :green)
  announcements = { :rds => {
                      :endpoint  => computer.machine.endpoint["Address"],
                      :port      => computer.machine.endpoint["Port"],
                      :root_user => launch_desc[:master_username],
                      :root_pass => launch_desc[:password],
                    }
                  }

  computer.node[:announces] = announcements
  computer.node.save
  
end

.destroy!(computer) ⇒ Object


225
226
227
228
229
230
# File 'lib/ironfan/provider/rds/machine.rb', line 225

def self.destroy!(computer)
  return unless computer.machine?
  forget computer.machine.name
  computer.machine.destroy
  computer.machine.reload            # show the node as shutting down
end

.expected_ids(computer) ⇒ Object


14
# File 'lib/ironfan/provider/rds/machine.rb', line 14

def self.expected_ids(computer) [computer.server.full_name];   end

.launch_description(computer) ⇒ Object


185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/ironfan/provider/rds/machine.rb', line 185

def self.launch_description(computer)
  cloud = computer.server.cloud(:rds)
  user_data_hsh =               {
    :chef_server =>             Chef::Config[:chef_server_url],
    :node_name =>               computer.name,
    :organization =>            Chef::Config[:organization],
    :cluster_name =>            computer.server.cluster_name,
    :facet_name =>              computer.server.facet_name,
    :facet_index =>             computer.server.index,
  }


  # main machine info
  # note that Fog does not actually create tags when it creates a
  #  server; they and permanence are applied during sync
  description = {
    :allocated_storage            => cloud.size,
    :auto_minor_version_upgrade   => cloud.autoupgrade,
    :availability_zone            => cloud.multi_az ? nil : cloud.default_availability_zone,
    :backup_retention_period      => cloud.backup_retention,
    :db_name                      => cloud.dbname,
    :engine                       => cloud.engine,
    :engine_version               => cloud.version,
    :flavor_id                    => cloud.flavor,
    :license_model                => cloud.license_model,
    :master_username              => cloud.username,
    :multi_az                     => cloud.multi_az, 
    :password                     => cloud.password,
    :port                         => cloud.port,
    :preferred_backup_window      => cloud.preferred_backup_window,
    :preferred_maintenance_window => cloud.preferred_maintenance_window,
    :security_group_names         => cloud.security_groups.keys,
    :user_data                    => JSON.pretty_generate(user_data_hsh),
#            :charset                    => cloud.charset, # Not supported in FOG?
#            :iops                       => cloud.iops, # Not supported in FOG?
  }

  description
end

.lint(computer) ⇒ Object


175
176
177
178
179
180
181
182
183
# File 'lib/ironfan/provider/rds/machine.rb', line 175

def self.lint(computer)
  cloud = computer.server.cloud(:rds)
  info  = [computer.name, cloud.inspect]
  errors = {}
  errors["No Password"] = info if cloud.password.empty?
  errors["No Username"] = info if cloud.username.empty?
  errors["Size"]        = info if cloud.size < 5
  errors
end

.load!(cluster = nil) ⇒ Object

Discovery


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ironfan/provider/rds/machine.rb', line 81

def self.load!(cluster=nil)
  Rds.connection.servers.each do |fs|
    machine = new(:adaptee => fs)
    if (not machine.created?)
      next unless Ironfan.chef_config[:include_terminated]
      remember machine, :append_id => "terminated:#{machine.id}"
    elsif recall? machine.name
      machine.bogus <<                 :duplicate_machines
      recall(machine.name).bogus <<    :duplicate_machines
      remember machine, :append_id => "duplicate:#{machine.id}"
    else # never seen it
      remember machine
    end
    Chef::Log.debug("Loaded #{machine}")
  end
end

.multiple?Boolean

Returns:

  • (Boolean)

12
# File 'lib/ironfan/provider/rds/machine.rb', line 12

def self.multiple?()    false;  end

.resource_typeObject


13
# File 'lib/ironfan/provider/rds/machine.rb', line 13

def self.resource_type()        :machine;   end

.save!(computer) ⇒ Object


232
233
234
# File 'lib/ironfan/provider/rds/machine.rb', line 232

def self.save!(computer)
  return unless computer.machine?
end

.shared?Boolean

Returns:

  • (Boolean)

11
# File 'lib/ironfan/provider/rds/machine.rb', line 11

def self.shared?()      false;  end

.validate_resources!(computers) ⇒ Object

Find active machines that haven't matched, but should have,

make sure all bogus machines have a computer to attach to
for display purposes

106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/ironfan/provider/rds/machine.rb', line 106

def self.validate_resources!(computers)
  recall.each_value do |machine|
    next unless machine.users.empty? and machine.name
    if machine.name.match("^#{computers.cluster.name}-")
      machine.bogus << :unexpected_machine
    end
    next unless machine.bogus?
    fake           = Ironfan::Broker::Computer.new
    fake[:machine] = machine
    fake.name      = machine.name
    machine.users << fake
    computers     << fake
  end
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)

43
44
45
# File 'lib/ironfan/provider/rds/machine.rb', line 43

def available?
  state == "available"
end

#created?Boolean

Returns:

  • (Boolean)

23
24
25
# File 'lib/ironfan/provider/rds/machine.rb', line 23

def created?
  not ['terminated', 'shutting-down'].include? state
end

#creating?Boolean

Returns:

  • (Boolean)

35
36
37
# File 'lib/ironfan/provider/rds/machine.rb', line 35

def creating?
  state == "creating"
end

#deleting?Boolean

Returns:

  • (Boolean)

27
28
29
# File 'lib/ironfan/provider/rds/machine.rb', line 27

def deleting?
  state == "deleting"
end

#nameObject


16
17
18
19
# File 'lib/ironfan/provider/rds/machine.rb', line 16

def name
  return id if tags.empty?
  tags["Name"] || tags["name"] || id
end

#pending?Boolean

Returns:

  • (Boolean)

31
32
33
# File 'lib/ironfan/provider/rds/machine.rb', line 31

def pending?
  state == "pending"
end

#perform_after_launch_tasks?Boolean

Returns:

  • (Boolean)

50
51
52
# File 'lib/ironfan/provider/rds/machine.rb', line 50

def perform_after_launch_tasks?
  false
end

#public_hostnameObject


21
# File 'lib/ironfan/provider/rds/machine.rb', line 21

def public_hostname  ; dns_name ; end

#rebooting?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'lib/ironfan/provider/rds/machine.rb', line 39

def rebooting?
  state == "rebooting"
end

#receive_adaptee(obj) ⇒ Object


98
99
100
101
# File 'lib/ironfan/provider/rds/machine.rb', line 98

def receive_adaptee(obj)
  obj = Rds.connection.servers.new(obj) if obj.is_a?(Hash)
  super
end

#stopped?Boolean

Returns:

  • (Boolean)

47
48
# File 'lib/ironfan/provider/rds/machine.rb', line 47

def stopped? 
end

#to_display(style, values = {}) ⇒ Object


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ironfan/provider/rds/machine.rb', line 54

def to_display(style,values={})
  # style == :minimal
  values["State"] =             state.to_sym
  values["Endpoint"]  =         adaptee.endpoint["Address"]
  values["Created On"] =        created_at.to_date
  return values if style == :minimal

  # style == :default
  values["Flavor"] =            flavor_id
  values["AZ"] =                availability_zone
  return values if style == :default

  # style == :expanded
  values["Port"]  =         adaptee.endpoint["Port"]
  values["Engine"]  =           engine
  values["EngineVersion"] =     engine_version
  values
end

#to_sObject


73
74
75
76
# File 'lib/ironfan/provider/rds/machine.rb', line 73

def to_s
  "<%-15s %-12s %-25s %-25s %-15s %-15s>" % [
    self.class.handle, id, created_at, tags['name'], flavor_id, availability_zone]
end