Class: Azure::StorageManagement::StorageManagementService
- Inherits:
-
BaseManagement::BaseManagementService
- Object
- BaseManagement::BaseManagementService
- Azure::StorageManagement::StorageManagementService
- Defined in:
- lib/azure/storage_management/storage_management_service.rb
Overview
Provides Storage Management API
Instance Method Summary collapse
-
#create_storage_account(name, options = {}) ⇒ Object
Public: Create a new storage account in Microsoft Azure.
-
#delete_storage_account(name) ⇒ Object
Public: Deletes the specified storage account of given subscription id from Microsoft Azure.
-
#get_storage_account(name) ⇒ Object
Public: Checks to see if the specified storage account is available.
-
#get_storage_account_keys(name) ⇒ Object
Public: Gets the primary and secondary access keys for the specified storage account.
-
#get_storage_account_properties(name) ⇒ Object
Public: Gets the properties of the storage account specified.
-
#initialize ⇒ StorageManagementService
constructor
A new instance of StorageManagementService.
-
#list_storage_accounts ⇒ Object
Public: Gets a list of storage accounts available under the current subscription.
-
#regenerate_storage_account_keys(name, key_type = 'primary') ⇒ Object
Public: Regenerates the primary or secondary access key for the specified storage account.
-
#update_storage_account(name, options) ⇒ Object
Public: Updates an existing storage account in Microsoft Azure.
Methods inherited from BaseManagement::BaseManagementService
#create_affinity_group, #delete_affinity_group, #get_affinity_group, #list_affinity_groups, #list_locations, #list_role_sizes, #update_affinity_group, #validate_configuration
Constructor Details
#initialize ⇒ StorageManagementService
Returns a new instance of StorageManagementService.
21 22 23 |
# File 'lib/azure/storage_management/storage_management_service.rb', line 21 def initialize super() end |
Instance Method Details
#create_storage_account(name, options = {}) ⇒ Object
Public: Create a new storage account in Microsoft Azure.
Attributes
-
name
- String. The name of the storage service. -
options
- Hash. Optional parameters.
Options
Accepted key/value pairs in options parameter are:
-
:label
- String. The label for this storage account. The name will
be used as label if none specified. (optional)
-
:location
- String. The location where the storage
service will be created. Reqruied if no affinity_group_name specified.
-
:description
- String. A description for the storage
service. (optional)
-
:affinity_group_name
- String. The name of an existing affinity group
in the specified subscription. Required if no location specified.
-
:geo_replication_enabled
- String. A flag indicating wheter to
turn Geo replication on or off. Values other than ‘true’/‘false’ will result in an error from the REST API. (optional)
-
:extended_properties
- Hash. Key/Value pairs of extended
properties to add to the storage account. The key is used as the property name and the value as its value. (optional)
-
:account_type
- String. Specifies the type of storage account
See msdn.microsoft.com/en-us/library/azure/hh264518.aspx
Returns None
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/azure/storage_management/storage_management_service.rb', line 91 def create_storage_account(name, = {}) raise 'Name not specified' if !name || name.class != String || name.empty? [:account_type] ||= 'Standard_GRS' if get_storage_account(name) Azure::Loggerx.warn "Storage Account #{name} already exists. Skipped..." else Azure::Loggerx.info "Creating Storage Account #{name}." body = Serialization.storage_services_to_xml(name, ) request_path = '/services/storageservices' request = Azure::BaseManagement::ManagementHttpRequest.new(:post, request_path, body) request.call end end |
#delete_storage_account(name) ⇒ Object
Public: Deletes the specified storage account of given subscription id from Microsoft Azure.
Attributes
-
name
- String. Storage account name.
See msdn.microsoft.com/en-us/library/azure/hh264517.aspx
Returns: None
154 155 156 157 158 159 160 161 |
# File 'lib/azure/storage_management/storage_management_service.rb', line 154 def delete_storage_account(name) Azure::Loggerx.info "Deleting Storage Account #{name}." request_path = "/services/storageservices/#{name}" request = Azure::BaseManagement::ManagementHttpRequest.new(:delete, request_path) request.call rescue => e e. end |
#get_storage_account(name) ⇒ Object
Public: Checks to see if the specified storage account is available
Attributes
-
name
- String. Storage account name.
Returns an Azure::StorageManagement::StorageAccount instance
42 43 44 |
# File 'lib/azure/storage_management/storage_management_service.rb', line 42 def get_storage_account(name) list_storage_accounts.select { |x| x.name.casecmp(name.to_s) == 0 }.first end |
#get_storage_account_keys(name) ⇒ Object
Public: Gets the primary and secondary access keys for the specified storage account.
Attributes
-
name
- String. Storage account name.
Returns an Azure::StorageManagement::StorageAccountKeys instance.
196 197 198 199 200 201 202 203 204 205 |
# File 'lib/azure/storage_management/storage_management_service.rb', line 196 def get_storage_account_keys(name) if get_storage_account name path = "/services/storageservices/#{name}/keys" request = Azure::BaseManagement::ManagementHttpRequest.new(:get, path) response = request.call Serialization.storage_account_keys_from_xml(response) else Azure::Loggerx.warn "Storage Account '#{name}' does not exist." end end |
#get_storage_account_properties(name) ⇒ Object
Public: Gets the properties of the storage account specified.
Attributes
-
name
- String. The name of the storage account. Required.
See msdn.microsoft.com/en-us/library/azure/ee460802.aspx
Returns the storage account
55 56 57 58 59 60 |
# File 'lib/azure/storage_management/storage_management_service.rb', line 55 def get_storage_account_properties(name) request_path = "/services/storageservices/#{name}" request = Azure::BaseManagement::ManagementHttpRequest.new(:get, request_path, nil) response = request.call Serialization.storage_services_from_xml(response).first end |
#list_storage_accounts ⇒ Object
Public: Gets a list of storage accounts available under the current subscription.
Returns an array of Azure::StorageManagement::StorageAccount objects
28 29 30 31 32 33 |
# File 'lib/azure/storage_management/storage_management_service.rb', line 28 def list_storage_accounts request_path = '/services/storageservices' request = Azure::BaseManagement::ManagementHttpRequest.new(:get, request_path, nil) response = request.call Serialization.storage_services_from_xml(response) end |
#regenerate_storage_account_keys(name, key_type = 'primary') ⇒ Object
Public: Regenerates the primary or secondary access key for the specified storage account
Attributes
-
name
- String. Storage account name. -
key_type
- String. Specifies which key(primary or secondary) to regenerate
Returns an Azure::StorageManagement::StorageAccountKeys instance.
174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/azure/storage_management/storage_management_service.rb', line 174 def regenerate_storage_account_keys(name, key_type = 'primary') if get_storage_account name path = "/services/storageservices/#{name}/keys?action=regenerate" body = Serialization.regenerate_storage_account_keys_to_xml key_type request = Azure::BaseManagement::ManagementHttpRequest.new(:post, path, body) response = request.call Serialization.storage_account_keys_from_xml(response) else Azure::Loggerx.warn "Storage Account '#{name}' does not exist." end end |
#update_storage_account(name, options) ⇒ Object
Public: Updates an existing storage account in Microsoft Azure
Attributes
-
name
- String. The name of the storage service. -
options
- Hash. parameters.
Options
Accepted key/value pairs in options parameter are:
-
:label
- String. A label for the storage service. Required if no
description is provided. If both label and description are provided, only the label will get updated.
-
:description
- String. A description for the storage service.
Required if no label is provided. If both label and description are provided, only the label will get updated.
-
:geo_replication_enabled
- Boolean (TrueClass/FalseClass). Boolean
flag indicating whether to turn Geo replication on or off. (optional)
-
:extended_properties
- Hash. Key/Value pairs of extended
properties to add to the storage account. The key is used as the property name and the value as its value. (optional)
-
:account_type
- String. Specifies the type of storage account
See msdn.microsoft.com/en-us/library/azure/hh264516.aspx
Returns None Fails with RuntimeError if invalid options specified
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/azure/storage_management/storage_management_service.rb', line 132 def update_storage_account(name, ) if get_storage_account name Azure::Loggerx.info "Account '#{name}' exists, updating..." body = Serialization.storage_update_to_xml request_path = "/services/storageservices/#{name}" request = Azure::BaseManagement::ManagementHttpRequest.new(:put, request_path, body) request.call else Azure::Loggerx.warn "Storage Account '#{name}' does not exist. Skipped..." end end |