Class: Bosh::Director::DeploymentPlan::Planner
- Includes:
- Bosh::Director::DnsHelper, ValidationHelper
- Defined in:
- lib/bosh/director/deployment_plan/planner.rb
Constant Summary
Constants included from Bosh::Director::DnsHelper
Bosh::Director::DnsHelper::SOA, Bosh::Director::DnsHelper::TTL_4H, Bosh::Director::DnsHelper::TTL_5M
Instance Attribute Summary collapse
-
#canonical_name ⇒ String
readonly
Deployment canonical name (for DNS).
-
#compilation ⇒ Bosh::Director::DeploymentPlan::CompilationConfig
Resource pool and other configuration for compilation workers.
-
#dns_domain ⇒ Object
Returns the value of attribute dns_domain.
-
#job_rename ⇒ Object
readonly
Returns the value of attribute job_rename.
-
#jobs ⇒ Array<Bosh::Director::DeploymentPlan::Job>
readonly
All jobs in the deployment.
-
#model ⇒ Models::Deployment
readonly
Deployment DB model.
-
#name ⇒ String
readonly
Deployment name.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#recreate ⇒ Boolean
readonly
Indicates whether VMs should be recreated.
-
#unneeded_instances ⇒ Object
Returns the value of attribute unneeded_instances.
-
#unneeded_vms ⇒ Object
Returns the value of attribute unneeded_vms.
-
#update ⇒ Bosh::Director::DeploymentPlan::UpdateConfig
Default job update configuration.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_job(job) ⇒ Object
Adds a job by name.
-
#add_network(network) ⇒ Object
Adds a network by name.
-
#add_release(release) ⇒ Object
Adds a release by name.
-
#add_resource_pool(resource_pool) ⇒ Object
Adds a resource pool by name.
-
#bind_model ⇒ void
Looks up deployment model in DB or creates one if needed.
-
#delete_instance(instance) ⇒ Object
Adds instance to deletion queue.
-
#delete_vm(vm) ⇒ Object
Adds a VM to deletion queue.
-
#initialize(name, options = {}) ⇒ Planner
constructor
A new instance of Planner.
-
#job(name) ⇒ Bosh::Director::DeploymentPlan::Job
Returns a named job.
- #jobs_starting_on_deploy ⇒ Object
-
#network(name) ⇒ Bosh::Director::DeploymentPlan::Network
Returns a named network.
-
#networks ⇒ Array<Bosh::Director::DeploymentPlan::Network>
Returns all networks in a deployment plan.
-
#release(name) ⇒ Bosh::Director::DeploymentPlan::ReleaseVersion
Returns a named release.
-
#releases ⇒ Array<Bosh::Director::DeploymentPlan::ReleaseVersion>
Returns all releases in a deployment plan.
- #rename_in_progress? ⇒ Boolean
-
#resource_pool(name) ⇒ Bosh::Director::DeploymentPlan::ResourcePool
Returns a named resource pool spec.
-
#resource_pools ⇒ Array<Bosh::Director::DeploymentPlan::ResourcePool>
Returns all resource pools in a deployment plan.
-
#vms ⇒ Array<Models::Vm>
Returns a list of VMs in the deployment (according to DB).
Methods included from ValidationHelper
Methods included from Bosh::Director::DnsHelper
#add_default_dns_server, #canonical, #default_dns_server, #delete_dns_records, #delete_empty_domain, #dns_domain_name, #dns_ns_record, #dns_servers, #invalid_dns, #reverse_domain, #reverse_host, #update_dns_a_record, #update_dns_ptr_record
Constructor Details
#initialize(name, options = {}) ⇒ Planner
Returns a new instance of Planner.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 54 def initialize(name, = {}) raise ArgumentError, 'name must not be nil' unless name @name = name @model = nil @properties = {} @releases = {} @networks = {} @networks_canonical_name_index = Set.new @resource_pools = {} @jobs = [] @jobs_name_index = {} @jobs_canonical_name_index = Set.new @unneeded_vms = [] @unneeded_instances = [] @dns_domain = nil @job_rename = safe_property(, 'job_rename', :class => Hash, :default => {}) @recreate = !!['recreate'] end |
Instance Attribute Details
#canonical_name ⇒ String (readonly)
Returns Deployment canonical name (for DNS).
15 16 17 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 15 def canonical_name @canonical_name end |
#compilation ⇒ Bosh::Director::DeploymentPlan::CompilationConfig
Returns Resource pool and other configuration for compilation workers.
24 25 26 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 24 def compilation @compilation end |
#dns_domain ⇒ Object
Returns the value of attribute dns_domain.
36 37 38 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 36 def dns_domain @dns_domain end |
#job_rename ⇒ Object (readonly)
Returns the value of attribute job_rename.
38 39 40 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 38 def job_rename @job_rename end |
#jobs ⇒ Array<Bosh::Director::DeploymentPlan::Job> (readonly)
Returns All jobs in the deployment.
32 33 34 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 32 def jobs @jobs end |
#model ⇒ Models::Deployment (readonly)
Returns Deployment DB model.
18 19 20 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 18 def model @model end |
#name ⇒ String (readonly)
Returns Deployment name.
12 13 14 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 12 def name @name end |
#properties ⇒ Object
Returns the value of attribute properties.
20 21 22 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 20 def properties @properties end |
#recreate ⇒ Boolean (readonly)
Returns Indicates whether VMs should be recreated.
41 42 43 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 41 def recreate @recreate end |
#unneeded_instances ⇒ Object
Returns the value of attribute unneeded_instances.
34 35 36 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 34 def unneeded_instances @unneeded_instances end |
#unneeded_vms ⇒ Object
Returns the value of attribute unneeded_vms.
35 36 37 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 35 def unneeded_vms @unneeded_vms end |
#update ⇒ Bosh::Director::DeploymentPlan::UpdateConfig
Returns Default job update configuration.
28 29 30 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 28 def update @update end |
Class Method Details
.parse(manifest, event_log, options) ⇒ Bosh::Director::DeploymentPlan::Planner
49 50 51 52 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 49 def self.parse(manifest, event_log, ) parser = DeploymentSpecParser.new(event_log) parser.parse(manifest, ) end |
Instance Method Details
#add_job(job) ⇒ Object
Adds a job by name
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 206 def add_job(job) if rename_in_progress? && @job_rename['old_name'] == job.name raise DeploymentRenamedJobNameStillUsed, "Renamed job `#{job.name}' is still referenced in " + 'deployment manifest' end if @jobs_canonical_name_index.include?(job.canonical_name) raise DeploymentCanonicalJobNameTaken, "Invalid job name `#{job.name}', canonical name already taken" end @jobs << job @jobs_name_index[job.name] = job @jobs_canonical_name_index << job.canonical_name end |
#add_network(network) ⇒ Object
Adds a network by name
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 119 def add_network(network) if @networks_canonical_name_index.include?(network.canonical_name) raise DeploymentCanonicalNetworkNameTaken, "Invalid network name `#{network.name}', " + 'canonical name already taken' end @networks[network.name] = network @networks_canonical_name_index << network.canonical_name end |
#add_release(release) ⇒ Object
Adds a release by name
168 169 170 171 172 173 174 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 168 def add_release(release) if @releases.has_key?(release.name) raise DeploymentDuplicateReleaseName, "Duplicate release name `#{release.name}'" end @releases[release.name] = release end |
#add_resource_pool(resource_pool) ⇒ Object
Adds a resource pool by name
145 146 147 148 149 150 151 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 145 def add_resource_pool(resource_pool) if @resource_pools[resource_pool.name] raise DeploymentDuplicateResourcePoolName, "Duplicate resource pool name `#{resource_pool.name}'" end @resource_pools[resource_pool.name] = resource_pool end |
#bind_model ⇒ void
This method returns an undefined value.
Looks up deployment model in DB or creates one if needed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 86 def bind_model attrs = {:name => @name} Models::Deployment.db.transaction do deployment = Models::Deployment.find(attrs) # Canonical uniqueness is not enforced in the DB if deployment.nil? Models::Deployment.each do |other| if canonical(other.name) == canonical_name raise DeploymentCanonicalNameTaken, "Invalid deployment name `#{@name}', " + 'canonical name already taken' end end deployment = Models::Deployment.create(attrs) end @model = deployment end end |
#delete_instance(instance) ⇒ Object
Adds instance to deletion queue
196 197 198 199 200 201 202 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 196 def delete_instance(instance) if @jobs_name_index.has_key?(instance.job) @jobs_name_index[instance.job].unneeded_instances << instance else @unneeded_instances << instance end end |
#delete_vm(vm) ⇒ Object
Adds a VM to deletion queue
190 191 192 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 190 def delete_vm(vm) @unneeded_vms << vm end |
#job(name) ⇒ Bosh::Director::DeploymentPlan::Job
Returns a named job
226 227 228 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 226 def job(name) @jobs_name_index[name] end |
#jobs_starting_on_deploy ⇒ Object
230 231 232 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 230 def jobs_starting_on_deploy @jobs.select(&:starts_on_deploy?) end |
#network(name) ⇒ Bosh::Director::DeploymentPlan::Network
Returns a named network
139 140 141 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 139 def network(name) @networks[name] end |
#networks ⇒ Array<Bosh::Director::DeploymentPlan::Network>
Returns all networks in a deployment plan
132 133 134 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 132 def networks @networks.values end |
#release(name) ⇒ Bosh::Director::DeploymentPlan::ReleaseVersion
Returns a named release
184 185 186 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 184 def release(name) @releases[name] end |
#releases ⇒ Array<Bosh::Director::DeploymentPlan::ReleaseVersion>
Returns all releases in a deployment plan
178 179 180 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 178 def releases @releases.values end |
#rename_in_progress? ⇒ Boolean
234 235 236 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 234 def rename_in_progress? @job_rename['old_name'] && @job_rename['new_name'] end |
#resource_pool(name) ⇒ Bosh::Director::DeploymentPlan::ResourcePool
Returns a named resource pool spec
162 163 164 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 162 def resource_pool(name) @resource_pools[name] end |
#resource_pools ⇒ Array<Bosh::Director::DeploymentPlan::ResourcePool>
Returns all resource pools in a deployment plan
155 156 157 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 155 def resource_pools @resource_pools.values end |
#vms ⇒ Array<Models::Vm>
Returns a list of VMs in the deployment (according to DB)
110 111 112 113 114 115 |
# File 'lib/bosh/director/deployment_plan/planner.rb', line 110 def vms if @model.nil? raise DirectorError, "Can't get VMs list, deployment model is unbound" end @model.vms end |