Class: Bosh::Bootstrap::Stages::MicroBoshDeploy
- Inherits:
-
Object
- Object
- Bosh::Bootstrap::Stages::MicroBoshDeploy
- Defined in:
- lib/bosh-bootstrap/stages/stage_micro_bosh_deploy.rb
Instance Attribute Summary collapse
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
-
#commands ⇒ Object
TODO “aws_us_east_1” should come from settings.bosh_name.
-
#initialize(settings) ⇒ MicroBoshDeploy
constructor
A new instance of MicroBoshDeploy.
- #micro_bosh_manifest ⇒ Object
-
#script(segment_name, variables = {}) ⇒ Object
Loads local script If
variables
, then injects KEY=VALUE environment variables into bash scripts. - #stage_name ⇒ Object
Constructor Details
#initialize(settings) ⇒ MicroBoshDeploy
Returns a new instance of MicroBoshDeploy.
7 8 9 |
# File 'lib/bosh-bootstrap/stages/stage_micro_bosh_deploy.rb', line 7 def initialize(settings) @settings = settings end |
Instance Attribute Details
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
5 6 7 |
# File 'lib/bosh-bootstrap/stages/stage_micro_bosh_deploy.rb', line 5 def settings @settings end |
Instance Method Details
#commands ⇒ Object
TODO “aws_us_east_1” should come from settings.bosh_name
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bosh-bootstrap/stages/stage_micro_bosh_deploy.rb', line 12 def commands settings[:bosh_name] ||= "unnamed_bosh" @commands ||= Bosh::Bootstrap::Commander::Commands.new do |server| server.upload_file \ "/var/vcap/store/microboshes/deployments/#{settings.bosh_name}/micro_bosh.yml", micro_bosh_manifest server.install "key pair for user", script("install_key_pair_for_user", "PRIVATE_KEY" => settings.bosh_key_pair.private_key, "KEY_PAIR_NAME" => settings.bosh_key_pair.name) server.deploy "micro bosh", script("bosh_micro_deploy", "BOSH_NAME" => settings.bosh_name, "MICRO_BOSH_STEMCELL_NAME" => settings.micro_bosh_stemcell_name, "MICRO_BOSH_STEMCELL_TYPE" => settings.micro_bosh_stemcell_type, "BOSH_HOST" => settings.bosh.ip_address, "BOSH_USERNAME" => settings.bosh_username, "BOSH_PASSWORD" => settings.bosh_password) end end |
#micro_bosh_manifest ⇒ Object
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/bosh-bootstrap/stages/stage_micro_bosh_deploy.rb', line 63 def micro_bosh_manifest name = settings.bosh_name salted_password = settings.bosh.salted_password ipaddress = settings.bosh.ip_address persistent_disk = settings.bosh.persistent_disk resources_cloud_properties = settings.bosh_resources_cloud_properties cloud_plugin = settings.bosh_provider # aws: # access_key_id: #{access_key} # secret_access_key: #{secret_key} # ec2_endpoint: ec2.#{region}.amazonaws.com # default_key_name: #{key_name} # default_security_groups: ["#{security_group}"] # ec2_private_key: /home/vcap/.ssh/#{key_name}.pem cloud_properties = settings.bosh_cloud_properties manifest = { "name" => name, "env" => { "bosh" => {"password" => salted_password}}, "logging" => { "level" => "DEBUG" }, "network" => { "type" => "dynamic", "vip" => ipaddress }, "resources" => { "persistent_disk" => persistent_disk, "cloud_properties" => resources_cloud_properties }, "cloud" => { "plugin" => cloud_plugin, "properties" => cloud_properties }, "apply_spec" => { "agent" => { "blobstore" => { "address" => ipaddress }, "nats" => { "address" => ipaddress } }, "properties" => { "#{cloud_plugin.downcase}_registry" => { "address" => ipaddress } } } } # Openstack settings if cloud_plugin.downcase == "openstack" # Delete OpenStack registry IP address manifest["apply_spec"]["properties"].delete("openstack_registry") # OpenStack private network label if settings.network_label manifest["network"]["label"] = settings.network_label end end manifest.to_yaml.gsub(/\s![^ ]+$/, '') # /![^ ]+\s/ removes object notation from the YAML which appears to cause problems when being interpretted by the # Ruby running on the inception vm. A before and after example would look like; # # properties: !map:Settingslogic # openstack: !map:Settingslogic # username: admin # api_key: xxxxxxxxxxxxxxxxxxx # tenant: CloudFoundry # auth_url: http://192.168.1.2:5000/v2.0/tokens # default_security_groups: # - !str:HighLine::String microbosh-openstack # default_key_name: !str:HighLine::String microbosh-openstack # private_key: /home/vcap/.ssh/microbosh-openstack.pem # # The regex strips the !Module::ClassName notation out and the result looks as it should # # properties: # openstack: # username: admin # api_key: xxxxxxxxxxxxxxxxxxx # tenant: CloudFoundry # auth_url: http://192.168.1.2:5000/v2.0/tokens # default_security_groups: # - microbosh-openstack # default_key_name: microbosh-openstack # private_key: /home/vcap/.ssh/microbosh-openstack.pem end |
#script(segment_name, variables = {}) ⇒ Object
Loads local script If variables
, then injects KEY=VALUE environment variables into bash scripts.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/bosh-bootstrap/stages/stage_micro_bosh_deploy.rb', line 39 def script(segment_name, variables={}) path = File.("../#{stage_name}/#{segment_name}", __FILE__) if File.exist?(path) script = File.read(path) if variables.keys.size > 0 env_variables = variables.reject { |var| var.is_a?(Symbol) } # inject variables into script if its bash script inline_variables = "#!/usr/bin/env bash\n\n" env_variables.each { |name, value| inline_variables << "#{name}='#{value}'\n" } script.gsub!("#!/usr/bin/env bash", inline_variables) # inject variables into script if its ruby script inline_variables = "#!/usr/bin/env ruby\n\n" env_variables.each { |name, value| inline_variables << "ENV['#{name}'] = '#{value}'\n" } script.gsub!("#!/usr/bin/env ruby", inline_variables) end script else Thor::Base.shell.new.say_status "error", "Missing script lib/bosh-bootstrap/stages/#{stage_name}/#{segment_name}", :red exit 1 end end |
#stage_name ⇒ Object
32 33 34 |
# File 'lib/bosh-bootstrap/stages/stage_micro_bosh_deploy.rb', line 32 def stage_name "stage_micro_bosh_deploy" end |