Class: Bosh::Deployer::InstanceManager::Openstack
- Inherits:
-
Bosh::Deployer::InstanceManager
- Object
- Bosh::Deployer::InstanceManager
- Bosh::Deployer::InstanceManager::Openstack
- Defined in:
- lib/bosh/deployer/instance_manager/openstack.rb
Constant Summary
Constants inherited from Bosh::Deployer::InstanceManager
Constants included from Helpers
Instance Attribute Summary
Attributes inherited from Bosh::Deployer::InstanceManager
Instance Method Summary collapse
-
#configure ⇒ Object
rubocop:disable MethodLength.
- #discover_bosh_ip ⇒ Object
-
#disk_size(cid) ⇒ Integer
Size in MiB.
- #persistent_disk_changed? ⇒ Boolean
- #service_ip ⇒ Object
-
#start ⇒ Object
rubocop:disable MethodLength.
-
#stop ⇒ Object
rubocop:enable MethodLength.
- #update_spec(spec) ⇒ Object
Methods inherited from Bosh::Deployer::InstanceManager
#agent, #apply, #attach_disk, #attach_missing_disk, #check_dependencies, #check_persistent_disk, #cloud, create, #create, #create_deployment, #create_disk, #create_stemcell, #create_vm, #delete_deployment, #delete_disk, #destroy, #detach_disk, #disk_info, #disk_model, #exists?, #initialize, #instance_model, #logger, #migrate_disk, #mount_disk, #step, #unmount_disk, #update, #update_deployment, #update_persistent_disk, #update_vm_metadata, #with_lifecycle
Methods included from Helpers
#close_ssh_sessions, #cloud_plugin, #dig_hash, #is_tgz?, #process_exists?, #remote_tunnel, #socket_readable?, #strip_relative_path
Constructor Details
This class inherits a constructor from Bosh::Deployer::InstanceManager
Instance Method Details
#configure ⇒ Object
rubocop:disable MethodLength
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bosh/deployer/instance_manager/openstack.rb', line 18 def configure properties = Config.['properties'] @ssh_user = properties['openstack']['ssh_user'] @ssh_port = properties['openstack']['ssh_port'] || 22 @ssh_wait = properties['openstack']['ssh_wait'] || 60 key = properties['openstack']['private_key'] err 'Missing properties.openstack.private_key' unless key @ssh_key = File.(key) unless File.exists?(@ssh_key) err "properties.openstack.private_key '#{key}' does not exist" end uri = URI.parse(properties['registry']['endpoint']) user, password = uri.userinfo.split(':', 2) @registry_port = uri.port @registry_db = Tempfile.new('bosh_registry_db') @registry_connection_settings = { 'adapter' => 'sqlite', 'database' => @registry_db.path } registry_config = { 'logfile' => './bosh-registry.log', 'http' => { 'port' => uri.port, 'user' => user, 'password' => password }, 'db' => @registry_connection_settings, 'cloud' => { 'plugin' => 'openstack', 'openstack' => properties['openstack'] } } @registry_config = Tempfile.new('bosh_registry_yml') @registry_config.write(Psych.dump(registry_config)) @registry_config.close end |
#discover_bosh_ip ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/bosh/deployer/instance_manager/openstack.rb', line 122 def discover_bosh_ip if state.vm_cid floating_ip = cloud.openstack.servers.get(state.vm_cid).floating_ip_address ip = floating_ip || service_ip if ip != Config.bosh_ip Config.bosh_ip = ip logger.info("discovered bosh ip=#{Config.bosh_ip}") end end super end |
#disk_size(cid) ⇒ Integer
Returns size in MiB.
141 142 143 144 |
# File 'lib/bosh/deployer/instance_manager/openstack.rb', line 141 def disk_size(cid) # OpenStack stores disk size in GiB but we work with MiB cloud.openstack.volumes.get(cid).size * 1024 end |
#persistent_disk_changed? ⇒ Boolean
146 147 148 149 150 151 152 153 |
# File 'lib/bosh/deployer/instance_manager/openstack.rb', line 146 def persistent_disk_changed? # since OpenStack stores disk size in GiB and we use MiB there # is a risk of conversion errors which lead to an unnecessary # disk migration, so we need to do a double conversion # here to avoid that requested = (Config.resources['persistent_disk'] / 1024.0).ceil * 1024 requested != disk_size(state.disk_cid) end |
#service_ip ⇒ Object
136 137 138 |
# File 'lib/bosh/deployer/instance_manager/openstack.rb', line 136 def service_ip cloud.openstack.servers.get(state.vm_cid).private_ip_address end |
#start ⇒ Object
rubocop:disable MethodLength
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/bosh/deployer/instance_manager/openstack.rb', line 62 def start configure Sequel.connect(@registry_connection_settings) do |db| migrate(db) instances = @deployments['registry_instances'] db[:registry_instances].insert_multiple(instances) if instances end unless has_bosh_registry? err 'bosh-registry command not found - ' + "run 'gem install bosh-registry'" end cmd = "bosh-registry -c #{@registry_config.path}" @registry_pid = spawn(cmd) 5.times do sleep 0.5 if Process.waitpid(@registry_pid, Process::WNOHANG) err "`#{cmd}` failed, exit status=#{$?.exitstatus}" end end timeout_time = Time.now.to_f + (60 * 5) http_client = HTTPClient.new begin http_client.head("http://127.0.0.1:#{@registry_port}") sleep 0.5 rescue URI::Error, SocketError, Errno::ECONNREFUSED, HTTPClient::ReceiveTimeoutError => e if timeout_time - Time.now.to_f > 0 retry else err "Cannot access bosh-registry: #{e.}" end end logger.info("bosh-registry is ready on port #{@registry_port}") ensure @registry_config.unlink if @registry_config end |
#stop ⇒ Object
rubocop:enable MethodLength
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/bosh/deployer/instance_manager/openstack.rb', line 106 def stop if @registry_pid && process_exists?(@registry_pid) Process.kill('INT', @registry_pid) Process.waitpid(@registry_pid) end return unless @registry_connection_settings Sequel.connect(@registry_connection_settings) do |db| @deployments['registry_instances'] = db[:registry_instances].map { |row| row } end save_state @registry_db.unlink if @registry_db end |
#update_spec(spec) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/bosh/deployer/instance_manager/openstack.rb', line 4 def update_spec(spec) properties = spec.properties properties['openstack'] = Config.spec_properties['openstack'] || Config.['properties']['openstack'].dup properties['openstack']['registry'] = Config.['properties']['registry'] properties['openstack']['stemcell'] = Config.['properties']['stemcell'] spec.delete('networks') end |