Class: Fog::Storage::AzureRM::Real
- Inherits:
-
Object
- Object
- Fog::Storage::AzureRM::Real
- Defined in:
- lib/fog/azurerm/storage.rb,
lib/fog/azurerm/requests/storage/delete_disk.rb,
lib/fog/azurerm/requests/storage/list_containers.rb,
lib/fog/azurerm/requests/storage/create_container.rb,
lib/fog/azurerm/requests/storage/delete_container.rb,
lib/fog/azurerm/requests/storage/get_blob_metadata.rb,
lib/fog/azurerm/requests/storage/set_blob_metadata.rb,
lib/fog/azurerm/requests/storage/list_storage_accounts.rb,
lib/fog/azurerm/requests/storage/create_storage_account.rb,
lib/fog/azurerm/requests/storage/delete_storage_account.rb,
lib/fog/azurerm/requests/storage/get_container_metadata.rb,
lib/fog/azurerm/requests/storage/set_container_metadata.rb,
lib/fog/azurerm/requests/storage/get_storage_access_keys.rb,
lib/fog/azurerm/requests/storage/get_container_properties.rb,
lib/fog/azurerm/requests/storage/list_storage_account_for_rg.rb,
lib/fog/azurerm/requests/storage/get_container_access_control_list.rb,
lib/fog/azurerm/requests/storage/check_storage_account_name_availability.rb
Overview
This class provides the actual implemention for service calls.
Instance Method Summary collapse
- #check_storage_account_name_availability(params) ⇒ Object
- #create_container(name, options = {}) ⇒ Object
- #create_storage_account(resource_group, name, params) ⇒ Object
- #delete_container(name, options = {}) ⇒ Object
- #delete_disk(resource_group, storage_account_name, blob_name) ⇒ Object
- #delete_storage_account(resource_group, name) ⇒ Object
- #get_blob_metadata(container_name, name) ⇒ Object
- #get_container_access_control_list(name, options = {}) ⇒ Object
- #get_container_metadata(name) ⇒ Object
- #get_container_properties(name, options = {}) ⇒ Object
- #get_storage_access_keys(resource_group, storage_account_name, options = {}) ⇒ Object
-
#initialize(options) ⇒ Real
constructor
A new instance of Real.
- #list_containers(options = {}) ⇒ Object
- #list_storage_account_for_rg(resource_group) ⇒ Object
- #list_storage_accounts ⇒ Object
- #set_blob_metadata(container_name, name, metadata) ⇒ Object
- #set_container_metadata(name, metadata) ⇒ Object
Constructor Details
#initialize(options) ⇒ Real
Returns a new instance of Real.
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 |
# File 'lib/fog/azurerm/storage.rb', line 59 def initialize() begin require 'azure_mgmt_storage' require 'azure/storage' @debug = ENV['DEBUG'] || [:debug] require 'azure/core/http/debug_filter' if @debug rescue LoadError => e retry if require('rubygems') raise e. end credentials = Fog::Credentials::AzureRM.get_credentials([:tenant_id], [:client_id], [:client_secret]) unless credentials.nil? @storage_mgmt_client = ::Azure::ARM::Storage::StorageManagementClient.new(credentials) @storage_mgmt_client.subscription_id = [:subscription_id] end if Fog::Credentials::AzureRM.new_account_credential? Azure::Storage.setup(storage_account_name: [:azure_storage_account_name], storage_access_key: [:azure_storage_access_key], storage_connection_string: [:azure_storage_connection_string]) @blob_client = Azure::Storage::Blob::BlobService.new @blob_client.with_filter(Azure::Storage::Core::Filter::ExponentialRetryPolicyFilter.new) @blob_client.with_filter(Azure::Core::Http::DebugFilter.new) if @debug end end |
Instance Method Details
#check_storage_account_name_availability(params) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fog/azurerm/requests/storage/check_storage_account_name_availability.rb', line 6 def check_storage_account_name_availability(params) Fog::Logger.debug "Checking Name availability: #{params.name}." begin promise = @storage_mgmt_client.storage_accounts.check_name_availability(params) result = promise.value! name_available_obj = Azure::ARM::Storage::Models::CheckNameAvailabilityResult.serialize_object(result.body) if name_available_obj['nameAvailable'] == true Fog::Logger.debug "Name: #{params.name} is available." true else Fog::Logger.debug "Name: #{params.name} is not available." Fog::Logger.debug "Reason: #{name_available_obj['reason']}." false end rescue MsRestAzure::AzureOperationError => e msg = "Exception checking name availability: #{e.body['error']['message']}" raise msg if e.body['error']['code'] == 'ResourceGroupNotFound' end end |
#create_container(name, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fog/azurerm/requests/storage/create_container.rb', line 6 def create_container(name, = {}) Fog::Logger.debug "Creating container: #{name}." begin container = @blob_client.create_container(name, ) Fog::Logger.debug "Container #{name} created successfully." container rescue Azure::Core::Http::HTTPError => ex raise "Exception in creating the container #{name}: #{ex.inspect}" end end |
#create_storage_account(resource_group, name, params) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fog/azurerm/requests/storage/create_storage_account.rb', line 6 def create_storage_account(resource_group, name, params) Fog::Logger.debug "Creating Storage Account: #{name}." begin promise = @storage_mgmt_client.storage_accounts.create(resource_group, name, params) response = promise.value! Fog::Logger.debug 'Storage Account created successfully.' body = response.body body.properties.last_geo_failover_time = DateTime.parse(Time.now.to_s) body.properties.creation_time = DateTime.parse(Time.now.to_s) result = Azure::ARM::Storage::Models::StorageAccount.serialize_object(response.body) result rescue MsRestAzure::AzureOperationError => e msg = "Exception creating Storage Account #{name} in Resource Group #{resource_group}. #{e.body['error']['message']}" raise msg end end |
#delete_container(name, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fog/azurerm/requests/storage/delete_container.rb', line 6 def delete_container(name, = {}) Fog::Logger.debug "Deleting container: #{name}." begin @blob_client.delete_container(name, ) Fog::Logger.debug "Container #{name} deleted successfully." true rescue Azure::Core::Http::HTTPError => ex raise "Exception in deleting the container #{name}: #{ex.inspect}" end end |
#delete_disk(resource_group, storage_account_name, blob_name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fog/azurerm/requests/storage/delete_disk.rb', line 6 def delete_disk(resource_group, storage_account_name, blob_name) Fog::Logger.debug "Deleting Disk: #{blob_name}." access_key = get_storage_access_keys(resource_group, storage_account_name)['key2'] client = Azure::Storage::Client.new(storage_account_name: storage_account_name, storage_access_key: access_key) blob_service = Azure::Storage::Blob::BlobService.new(client: client) begin result = blob_service.delete_blob('vhds', "#{blob_name}.vhd") if result.nil? Fog::Logger.debug "Successfully deleted Disk: #{blob_name}." true else Fog::Logger.debug 'Error deleting Disk.' false end rescue Azure::Core::Http::HTTPError => e msg = "Error deleting Disk. #{e.description}" raise msg end end |
#delete_storage_account(resource_group, name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/fog/azurerm/requests/storage/delete_storage_account.rb', line 6 def delete_storage_account(resource_group, name) Fog::Logger.debug "Deleting Storage Account: #{name}." begin promise = @storage_mgmt_client.storage_accounts.delete(resource_group, name) promise.value! Fog::Logger.debug "Storage Account #{name} deleted successfully." true rescue MsRestAzure::AzureOperationError => e msg = "Exception deleting Storage Account #{name} in Resource Group #{resource_group}. #{e.body['error']['message']}" raise msg end end |
#get_blob_metadata(container_name, name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fog/azurerm/requests/storage/get_blob_metadata.rb', line 6 def (container_name, name) Fog::Logger.debug "Get Blob #{name} metadata in container #{container_name}." begin blob = @blob_client.(container_name, name) Fog::Logger.debug "Getting metadata of blob #{name} successfully." blob. rescue Azure::Core::Http::HTTPError => ex raise "Exception in getting metadata of Blob #{name}: #{ex.inspect}" end end |
#get_container_access_control_list(name, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fog/azurerm/requests/storage/get_container_access_control_list.rb', line 6 def get_container_access_control_list(name, = {}) Fog::Logger.debug "Get container ACL: #{name}." begin container_acl = @blob_client.get_container_acl(name, ) Fog::Logger.debug "Getting ACL of container #{name} successfully." container_acl rescue Azure::Core::Http::HTTPError => ex raise "Exception in getting ACL of container #{name}: #{ex.inspect}" end end |
#get_container_metadata(name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fog/azurerm/requests/storage/get_container_metadata.rb', line 6 def (name) Fog::Logger.debug "Get Container #{name} metadata." begin container = @blob_client.(name) Fog::Logger.debug "Getting metadata of container #{name} successfully." container. rescue Azure::Core::Http::HTTPError => ex raise "Exception in getting metadata of Container #{name}: #{ex.inspect}" end end |
#get_container_properties(name, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fog/azurerm/requests/storage/get_container_properties.rb', line 6 def get_container_properties(name, = {}) Fog::Logger.debug "Get container properties: #{name}." begin container_properties = @blob_client.get_container_properties(name, ) Fog::Logger.debug "Getting properties of container #{name} successfully." container_properties rescue Azure::Core::Http::HTTPError => ex raise "Exception in getting properties of container #{name}: #{ex.inspect}" end end |
#get_storage_access_keys(resource_group, storage_account_name, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/storage/get_storage_access_keys.rb', line 6 def get_storage_access_keys(resource_group, storage_account_name, = {}) Fog::Logger.debug "Getting storage access keys for storage account: #{storage_account_name}." begin storage_account_keys = @storage_mgmt_client.storage_accounts.list_keys(resource_group, storage_account_name, ).value! Fog::Logger.debug "Storage access keys for storage account: #{storage_account_name} listed successfully." Azure::ARM::Storage::Models::StorageAccountKeys.serialize_object(storage_account_keys.body) rescue MsRestAzure::AzureOperationError => e msg = "Error getting storage access keys. #{e.body['error']['message']}" raise msg end end |
#list_containers(options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fog/azurerm/requests/storage/list_containers.rb', line 6 def list_containers( = {}) Fog::Logger.debug "Listing containers." begin containers = @blob_client.list_containers() Fog::Logger.debug 'Listing containers successfully.' containers rescue Azure::Core::Http::HTTPError => ex raise "Exception in listing containers: #{ex.inspect}" end end |
#list_storage_account_for_rg(resource_group) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/fog/azurerm/requests/storage/list_storage_account_for_rg.rb', line 6 def list_storage_account_for_rg(resource_group) begin promise = @storage_mgmt_client.storage_accounts.list_by_resource_group(resource_group) response = promise.value! body = response.body.value body.each do |obj| obj.properties.last_geo_failover_time = DateTime.parse(Time.now.to_s) end result = Azure::ARM::Storage::Models::StorageAccountListResult.serialize_object(response.body)['value'] result rescue MsRestAzure::AzureOperationError => e msg = "Exception listing Storage Accounts in Resource Group #{resource_group}. #{e.body['error']['message']}" raise msg end end |
#list_storage_accounts ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fog/azurerm/requests/storage/list_storage_accounts.rb', line 6 def list_storage_accounts begin promise = @storage_mgmt_client.storage_accounts.list response = promise.value! body = response.body.value body.each do |obj| obj.properties.last_geo_failover_time = DateTime.parse(Time.now.to_s) end result = Azure::ARM::Storage::Models::StorageAccountListResult.serialize_object(response.body)['value'] puts "Result: #{result}" result rescue MsRestAzure::AzureOperationError => e msg = "Exception listing Storage Accounts. #{e.body['error']['message']}" raise msg end end |
#set_blob_metadata(container_name, name, metadata) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fog/azurerm/requests/storage/set_blob_metadata.rb', line 6 def (container_name, name, ) Fog::Logger.debug "Set Blob #{name} metadata in a container #{container_name}." begin @blob_client.(container_name, name, ) Fog::Logger.debug "Setting metadata of blob #{name} successfully." true rescue Azure::Core::Http::HTTPError => ex raise "Exception in setting metadata of Blob #{name}: #{ex.inspect}" end end |
#set_container_metadata(name, metadata) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fog/azurerm/requests/storage/set_container_metadata.rb', line 6 def (name, ) Fog::Logger.debug "Set Container #{name} metadata." begin @blob_client.(name, ) Fog::Logger.debug "Setting metadata of container #{name} successfully." true rescue Azure::Core::Http::HTTPError => ex raise "Exception in setting metadata of Container #{name}: #{ex.inspect}" end end |