Class: Inception::Providers::Clients::OpenStackProviderClient

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

Instance Attribute Summary

Attributes inherited from FogProviderClient

#attributes, #fog_compute

Instance Method Summary collapse

Methods inherited from FogProviderClient

#bootstrap, #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, #flavor_id, #initialize, #port_open?, #provision_or_reuse_public_ip_address, #set_resource_name

Constructor Details

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

Instance Method Details

#associate_ip_address_with_server(ip_address, server) ⇒ Object


17
18
19
20
# File 'lib/inception/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/inception/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/inception/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

#find_server_device(server, device) ⇒ Object


32
33
34
35
# File 'lib/inception/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

#fog_attributes(inception_server) ⇒ Object


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/inception/providers/clients/openstack_provider_client.rb', line 59

def fog_attributes(inception_server)
  # :name => "Inception VM",
  # :key_name => key_name,
  # :private_key_path => inception_vm_private_key_path,
  # :flavor_ref => inception_flavor.id,
  # :image_ref => inception_image.id,
  # :security_groups => [settings["inception"]["security_group"]],
  # :username => username
  {
    name: inception_server.server_name,
    key_name: inception_server.key_name,
    private_key_path: inception_server.private_key_path,
    image_ref: inception_server.image_id,
    flavor_ref: flavor_id(inception_server.flavor),
    security_groups: inception_server.security_groups,
    public_key: inception_server.public_key,
    public_ip_address: inception_server.ip_address,
    bits: 64,
    username: "ubuntu",
  }
end

#image_idObject


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

def image_id
  raise "Not yet implemented"
end

#ip_permissions(sg) ⇒ Object

Hook method for FogProviderClient#create_security_group


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

def ip_permissions(sg)
  sg.rules
end

#openstack_constantsObject


81
82
83
# File 'lib/inception/providers/clients/openstack_provider_client.rb', line 81

def openstack_constants
  Inception::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/inception/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
# File 'lib/inception/providers/clients/openstack_provider_client.rb', line 53

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