Class: Bosh::OpenStackCloud::VipNetwork

Inherits:
Network
  • Object
show all
Defined in:
lib/cloud/openstack/vip_network.rb

Overview

Represents OpenStack vip network: where users sets VM’s IP (floating IP’s in OpenStack)

Constant Summary

Constants included from Helpers

Helpers::DEFAULT_RETRY_TIMEOUT, Helpers::DEFAULT_STATE_TIMEOUT, Helpers::MAX_RETRIES

Instance Method Summary collapse

Methods included from Helpers

#cloud_error, #parse_openstack_response, #wait_resource, #with_openstack

Constructor Details

#initialize(name, spec) ⇒ VipNetwork

Creates a new vip network

Parameters:

  • name (String)

    Network name

  • spec (Hash)

    Raw network spec



15
16
17
# File 'lib/cloud/openstack/vip_network.rb', line 15

def initialize(name, spec)
  super
end

Instance Method Details

#configure(openstack, server) ⇒ Object

Configures OpenStack vip network

Parameters:

  • openstack (Fog::Compute::OpenStack)

    Fog OpenStack Compute client

  • server (Fog::Compute::OpenStack::Server)

    OpenStack server to configure



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cloud/openstack/vip_network.rb', line 25

def configure(openstack, server)
  if @ip.nil?
    cloud_error("No IP provided for vip network `#{@name}'")
  end

  # Check if the OpenStack floating IP is allocated. If true, disassociate
  # it from any server before associating it to the new server
  with_openstack do
    address = openstack.addresses.find { |a| a.ip == @ip }
    if address
      unless address.instance_id.nil?
        @logger.info("Disassociating floating IP `#{@ip}' " \
                     "from server `#{address.instance_id}'")
        address.server = nil
      end

      @logger.info("Associating server `#{server.id}' " \
                   "with floating IP `#{@ip}'")
      address.server = server
    else
      cloud_error("Floating IP #{@ip} not allocated")
    end
  end
end