Class: Bosh::Cloudfoundry::DeploymentFile
- Inherits:
-
Object
- Object
- Bosh::Cloudfoundry::DeploymentFile
- Includes:
- Bosh::Cli::Validation, FileUtils
- Defined in:
- lib/bosh/cloudfoundry/deployment_file.rb
Overview
Prior to deploying (creating or updating or deleting) a bosh release we need a deployment file. This is created with this class DeploymentFile
.
The deployment file is a product of:
-
a release version/CPI/size (
ReleaseVersionCpiSize
) which provides a template; and -
attributes (
DeploymentAttributes
) which populate the template
Instance Attribute Summary collapse
-
#bosh_status ⇒ Object
readonly
Returns the value of attribute bosh_status.
-
#deployment_attributes ⇒ Object
readonly
Returns the value of attribute deployment_attributes.
-
#release_version_cpi_size ⇒ Object
readonly
Returns the value of attribute release_version_cpi_size.
Class Method Summary collapse
-
.properties_key ⇒ Object
attributes are stored within deployment file at properties.cf.
-
.reconstruct_from_deployment_file(deployment_file_path, director_client, bosh_status) ⇒ Object
The trio of DeploymentFile, DeploymentAttributes & ReleaseVersionCpiSize can be reconstructed from a deployment file that was previously generated by this class.
Instance Method Summary collapse
- #biff ⇒ Object
- #biff_cmd(options = {}) ⇒ Object
- #bosh_cpi ⇒ Object
- #bosh_uuid ⇒ Object
-
#create_deployment_file ⇒ Object
Create an initial deployment file; upon which the CPI-specific template will be applied below Initial file will look like: — name: NAME director_uuid: 4ae3a0f0-70a5-4c0d-95f2-7fafaefe8b9e networks: {} properties: cf: dns: mycloud.com ip_addresses: [‘1.2.3.4’] deployment_size: medium security_group: cf persistent_disk: 4096.
-
#deploy(options = {}) ⇒ Object
Perform the create/update deployment described by this
DeploymentFile
. - #deployment_cmd(options = {}) ⇒ Object
- #deployment_file ⇒ Object
- #deployment_file_dir ⇒ Object
- #deployment_size ⇒ Object
-
#initialize(release_version_cpi_size, deployment_attributes, bosh_status) ⇒ DeploymentFile
constructor
A new instance of DeploymentFile.
- #perform(deploy_options = {}) ⇒ Object
- #prepare_environment ⇒ Object
- #quieten_output(&block) ⇒ Object
- #release_cmd(options = {}) ⇒ Object
- #release_name ⇒ Object
- #release_version_number ⇒ Object
- #template_file ⇒ Object
Constructor Details
#initialize(release_version_cpi_size, deployment_attributes, bosh_status) ⇒ DeploymentFile
Returns a new instance of DeploymentFile.
16 17 18 19 20 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 16 def initialize(release_version_cpi_size, deployment_attributes, bosh_status) @release_version_cpi_size = release_version_cpi_size @deployment_attributes = deployment_attributes @bosh_status = bosh_status end |
Instance Attribute Details
#bosh_status ⇒ Object (readonly)
Returns the value of attribute bosh_status.
14 15 16 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 14 def bosh_status @bosh_status end |
#deployment_attributes ⇒ Object (readonly)
Returns the value of attribute deployment_attributes.
13 14 15 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 13 def deployment_attributes @deployment_attributes end |
#release_version_cpi_size ⇒ Object (readonly)
Returns the value of attribute release_version_cpi_size.
12 13 14 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 12 def release_version_cpi_size @release_version_cpi_size end |
Class Method Details
.properties_key ⇒ Object
attributes are stored within deployment file at properties.cf
181 182 183 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 181 def self.properties_key "cf" end |
.reconstruct_from_deployment_file(deployment_file_path, director_client, bosh_status) ⇒ Object
The trio of DeploymentFile, DeploymentAttributes & ReleaseVersionCpiSize can be reconstructed from a deployment file that was previously generated by this class.
Specifically, it requires the deployment file to look like:
name: NAME releases:
- name: cf-release
version: 132
properties:
cf:
dns: mycloud.com
ip_addresses: ['1.2.3.4']
deployment_size: medium
security_group: cf
persistent_disk: 4096
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 98 def self.reconstruct_from_deployment_file(deployment_file_path, director_client, bosh_status) deployment_file = YAML.load_file(deployment_file_path) bosh_cpi = bosh_status["cpi"] release = deployment_file["releases"].find do |release| release["name"] == "cf" || release["name"] == "cf-release" end release_version = release["version"] release_version_cpi = ReleaseVersionCpi.new(release_version, bosh_cpi) attributes = deployment_file["properties"][properties_key] # convert string keys to symbol keys attributes = attributes.inject({}) do |mem, key_value| k, v = key_value; mem[k.to_sym] = v; mem end deployment_attributes = DeploymentAttributes.new(director_client, bosh_status, release_version_cpi, attributes) deployment_size = deployment_attributes.deployment_size release_version_cpi_size = ReleaseVersionCpiSize.new(release_version_cpi, deployment_size) self.new(release_version_cpi_size, deployment_attributes, bosh_status) end |
Instance Method Details
#biff ⇒ Object
161 162 163 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 161 def biff @biff_cmd ||= Bosh::Cli::Command::Biff.new end |
#biff_cmd(options = {}) ⇒ Object
165 166 167 168 169 170 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 165 def biff_cmd( = {}) .each do |key, value| biff.add_option key.to_sym, value end biff end |
#bosh_cpi ⇒ Object
176 177 178 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 176 def bosh_cpi bosh_status["cpi"] end |
#bosh_uuid ⇒ Object
172 173 174 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 172 def bosh_uuid bosh_status["uuid"] end |
#create_deployment_file ⇒ Object
Create an initial deployment file; upon which the CPI-specific template will be applied below Initial file will look like:
name: NAME director_uuid: 4ae3a0f0-70a5-4c0d-95f2-7fafaefe8b9e networks: {} properties:
cf:
dns: mycloud.com
ip_addresses: ['1.2.3.4']
deployment_size: medium
security_group: cf
persistent_disk: 4096
It is then merged with the corresponding template from release_version_cpi_size
.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 50 def create_deployment_file step("Creating deployment file #{deployment_file}", "Failed to create deployment file #{deployment_file}", :fatal) do File.open(deployment_file, "w") do |file| file << { "name" => deployment_attributes.name, "director_uuid" => bosh_uuid, "networks" => {}, "properties" => { self.class.properties_key => deployment_attributes.attributes_with_string_keys } }.to_yaml end quieten_output do deployment_cmd(non_interactive: true).set_current(deployment_file) biff_cmd(non_interactive: true).biff(template_file) end end rescue Bosh::Cli::ValidationHalted errors.each do |error| say error.make_red end end |
#deploy(options = {}) ⇒ Object
Perform the create/update deployment described by this DeploymentFile
76 77 78 79 80 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 76 def deploy(={}) # set current deployment to show the change in the output deployment_cmd.set_current(deployment_file) deployment_cmd(non_interactive: [:non_interactive]).perform end |
#deployment_cmd(options = {}) ⇒ Object
145 146 147 148 149 150 151 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 145 def deployment_cmd( = {}) cmd ||= Bosh::Cli::Command::Deployment.new .each do |key, value| cmd.add_option key.to_sym, value end cmd end |
#deployment_file ⇒ Object
133 134 135 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 133 def deployment_file File.join(deployment_file_dir, "#{deployment_attributes.name}.yml") end |
#deployment_file_dir ⇒ Object
137 138 139 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 137 def deployment_file_dir File.("deployments/cf") end |
#deployment_size ⇒ Object
129 130 131 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 129 def deployment_size deployment_attributes.deployment_size end |
#perform(deploy_options = {}) ⇒ Object
22 23 24 25 26 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 22 def perform(={}) prepare_environment create_deployment_file deploy() end |
#prepare_environment ⇒ Object
28 29 30 31 32 33 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 28 def prepare_environment step("Checking/creating #{deployment_file_dir} for deployment files", "Failed to create #{deployment_file_dir} for deployment files", :fatal) do mkdir_p(deployment_file_dir) end end |
#quieten_output(&block) ⇒ Object
185 186 187 188 189 190 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 185 def quieten_output(&block) stdout = Bosh::Cli::Config.output Bosh::Cli::Config.output = nil yield Bosh::Cli::Config.output = stdout end |
#release_cmd(options = {}) ⇒ Object
153 154 155 156 157 158 159 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 153 def release_cmd( = {}) cmd ||= Bosh::Cli::Command::Release.new .each do |key, value| cmd.add_option key.to_sym, value end cmd end |
#release_name ⇒ Object
121 122 123 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 121 def release_name release_version_cpi_size.release_name end |
#release_version_number ⇒ Object
125 126 127 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 125 def release_version_number release_version_cpi_size.release_version_number end |
#template_file ⇒ Object
141 142 143 |
# File 'lib/bosh/cloudfoundry/deployment_file.rb', line 141 def template_file release_version_cpi_size.template_file_path end |