Parent

Blimpy::Boxes::OpenStack

Attributes

floating_ip[RW]
key_name[RW]

Public Class Methods

fog_server_for_instance(id, blimpdata) click to toggle source
# File lib/blimpy/boxes/openstack.rb, line 6
def self.fog_server_for_instance(id, blimpdata)
  region = blimpdata[:region]
  fog = Fog::Compute.new(:provider => 'OpenStack', :openstack_tenant => region)
  fog.servers.get(id)
end
new(server=nil) click to toggle source
# File lib/blimpy/boxes/openstack.rb, line 27
def initialize(server=nil)
  super(server)
  @username = 'ubuntu'
  @flavor = 'm1.tiny'
  @group = 'default'
  @key_name = nil
  @floating_ip = nil
end

Public Instance Methods

allocate_ip() click to toggle source
# File lib/blimpy/boxes/openstack.rb, line 98
def allocate_ip
  response = fog.allocate_address
  unless response.status == 200
    raise Blimpy::UnknownError, "Blimpy was unable to allocate a floating IP address; #{response.inspect}"
  end

  details = response.body['floating_ip']
  @floating_ip = FloatingIp.new(details['ip'], details['id'])
end
associate_ip() click to toggle source
# File lib/blimpy/boxes/openstack.rb, line 108
def associate_ip
  if floating_ip.nil?
    raise Blimpy::UnknownError, "Blimpy cannot associate a floating IP until it's been allocated properly!"
  end
  response = fog.associate_address(@server.id, floating_ip.address)

  unless response.status == 202
    raise Blimpy::UnknownError, "Blimpy failed to associate the IP somehow #{response.inspect}"
  end
end
deallocate_ip() click to toggle source
# File lib/blimpy/boxes/openstack.rb, line 131
def deallocate_ip
  fog.release_address(floating_ip.id)
end
disassociate_ip() click to toggle source
# File lib/blimpy/boxes/openstack.rb, line 127
def disassociate_ip
  fog.disassociate_address(@server.id, floating_ip.address)
end
dns() click to toggle source
# File lib/blimpy/boxes/openstack.rb, line 55
def dns
  if floating_ip.nil?
    'unavailable'
  else
    floating_ip.address
  end
end
flavor_id(name) click to toggle source
# File lib/blimpy/boxes/openstack.rb, line 87
def flavor_id(name)
  flavors.each do |flavor|
    return flavor.id if flavor.name == name
  end
  nil
end
flavors() click to toggle source
# File lib/blimpy/boxes/openstack.rb, line 83
def flavors
  @flavors ||= fog.flavors
end
fog() click to toggle source
# File lib/blimpy/boxes/openstack.rb, line 77
def fog
  @fog ||= begin
    Fog::Compute.new(:provider => 'openstack', :openstack_tenant => @region)
  end
end
internal_dns() click to toggle source
# File lib/blimpy/boxes/openstack.rb, line 63
def internal_dns
  'unavailable'
end
ports=(new_pors) click to toggle source
# File lib/blimpy/boxes/openstack.rb, line 36
def ports=(new_pors)
  raise Blimpy::UnsupportedFeatureException, 'Opening arbitrary ports in OpenStack is currently not supported'
end
postdestroy() click to toggle source
# File lib/blimpy/boxes/openstack.rb, line 123
def postdestroy
  deallocate_ip unless floating_ip.nil?
end
predestroy() click to toggle source
# File lib/blimpy/boxes/openstack.rb, line 119
def predestroy
  disassociate_ip unless floating_ip.nil?
end
prestart() click to toggle source
# File lib/blimpy/boxes/openstack.rb, line 94
def prestart
  allocate_ip
end
serializable_attributes() click to toggle source
# File lib/blimpy/boxes/openstack.rb, line 51
def serializable_attributes
  super + [:floating_ip]
end
validate!() click to toggle source
# File lib/blimpy/boxes/openstack.rb, line 67
def validate!
  if @region.nil?
    raise Blimpy::BoxValidationError, "Cannot spin up machine without a set region"
  end

  if flavor_id(@flavor).nil?
    raise Blimpy::BoxValidationError, "'#{@flavor}' is not a valid OpenStack tenant name"
  end
end
wait_for_state(until_state, &block) click to toggle source
# File lib/blimpy/boxes/openstack.rb, line 40
def wait_for_state(until_state, &block)
  until @server.ready?
    sleep 1
    @server.reload
  end
  # OpenStack doesn't seem to like it if you try to associate the IP
  # address too early, but will properly associate it after the machine is
  # ready
  associate_ip
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.