Class: Dcmgr::StorageService
- Inherits:
-
Object
- Object
- Dcmgr::StorageService
- Defined in:
- lib/dcmgr/storage_service.rb
Class Method Summary collapse
- .destination_key(account_id, destination, store_path, filename) ⇒ Object
- .has_driver?(driver) ⇒ Boolean
- .repository(repository_address) ⇒ Object
- .repository_address(destination_key) ⇒ Object
- .snapshot_repository_config ⇒ Object
Instance Method Summary collapse
- #bucket(name) ⇒ Object
-
#initialize(provider, access_key, secret_key) ⇒ StorageService
constructor
A new instance of StorageService.
Constructor Details
#initialize(provider, access_key, secret_key) ⇒ StorageService
Returns a new instance of StorageService.
8 9 10 11 12 13 |
# File 'lib/dcmgr/storage_service.rb', line 8 def initialize(provider, access_key, secret_key) @account = {} @account[:provider] = provider.upcase @account[:access_key] = access_key @account[:secret_key] = secret_key end |
Class Method Details
.destination_key(account_id, destination, store_path, filename) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/dcmgr/storage_service.rb', line 80 def self.destination_key(account_id, destination, store_path, filename) format = '%s@%s:%s:%s' if destination == 'local' config = { "driver" => "local", "bucket" => "none" } else config_data = snapshot_repository_config config = config_data[destination] if config.nil? raise "Destination isn't exists" end store_path = "snapshots/#{account_id}/" end sprintf(format, *[destination, config["driver"], config["bucket"], File.join(store_path, filename)]) end |
.has_driver?(driver) ⇒ Boolean
24 25 26 |
# File 'lib/dcmgr/storage_service.rb', line 24 def self.has_driver?(driver) %w(S3 IIJGIO).include? driver.upcase end |
.repository(repository_address) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/dcmgr/storage_service.rb', line 44 def self.repository(repository_address) if repository_address.nil? return {} end tmp = repository_address.split(',') destination_key = tmp[0] dest = destination_key.match(/^([a-z0-9_]+)@([a-z0-9_-]+):([a-z0-9_-]+):([a-z0-9_\-\/]+)(snap-[a-z0-9]+\.zsnap)+$/) if dest.nil? raise "Invalid format: #{repository_address}" end h = { :destination => dest[1], :driver => dest[2], :bucket => dest[3], :path => dest[4], :filename => dest[5], :access_key => tmp[1], :secret_key => tmp[2], } end |
.repository_address(destination_key) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/dcmgr/storage_service.rb', line 66 def self.repository_address(destination_key) format = '%s,%s,%s' config_data = self.snapshot_repository_config destination = destination_key.split('@')[0] if destination == 'local' config = {:access_key => '', :secret_key => ''} else config = config_data[destination] end sprintf(format, *[destination_key, config["access_key"], config["secret_key"]]) end |
.snapshot_repository_config ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/dcmgr/storage_service.rb', line 15 def self.snapshot_repository_config if @snapshot_repository_config.nil? config_file = YAML.load_file(File.join(File.(DCMGR_ROOT), 'config', 'snapshot_repository.yml')) @snapshot_repository_config = config_file else @snapshot_repository_config end end |
Instance Method Details
#bucket(name) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dcmgr/storage_service.rb', line 28 def bucket(name) case @account[:provider] when 'S3' @driver = Dcmgr::Drivers::S3Storage.new(name) when 'IIJGIO' @driver = Dcmgr::Drivers::IIJGIOStorage.new(name) else raise "#{@account[:provider]} is not a recognized storage provider" end @driver.setenv('SERVICE', @account[:provider].downcase) @driver.setenv('ACCESS_KEY_ID', @account[:access_key]) @driver.setenv('SECRET_ACCESS_KEY', @account[:secret_key]) @driver end |