Class: Rubber::Configuration::InstanceItem

Inherits:
Object
  • Object
show all
Defined in:
lib/rubber/instance.rb

Overview

The configuration for a single instance

Constant Summary collapse

UBUNTU_OS_VERSION_CMD =
'lsb_release -sr'.freeze
VARIABLES_TO_OMIT_IN_SERIALIZATION =
[
  '@capistrano', '@os_version', '@subnet_id', '@vpc_id',
  '@vpc_cidr'
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, domain, roles, instance_id, image_type, image_id, security_group_list = []) ⇒ InstanceItem

Returns a new instance of InstanceItem.



218
219
220
221
222
223
224
225
226
227
# File 'lib/rubber/instance.rb', line 218

def initialize(name, domain, roles, instance_id, image_type, image_id, security_group_list=[])
  @name = name
  @domain = domain
  @roles = roles
  @instance_id = instance_id
  @image_type = image_type
  @image_id = image_id
  @security_groups = security_group_list
  @os_version = nil
end

Instance Attribute Details

#capistranoObject

Returns the value of attribute capistrano.



211
212
213
# File 'lib/rubber/instance.rb', line 211

def capistrano
  @capistrano
end

#domainObject (readonly)

Returns the value of attribute domain.



204
205
206
# File 'lib/rubber/instance.rb', line 204

def domain
  @domain
end

#external_hostObject

Returns the value of attribute external_host.



206
207
208
# File 'lib/rubber/instance.rb', line 206

def external_host
  @external_host
end

#external_ipObject

Returns the value of attribute external_ip.



206
207
208
# File 'lib/rubber/instance.rb', line 206

def external_ip
  @external_ip
end

#gatewayObject

Returns the value of attribute gateway.



216
217
218
# File 'lib/rubber/instance.rb', line 216

def gateway
  @gateway
end

#image_idObject (readonly)

Returns the value of attribute image_id.



204
205
206
# File 'lib/rubber/instance.rb', line 204

def image_id
  @image_id
end

#image_typeObject (readonly)

Returns the value of attribute image_type.



204
205
206
# File 'lib/rubber/instance.rb', line 204

def image_type
  @image_type
end

#instance_idObject (readonly)

Returns the value of attribute instance_id.



204
205
206
# File 'lib/rubber/instance.rb', line 204

def instance_id
  @instance_id
end

#internal_hostObject

Returns the value of attribute internal_host.



207
208
209
# File 'lib/rubber/instance.rb', line 207

def internal_host
  @internal_host
end

#internal_ipObject

Returns the value of attribute internal_ip.



207
208
209
# File 'lib/rubber/instance.rb', line 207

def internal_ip
  @internal_ip
end

#nameObject (readonly)

Returns the value of attribute name.



204
205
206
# File 'lib/rubber/instance.rb', line 204

def name
  @name
end

#networkObject

more generic term for vpc_alias



213
214
215
# File 'lib/rubber/instance.rb', line 213

def network
  @network
end

#partitionsObject

Returns the value of attribute partitions.



208
209
210
# File 'lib/rubber/instance.rb', line 208

def partitions
  @partitions
end

#platformObject

Returns the value of attribute platform.



210
211
212
# File 'lib/rubber/instance.rb', line 210

def platform
  @platform
end

#providerObject

Returns the value of attribute provider.



210
211
212
# File 'lib/rubber/instance.rb', line 210

def provider
  @provider
end

#rolesObject

Returns the value of attribute roles.



205
206
207
# File 'lib/rubber/instance.rb', line 205

def roles
  @roles
end

#root_device_typeObject

Returns the value of attribute root_device_type.



208
209
210
# File 'lib/rubber/instance.rb', line 208

def root_device_type
  @root_device_type
end

#security_groupsObject (readonly)

Returns the value of attribute security_groups.



204
205
206
# File 'lib/rubber/instance.rb', line 204

def security_groups
  @security_groups
end

#spot_instance_request_idObject

Returns the value of attribute spot_instance_request_id.



209
210
211
# File 'lib/rubber/instance.rb', line 209

def spot_instance_request_id
  @spot_instance_request_id
end

#static_ipObject

Returns the value of attribute static_ip.



208
209
210
# File 'lib/rubber/instance.rb', line 208

def static_ip
  @static_ip
end

#subnet_idObject

Returns the value of attribute subnet_id.



215
216
217
# File 'lib/rubber/instance.rb', line 215

def subnet_id
  @subnet_id
end

#volumesObject

Returns the value of attribute volumes.



208
209
210
# File 'lib/rubber/instance.rb', line 208

def volumes
  @volumes
end

#vpc_cidrObject

Returns the value of attribute vpc_cidr.



214
215
216
# File 'lib/rubber/instance.rb', line 214

def vpc_cidr
  @vpc_cidr
end

#vpc_idObject

Returns the value of attribute vpc_id.



212
213
214
# File 'lib/rubber/instance.rb', line 212

def vpc_id
  @vpc_id
end

#zoneObject

Returns the value of attribute zone.



205
206
207
# File 'lib/rubber/instance.rb', line 205

def zone
  @zone
end

Class Method Details

.from_hash(hash) ⇒ Object



229
230
231
232
233
234
235
236
237
# File 'lib/rubber/instance.rb', line 229

def self.from_hash(hash)
  item = allocate
  hash.each do |k, v|
    sym = "@#{k}".to_sym
    v = v.collect {|r| RoleItem.parse(r) } if k == 'roles'
    item.instance_variable_set(sym, v)
  end
  return item
end

Instance Method Details

#<=>(rhs) ⇒ Object



252
253
254
# File 'lib/rubber/instance.rb', line 252

def <=>(rhs)
  name <=> rhs.name
end

#encode_with(coder) ⇒ Object



304
305
306
307
308
309
310
311
# File 'lib/rubber/instance.rb', line 304

def encode_with(coder)
  vars = instance_variables.map { |x| x.to_s }
  vars = vars - VARIABLES_TO_OMIT_IN_SERIALIZATION

  vars.each do |var|
    coder[var.gsub('@', '')] = eval(var)
  end
end

#full_nameObject



256
257
258
# File 'lib/rubber/instance.rb', line 256

def full_name
  "#{@name}.#{@domain}"
end

#linux?Boolean

Returns:

  • (Boolean)


274
275
276
# File 'lib/rubber/instance.rb', line 274

def linux?
  platform == Rubber::Platforms::LINUX
end

#mac?Boolean

Returns:

  • (Boolean)


278
279
280
# File 'lib/rubber/instance.rb', line 278

def mac?
  platform == Rubber::Platforms::MAC
end

#os_versionObject



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/rubber/instance.rb', line 286

def os_version
  @os_version ||= begin
    os_version_cmd = Rubber.config.os_version_cmd || UBUNTU_OS_VERSION_CMD

    if capistrano
      @os_version = capistrano.capture(os_version_cmd, :host => self.full_name).chomp
    else
      # If we can't SSH to the machine, we may be able to execute the command locally if this
      # instance item happens to refer to the same machine we're executing on.
      if Socket::gethostname == self.full_name
        @os_version = `#{os_version_cmd}`.chomp
      else
        raise "Unable to get os_version for #{self.full_name}"
      end
    end
  end
end

#role_namesObject



260
261
262
# File 'lib/rubber/instance.rb', line 260

def role_names
  roles.collect {|r| r.name}
end

#to_hashObject



239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/rubber/instance.rb', line 239

def to_hash
  hash = {}
  instance_variables.each do |iv|
    next if VARIABLES_TO_OMIT_IN_SERIALIZATION.include?(iv.to_s)

    name = iv.to_s.gsub(/^@/, '')
    value = instance_variable_get(iv)
    value = value.collect {|r| r.to_s } if name == 'roles'
    hash[name] = value
  end
  return hash
end

#windows?Boolean

Returns:

  • (Boolean)


282
283
284
# File 'lib/rubber/instance.rb', line 282

def windows?
  platform == Rubber::Platforms::WINDOWS
end