Class: Bosh::Director::Api::ResourceManager

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/api/resource_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(blobstore_client = App.instance.blobstores.blobstore) ⇒ ResourceManager

Returns a new instance of ResourceManager.



7
8
9
10
# File 'lib/bosh/director/api/resource_manager.rb', line 7

def initialize(blobstore_client=App.instance.blobstores.blobstore)
  @logger = Config.logger
  @blobstore_client = blobstore_client
end

Instance Method Details

#delete_resource(id) ⇒ Object

Deletes the resource ‘id` from the blobstore

Parameters:

  • id (String)


48
49
50
51
52
53
54
55
56
# File 'lib/bosh/director/api/resource_manager.rb', line 48

def delete_resource(id)
  @logger.debug("Deleting #{id} from blobstore...")

  blobstore_resource(id) do |blobstore|
    blobstore.delete(id)
  end

  @logger.debug("Deleted #{id} from blobstore")
end

#get_resource(id) ⇒ String

Retrieves the resource ‘id` from the blobstore and returns the contents of it.

Parameters:

  • id (String)

Returns:

  • (String)

    contents of the blobstore id



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bosh/director/api/resource_manager.rb', line 34

def get_resource(id)
  @logger.debug("Downloading #{id} from blobstore...")

  blob = nil
  blobstore_resource(id) do |blobstore|
    blob = blobstore.get(id)
  end

  @logger.debug("Downloaded #{id} from blobstore")
  blob
end

#get_resource_path(id) ⇒ String

Retrieves the resource ‘id` from the blobstore and stores it locally, and returns the path to the file

Parameters:

  • id (String)

Returns:

  • (String)

    path to the contents of the blobstore id



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bosh/director/api/resource_manager.rb', line 17

def get_resource_path(id)
  blobstore_resource(id) do |blobstore|
    random_name = "resource-#{SecureRandom.uuid}"
    path = File.join(Dir.tmpdir, random_name)

    File.open(path, "w") do |f|
      blobstore.get(id, f)
    end

    path
  end
end