Class: Bosh::Director::Api::StemcellManager
Constant Summary
Constants included
from ApiHelper
ApiHelper::READ_CHUNK_SIZE
Instance Method Summary
collapse
-
#create_stemcell_from_file_path(username, stemcell_path, options) ⇒ Object
-
#create_stemcell_from_url(username, stemcell_url, options) ⇒ Object
-
#delete_stemcell(username, stemcell, options = {}) ⇒ Object
-
#find_all_stemcells ⇒ Object
-
#find_by_name_and_version(name, version) ⇒ Object
-
#find_by_os_and_version(os, version) ⇒ Object
-
#latest_by_name(name, prefix = nil) ⇒ Object
-
#latest_by_os(os, prefix = nil) ⇒ Object
-
#stemcell_exists?(name, version) ⇒ Boolean
Methods included from ApiHelper
#check_available_disk_space, #json_decode, #json_encode, #prepare_yml_file, #send_disposable_file, #start_task, #validate_manifest_yml, #write_file
Instance Method Details
#create_stemcell_from_file_path(username, stemcell_path, options) ⇒ Object
88
89
90
91
92
93
94
|
# File 'lib/bosh/director/api/stemcell_manager.rb', line 88
def create_stemcell_from_file_path(username, stemcell_path, options)
unless File.exists?(stemcell_path)
raise DirectorError, "Failed to create stemcell: file not found - #{stemcell_path}"
end
JobQueue.new.enqueue(username, Jobs::UpdateStemcell, 'create stemcell', [stemcell_path, options])
end
|
#create_stemcell_from_url(username, stemcell_url, options) ⇒ Object
83
84
85
86
|
# File 'lib/bosh/director/api/stemcell_manager.rb', line 83
def create_stemcell_from_url(username, stemcell_url, options)
options[:remote] = true
JobQueue.new.enqueue(username, Jobs::UpdateStemcell, 'create stemcell', [stemcell_url, options])
end
|
#delete_stemcell(username, stemcell, options = {}) ⇒ Object
96
97
98
99
100
|
# File 'lib/bosh/director/api/stemcell_manager.rb', line 96
def delete_stemcell(username, stemcell, options={})
description = "delete stemcell: #{stemcell.name}/#{stemcell.version}"
JobQueue.new.enqueue(username, Jobs::DeleteStemcell, description, [stemcell.name, stemcell.version, options])
end
|
#find_all_stemcells ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/bosh/director/api/stemcell_manager.rb', line 18
def find_all_stemcells
Models::Stemcell.order_by(Sequel.asc(:name)).map do |stemcell|
{
'name' => stemcell.name,
'operating_system' => stemcell.operating_system,
'version' => stemcell.version,
'cid' => stemcell.cid,
'deployments' => stemcell.deployments.map { |d| { name: d.name } }
}
end
end
|
#find_by_name_and_version(name, version) ⇒ Object
9
10
11
12
13
14
15
16
|
# File 'lib/bosh/director/api/stemcell_manager.rb', line 9
def find_by_name_and_version(name, version)
stemcell = Models::Stemcell[:name => name, :version => version]
if stemcell.nil?
raise StemcellNotFound,
"Stemcell '#{name}/#{version}' doesn't exist"
end
stemcell
end
|
#find_by_os_and_version(os, version) ⇒ Object
66
67
68
69
70
71
72
73
74
|
# File 'lib/bosh/director/api/stemcell_manager.rb', line 66
def find_by_os_and_version(os, version)
stemcell = Bosh::Director::Models::Stemcell.
dataset.order(:name)[:operating_system => os, :version => version]
if stemcell.nil?
raise StemcellNotFound,
"Stemcell version '#{version}' for OS '#{os}' doesn't exist"
end
stemcell
end
|
#latest_by_name(name, prefix = nil) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/bosh/director/api/stemcell_manager.rb', line 48
def latest_by_name(name, prefix = nil)
stemcells = Bosh::Director::Models::Stemcell.where(:name => name).all
if stemcells.empty?
raise StemcellNotFound,
"Stemcell '#{name}' doesn't exist"
end
latest = find_latest(stemcells, prefix)
if latest.nil?
raise StemcellNotFound,
"Stemcell '#{name}' exists, but version with prefix '#{prefix}' not found."
end
latest
end
|
#latest_by_os(os, prefix = nil) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/bosh/director/api/stemcell_manager.rb', line 30
def latest_by_os(os, prefix = nil)
stemcells = Bosh::Director::Models::Stemcell.where(:operating_system => os).all
if stemcells.empty?
raise StemcellNotFound,
"Stemcell with Operating System '#{os}' doesn't exist"
end
latest = find_latest(stemcells, prefix)
if latest.nil?
raise StemcellNotFound,
"Stemcell with Operating System '#{os}' exists, but version with prefix '#{prefix}' not found."
end
latest
end
|
#stemcell_exists?(name, version) ⇒ Boolean
76
77
78
79
80
81
|
# File 'lib/bosh/director/api/stemcell_manager.rb', line 76
def stemcell_exists?(name, version)
find_by_name_and_version(name, version)
true
rescue StemcellNotFound
false
end
|