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

Inherits:
Base
  • Object
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, #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



120
121
122
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 120

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

#cloud_propertiesObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 90

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,
    "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



151
152
153
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 151

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



141
142
143
144
145
146
147
148
149
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 141

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



125
126
127
128
129
130
131
132
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 125

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


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

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)


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

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

#nova?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 69

def nova?
  !neutron?
end

#owned_imagesObject



134
135
136
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 134

def owned_images
  fog_compute.images
end

#persistent_diskObject



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

def persistent_disk
  settings.bosh.persistent_disk
end

#regionObject



107
108
109
110
111
112
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 107

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



86
87
88
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 86

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

#security_groupsObject



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

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
# File 'lib/bosh-bootstrap/microbosh_providers/openstack.rb', line 6

def to_hash
  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"]}}
  })
end

#using_external_gateway?Boolean

Returns:

  • (Boolean)


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

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