bosh-director 1.5.0.pre.1113
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +34 -0
- data/bin/bosh-director +36 -0
- data/bin/bosh-director-console +84 -0
- data/bin/bosh-director-drain-workers +42 -0
- data/bin/bosh-director-migrate +58 -0
- data/bin/bosh-director-scheduler +27 -0
- data/bin/bosh-director-worker +76 -0
- data/db/migrations/README +1 -0
- data/db/migrations/director/20110209010747_initial.rb +118 -0
- data/db/migrations/director/20110406055800_add_task_user.rb +9 -0
- data/db/migrations/director/20110518225809_remove_cid_constrain.rb +13 -0
- data/db/migrations/director/20110617211923_add_deployments_release_versions.rb +32 -0
- data/db/migrations/director/20110622212607_add_task_checkpoint_timestamp.rb +9 -0
- data/db/migrations/director/20110628023039_add_state_to_instances.rb +21 -0
- data/db/migrations/director/20110709012332_add_disk_size_to_instances.rb +9 -0
- data/db/migrations/director/20110906183441_add_log_bundles.rb +11 -0
- data/db/migrations/director/20110907194830_add_logs_json_to_templates.rb +9 -0
- data/db/migrations/director/20110915205610_add_persistent_disks.rb +51 -0
- data/db/migrations/director/20111005180929_add_properties.rb +14 -0
- data/db/migrations/director/20111110024617_add_deployment_problems.rb +24 -0
- data/db/migrations/director/20111216214145_recreate_support_for_vms.rb +9 -0
- data/db/migrations/director/20120102084027_add_credentials_to_vms.rb +7 -0
- data/db/migrations/director/20120427235217_allow_multiple_releases_per_deployment.rb +36 -0
- data/db/migrations/director/20120524175805_add_task_type.rb +44 -0
- data/db/migrations/director/20120614001930_delete_redundant_deployment_release_relation.rb +34 -0
- data/db/migrations/director/20120822004528_add_fingerprint_to_templates_and_packages.rb +17 -0
- data/db/migrations/director/20120830191244_add_properties_to_templates.rb +9 -0
- data/db/migrations/director/20121106190739_persist_vm_env.rb +9 -0
- data/db/migrations/director/20130222232131_add_sha1_to_stemcells.rb +9 -0
- data/db/migrations/director/20130312211407_add_commit_hash_to_release_versions.rb +19 -0
- data/db/migrations/director/20130409235338_snapshot.rb +15 -0
- data/db/migrations/director/20130530164918_add_paused_flag_to_instance.rb +14 -0
- data/db/migrations/director/20130531172604_add_director_attributes.rb +13 -0
- data/db/migrations/dns/20120123234908_initial.rb +27 -0
- data/lib/bosh/director.rb +133 -0
- data/lib/bosh/director/agent_client.rb +78 -0
- data/lib/bosh/director/api.rb +29 -0
- data/lib/bosh/director/api/api_helper.rb +81 -0
- data/lib/bosh/director/api/backup_manager.rb +15 -0
- data/lib/bosh/director/api/controller.rb +639 -0
- data/lib/bosh/director/api/controller_helpers.rb +34 -0
- data/lib/bosh/director/api/deployment_lookup.rb +13 -0
- data/lib/bosh/director/api/deployment_manager.rb +60 -0
- data/lib/bosh/director/api/http_constants.rb +16 -0
- data/lib/bosh/director/api/instance_lookup.rb +44 -0
- data/lib/bosh/director/api/instance_manager.rb +63 -0
- data/lib/bosh/director/api/problem_manager.rb +40 -0
- data/lib/bosh/director/api/property_manager.rb +69 -0
- data/lib/bosh/director/api/release_manager.rb +59 -0
- data/lib/bosh/director/api/resource_manager.rb +69 -0
- data/lib/bosh/director/api/resurrector_manager.rb +15 -0
- data/lib/bosh/director/api/snapshot_manager.rb +94 -0
- data/lib/bosh/director/api/stemcell_manager.rb +50 -0
- data/lib/bosh/director/api/task_helper.rb +46 -0
- data/lib/bosh/director/api/task_manager.rb +64 -0
- data/lib/bosh/director/api/user_manager.rb +72 -0
- data/lib/bosh/director/api/vm_state_manager.rb +11 -0
- data/lib/bosh/director/app.rb +35 -0
- data/lib/bosh/director/blob_util.rb +87 -0
- data/lib/bosh/director/blobstores.rb +29 -0
- data/lib/bosh/director/client.rb +156 -0
- data/lib/bosh/director/cloudcheck_helper.rb +204 -0
- data/lib/bosh/director/compile_task.rb +157 -0
- data/lib/bosh/director/config.rb +370 -0
- data/lib/bosh/director/configuration_hasher.rb +114 -0
- data/lib/bosh/director/cycle_helper.rb +36 -0
- data/lib/bosh/director/db_backup.rb +22 -0
- data/lib/bosh/director/db_backup/adapter.rb +3 -0
- data/lib/bosh/director/db_backup/adapter/mysql2.rb +27 -0
- data/lib/bosh/director/db_backup/adapter/postgres.rb +36 -0
- data/lib/bosh/director/db_backup/adapter/sqlite.rb +17 -0
- data/lib/bosh/director/db_backup/error.rb +10 -0
- data/lib/bosh/director/deployment_plan.rb +26 -0
- data/lib/bosh/director/deployment_plan/assembler.rb +430 -0
- data/lib/bosh/director/deployment_plan/compilation_config.rb +54 -0
- data/lib/bosh/director/deployment_plan/compiled_package.rb +35 -0
- data/lib/bosh/director/deployment_plan/dynamic_network.rb +91 -0
- data/lib/bosh/director/deployment_plan/idle_vm.rb +109 -0
- data/lib/bosh/director/deployment_plan/instance.rb +413 -0
- data/lib/bosh/director/deployment_plan/job.rb +470 -0
- data/lib/bosh/director/deployment_plan/manual_network.rb +137 -0
- data/lib/bosh/director/deployment_plan/network.rb +74 -0
- data/lib/bosh/director/deployment_plan/network_subnet.rb +167 -0
- data/lib/bosh/director/deployment_plan/planner.rb +288 -0
- data/lib/bosh/director/deployment_plan/preparer.rb +52 -0
- data/lib/bosh/director/deployment_plan/release.rb +126 -0
- data/lib/bosh/director/deployment_plan/resource_pool.rb +143 -0
- data/lib/bosh/director/deployment_plan/resource_pools.rb +68 -0
- data/lib/bosh/director/deployment_plan/stemcell.rb +56 -0
- data/lib/bosh/director/deployment_plan/template.rb +94 -0
- data/lib/bosh/director/deployment_plan/update_config.rb +80 -0
- data/lib/bosh/director/deployment_plan/updater.rb +55 -0
- data/lib/bosh/director/deployment_plan/vip_network.rb +79 -0
- data/lib/bosh/director/dns_helper.rb +204 -0
- data/lib/bosh/director/download_helper.rb +44 -0
- data/lib/bosh/director/duration.rb +36 -0
- data/lib/bosh/director/encryption_helper.rb +10 -0
- data/lib/bosh/director/errors.rb +198 -0
- data/lib/bosh/director/event_log.rb +136 -0
- data/lib/bosh/director/ext.rb +64 -0
- data/lib/bosh/director/hash_string_vals.rb +13 -0
- data/lib/bosh/director/instance_deleter.rb +109 -0
- data/lib/bosh/director/instance_updater.rb +506 -0
- data/lib/bosh/director/ip_util.rb +67 -0
- data/lib/bosh/director/job_queue.rb +16 -0
- data/lib/bosh/director/job_runner.rb +162 -0
- data/lib/bosh/director/job_updater.rb +121 -0
- data/lib/bosh/director/jobs/backup.rb +86 -0
- data/lib/bosh/director/jobs/base_job.rb +66 -0
- data/lib/bosh/director/jobs/cloud_check/apply_resolutions.rb +46 -0
- data/lib/bosh/director/jobs/cloud_check/scan.rb +38 -0
- data/lib/bosh/director/jobs/cloud_check/scan_and_fix.rb +73 -0
- data/lib/bosh/director/jobs/create_snapshot.rb +23 -0
- data/lib/bosh/director/jobs/delete_deployment.rb +183 -0
- data/lib/bosh/director/jobs/delete_deployment_snapshots.rb +34 -0
- data/lib/bosh/director/jobs/delete_release.rb +219 -0
- data/lib/bosh/director/jobs/delete_snapshots.rb +23 -0
- data/lib/bosh/director/jobs/delete_stemcell.rb +102 -0
- data/lib/bosh/director/jobs/fetch_logs.rb +99 -0
- data/lib/bosh/director/jobs/scheduled_backup.rb +38 -0
- data/lib/bosh/director/jobs/snapshot_deployment.rb +61 -0
- data/lib/bosh/director/jobs/snapshot_deployments.rb +23 -0
- data/lib/bosh/director/jobs/snapshot_self.rb +43 -0
- data/lib/bosh/director/jobs/ssh.rb +59 -0
- data/lib/bosh/director/jobs/update_deployment.rb +110 -0
- data/lib/bosh/director/jobs/update_release.rb +672 -0
- data/lib/bosh/director/jobs/update_stemcell.rb +109 -0
- data/lib/bosh/director/jobs/vm_state.rb +89 -0
- data/lib/bosh/director/lock.rb +133 -0
- data/lib/bosh/director/lock_helper.rb +92 -0
- data/lib/bosh/director/models.rb +29 -0
- data/lib/bosh/director/models/compiled_package.rb +33 -0
- data/lib/bosh/director/models/deployment.rb +22 -0
- data/lib/bosh/director/models/deployment_problem.rb +49 -0
- data/lib/bosh/director/models/deployment_property.rb +21 -0
- data/lib/bosh/director/models/director_attribute.rb +9 -0
- data/lib/bosh/director/models/dns.rb +9 -0
- data/lib/bosh/director/models/dns/domain.rb +9 -0
- data/lib/bosh/director/models/dns/record.rb +7 -0
- data/lib/bosh/director/models/helpers/model_helper.rb +7 -0
- data/lib/bosh/director/models/instance.rb +28 -0
- data/lib/bosh/director/models/log_bundle.rb +10 -0
- data/lib/bosh/director/models/package.rb +30 -0
- data/lib/bosh/director/models/persistent_disk.rb +13 -0
- data/lib/bosh/director/models/release.rb +17 -0
- data/lib/bosh/director/models/release_version.rb +16 -0
- data/lib/bosh/director/models/snapshot.rb +13 -0
- data/lib/bosh/director/models/stemcell.rb +18 -0
- data/lib/bosh/director/models/task.rb +10 -0
- data/lib/bosh/director/models/template.rb +44 -0
- data/lib/bosh/director/models/user.rb +11 -0
- data/lib/bosh/director/models/vm.rb +42 -0
- data/lib/bosh/director/nats_rpc.rb +54 -0
- data/lib/bosh/director/network_reservation.rb +121 -0
- data/lib/bosh/director/next_rebase_version.rb +20 -0
- data/lib/bosh/director/package_compiler.rb +423 -0
- data/lib/bosh/director/problem_handlers/base.rb +153 -0
- data/lib/bosh/director/problem_handlers/inactive_disk.rb +112 -0
- data/lib/bosh/director/problem_handlers/invalid_problem.rb +28 -0
- data/lib/bosh/director/problem_handlers/missing_vm.rb +34 -0
- data/lib/bosh/director/problem_handlers/mount_info_mismatch.rb +62 -0
- data/lib/bosh/director/problem_handlers/out_of_sync_vm.rb +64 -0
- data/lib/bosh/director/problem_handlers/unbound_instance_vm.rb +85 -0
- data/lib/bosh/director/problem_handlers/unresponsive_agent.rb +78 -0
- data/lib/bosh/director/problem_resolver.rb +103 -0
- data/lib/bosh/director/problem_scanner.rb +268 -0
- data/lib/bosh/director/resource_pool_updater.rb +216 -0
- data/lib/bosh/director/scheduler.rb +57 -0
- data/lib/bosh/director/sequel.rb +13 -0
- data/lib/bosh/director/tar_gzipper.rb +47 -0
- data/lib/bosh/director/task_result_file.rb +19 -0
- data/lib/bosh/director/thread_pool.rb +8 -0
- data/lib/bosh/director/validation_helper.rb +55 -0
- data/lib/bosh/director/version.rb +7 -0
- data/lib/bosh/director/vm_creator.rb +80 -0
- data/lib/bosh/director/vm_data.rb +63 -0
- data/lib/bosh/director/vm_metadata_updater.rb +29 -0
- data/lib/bosh/director/vm_reuser.rb +63 -0
- data/lib/cloud/dummy.rb +149 -0
- metadata +664 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
module Bosh::Director
|
2
|
+
module DeploymentPlan
|
3
|
+
class Preparer
|
4
|
+
def initialize(job, compiler)
|
5
|
+
@job = job
|
6
|
+
@assembler = compiler
|
7
|
+
end
|
8
|
+
|
9
|
+
def prepare
|
10
|
+
job.track_and_log('Binding deployment') do
|
11
|
+
@assembler.bind_deployment
|
12
|
+
end
|
13
|
+
|
14
|
+
job.track_and_log('Binding releases') do
|
15
|
+
@assembler.bind_releases
|
16
|
+
end
|
17
|
+
|
18
|
+
job.track_and_log('Binding existing deployment') do
|
19
|
+
@assembler.bind_existing_deployment
|
20
|
+
end
|
21
|
+
|
22
|
+
job.track_and_log('Binding resource pools') do
|
23
|
+
@assembler.bind_resource_pools
|
24
|
+
end
|
25
|
+
|
26
|
+
job.track_and_log('Binding stemcells') do
|
27
|
+
@assembler.bind_stemcells
|
28
|
+
end
|
29
|
+
|
30
|
+
job.track_and_log('Binding templates') do
|
31
|
+
@assembler.bind_templates
|
32
|
+
end
|
33
|
+
|
34
|
+
job.track_and_log('Binding properties') do
|
35
|
+
@assembler.bind_properties
|
36
|
+
end
|
37
|
+
|
38
|
+
job.track_and_log('Binding unallocated VMs') do
|
39
|
+
@assembler.bind_unallocated_vms
|
40
|
+
end
|
41
|
+
|
42
|
+
job.track_and_log('Binding instance networks') do
|
43
|
+
@assembler.bind_instance_networks
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
attr_reader :job
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# Copyright (c) 2009-2012 VMware, Inc.
|
2
|
+
|
3
|
+
module Bosh::Director
|
4
|
+
module DeploymentPlan
|
5
|
+
class Release
|
6
|
+
include ValidationHelper
|
7
|
+
|
8
|
+
# @return [String] Release name
|
9
|
+
attr_reader :name
|
10
|
+
# @return [String] Release version
|
11
|
+
attr_reader :version
|
12
|
+
# @return [Models::ReleaseVersion] Release version model
|
13
|
+
attr_reader :model
|
14
|
+
|
15
|
+
# @param [DeploymentPlan] deployment_plan Deployment plan
|
16
|
+
# @param [Hash] spec Raw release spec from the deployment
|
17
|
+
# manifest
|
18
|
+
def initialize(deployment_plan, spec)
|
19
|
+
@deployment_plan = deployment_plan
|
20
|
+
|
21
|
+
@name = safe_property(spec, "name", :class => String)
|
22
|
+
@version = safe_property(spec, "version", :class => String)
|
23
|
+
|
24
|
+
@model = nil
|
25
|
+
@templates = {}
|
26
|
+
|
27
|
+
@logger = Config.logger
|
28
|
+
@manager = Api::ReleaseManager.new
|
29
|
+
end
|
30
|
+
|
31
|
+
# Looks up release version in database and binds it to the deployment
|
32
|
+
# @return [void]
|
33
|
+
def bind_model
|
34
|
+
deployment = @deployment_plan.model
|
35
|
+
if deployment.nil?
|
36
|
+
raise DirectorError, "Deployment not bound in the deployment plan"
|
37
|
+
end
|
38
|
+
|
39
|
+
release = @manager.find_by_name(@name)
|
40
|
+
@model = @manager.find_version(release, @version)
|
41
|
+
@logger.debug("Found release `#{@name}/#{@version}'")
|
42
|
+
|
43
|
+
unless deployment.release_versions.include?(@model)
|
44
|
+
@logger.debug("Binding release `#{@name}/#{@version}' " +
|
45
|
+
"to deployment `#{deployment.name}'")
|
46
|
+
deployment.add_release_version(@model)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Looks up package and template models in DB and binds them to this
|
51
|
+
# release spec
|
52
|
+
# @return [void]
|
53
|
+
def bind_templates
|
54
|
+
# Release version model needs to be known so we can look up its
|
55
|
+
# templates
|
56
|
+
if @model.nil?
|
57
|
+
raise DirectorError, "Release model not bound in release spec"
|
58
|
+
end
|
59
|
+
|
60
|
+
# By now job specs from the deployment manifest should
|
61
|
+
# have been parsed, so we can assume @templates contains
|
62
|
+
# the list of templates that need to be bound
|
63
|
+
@templates.each_value do |template|
|
64
|
+
@logger.debug("Binding template `#{template.name}'")
|
65
|
+
template.bind_models
|
66
|
+
@logger.debug("Bound template `#{template.name}'")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# @return [Hash] Hash representation
|
71
|
+
def spec
|
72
|
+
{
|
73
|
+
"name" => @name,
|
74
|
+
"version" => @version
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
# Looks up up template model by template name
|
79
|
+
# @param [String] name Template name
|
80
|
+
# @return [Models::Template]
|
81
|
+
def get_template_model_by_name(name)
|
82
|
+
@all_templates ||= @model.templates.inject({}) do |hash, template|
|
83
|
+
hash[template.name] = template
|
84
|
+
hash
|
85
|
+
end
|
86
|
+
|
87
|
+
@all_templates[name]
|
88
|
+
end
|
89
|
+
|
90
|
+
# Looks up up package model by package name
|
91
|
+
# @param [String] name Package name
|
92
|
+
# @return [Models::Package]
|
93
|
+
def get_package_model_by_name(name)
|
94
|
+
@all_packages ||= @model.packages.inject({}) do |hash, package|
|
95
|
+
hash[package.name] = package
|
96
|
+
hash
|
97
|
+
end
|
98
|
+
|
99
|
+
@all_packages[name]
|
100
|
+
end
|
101
|
+
|
102
|
+
# Adds template to a list of templates used by this release for the
|
103
|
+
# current deployment
|
104
|
+
# @param [String] template_name Template name
|
105
|
+
def use_template_named(template_name)
|
106
|
+
@templates[template_name] ||= Template.new(self, template_name)
|
107
|
+
end
|
108
|
+
|
109
|
+
# @param [String] name Template name
|
110
|
+
# @return [DeploymentPlan::Template] Template with given name used by this
|
111
|
+
# release (if any)
|
112
|
+
def template(name)
|
113
|
+
@templates[name]
|
114
|
+
end
|
115
|
+
|
116
|
+
# Returns a list of job templates that need to be included into this
|
117
|
+
# release. Note that this is not just a list of all templates existing
|
118
|
+
# in the release but rather a list of templates for jobs that are included
|
119
|
+
# into current deployment plan.
|
120
|
+
# @return [Array<DeploymentPlan::Template>] List of job templates
|
121
|
+
def templates
|
122
|
+
@templates.values
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# Copyright (c) 2009-2012 VMware, Inc.
|
2
|
+
|
3
|
+
module Bosh::Director
|
4
|
+
module DeploymentPlan
|
5
|
+
class ResourcePool
|
6
|
+
include ValidationHelper
|
7
|
+
|
8
|
+
# @return [String] Resource pool name
|
9
|
+
attr_reader :name
|
10
|
+
|
11
|
+
# @return [Integer] Expected resource pool size (in VMs)
|
12
|
+
attr_reader :size
|
13
|
+
|
14
|
+
# @return [DeploymentPlan] Deployment plan
|
15
|
+
attr_reader :deployment_plan
|
16
|
+
|
17
|
+
# @return [DeploymentPlan::Stemcell] Stemcell spec
|
18
|
+
attr_reader :stemcell
|
19
|
+
|
20
|
+
# @return [DeploymentPlan::Network] Network spec
|
21
|
+
attr_reader :network
|
22
|
+
|
23
|
+
# @return [Hash] Cloud properties
|
24
|
+
attr_reader :cloud_properties
|
25
|
+
|
26
|
+
# @return [Hash] Resource pool environment
|
27
|
+
attr_reader :env
|
28
|
+
|
29
|
+
# @return [Array<DeploymentPlan::IdleVm>] List of idle VMs
|
30
|
+
attr_reader :idle_vms
|
31
|
+
|
32
|
+
# @return [Array<DeploymentPlan::IdleVm] List of allocated idle VMs
|
33
|
+
attr_reader :allocated_vms
|
34
|
+
|
35
|
+
# @return [Integer] Number of active resource pool VMs
|
36
|
+
attr_reader :active_vm_count
|
37
|
+
|
38
|
+
# @param [DeploymentPlan] deployment_plan Deployment plan
|
39
|
+
# @param [Hash] spec Raw resource pool spec from the deployment manifest
|
40
|
+
def initialize(deployment_plan, spec)
|
41
|
+
@deployment_plan = deployment_plan
|
42
|
+
|
43
|
+
@name = safe_property(spec, "name", :class => String)
|
44
|
+
@size = safe_property(spec, "size", :class => Integer)
|
45
|
+
|
46
|
+
@cloud_properties =
|
47
|
+
safe_property(spec, "cloud_properties", :class => Hash)
|
48
|
+
|
49
|
+
stemcell_spec = safe_property(spec, "stemcell", :class => Hash)
|
50
|
+
@stemcell = Stemcell.new(self, stemcell_spec)
|
51
|
+
|
52
|
+
network_name = safe_property(spec, "network", :class => String)
|
53
|
+
@network = @deployment_plan.network(network_name)
|
54
|
+
|
55
|
+
if @network.nil?
|
56
|
+
raise ResourcePoolUnknownNetwork,
|
57
|
+
"Resource pool `#{@name}' references " +
|
58
|
+
"an unknown network `#{network_name}'"
|
59
|
+
end
|
60
|
+
|
61
|
+
@env = safe_property(spec, "env", :class => Hash, :default => {})
|
62
|
+
|
63
|
+
@idle_vms = []
|
64
|
+
@allocated_vms = []
|
65
|
+
@active_vm_count = 0
|
66
|
+
@required_capacity = 0
|
67
|
+
end
|
68
|
+
|
69
|
+
# Returns resource pools spec as Hash (usually for agent to serialize)
|
70
|
+
# @return [Hash] Resource pool spec
|
71
|
+
def spec
|
72
|
+
{
|
73
|
+
"name" => @name,
|
74
|
+
"cloud_properties" => @cloud_properties,
|
75
|
+
"stemcell" => @stemcell.spec
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
# Creates IdleVm objects for any missing resource pool VMs and reserves
|
80
|
+
# dynamic networks for all idle VMs.
|
81
|
+
# @return [void]
|
82
|
+
def process_idle_vms
|
83
|
+
# First, see if we need any data structures to balance the pool size
|
84
|
+
missing_vm_count.times { add_idle_vm }
|
85
|
+
|
86
|
+
# Second, see if some of idle VMs still need network reservations
|
87
|
+
idle_vms.each do |idle_vm|
|
88
|
+
unless idle_vm.has_network_reservation?
|
89
|
+
idle_vm.use_reservation(reserve_dynamic_network)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Tries to obtain one dynamic reservation in its own network
|
95
|
+
# @raise [NetworkReservationError]
|
96
|
+
# @return [NetworkReservation] Obtained reservation
|
97
|
+
def reserve_dynamic_network
|
98
|
+
reservation = NetworkReservation.new_dynamic
|
99
|
+
@network.reserve!(reservation, "Resource pool `#{@name}'")
|
100
|
+
reservation
|
101
|
+
end
|
102
|
+
|
103
|
+
# Returns a number of VMs that need to be created in order to bring
|
104
|
+
# this resource pool to a desired size
|
105
|
+
# @return [Integer]
|
106
|
+
def missing_vm_count
|
107
|
+
@size - @active_vm_count - @idle_vms.size
|
108
|
+
end
|
109
|
+
|
110
|
+
# Adds a new VM to a list of managed idle VMs
|
111
|
+
def add_idle_vm
|
112
|
+
idle_vm = IdleVm.new(self)
|
113
|
+
@idle_vms << idle_vm
|
114
|
+
idle_vm
|
115
|
+
end
|
116
|
+
|
117
|
+
def allocate_vm
|
118
|
+
allocated_vm = @idle_vms.pop
|
119
|
+
@allocated_vms << allocated_vm
|
120
|
+
allocated_vm
|
121
|
+
end
|
122
|
+
|
123
|
+
# "Active" VM is a VM that is currently running a job
|
124
|
+
# @return [void]
|
125
|
+
def mark_active_vm
|
126
|
+
@active_vm_count += 1
|
127
|
+
end
|
128
|
+
|
129
|
+
# Checks if there is enough capacity to run extra N VMs,
|
130
|
+
# raise error if not enough capacity
|
131
|
+
# @raise [ResourcePoolNotEnoughCapacity]
|
132
|
+
# @return [void]
|
133
|
+
def reserve_capacity(n)
|
134
|
+
@required_capacity += n
|
135
|
+
if @required_capacity > @size
|
136
|
+
raise ResourcePoolNotEnoughCapacity,
|
137
|
+
"Resource pool `#{@name}' is not big enough: " +
|
138
|
+
"#{@required_capacity} VMs needed, capacity is #{@size}"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Bosh::Director
|
2
|
+
module DeploymentPlan
|
3
|
+
class ResourcePools
|
4
|
+
def initialize(event_log, resource_pool_updaters)
|
5
|
+
@event_log = event_log
|
6
|
+
@resource_pool_updaters = resource_pool_updaters
|
7
|
+
end
|
8
|
+
|
9
|
+
def update
|
10
|
+
ThreadPool.new(:max_threads => Config.max_threads).wrap do |thread_pool|
|
11
|
+
# Delete extra VMs across resource pools
|
12
|
+
event_log.begin_stage('Deleting extra VMs', sum_across_pools(:extra_vm_count))
|
13
|
+
resource_pool_updaters.each do |updater|
|
14
|
+
updater.delete_extra_vms(thread_pool)
|
15
|
+
end
|
16
|
+
thread_pool.wait
|
17
|
+
|
18
|
+
# Delete outdated idle vms across resource pools, outdated allocated
|
19
|
+
# VMs are handled by instance updater
|
20
|
+
event_log.begin_stage('Deleting outdated idle VMs', sum_across_pools(:outdated_idle_vm_count))
|
21
|
+
|
22
|
+
resource_pool_updaters.each do |updater|
|
23
|
+
updater.delete_outdated_idle_vms(thread_pool)
|
24
|
+
end
|
25
|
+
thread_pool.wait
|
26
|
+
|
27
|
+
# Create missing VMs across resource pools phase 1:
|
28
|
+
# only creates VMs that have been bound to instances
|
29
|
+
# to avoid refilling the resource pool before instances
|
30
|
+
# that are no longer needed have been deleted.
|
31
|
+
event_log.begin_stage('Creating bound missing VMs', sum_across_pools(:bound_missing_vm_count))
|
32
|
+
resource_pool_updaters.each do |updater|
|
33
|
+
updater.create_bound_missing_vms(thread_pool)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def refill
|
39
|
+
# Instance updaters might have added some idle vms
|
40
|
+
# so they can be returned to resource pool. In that case
|
41
|
+
# we need to pre-allocate network settings for all of them.
|
42
|
+
resource_pool_updaters.each do |resource_pool_updater|
|
43
|
+
resource_pool_updater.reserve_networks
|
44
|
+
end
|
45
|
+
|
46
|
+
event_log.begin_stage('Refilling resource pools', sum_across_pools(:missing_vm_count))
|
47
|
+
ThreadPool.new(:max_threads => Config.max_threads).wrap do |thread_pool|
|
48
|
+
# Create missing VMs across resource pools phase 2:
|
49
|
+
# should be called after all instance updaters are finished to
|
50
|
+
# create additional VMs in order to balance resource pools
|
51
|
+
resource_pool_updaters.each do |resource_pool_updater|
|
52
|
+
resource_pool_updater.create_missing_vms(thread_pool)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
attr_reader :event_log, :resource_pool_updaters
|
60
|
+
|
61
|
+
def sum_across_pools(counting_method)
|
62
|
+
resource_pool_updaters.inject(0) do |sum, updater|
|
63
|
+
sum + updater.send(counting_method.to_sym)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# Copyright (c) 2009-2012 VMware, Inc.
|
2
|
+
|
3
|
+
module Bosh::Director
|
4
|
+
module DeploymentPlan
|
5
|
+
class Stemcell
|
6
|
+
include ValidationHelper
|
7
|
+
|
8
|
+
# @return [DeploymentPlan::ResourcePool] Resource pool
|
9
|
+
attr_reader :resource_pool
|
10
|
+
|
11
|
+
# @return [String] Stemcell name
|
12
|
+
attr_reader :name
|
13
|
+
|
14
|
+
# @return [String] Stemcell version
|
15
|
+
attr_reader :version
|
16
|
+
|
17
|
+
# @return [Models::Stemcell] Stemcell DB model
|
18
|
+
attr_reader :model
|
19
|
+
|
20
|
+
# @param [DeploymentPlan::ResourcePool] resource_pool Resource pool
|
21
|
+
# this stemcell belongs to
|
22
|
+
# @param [Hash] spec Raw stemcell spec according to deployment manifest
|
23
|
+
def initialize(resource_pool, spec)
|
24
|
+
@resource_pool = resource_pool
|
25
|
+
@name = safe_property(spec, "name", :class => String)
|
26
|
+
@version = safe_property(spec, "version", :class => String)
|
27
|
+
|
28
|
+
@manager = Api::StemcellManager.new
|
29
|
+
@model = nil
|
30
|
+
end
|
31
|
+
|
32
|
+
# Looks up the stemcell matching provided spec
|
33
|
+
# @return [void]
|
34
|
+
def bind_model
|
35
|
+
deployment = @resource_pool.deployment_plan.model
|
36
|
+
if deployment.nil?
|
37
|
+
raise DirectorError, "Deployment not bound in the deployment plan"
|
38
|
+
end
|
39
|
+
|
40
|
+
@model = @manager.find_by_name_and_version(@name, @version)
|
41
|
+
|
42
|
+
unless @model.deployments.include?(deployment)
|
43
|
+
@model.add_deployment(deployment)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def spec
|
48
|
+
{
|
49
|
+
"name" => @name,
|
50
|
+
"version" => @version
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|