Class: Bosh::Bootstrap::MicroboshProviders::OpenStack

Inherits:
Base
  • Object
show all
Defined in:
lib/bosh-bootstrap/microbosh_providers/openstack.rb

Constant Summary

Constants inherited from Base

Base::DEFAULT_NTP_SERVERS

Instance Attribute Summary

Attributes inherited from Base

#fog_compute, #manifest_path, #settings

Instance Method Summary collapse

Methods inherited from Base

#create_microbosh_yml, #default_spec, #download_stemcell, #initialize, #jenkins_bucket, #microbosh_name, #ntp_servers, #private_key_path, #proxy, #proxy?, #public_ip, #public_ip?, #recent_stemcells, #salted_password, #stemcell_dir, #stemcell_path

Constructor Details

This class inherits a constructor from Bosh::Bootstrap::MicroboshProviders::Base

Instance Method Details

#boot_from_volumeObject



128
129
130
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 128

def boot_from_volume
  !!(settings.provider["options"] && settings.provider.options.boot_from_volume)
end

#cloud_propertiesObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 97

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,
    # TODO: Only ignore SSL verification if requested by user
    "connection_options"=>{
      "ssl_verify_peer"=>false
    },
    "boot_from_volume"=>boot_from_volume}
end

#discover_if_stemcell_image_already_uploadedObject



159
160
161
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 159

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”)

Returns:

  • (String)

    Any AMI imageID



149
150
151
152
153
154
155
156
157
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 149

def find_image_for_stemcell(name, version)
  image = owned_images.find do |image|
     = image.
     = .find { |m| m.key == "name" }
     = .find { |m| m.key == "version" }
     &&  && .value == name && .value == version
  end
  image.name if image
end

#latest_stemcellObject

Returns Bosh::Cli::PublicStemcell latest stemcell for openstack/trusty.

Returns:

  • Bosh::Cli::PublicStemcell latest stemcell for openstack/trusty



133
134
135
136
137
138
139
140
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 133

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_configurationObject

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


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 47

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

Returns:

  • (Boolean)


76
77
78
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 76

def neutron?
  settings.exists?("address.subnet_id")
end

#nova?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 72

def nova?
  !neutron?
end

#owned_imagesObject



142
143
144
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 142

def owned_images
  fog_compute.images
end

#persistent_diskObject



84
85
86
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 84

def persistent_disk
  settings.bosh.persistent_disk
end

#provider_state_timeoutObject



93
94
95
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 93

def provider_state_timeout
  settings.exists?("provider") && settings.provider.exists?("state_timeout") ? settings.provider.state_timeout : 300
end

#regionObject



115
116
117
118
119
120
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 115

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_propertiesObject

TODO Allow discovery of an appropriate OpenStack flavor with 2+CPUs, 3+G RAM



89
90
91
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 89

def resources_cloud_properties
  {"instance_type"=>"m1.medium"}
end

#security_groupsObject



122
123
124
125
126
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 122

def security_groups
  ["ssh",
   "dns-server",
   "bosh"]
end

#to_hashObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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}}}
  })
  if proxy?
    data["apply_spec"]["properties"]["director"]["env"] = proxy
  end
  data
end

#using_external_gateway?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 80

def using_external_gateway?
  settings.exists?("address.pool_name")
end