Class: Bosh::Bootstrap::MicroboshProviders::OpenStack
- Inherits:
-
Base
- Object
- Base
- Bosh::Bootstrap::MicroboshProviders::OpenStack
show all
- Defined in:
- lib/bosh-bootstrap/microbosh_providers/openstack.rb
Instance Attribute Summary
Attributes inherited from Base
#fog_compute, #manifest_path, #settings
Instance Method Summary
collapse
Methods inherited from Base
#create_microbosh_yml, #default_apply_spec, #download_stemcell, #initialize, #jenkins_bucket, #microbosh_name, #private_key_path, #proxy, #proxy?, #public_ip, #public_ip?, #recent_stemcells, #salted_password, #stemcell_dir, #stemcell_path
Instance Method Details
#boot_from_volume ⇒ Object
129
130
131
|
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 129
def boot_from_volume
!!(settings.provider["options"] && settings.provider.options.boot_from_volume)
end
|
#cloud_properties ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 98
def cloud_properties
{
"auth_url"=>settings.provider.credentials.openstack_auth_url,
"username"=>settings.provider.credentials.openstack_username,
"api_key"=>settings.provider.credentials.openstack_api_key,
"tenant"=>settings.provider.credentials.openstack_tenant,
"region"=>region,
"default_security_groups"=>security_groups,
"default_key_name"=>microbosh_name,
"state_timeout"=>provider_state_timeout,
"private_key"=>private_key_path,
"connection_options"=>{
"ssl_verify_peer"=>false
},
"boot_from_volume"=>boot_from_volume}
end
|
#discover_if_stemcell_image_already_uploaded ⇒ Object
160
161
162
|
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 160
def discover_if_stemcell_image_already_uploaded
find_image_for_stemcell(latest_stemcell.stemcell_name, latest_stemcell.version)
end
|
#find_image_for_stemcell(name, version) ⇒ String
e.g. “BOSH-14c85f35-3dd3-4200-af85-ada65216b2de” for given BOSH stemcell name/version Usage: find_ami_for_stemcell(“bosh-openstack-kvm-ubuntu-trusty-go_agent”, “2732”)
150
151
152
153
154
155
156
157
158
|
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 150
def find_image_for_stemcell(name, version)
image = owned_images.find do |image|
metadata = image.metadata
metadata_name = metadata.find { |m| m.key == "name" }
metadata_version = metadata.find { |m| m.key == "version" }
metadata_name && metadata_version && metadata_name.value == name && metadata_version.value == version
end
image.name if image
end
|
#latest_stemcell ⇒ Object
Returns Bosh::Cli::PublicStemcell latest stemcell for openstack/trusty.
134
135
136
137
138
139
140
141
|
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 134
def latest_stemcell
@latest_stemcell ||= begin
trusty_stemcells = recent_stemcells.select do |s|
s.name =~ /openstack/ && s.name =~ /trusty/
end
trusty_stemcells.sort {|s1, s2| s2.version <=> s1.version}.first
end
end
|
#network_configuration ⇒ Object
For Nova/Floating IP:
network:
type: dynamic
vip: 1.2.3.4
For Neutron/Floating IP:
network:
type: dynamic
vip: 1.2.3.4 # public floating IP
cloud_properties:
net_id: XXX # internal subnet
For Neutron/Internal IP:
network:
type: manual
vip: 10.10.10.3 # an IP in subnets range
cloud_properties:
net_id: XXX # internal subnet
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 48
def network_configuration
if nova?
{
"type"=>"dynamic",
"vip"=>public_ip
}
elsif neutron? && using_external_gateway?
{
"type"=>"dynamic",
"vip"=>public_ip,
"cloud_properties" => {
"net_id" => settings.address.subnet_id
}
}
else
{
"type"=>"manual",
"ip"=>public_ip,
"cloud_properties" => {
"net_id" => settings.address.subnet_id
}
}
end
end
|
#neutron? ⇒ Boolean
77
78
79
|
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 77
def neutron?
settings.exists?("address.subnet_id")
end
|
#nova? ⇒ Boolean
73
74
75
|
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 73
def nova?
!neutron?
end
|
#owned_images ⇒ Object
143
144
145
|
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 143
def owned_images
fog_compute.images
end
|
#persistent_disk ⇒ Object
85
86
87
|
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 85
def persistent_disk
settings.bosh.persistent_disk
end
|
#provider_state_timeout ⇒ Object
94
95
96
|
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 94
def provider_state_timeout
settings.exists?("provider") && settings.provider.exists?("state_timeout") ? settings.provider.state_timeout : 300
end
|
#region ⇒ Object
116
117
118
119
120
121
|
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 116
def region
if settings.provider.credentials.openstack_region && !settings.provider.credentials.openstack_region.empty?
return settings.provider.credentials.openstack_region
end
nil
end
|
#resources_cloud_properties ⇒ Object
TODO Allow discovery of an appropriate OpenStack flavor with 2+CPUs, 3+G RAM
90
91
92
|
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 90
def resources_cloud_properties
{"instance_type"=>"m1.medium"}
end
|
#security_groups ⇒ Object
123
124
125
126
127
|
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 123
def security_groups
["ssh",
"dns-server",
"bosh"]
end
|
#to_hash ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 6
def to_hash
data = super.deep_merge({
"network"=>network_configuration,
"resources"=>
{"persistent_disk"=>persistent_disk,
"cloud_properties"=>resources_cloud_properties},
"cloud"=>
{"plugin"=>"openstack",
"properties"=>
{"openstack"=>cloud_properties}},
"apply_spec"=>
{"agent"=>
{"blobstore"=>{"address"=>public_ip},
"nats"=>{"address"=>public_ip}},
"properties"=>
{"director"=>
{"max_threads"=>3},
"hm"=>{"resurrector_enabled" => true},
"ntp"=>["0.north-america.pool.ntp.org","1.north-america.pool.ntp.org"]}}
})
if proxy?
data["apply_spec"]["properties"]["director"]["env"] = proxy
end
data
end
|
#using_external_gateway? ⇒ Boolean
81
82
83
|
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 81
def using_external_gateway?
settings.exists?("address.pool_name")
end
|