Class: Bosh::Providers::Clients::OpenStackProviderClient

Inherits:
FogProviderClient show all
Defined in:
lib/bosh/providers/clients/openstack_provider_client.rb

Instance Attribute Summary

Attributes inherited from FogProviderClient

#attributes, #fog_compute

Instance Method Summary collapse

Methods inherited from FogProviderClient

#cleanup_unused_ip_addresses, #create_key_pair, #create_security_group, #delete_key_pair_if_exists, #delete_servers_with_name, #delete_volumes_with_name, #extract_port_definition, #find_unused_public_ip_address, #initialize, #port_open?, #provision_or_reuse_public_ip_address, #set_resource_name

Constructor Details

This class inherits a constructor from Bosh::Providers::Clients::FogProviderClient

Instance Method Details

#associate_ip_address_with_server(ip_address, server) ⇒ Object



17
18
19
20
# File 'lib/bosh/providers/clients/openstack_provider_client.rb', line 17

def associate_ip_address_with_server(ip_address, server)
  address = fog_compute.addresses.find { |a| a.ip == ip_address }
  address.server = server
end

#authorize_port_range(sg, port_range, protocol, ip_range) ⇒ Object

Hook method for FogProviderClient#create_security_group



28
29
30
# File 'lib/bosh/providers/clients/openstack_provider_client.rb', line 28

def authorize_port_range(sg, port_range, protocol, ip_range)
  sg.create_security_group_rule(port_range.min, port_range.max, protocol, ip_range)
end

#create_and_attach_volume(name, disk_size, server, device) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/bosh/providers/clients/openstack_provider_client.rb', line 37

def create_and_attach_volume(name, disk_size, server, device)
  volume = fog_compute.volumes.create(:name => name,
                                      :description => "",
                                      :size => disk_size,
                                      :availability_zone => server.availability_zone)
  volume.wait_for { volume.status == 'available' }
  volume.attach(server.id, device)
  volume.wait_for { volume.status == 'in-use' }
end

#delete_security_group_and_servers(sg_name) ⇒ Object



47
48
49
# File 'lib/bosh/providers/clients/openstack_provider_client.rb', line 47

def delete_security_group_and_servers(sg_name)
  raise "not implemented yet"
end

#find_server_device(server, device) ⇒ Object



32
33
34
35
# File 'lib/bosh/providers/clients/openstack_provider_client.rb', line 32

def find_server_device(server, device)
  va = fog_compute.get_server_volumes(server.id).body['volumeAttachments']
  va.find { |v| v["device"] == device }
end

#ip_permissions(sg) ⇒ Object

Hook method for FogProviderClient#create_security_group



23
24
25
# File 'lib/bosh/providers/clients/openstack_provider_client.rb', line 23

def ip_permissions(sg)
  sg.rules
end

#openstack_constantsObject



62
63
64
# File 'lib/bosh/providers/clients/openstack_provider_client.rb', line 62

def openstack_constants
  Bosh::Providers::Constants::OpenStackConstants
end

#provision_public_ip_address(options = {}) ⇒ String

TODO nil if none available

Returns:

  • (String)

    provisions a new public IP address in target region



11
12
13
14
15
# File 'lib/bosh/providers/clients/openstack_provider_client.rb', line 11

def provision_public_ip_address(options={})
  address = fog_compute.addresses.create
  address.ip
  # TODO catch error and return nil
end

#setup_fog_connectionObject

Construct a Fog::Compute object Uses attributes which normally originates from settings.provider



53
54
55
56
57
58
59
60
# File 'lib/bosh/providers/clients/openstack_provider_client.rb', line 53

def setup_fog_connection
  configuration = Fog.symbolize_credentials(attributes.credentials)
  configuration[:provider] = "OpenStack"
  unless attributes.region == openstack_constants.no_region_code
    configuration[:openstack_region] = attributes.region
  end
  @fog_compute = Fog::Compute.new(configuration)
end