Class: Bosh::Director::BlobUtil
- Defined in:
- lib/bosh/director/blob_util.rb
Class Method Summary collapse
- .copy_blob(blobstore_id) ⇒ Object
-
.create_blob(path) ⇒ String
Created blob id.
- .delete_blob(blobstore_id) ⇒ Object
- .exists_in_global_cache?(package, cache_key) ⇒ Boolean
- .fetch_from_global_cache(package, stemcell, cache_key, dependency_key) ⇒ Object
- .save_to_global_cache(compiled_package, cache_key) ⇒ Object
- .verify_blob(blobstore_id, sha1) ⇒ Object
Class Method Details
.copy_blob(blobstore_id) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bosh/director/blob_util.rb', line 11 def self.copy_blob(blobstore_id) # Create a copy of the given blob Dir.mktmpdir do |path| temp_path = File.join(path, "blob") File.open(temp_path, 'w') do |file| blobstore.get(blobstore_id, file) end File.open(temp_path, 'r') do |file| blobstore_id = blobstore.create(file) end end blobstore_id end |
.create_blob(path) ⇒ String
Returns Created blob id.
7 8 9 |
# File 'lib/bosh/director/blob_util.rb', line 7 def self.create_blob(path) File.open(path) { |f| blobstore.create(f) } end |
.delete_blob(blobstore_id) ⇒ Object
25 26 27 |
# File 'lib/bosh/director/blob_util.rb', line 25 def self.delete_blob(blobstore_id) blobstore.delete(blobstore_id) end |
.exists_in_global_cache?(package, cache_key) ⇒ Boolean
49 50 51 52 |
# File 'lib/bosh/director/blob_util.rb', line 49 def self.exists_in_global_cache?(package, cache_key) global_cache_filename = [package.name, cache_key].join('-') compiled_package_cache_blobstore.exists?(global_cache_filename) end |
.fetch_from_global_cache(package, stemcell, cache_key, dependency_key) ⇒ Object
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 79 80 81 82 83 84 85 86 |
# File 'lib/bosh/director/blob_util.rb', line 54 def self.fetch_from_global_cache(package, stemcell, cache_key, dependency_key) global_cache_filename = [package.name, cache_key].join('-') blobstore_id = nil compiled_package_sha1 = nil Dir.mktmpdir do |path| blob_path = File.join(path, 'blob') begin File.open(blob_path, 'wb') do |file| compiled_package_cache_blobstore.get(global_cache_filename, file) end rescue Bosh::Blobstore::NotFound => e # if the object is not found in the cache, we ignore it and return nil return nil end File.open(blob_path) do |file| blobstore_id = blobstore.create(file) compiled_package_sha1 = Digest::SHA1.file(blob_path).hexdigest end end Models::CompiledPackage.create do |p| p.package = package p.stemcell_os = stemcell. p.stemcell_version = stemcell.version p.sha1 = compiled_package_sha1 p.build = Models::CompiledPackage.generate_build_number(package, stemcell., stemcell.version) p.blobstore_id = blobstore_id p.dependency_key = dependency_key end end |
.save_to_global_cache(compiled_package, cache_key) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bosh/director/blob_util.rb', line 35 def self.save_to_global_cache(compiled_package, cache_key) global_cache_filename = [compiled_package.package.name, cache_key].join('-') Dir.mktmpdir do |path| temp_path = File.join(path, 'blob') File.open(temp_path, 'wb') do |file| blobstore.get(compiled_package.blobstore_id, file) end File.open(temp_path) do |file| compiled_package_cache_blobstore.create(file, global_cache_filename) end end end |