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,15 @@
|
|
1
|
+
module Bosh::Director
|
2
|
+
module Api
|
3
|
+
class ResurrectorManager
|
4
|
+
def set_pause_for_instance(deployment_name, job_name, job_index, desired_state)
|
5
|
+
instance = InstanceLookup.new.by_attributes(deployment_name, job_name, job_index)
|
6
|
+
instance.resurrection_paused = desired_state
|
7
|
+
instance.save
|
8
|
+
end
|
9
|
+
|
10
|
+
def set_pause_for_all(desired_state)
|
11
|
+
Models::Instance.update(resurrection_paused: desired_state)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Bosh::Director
|
2
|
+
module Api
|
3
|
+
class SnapshotManager
|
4
|
+
def create_deployment_snapshot_task(user, deployment, options = {})
|
5
|
+
JobQueue.new.enqueue(user, Jobs::SnapshotDeployment, 'snapshot deployment', [deployment.name, options])
|
6
|
+
end
|
7
|
+
|
8
|
+
def create_snapshot_task(user, instance, options)
|
9
|
+
JobQueue.new.enqueue(user, Jobs::CreateSnapshot, 'create snapshot', [instance.id, options])
|
10
|
+
end
|
11
|
+
|
12
|
+
def delete_deployment_snapshots_task(user, deployment)
|
13
|
+
JobQueue.new.enqueue(user, Jobs::DeleteDeploymentSnapshots, 'delete deployment snapshots', [deployment.name])
|
14
|
+
end
|
15
|
+
|
16
|
+
def delete_snapshots_task(user, snapshot_cids)
|
17
|
+
JobQueue.new.enqueue(user, Jobs::DeleteSnapshots, 'delete snapshot', [snapshot_cids])
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_by_cid(deployment, snapshot_cid)
|
21
|
+
snapshot = Models::Snapshot.find(snapshot_cid: snapshot_cid)
|
22
|
+
raise SnapshotNotFound, "snapshot #{snapshot_cid} not found" unless snapshot
|
23
|
+
unless deployment == snapshot.persistent_disk.instance.deployment
|
24
|
+
raise SnapshotNotFound, "snapshot #{snapshot_cid} not found in deployment #{deployment.name}"
|
25
|
+
end
|
26
|
+
snapshot
|
27
|
+
end
|
28
|
+
|
29
|
+
def snapshots(deployment, job=nil, index=nil)
|
30
|
+
filter = { deployment: deployment }
|
31
|
+
filter[:job] = job if job
|
32
|
+
filter[:index] = index if index
|
33
|
+
|
34
|
+
result = []
|
35
|
+
instances = Models::Instance.filter(filter).all
|
36
|
+
|
37
|
+
instances.each do |instance|
|
38
|
+
instance.persistent_disks.each do |disk|
|
39
|
+
disk.snapshots.each do |snapshot|
|
40
|
+
result << {
|
41
|
+
'job' => instance.job,
|
42
|
+
'index' => instance.index,
|
43
|
+
'snapshot_cid' => snapshot.snapshot_cid,
|
44
|
+
'created_at' => snapshot.created_at.to_s,
|
45
|
+
'clean' => snapshot.clean
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
result
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.delete_snapshots(snapshots)
|
55
|
+
snapshots.each do |snapshot|
|
56
|
+
Config.cloud.delete_snapshot(snapshot.snapshot_cid)
|
57
|
+
snapshot.delete
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.take_snapshot(instance, options={})
|
62
|
+
unless Config.enable_snapshots
|
63
|
+
Config.logger.info('Snapshots are disabled; skipping')
|
64
|
+
return []
|
65
|
+
end
|
66
|
+
|
67
|
+
clean = options.fetch(:clean, false)
|
68
|
+
snapshot_cids = []
|
69
|
+
metadata = {
|
70
|
+
deployment: instance.deployment.name,
|
71
|
+
job: instance.job,
|
72
|
+
index: instance.index,
|
73
|
+
director_name: Config.name,
|
74
|
+
director_uuid: Config.uuid,
|
75
|
+
agent_id: instance.vm.agent_id,
|
76
|
+
instance_id: instance.vm_id
|
77
|
+
}
|
78
|
+
|
79
|
+
instance.persistent_disks.each do |disk|
|
80
|
+
cid = Config.cloud.snapshot_disk(disk.disk_cid, metadata)
|
81
|
+
snapshot = Models::Snapshot.new(persistent_disk: disk, snapshot_cid: cid, clean: clean)
|
82
|
+
snapshot.save
|
83
|
+
snapshot_cids << snapshot.snapshot_cid
|
84
|
+
end
|
85
|
+
|
86
|
+
snapshot_cids
|
87
|
+
|
88
|
+
rescue Bosh::Clouds::NotImplemented
|
89
|
+
Config.logger.info('CPI does not support disk snapshots; skipping')
|
90
|
+
[]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Copyright (c) 2009-2012 VMware, Inc.
|
2
|
+
|
3
|
+
module Bosh::Director
|
4
|
+
module Api
|
5
|
+
class StemcellManager
|
6
|
+
include ApiHelper
|
7
|
+
|
8
|
+
def find_by_name_and_version(name, version)
|
9
|
+
stemcell = Models::Stemcell[:name => name, :version => version]
|
10
|
+
if stemcell.nil?
|
11
|
+
raise StemcellNotFound,
|
12
|
+
"Stemcell `#{name}/#{version}' doesn't exist"
|
13
|
+
end
|
14
|
+
stemcell
|
15
|
+
end
|
16
|
+
|
17
|
+
def stemcell_exists?(name, version)
|
18
|
+
find_by_name_and_version(name, version)
|
19
|
+
true
|
20
|
+
rescue StemcellNotFound
|
21
|
+
false
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_stemcell(user, stemcell, options = {})
|
25
|
+
if options[:remote]
|
26
|
+
stemcell_file = stemcell
|
27
|
+
else
|
28
|
+
random_name = "stemcell-#{SecureRandom.uuid}"
|
29
|
+
stemcell_dir = Dir::tmpdir
|
30
|
+
stemcell_file = File.join(stemcell_dir, random_name)
|
31
|
+
|
32
|
+
unless check_available_disk_space(stemcell_dir, stemcell.size)
|
33
|
+
raise NotEnoughDiskSpace, "Uploading stemcell archive failed. " +
|
34
|
+
"Insufficient space on BOSH director in #{stemcell_dir}"
|
35
|
+
end
|
36
|
+
|
37
|
+
write_file(stemcell_file, stemcell)
|
38
|
+
end
|
39
|
+
|
40
|
+
JobQueue.new.enqueue(user, Jobs::UpdateStemcell, 'create stemcell', [stemcell_file, options])
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete_stemcell(user, stemcell, options={})
|
44
|
+
description = "delete stemcell: #{stemcell.name}/#{stemcell.version}"
|
45
|
+
|
46
|
+
JobQueue.new.enqueue(user, Jobs::DeleteStemcell, description, [stemcell.name, stemcell.version, options])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Copyright (c) 2009-2012 VMware, Inc.
|
2
|
+
|
3
|
+
module Bosh::Director
|
4
|
+
module Api
|
5
|
+
module TaskHelper
|
6
|
+
def create_task(user, type, description)
|
7
|
+
user = Models::User[:username => user]
|
8
|
+
task = Models::Task.create(:user => user,
|
9
|
+
:type => type,
|
10
|
+
:description => description,
|
11
|
+
:state => :queued,
|
12
|
+
:timestamp => Time.now,
|
13
|
+
:checkpoint_time => Time.now)
|
14
|
+
log_dir = File.join(Config.base_dir, "tasks", task.id.to_s)
|
15
|
+
task_status_file = File.join(log_dir, "debug")
|
16
|
+
FileUtils.mkdir_p(log_dir)
|
17
|
+
logger = Logger.new(task_status_file)
|
18
|
+
logger.level= Config.logger.level
|
19
|
+
logger.info("Director Version : #{Bosh::Director::VERSION}")
|
20
|
+
logger.info("Enqueuing task: #{task.id}")
|
21
|
+
|
22
|
+
# remove old tasks
|
23
|
+
min_task_id = task.id - Config.max_tasks
|
24
|
+
task_files = Dir.glob(File.join(Config.base_dir, "tasks/*"))
|
25
|
+
task_files.each do |file_path|
|
26
|
+
begin
|
27
|
+
task_file = File.basename(file_path)
|
28
|
+
task_id = Integer(task_file)
|
29
|
+
|
30
|
+
if task_id <= min_task_id && task_id >= 0
|
31
|
+
logger.info("Delete #{task_file}")
|
32
|
+
FileUtils.rm_rf file_path
|
33
|
+
Models::Task[task_id].destroy
|
34
|
+
end
|
35
|
+
rescue
|
36
|
+
# skip over invalid task files
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task.output = log_dir
|
41
|
+
task.save
|
42
|
+
task
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Copyright (c) 2009-2012 VMware, Inc.
|
2
|
+
|
3
|
+
module Bosh::Director
|
4
|
+
module Api
|
5
|
+
class TaskManager
|
6
|
+
# Looks up director task in DB
|
7
|
+
# @param [Integer] task_id
|
8
|
+
# @return [Models::Task] Task
|
9
|
+
# @raise [TaskNotFound]
|
10
|
+
def find_task(task_id)
|
11
|
+
task = Models::Task[task_id]
|
12
|
+
if task.nil?
|
13
|
+
raise TaskNotFound, "Task #{task_id} not found"
|
14
|
+
end
|
15
|
+
task
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns hash representation of the task
|
19
|
+
# @param [Models::Task] task Director task
|
20
|
+
# @return [Hash] Hash task representation
|
21
|
+
def task_to_hash(task)
|
22
|
+
{
|
23
|
+
"id" => task.id,
|
24
|
+
"state" => task.state,
|
25
|
+
"description" => task.description,
|
26
|
+
"timestamp" => task.timestamp.to_i,
|
27
|
+
"result" => task.result,
|
28
|
+
"user" => task.user ? task.user.username : "admin"
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def log_file(task, log_type)
|
33
|
+
# Backward compatibility
|
34
|
+
return task.output unless File.directory?(task.output)
|
35
|
+
|
36
|
+
# Backward compatbility from renaming `soap` log to `cpi` log.
|
37
|
+
# Old tasks might have been written to the file `soap` and we should
|
38
|
+
# still return them if log_type = cpi. Same goes for new task logs
|
39
|
+
# written to `cpi` but an old CLI has requested log_type = soap.
|
40
|
+
if %w(soap cpi).include?(log_type)
|
41
|
+
log_type = File.file?(File.join(task.output, "soap")) ? "soap" : "cpi"
|
42
|
+
end
|
43
|
+
file = File.join(task.output, log_type)
|
44
|
+
file_gz = [file, 'gz'].join('.')
|
45
|
+
|
46
|
+
decompress(file_gz, file)
|
47
|
+
|
48
|
+
file
|
49
|
+
end
|
50
|
+
|
51
|
+
def decompress(src, dst)
|
52
|
+
# only decompress if log_file is missing and we have a compressed file
|
53
|
+
return unless !File.file?(dst) && File.file?(src)
|
54
|
+
|
55
|
+
File.open(dst, 'w') do |file|
|
56
|
+
Zlib::GzipReader.open(src) do |gz|
|
57
|
+
file.write gz.read
|
58
|
+
end
|
59
|
+
end
|
60
|
+
FileUtils.rm(src)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Copyright (c) 2009-2012 VMware, Inc.
|
2
|
+
|
3
|
+
module Bosh::Director
|
4
|
+
module Api
|
5
|
+
class UserManager
|
6
|
+
|
7
|
+
# @param [String] name User name
|
8
|
+
# @return [Models::User] User
|
9
|
+
def find_by_name(name)
|
10
|
+
user = Models::User[:username => name]
|
11
|
+
if user.nil?
|
12
|
+
raise UserNotFound, "User `#{name}' doesn't exist"
|
13
|
+
end
|
14
|
+
user
|
15
|
+
end
|
16
|
+
|
17
|
+
def authenticate(username, password)
|
18
|
+
# This is a dev-mode shortcut
|
19
|
+
if Models::User.count == 0
|
20
|
+
return username == "admin" && password == "admin"
|
21
|
+
end
|
22
|
+
|
23
|
+
user = find_by_name(username)
|
24
|
+
BCrypt::Password.new(user.password) == password
|
25
|
+
rescue UserNotFound
|
26
|
+
false
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete_user(username)
|
30
|
+
find_by_name(username).destroy
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_user(new_user)
|
34
|
+
user = Models::User.new
|
35
|
+
user.username = new_user.username
|
36
|
+
if new_user.password
|
37
|
+
user.password = BCrypt::Password.create(new_user.password).to_s
|
38
|
+
end
|
39
|
+
save_user(user)
|
40
|
+
user
|
41
|
+
end
|
42
|
+
|
43
|
+
def update_user(updated_user)
|
44
|
+
user = find_by_name(updated_user.username)
|
45
|
+
user.password = BCrypt::Password.create(updated_user.password).to_s
|
46
|
+
save_user(user)
|
47
|
+
user
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_user_from_request(request)
|
51
|
+
hash = Yajl::Parser.new.parse(request.body)
|
52
|
+
Models::User.new(:username => hash["username"],
|
53
|
+
:password => hash["password"])
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
# Saves user in DB and handles validation errors.
|
59
|
+
# @param [Models::User]
|
60
|
+
# @return [void]
|
61
|
+
def save_user(user)
|
62
|
+
user.save
|
63
|
+
rescue Sequel::ValidationFailed => e
|
64
|
+
username_errors = e.errors.on(:username)
|
65
|
+
if username_errors && username_errors.include?(:unique)
|
66
|
+
raise UserNameTaken, "The username #{user.username} is already taken"
|
67
|
+
end
|
68
|
+
raise UserInvalid, "The user is invalid: #{e.errors.full_messages}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# Copyright (c) 2009-2012 VMware, Inc.
|
2
|
+
|
3
|
+
module Bosh::Director
|
4
|
+
module Api
|
5
|
+
class VmStateManager
|
6
|
+
def fetch_vm_state(user, deployment, format)
|
7
|
+
JobQueue.new.enqueue(user, Jobs::VmState, 'retrieve vm-stats', [deployment.id, format])
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Bosh::Director
|
2
|
+
|
3
|
+
# This is a work in progress.
|
4
|
+
#
|
5
|
+
# The App is the "top of the world"; it holds all the stateful components in the
|
6
|
+
# system. There should be only one instance, available as a class instance to the
|
7
|
+
# (hopefully few) components that require it.
|
8
|
+
|
9
|
+
class App
|
10
|
+
|
11
|
+
class << self
|
12
|
+
# Some places (ie, resque jobs) need to reference the authoriative app instance
|
13
|
+
# from class methods.
|
14
|
+
def instance
|
15
|
+
@@instance
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_reader :blobstores
|
20
|
+
|
21
|
+
def initialize(config)
|
22
|
+
# You should only create one of these at a time, but when you create one
|
23
|
+
# it becomes the authoritative official version across the whole app.
|
24
|
+
@@instance = self
|
25
|
+
|
26
|
+
# This is the legacy config system that we are trying to get rid of by
|
27
|
+
# decomposing and moving all the dependent components into this App
|
28
|
+
Bosh::Director::Config.configure(config.hash)
|
29
|
+
|
30
|
+
@blobstores = Blobstores.new(config)
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# Copyright (c) 2009-2012 VMware, Inc.
|
2
|
+
|
3
|
+
module Bosh::Director
|
4
|
+
class BlobUtil
|
5
|
+
# @param [String] path Path to a file to be uploaded
|
6
|
+
# @return [String] Created blob id
|
7
|
+
def self.create_blob(path)
|
8
|
+
File.open(path) { |f| blobstore.create(f) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.copy_blob(blobstore_id)
|
12
|
+
# Create a copy of the given blob
|
13
|
+
Dir.mktmpdir do |path|
|
14
|
+
temp_path = File.join(path, "blob")
|
15
|
+
File.open(temp_path, 'w') do |file|
|
16
|
+
blobstore.get(blobstore_id, file)
|
17
|
+
end
|
18
|
+
File.open(temp_path, 'r') do |file|
|
19
|
+
blobstore_id = blobstore.create(file)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
blobstore_id
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.save_to_global_cache(compiled_package, cache_key)
|
26
|
+
global_cache_filename = [compiled_package.package.name, cache_key].join('-')
|
27
|
+
Dir.mktmpdir do |path|
|
28
|
+
temp_path = File.join(path, 'blob')
|
29
|
+
File.open(temp_path, 'wb') do |file|
|
30
|
+
blobstore.get(compiled_package.blobstore_id, file)
|
31
|
+
end
|
32
|
+
|
33
|
+
File.open(temp_path) do |file|
|
34
|
+
compiled_package_cache_blobstore.create(file, global_cache_filename)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.exists_in_global_cache?(package, cache_key)
|
40
|
+
global_cache_filename = [package.name, cache_key].join('-')
|
41
|
+
compiled_package_cache_blobstore.exists?(global_cache_filename)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.fetch_from_global_cache(package, stemcell, cache_key, dependency_key)
|
45
|
+
global_cache_filename = [package.name, cache_key].join('-')
|
46
|
+
|
47
|
+
blobstore_id = nil
|
48
|
+
compiled_package_sha1 = nil
|
49
|
+
|
50
|
+
Dir.mktmpdir do |path|
|
51
|
+
blob_path = File.join(path, 'blob')
|
52
|
+
begin
|
53
|
+
File.open(blob_path, 'wb') do |file|
|
54
|
+
compiled_package_cache_blobstore.get(global_cache_filename, file)
|
55
|
+
end
|
56
|
+
rescue Bosh::Blobstore::NotFound => e
|
57
|
+
# if the object is not found in the cache, we ignore it and return nil
|
58
|
+
return nil
|
59
|
+
end
|
60
|
+
|
61
|
+
File.open(blob_path) do |file|
|
62
|
+
blobstore_id = blobstore.create(file)
|
63
|
+
compiled_package_sha1 = Digest::SHA1.file(blob_path).hexdigest
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
Models::CompiledPackage.create do |p|
|
68
|
+
p.package = package
|
69
|
+
p.stemcell = stemcell
|
70
|
+
p.sha1 = compiled_package_sha1
|
71
|
+
p.build = Models::CompiledPackage.generate_build_number(package, stemcell)
|
72
|
+
p.blobstore_id = blobstore_id
|
73
|
+
p.dependency_key = dependency_key
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def self.blobstore
|
80
|
+
App.instance.blobstores.blobstore
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.compiled_package_cache_blobstore
|
84
|
+
Config.compiled_package_cache_blobstore
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|