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/get_storage_account.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 implementation for service calls.
Instance Method Summary collapse
- #check_storage_account_name_availability(params) ⇒ Object
- #create_container(name, options = {}) ⇒ Object
- #create_storage_account(storage_account_hash) ⇒ 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
- #get_storage_account(resource_group_name, storage_account_name) ⇒ 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 |
# File 'lib/fog/azurerm/requests/storage/check_storage_account_name_availability.rb', line 6 def check_storage_account_name_availability(params) msg = "Checking Name availability: #{params.name}." Fog::Logger.debug msg begin name_available_obj = @storage_mgmt_client.storage_accounts.check_name_availability(params) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end if name_available_obj.name_available 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 end |
#create_container(name, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/storage/create_container.rb', line 6 def create_container(name, = {}) msg = "Creating container: #{name}." Fog::Logger.debug msg begin container = @blob_client.create_container(name, ) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Container #{name} created successfully." container end |
#create_storage_account(storage_account_hash) ⇒ 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(storage_account_hash) msg = "Creating Storage Account: #{storage_account_hash[:name]} in Resource Group #{storage_account_hash[:resource_group]}." Fog::Logger.debug msg storage_account_params = get_storage_account_params(storage_account_hash[:sku_name], storage_account_hash[:location], storage_account_hash[:replication]) begin storage_account = @storage_mgmt_client.storage_accounts.create(storage_account_hash[:resource_group], storage_account_hash[:name], storage_account_params) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug 'Storage Account created successfully.' storage_account end |
#delete_container(name, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/storage/delete_container.rb', line 6 def delete_container(name, = {}) msg = "Deleting container: #{name}." Fog::Logger.debug msg begin @blob_client.delete_container(name, ) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Container #{name} deleted successfully." true 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 25 |
# File 'lib/fog/azurerm/requests/storage/delete_disk.rb', line 6 def delete_disk(resource_group, storage_account_name, blob_name) msg = "Deleting Disk: #{blob_name}." Fog::Logger.debug msg keys = get_storage_access_keys(resource_group, storage_account_name) access_key = keys[1].value 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") rescue Azure::Core::Http::HTTPError => e raise_azure_exception(e, msg) end if result.nil? Fog::Logger.debug "Successfully deleted Disk: #{blob_name}." true else Fog::Logger.debug 'Error deleting Disk.' false end end |
#delete_storage_account(resource_group, name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/storage/delete_storage_account.rb', line 6 def delete_storage_account(resource_group, name) msg = "Deleting Storage Account: #{name} in Resource Group #{resource_group}." Fog::Logger.debug msg begin @storage_mgmt_client.storage_accounts.delete(resource_group, name) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Storage Account #{name} deleted successfully." true end |
#get_blob_metadata(container_name, name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/storage/get_blob_metadata.rb', line 6 def (container_name, name) msg = "Getting Blob #{name} metadata in container #{container_name}." Fog::Logger.debug msg begin blob = @blob_client.(container_name, name) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Getting metadata of blob #{name} successfully." blob. end |
#get_container_access_control_list(name, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/storage/get_container_access_control_list.rb', line 6 def get_container_access_control_list(name, = {}) msg = "Get container ACL: #{name}." Fog::Logger.debug msg begin container_acl = @blob_client.get_container_acl(name, ) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Getting ACL of container #{name} successfully." container_acl end |
#get_container_metadata(name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/storage/get_container_metadata.rb', line 6 def (name) msg = "Getting Container #{name} metadata." Fog::Logger.debug msg begin container = @blob_client.(name) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Getting metadata of container #{name} successfully." container. end |
#get_container_properties(name, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/storage/get_container_properties.rb', line 6 def get_container_properties(name, = {}) msg = "Getting container properties: #{name}." Fog::Logger.debug msg begin container_properties = @blob_client.get_container_properties(name, ) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Getting properties of container #{name} successfully." container_properties 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, = {}) msg = "Getting storage access keys for storage account: #{storage_account_name}." Fog::Logger.debug msg begin storage_account_keys = @storage_mgmt_client.storage_accounts.list_keys(resource_group, storage_account_name, ) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Storage access keys for storage account: #{storage_account_name} listed successfully." storage_account_keys.keys end |
#get_storage_account(resource_group_name, storage_account_name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/storage/get_storage_account.rb', line 6 def get_storage_account(resource_group_name, storage_account_name) msg = "Getting storage account: #{storage_account_name}." Fog::Logger.debug msg begin storage_account = @storage_mgmt_client.storage_accounts.get_properties(resource_group_name, storage_account_name) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end Fog::Logger.debug "Getting storage account: #{storage_account_name} successfully." storage_account end |
#list_containers(options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/storage/list_containers.rb', line 6 def list_containers( = {}) msg = "Listing containers." Fog::Logger.debug msg begin containers = @blob_client.list_containers() rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug 'Listing containers successfully.' containers end |
#list_storage_account_for_rg(resource_group) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fog/azurerm/requests/storage/list_storage_account_for_rg.rb', line 6 def list_storage_account_for_rg(resource_group) msg = "Listing Storage Accounts in Resource Group #{resource_group}." Fog::Logger.debug msg begin result = @storage_mgmt_client.storage_accounts.list_by_resource_group(resource_group) rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end result.value end |
#list_storage_accounts ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fog/azurerm/requests/storage/list_storage_accounts.rb', line 6 def list_storage_accounts msg = 'Listing Storage Accounts.' Fog::Logger.debug msg begin result = @storage_mgmt_client.storage_accounts.list rescue MsRestAzure::AzureOperationError => e raise_azure_exception(e, msg) end result.value end |
#set_blob_metadata(container_name, name, metadata) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/storage/set_blob_metadata.rb', line 6 def (container_name, name, ) msg = "Setting Blob #{name} metadata in a container #{container_name}." Fog::Logger.debug msg begin @blob_client.(container_name, name, ) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Setting metadata of blob #{name} successfully." true end |
#set_container_metadata(name, metadata) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fog/azurerm/requests/storage/set_container_metadata.rb', line 6 def (name, ) msg = "Setting Container #{name} metadata." Fog::Logger.debug msg begin @blob_client.(name, ) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Setting metadata of container #{name} successfully." true end |