bosh-director 1.5.0.pre.1113

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. data/CHANGELOG +34 -0
  2. data/bin/bosh-director +36 -0
  3. data/bin/bosh-director-console +84 -0
  4. data/bin/bosh-director-drain-workers +42 -0
  5. data/bin/bosh-director-migrate +58 -0
  6. data/bin/bosh-director-scheduler +27 -0
  7. data/bin/bosh-director-worker +76 -0
  8. data/db/migrations/README +1 -0
  9. data/db/migrations/director/20110209010747_initial.rb +118 -0
  10. data/db/migrations/director/20110406055800_add_task_user.rb +9 -0
  11. data/db/migrations/director/20110518225809_remove_cid_constrain.rb +13 -0
  12. data/db/migrations/director/20110617211923_add_deployments_release_versions.rb +32 -0
  13. data/db/migrations/director/20110622212607_add_task_checkpoint_timestamp.rb +9 -0
  14. data/db/migrations/director/20110628023039_add_state_to_instances.rb +21 -0
  15. data/db/migrations/director/20110709012332_add_disk_size_to_instances.rb +9 -0
  16. data/db/migrations/director/20110906183441_add_log_bundles.rb +11 -0
  17. data/db/migrations/director/20110907194830_add_logs_json_to_templates.rb +9 -0
  18. data/db/migrations/director/20110915205610_add_persistent_disks.rb +51 -0
  19. data/db/migrations/director/20111005180929_add_properties.rb +14 -0
  20. data/db/migrations/director/20111110024617_add_deployment_problems.rb +24 -0
  21. data/db/migrations/director/20111216214145_recreate_support_for_vms.rb +9 -0
  22. data/db/migrations/director/20120102084027_add_credentials_to_vms.rb +7 -0
  23. data/db/migrations/director/20120427235217_allow_multiple_releases_per_deployment.rb +36 -0
  24. data/db/migrations/director/20120524175805_add_task_type.rb +44 -0
  25. data/db/migrations/director/20120614001930_delete_redundant_deployment_release_relation.rb +34 -0
  26. data/db/migrations/director/20120822004528_add_fingerprint_to_templates_and_packages.rb +17 -0
  27. data/db/migrations/director/20120830191244_add_properties_to_templates.rb +9 -0
  28. data/db/migrations/director/20121106190739_persist_vm_env.rb +9 -0
  29. data/db/migrations/director/20130222232131_add_sha1_to_stemcells.rb +9 -0
  30. data/db/migrations/director/20130312211407_add_commit_hash_to_release_versions.rb +19 -0
  31. data/db/migrations/director/20130409235338_snapshot.rb +15 -0
  32. data/db/migrations/director/20130530164918_add_paused_flag_to_instance.rb +14 -0
  33. data/db/migrations/director/20130531172604_add_director_attributes.rb +13 -0
  34. data/db/migrations/dns/20120123234908_initial.rb +27 -0
  35. data/lib/bosh/director.rb +133 -0
  36. data/lib/bosh/director/agent_client.rb +78 -0
  37. data/lib/bosh/director/api.rb +29 -0
  38. data/lib/bosh/director/api/api_helper.rb +81 -0
  39. data/lib/bosh/director/api/backup_manager.rb +15 -0
  40. data/lib/bosh/director/api/controller.rb +639 -0
  41. data/lib/bosh/director/api/controller_helpers.rb +34 -0
  42. data/lib/bosh/director/api/deployment_lookup.rb +13 -0
  43. data/lib/bosh/director/api/deployment_manager.rb +60 -0
  44. data/lib/bosh/director/api/http_constants.rb +16 -0
  45. data/lib/bosh/director/api/instance_lookup.rb +44 -0
  46. data/lib/bosh/director/api/instance_manager.rb +63 -0
  47. data/lib/bosh/director/api/problem_manager.rb +40 -0
  48. data/lib/bosh/director/api/property_manager.rb +69 -0
  49. data/lib/bosh/director/api/release_manager.rb +59 -0
  50. data/lib/bosh/director/api/resource_manager.rb +69 -0
  51. data/lib/bosh/director/api/resurrector_manager.rb +15 -0
  52. data/lib/bosh/director/api/snapshot_manager.rb +94 -0
  53. data/lib/bosh/director/api/stemcell_manager.rb +50 -0
  54. data/lib/bosh/director/api/task_helper.rb +46 -0
  55. data/lib/bosh/director/api/task_manager.rb +64 -0
  56. data/lib/bosh/director/api/user_manager.rb +72 -0
  57. data/lib/bosh/director/api/vm_state_manager.rb +11 -0
  58. data/lib/bosh/director/app.rb +35 -0
  59. data/lib/bosh/director/blob_util.rb +87 -0
  60. data/lib/bosh/director/blobstores.rb +29 -0
  61. data/lib/bosh/director/client.rb +156 -0
  62. data/lib/bosh/director/cloudcheck_helper.rb +204 -0
  63. data/lib/bosh/director/compile_task.rb +157 -0
  64. data/lib/bosh/director/config.rb +370 -0
  65. data/lib/bosh/director/configuration_hasher.rb +114 -0
  66. data/lib/bosh/director/cycle_helper.rb +36 -0
  67. data/lib/bosh/director/db_backup.rb +22 -0
  68. data/lib/bosh/director/db_backup/adapter.rb +3 -0
  69. data/lib/bosh/director/db_backup/adapter/mysql2.rb +27 -0
  70. data/lib/bosh/director/db_backup/adapter/postgres.rb +36 -0
  71. data/lib/bosh/director/db_backup/adapter/sqlite.rb +17 -0
  72. data/lib/bosh/director/db_backup/error.rb +10 -0
  73. data/lib/bosh/director/deployment_plan.rb +26 -0
  74. data/lib/bosh/director/deployment_plan/assembler.rb +430 -0
  75. data/lib/bosh/director/deployment_plan/compilation_config.rb +54 -0
  76. data/lib/bosh/director/deployment_plan/compiled_package.rb +35 -0
  77. data/lib/bosh/director/deployment_plan/dynamic_network.rb +91 -0
  78. data/lib/bosh/director/deployment_plan/idle_vm.rb +109 -0
  79. data/lib/bosh/director/deployment_plan/instance.rb +413 -0
  80. data/lib/bosh/director/deployment_plan/job.rb +470 -0
  81. data/lib/bosh/director/deployment_plan/manual_network.rb +137 -0
  82. data/lib/bosh/director/deployment_plan/network.rb +74 -0
  83. data/lib/bosh/director/deployment_plan/network_subnet.rb +167 -0
  84. data/lib/bosh/director/deployment_plan/planner.rb +288 -0
  85. data/lib/bosh/director/deployment_plan/preparer.rb +52 -0
  86. data/lib/bosh/director/deployment_plan/release.rb +126 -0
  87. data/lib/bosh/director/deployment_plan/resource_pool.rb +143 -0
  88. data/lib/bosh/director/deployment_plan/resource_pools.rb +68 -0
  89. data/lib/bosh/director/deployment_plan/stemcell.rb +56 -0
  90. data/lib/bosh/director/deployment_plan/template.rb +94 -0
  91. data/lib/bosh/director/deployment_plan/update_config.rb +80 -0
  92. data/lib/bosh/director/deployment_plan/updater.rb +55 -0
  93. data/lib/bosh/director/deployment_plan/vip_network.rb +79 -0
  94. data/lib/bosh/director/dns_helper.rb +204 -0
  95. data/lib/bosh/director/download_helper.rb +44 -0
  96. data/lib/bosh/director/duration.rb +36 -0
  97. data/lib/bosh/director/encryption_helper.rb +10 -0
  98. data/lib/bosh/director/errors.rb +198 -0
  99. data/lib/bosh/director/event_log.rb +136 -0
  100. data/lib/bosh/director/ext.rb +64 -0
  101. data/lib/bosh/director/hash_string_vals.rb +13 -0
  102. data/lib/bosh/director/instance_deleter.rb +109 -0
  103. data/lib/bosh/director/instance_updater.rb +506 -0
  104. data/lib/bosh/director/ip_util.rb +67 -0
  105. data/lib/bosh/director/job_queue.rb +16 -0
  106. data/lib/bosh/director/job_runner.rb +162 -0
  107. data/lib/bosh/director/job_updater.rb +121 -0
  108. data/lib/bosh/director/jobs/backup.rb +86 -0
  109. data/lib/bosh/director/jobs/base_job.rb +66 -0
  110. data/lib/bosh/director/jobs/cloud_check/apply_resolutions.rb +46 -0
  111. data/lib/bosh/director/jobs/cloud_check/scan.rb +38 -0
  112. data/lib/bosh/director/jobs/cloud_check/scan_and_fix.rb +73 -0
  113. data/lib/bosh/director/jobs/create_snapshot.rb +23 -0
  114. data/lib/bosh/director/jobs/delete_deployment.rb +183 -0
  115. data/lib/bosh/director/jobs/delete_deployment_snapshots.rb +34 -0
  116. data/lib/bosh/director/jobs/delete_release.rb +219 -0
  117. data/lib/bosh/director/jobs/delete_snapshots.rb +23 -0
  118. data/lib/bosh/director/jobs/delete_stemcell.rb +102 -0
  119. data/lib/bosh/director/jobs/fetch_logs.rb +99 -0
  120. data/lib/bosh/director/jobs/scheduled_backup.rb +38 -0
  121. data/lib/bosh/director/jobs/snapshot_deployment.rb +61 -0
  122. data/lib/bosh/director/jobs/snapshot_deployments.rb +23 -0
  123. data/lib/bosh/director/jobs/snapshot_self.rb +43 -0
  124. data/lib/bosh/director/jobs/ssh.rb +59 -0
  125. data/lib/bosh/director/jobs/update_deployment.rb +110 -0
  126. data/lib/bosh/director/jobs/update_release.rb +672 -0
  127. data/lib/bosh/director/jobs/update_stemcell.rb +109 -0
  128. data/lib/bosh/director/jobs/vm_state.rb +89 -0
  129. data/lib/bosh/director/lock.rb +133 -0
  130. data/lib/bosh/director/lock_helper.rb +92 -0
  131. data/lib/bosh/director/models.rb +29 -0
  132. data/lib/bosh/director/models/compiled_package.rb +33 -0
  133. data/lib/bosh/director/models/deployment.rb +22 -0
  134. data/lib/bosh/director/models/deployment_problem.rb +49 -0
  135. data/lib/bosh/director/models/deployment_property.rb +21 -0
  136. data/lib/bosh/director/models/director_attribute.rb +9 -0
  137. data/lib/bosh/director/models/dns.rb +9 -0
  138. data/lib/bosh/director/models/dns/domain.rb +9 -0
  139. data/lib/bosh/director/models/dns/record.rb +7 -0
  140. data/lib/bosh/director/models/helpers/model_helper.rb +7 -0
  141. data/lib/bosh/director/models/instance.rb +28 -0
  142. data/lib/bosh/director/models/log_bundle.rb +10 -0
  143. data/lib/bosh/director/models/package.rb +30 -0
  144. data/lib/bosh/director/models/persistent_disk.rb +13 -0
  145. data/lib/bosh/director/models/release.rb +17 -0
  146. data/lib/bosh/director/models/release_version.rb +16 -0
  147. data/lib/bosh/director/models/snapshot.rb +13 -0
  148. data/lib/bosh/director/models/stemcell.rb +18 -0
  149. data/lib/bosh/director/models/task.rb +10 -0
  150. data/lib/bosh/director/models/template.rb +44 -0
  151. data/lib/bosh/director/models/user.rb +11 -0
  152. data/lib/bosh/director/models/vm.rb +42 -0
  153. data/lib/bosh/director/nats_rpc.rb +54 -0
  154. data/lib/bosh/director/network_reservation.rb +121 -0
  155. data/lib/bosh/director/next_rebase_version.rb +20 -0
  156. data/lib/bosh/director/package_compiler.rb +423 -0
  157. data/lib/bosh/director/problem_handlers/base.rb +153 -0
  158. data/lib/bosh/director/problem_handlers/inactive_disk.rb +112 -0
  159. data/lib/bosh/director/problem_handlers/invalid_problem.rb +28 -0
  160. data/lib/bosh/director/problem_handlers/missing_vm.rb +34 -0
  161. data/lib/bosh/director/problem_handlers/mount_info_mismatch.rb +62 -0
  162. data/lib/bosh/director/problem_handlers/out_of_sync_vm.rb +64 -0
  163. data/lib/bosh/director/problem_handlers/unbound_instance_vm.rb +85 -0
  164. data/lib/bosh/director/problem_handlers/unresponsive_agent.rb +78 -0
  165. data/lib/bosh/director/problem_resolver.rb +103 -0
  166. data/lib/bosh/director/problem_scanner.rb +268 -0
  167. data/lib/bosh/director/resource_pool_updater.rb +216 -0
  168. data/lib/bosh/director/scheduler.rb +57 -0
  169. data/lib/bosh/director/sequel.rb +13 -0
  170. data/lib/bosh/director/tar_gzipper.rb +47 -0
  171. data/lib/bosh/director/task_result_file.rb +19 -0
  172. data/lib/bosh/director/thread_pool.rb +8 -0
  173. data/lib/bosh/director/validation_helper.rb +55 -0
  174. data/lib/bosh/director/version.rb +7 -0
  175. data/lib/bosh/director/vm_creator.rb +80 -0
  176. data/lib/bosh/director/vm_data.rb +63 -0
  177. data/lib/bosh/director/vm_metadata_updater.rb +29 -0
  178. data/lib/bosh/director/vm_reuser.rb +63 -0
  179. data/lib/cloud/dummy.rb +149 -0
  180. metadata +664 -0
@@ -0,0 +1,34 @@
1
+ module Bosh::Director
2
+ module Api::ControllerHelpers
3
+ def task_timeout?(task)
4
+ # Some of the old task entries might not have the checkpoint_time
5
+ unless task.checkpoint_time
6
+ task.checkpoint_time = Time.now
7
+ task.save
8
+ end
9
+
10
+ # If no checkpoint update in 3 cycles --> timeout
11
+ (task.state == 'processing' || task.state == 'cancelling') &&
12
+ (Time.now - task.checkpoint_time > Config.task_checkpoint_interval * 3)
13
+ end
14
+
15
+ def protected!
16
+ unless authorized?
17
+ response['WWW-Authenticate'] = 'Basic realm="BOSH Director"'
18
+ throw(:halt, [401, "Not authorized\n"])
19
+ end
20
+ end
21
+
22
+ def authorized?
23
+ @auth ||= Rack::Auth::Basic::Request.new(request.env)
24
+ @auth.provided? && @auth.basic? && @auth.credentials && authenticate(*@auth.credentials)
25
+ end
26
+
27
+ def convert_job_instance_hash(hash)
28
+ hash.reduce([]) do |jobs, kv|
29
+ job, indicies = kv
30
+ jobs + indicies.map { |index| [job, index] }
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,13 @@
1
+ module Bosh::Director
2
+ module Api
3
+ class DeploymentLookup
4
+ def by_name(name)
5
+ deployment = Models::Deployment[name: name]
6
+ if deployment.nil?
7
+ raise DeploymentNotFound, "Deployment `#{name}' doesn't exist"
8
+ end
9
+ deployment
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,60 @@
1
+ # Copyright (c) 2009-2012 VMware, Inc.
2
+
3
+ module Bosh::Director
4
+ module Api
5
+ class DeploymentManager
6
+ include ApiHelper
7
+
8
+ # Finds deployment by name
9
+ # @param [String] name
10
+ # @return [Models::Deployment] Deployment model
11
+ # @raise [DeploymentNotFound]
12
+ def find_by_name(name)
13
+ DeploymentLookup.new.by_name(name)
14
+ end
15
+
16
+ def create_deployment(user, deployment_manifest, options = {})
17
+ random_name = "deployment-#{SecureRandom.uuid}"
18
+ deployment_manifest_dir = Dir::tmpdir
19
+ deployment_manifest_file = File.join(deployment_manifest_dir, random_name)
20
+ unless check_available_disk_space(deployment_manifest_dir, deployment_manifest.size)
21
+ raise NotEnoughDiskSpace, "Uploading deployment manifest failed. " +
22
+ "Insufficient space on BOSH director in #{deployment_manifest_dir}"
23
+ end
24
+
25
+ write_file(deployment_manifest_file, deployment_manifest)
26
+
27
+ JobQueue.new.enqueue(user, Jobs::UpdateDeployment, 'create deployment', [deployment_manifest_file, options])
28
+ end
29
+
30
+ def delete_deployment(user, deployment, options = {})
31
+ JobQueue.new.enqueue(user, Jobs::DeleteDeployment, "delete deployment #{deployment.name}", [deployment.name, options])
32
+ end
33
+
34
+ def deployment_to_json(deployment)
35
+ result = {
36
+ "manifest" => deployment.manifest,
37
+ }
38
+
39
+ Yajl::Encoder.encode(result)
40
+ end
41
+
42
+ def deployment_vms_to_json(deployment)
43
+ vms = []
44
+ filters = {:deployment_id => deployment.id}
45
+ Models::Vm.eager(:instance).filter(filters).all.each do |vm|
46
+ instance = vm.instance
47
+
48
+ vms << {
49
+ "agent_id" => vm.agent_id,
50
+ "cid" => vm.cid,
51
+ "job" => instance ? instance.job : nil,
52
+ "index" => instance ? instance.index : nil
53
+ }
54
+ end
55
+
56
+ Yajl::Encoder.encode(vms)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,16 @@
1
+ # Copyright (c) 2009-2012 VMware, Inc.
2
+
3
+ module Bosh::Director::Api
4
+ module Http
5
+ OK = 200
6
+ CREATED = 201
7
+ NO_CONTENT = 204
8
+
9
+ BAD_REQUEST = 400
10
+ UNAUTHORIZED = 401
11
+ FORBIDDEN = 403
12
+ NOT_FOUND = 404
13
+
14
+ INTERNAL_SERVER_ERROR = 500
15
+ end
16
+ end
@@ -0,0 +1,44 @@
1
+ require 'bosh/director/api/deployment_lookup'
2
+
3
+ module Bosh::Director
4
+ module Api
5
+ class InstanceLookup
6
+ def by_id(instance_id)
7
+ instance = Models::Instance[instance_id]
8
+ if instance.nil?
9
+ raise InstanceNotFound, "Instance #{instance_id} doesn't exist"
10
+ end
11
+ instance
12
+ end
13
+
14
+ def by_attributes(deployment_name, job_name, job_index)
15
+ deployment = DeploymentLookup.new.by_name(deployment_name)
16
+
17
+ filter = {
18
+ deployment_id: deployment.id,
19
+ job: job_name,
20
+ index: job_index
21
+ }
22
+
23
+ instance = Models::Instance.find(filter)
24
+ if instance.nil?
25
+ raise InstanceNotFound,
26
+ "`#{deployment_name}/#{job_name}/#{job_index}' doesn't exist"
27
+ end
28
+ instance
29
+ end
30
+
31
+ def by_filter(filter)
32
+ instances = Models::Instance.filter(filter).all
33
+ if instances.empty?
34
+ raise InstanceNotFound, "No instances matched #{filter.inspect}"
35
+ end
36
+ instances
37
+ end
38
+
39
+ def find_all
40
+ Models::Instance.all
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,63 @@
1
+ # Copyright (c) 2009-2012 VMware, Inc.
2
+
3
+ module Bosh::Director
4
+ module Api
5
+ class InstanceManager
6
+ # @param [Integer] instance_id Instance id
7
+ # @return [Models::Instance] Instance
8
+ # @raise [InstanceNotFound]
9
+ def find_instance(instance_id)
10
+ InstanceLookup.new.by_id(instance_id)
11
+ end
12
+
13
+ # @param [String] deployment_name Deployment name
14
+ # @param [String] job Job name
15
+ # @param [String] index Job index
16
+ # @return [Models::Instance]
17
+ def find_by_name(deployment_name, job, index)
18
+ InstanceLookup.new.by_attributes(deployment_name, job, index)
19
+ end
20
+
21
+ # @param [Hash] filter Sequel-style DB record filter
22
+ # @return [Array] List of instances that matched the filter
23
+ # @raise [InstanceNotFound]
24
+ def filter_by(filter)
25
+ InstanceLookup.new.by_filter(filter)
26
+ end
27
+
28
+ # @param [Models::Instance] instance Instance
29
+ # @return [AgentClient] Agent client to talk to instance
30
+ def agent_client_for(instance)
31
+ vm = instance.vm
32
+ if vm.nil?
33
+ raise InstanceVmMissing,
34
+ "`#{instance.job}/#{instance.index}' doesn't reference a VM"
35
+ end
36
+
37
+ if vm.agent_id.nil?
38
+ raise VmAgentIdMissing, "VM `#{vm.cid}' doesn't have an agent id"
39
+ end
40
+
41
+ AgentClient.new(vm.agent_id)
42
+ end
43
+
44
+ def fetch_logs(user, deployment_name, job, index, options = {})
45
+ if deployment_name.nil? || job.nil? || index.nil?
46
+ raise DirectorError,
47
+ "deployment, job and index parameters are required"
48
+ end
49
+
50
+ instance = find_by_name(deployment_name, job, index)
51
+
52
+ JobQueue.new.enqueue(user, Jobs::FetchLogs, 'fetch logs', [instance.id, options])
53
+ end
54
+
55
+ def ssh(user, options)
56
+ description = "ssh: #{options['command']}:#{options['target']}"
57
+ deployment = DeploymentLookup.new.by_name(options['deployment_name'])
58
+
59
+ JobQueue.new.enqueue(user, Jobs::Ssh, description, [deployment.id, options])
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,40 @@
1
+ # Copyright (c) 2009-2012 VMware, Inc.
2
+
3
+ module Bosh::Director
4
+ module Api
5
+ class ProblemManager
6
+
7
+ def initialize(deployment_manager = DeploymentManager.new)
8
+ @deployment_manager = deployment_manager
9
+ end
10
+
11
+ def perform_scan(user, deployment_name)
12
+ deployment = @deployment_manager.find_by_name(deployment_name)
13
+
14
+ JobQueue.new.enqueue(user, Jobs::CloudCheck::Scan, 'scan cloud', [deployment.name])
15
+ end
16
+
17
+ def get_problems(deployment_name)
18
+ deployment = @deployment_manager.find_by_name(deployment_name)
19
+
20
+ filters = {
21
+ :deployment_id => deployment.id,
22
+ :state => 'open'
23
+ }
24
+
25
+ Models::DeploymentProblem.filter(filters).order(:created_at).all
26
+ end
27
+
28
+ def apply_resolutions(user, deployment_name, resolutions)
29
+ deployment = @deployment_manager.find_by_name(deployment_name)
30
+ JobQueue.new.enqueue(user, Jobs::CloudCheck::ApplyResolutions, 'apply resolutions', [deployment.name, resolutions])
31
+ end
32
+
33
+ def scan_and_fix(user, deployment_name, jobs)
34
+ deployment = @deployment_manager.find_by_name(deployment_name)
35
+
36
+ JobQueue.new.enqueue(user, Jobs::CloudCheck::ScanAndFix, 'scan and fix', [deployment.name, jobs, Bosh::Director::Config.fix_stateful_nodes])
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,69 @@
1
+ # Copyright (c) 2009-2012 VMware, Inc.
2
+
3
+ module Bosh::Director
4
+ module Api
5
+ class PropertyManager
6
+
7
+ def initialize
8
+ @deployment_manager = DeploymentManager.new
9
+ end
10
+
11
+ def create_property(deployment_name, property_name, value)
12
+ property = Models::DeploymentProperty.new
13
+ property.deployment = find_deployment(deployment_name)
14
+ property.name = property_name
15
+ property.value = value
16
+ property.save
17
+
18
+ rescue Sequel::ValidationFailed => e
19
+ if e.errors[[:name, :deployment_id]].include?(:unique)
20
+ raise PropertyAlreadyExists,
21
+ "Property `#{property_name}' already exists " +
22
+ "for deployment `#{deployment_name}'"
23
+ end
24
+ invalid_property(e.errors)
25
+ end
26
+
27
+ def update_property(deployment_name, property_name, value)
28
+ property = get_property(deployment_name, property_name)
29
+ property.value = value
30
+ property.save
31
+
32
+ rescue Sequel::ValidationFailed => e
33
+ invalid_property(e.errors)
34
+ end
35
+
36
+ def delete_property(deployment_name, property_name)
37
+ get_property(deployment_name, property_name).destroy
38
+ end
39
+
40
+ def get_property(deployment_name, property_name)
41
+ deployment = find_deployment(deployment_name)
42
+ filters = {:deployment_id => deployment.id, :name => property_name}
43
+ property = Models::DeploymentProperty.find(filters)
44
+ if property.nil?
45
+ raise PropertyNotFound,
46
+ "Property `#{property_name}' not found " +
47
+ "for deployment `#{deployment_name}'"
48
+ end
49
+ property
50
+ end
51
+
52
+ def get_properties(deployment_name)
53
+ filters = {:deployment_id => find_deployment(deployment_name).id}
54
+ Models::DeploymentProperty.filter(filters).all
55
+ end
56
+
57
+ private
58
+
59
+ def invalid_property(errors)
60
+ raise PropertyInvalid,
61
+ "Property is invalid: #{errors.full_messages.sort.join(", ")}"
62
+ end
63
+
64
+ def find_deployment(name)
65
+ @deployment_manager.find_by_name(name)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,59 @@
1
+ # Copyright (c) 2009-2012 VMware, Inc.
2
+
3
+ module Bosh::Director
4
+ module Api
5
+ class ReleaseManager
6
+ include ApiHelper
7
+
8
+ RELEASE_TGZ = "release.tgz"
9
+
10
+ # Finds release by name
11
+ # @param [String] name Release name
12
+ # @return [Models::Release]
13
+ # @raise [ReleaseNotFound]
14
+ def find_by_name(name)
15
+ release = Models::Release[:name => name]
16
+ if release.nil?
17
+ raise ReleaseNotFound, "Release `#{name}' doesn't exist"
18
+ end
19
+ release
20
+ end
21
+
22
+ # @param [Models::Release] release Release model
23
+ # @param [String] version Release version
24
+ # @return [Models::ReleaseVersion] Release version model
25
+ # @raise [ReleaseVersionNotFound]
26
+ def find_version(release, version)
27
+ dataset = release.versions_dataset
28
+ release_version = dataset.filter(:version => version).first
29
+ if release_version.nil?
30
+ raise ReleaseVersionNotFound,
31
+ "Release version `#{release.name}/#{version}' doesn't exist"
32
+ end
33
+
34
+ release_version
35
+ end
36
+
37
+ def create_release(user, release_bundle, options = {})
38
+ release_dir = Dir.mktmpdir("release")
39
+
40
+ if options['remote']
41
+ options['location'] = release_bundle
42
+ else
43
+ unless check_available_disk_space(release_dir, release_bundle.size)
44
+ raise NotEnoughDiskSpace, "Uploading release archive failed. " +
45
+ "Insufficient space on BOSH director in #{release_dir}"
46
+ end
47
+
48
+ write_file(File.join(release_dir, RELEASE_TGZ), release_bundle)
49
+ end
50
+
51
+ JobQueue.new.enqueue(user, Jobs::UpdateRelease, 'create release', [release_dir, options])
52
+ end
53
+
54
+ def delete_release(user, release, options = {})
55
+ JobQueue.new.enqueue(user, Jobs::DeleteRelease, "delete release: #{release.name}", [release.name, options])
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,69 @@
1
+ # Copyright (c) 2009-2012 VMware, Inc.
2
+
3
+ module Bosh::Director
4
+ module Api
5
+ class ResourceManager
6
+
7
+ def initialize(blobstore_client=App.instance.blobstores.blobstore)
8
+ @logger = Config.logger
9
+ @blobstore_client = blobstore_client
10
+ end
11
+
12
+ # Retrieves the resource `id` from the blobstore and stores it
13
+ # locally, and returns the path to the file
14
+ #
15
+ # @param [String] id
16
+ # @return [String] path to the contents of the blobstore id
17
+ def get_resource_path(id)
18
+ blobstore_resource(id) do |blobstore|
19
+ random_name = "resource-#{SecureRandom.uuid}"
20
+ path = File.join(Dir.tmpdir, random_name)
21
+
22
+ File.open(path, "w") do |f|
23
+ blobstore.get(id, f)
24
+ end
25
+
26
+ path
27
+ end
28
+ end
29
+
30
+ # Retrieves the resource `id` from the blobstore and returns the
31
+ # contents of it.
32
+ # @param [String] id
33
+ # @return [String] contents of the blobstore id
34
+ def get_resource(id)
35
+ @logger.debug("Downloading #{id} from blobstore...")
36
+
37
+ blob = nil
38
+ blobstore_resource(id) do |blobstore|
39
+ blob = blobstore.get(id)
40
+ end
41
+
42
+ @logger.debug("Downloaded #{id} from blobstore")
43
+ blob
44
+ end
45
+
46
+ # Deletes the resource `id` from the blobstore
47
+ # @param [String] id
48
+ def delete_resource(id)
49
+ @logger.debug("Deleting #{id} from blobstore...")
50
+
51
+ blobstore_resource(id) do |blobstore|
52
+ blobstore.delete(id)
53
+ end
54
+
55
+ @logger.debug("Deleted #{id} from blobstore")
56
+ end
57
+
58
+ private
59
+
60
+ def blobstore_resource(id)
61
+ yield @blobstore_client
62
+ rescue Bosh::Blobstore::NotFound
63
+ raise ResourceNotFound, "Resource `#{id}' not found in the blobstore"
64
+ rescue Bosh::Blobstore::BlobstoreError => e
65
+ raise ResourceError, "Blobstore error accessing resource `#{id}': #{e}"
66
+ end
67
+ end
68
+ end
69
+ end