Class: RightImage::IdList
- Inherits:
-
Object
- Object
- RightImage::IdList
- Defined in:
- lib/id_list.rb
Overview
Manages a global store of image ids for images that have been on a single rightimage creator instance. The image data is persisted on the local filesystem.
Instance Method Summary collapse
-
#add(id, storage_type = nil) ⇒ Object
Pass in id that the cloud provider passes back upon registration NOTE: Be sure to set storage type for EC2 “EBS” images so we can properly know what kind of MCI to make later.
-
#clear ⇒ Object
Wipes out the list by deleting the file.
-
#initialize(logger = nil) ⇒ IdList
constructor
A new instance of IdList.
-
#to_hash ⇒ Object
Returns a hash of image ids registered from this instance.
Constructor Details
#initialize(logger = nil) ⇒ IdList
Returns a new instance of IdList.
10 11 12 13 |
# File 'lib/id_list.rb', line 10 def initialize(logger = nil) @log = (logger) ? logger : Logger.new(STDOUT) @file = ::File.join(ENV["HOME"], "rightimage_id_list") end |
Instance Method Details
#add(id, storage_type = nil) ⇒ Object
Pass in id that the cloud provider passes back upon registration NOTE: Be sure to set storage type for EC2 “EBS” images so we can properly know what kind of MCI to make later.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/id_list.rb', line 19 def add(id, storage_type = nil) list_load key = id.to_s key.chomp! @log.info("Adding #{key} to #{(@list) ? 'existing' : 'empty'} id list.") entry = { key => { } } entry[key]["storage_type"] = storage_type if storage_type @list.merge!(entry) list_save end |
#clear ⇒ Object
Wipes out the list by deleting the file.
47 48 49 50 51 52 |
# File 'lib/id_list.rb', line 47 def clear if ::File.exists?(@file) @log.info("Deleted id list file.") ::File.delete(@file) end end |
#to_hash ⇒ Object
Returns a hash of image ids registered from this instance. The keys are image ids, the values contain metadata (like “storage_type”) Intended to be used in a loop. For Example:
images = RightImage::IdList.new(Chef::Log).to_hash
images.each do |id, params|
...
end
39 40 41 42 43 |
# File 'lib/id_list.rb', line 39 def to_hash list_load @log.info("Loaded #{(@list)?"existing":"empty"} id list.") @list end |