Class: Azure::Armrest::StorageAccountService
- Inherits:
-
ResourceGroupBasedService
- Object
- ArmrestService
- ResourceGroupBasedService
- Azure::Armrest::StorageAccountService
- Defined in:
- lib/azure/armrest/storage_account_service.rb
Overview
Class for managing storage accounts.
Instance Attribute Summary
Attributes inherited from ArmrestService
#api_version, #armrest_configuration, #base_url, #provider
Instance Method Summary collapse
- #accounts_by_name ⇒ Object
-
#create(account_name, rgroup = configuration.resource_group, options) ⇒ Object
Creates a new storage account, or updates an existing account with the specified parameters.
-
#get(name, resource_group = configuration.resource_group) ⇒ Object
Same as other resource based get methods, but also sets the proxy on the model object.
-
#initialize(configuration, options = {}) ⇒ StorageAccountService
constructor
Creates and returns a new StorageAccountService (SAS) instance.
-
#list(resource_group = configuration.resource_group) ⇒ Object
Same as other resource based list methods, but also sets the proxy on each model object.
-
#list_account_key_objects(account_name, group = configuration.resource_group) ⇒ Object
(also: #list_storage_account_key_objects)
Returns a list of StorageAccountKey objects consisting of information the primary and secondary keys.
-
#list_account_keys(account_name, group = configuration.resource_group) ⇒ Object
(also: #list_storage_account_keys)
Returns the primary and secondary access keys for the given storage account.
-
#list_all ⇒ Object
Same as other resource based list_all methods, but also sets the proxy on each model object.
-
#list_all_private_images(filter = {}) ⇒ Object
Returns a list of PrivateImage objects that are available for provisioning for all storage accounts in the current subscription.
-
#list_private_images(group = configuration.resource_group) ⇒ Object
Returns a list of PrivateImage objects that are available for provisioning for all storage accounts in the provided resource group.
- #parse_uri(uri) ⇒ Object
-
#regenerate_account_key_objects(account_name, group = configuration.resource_group, key_name = 'key1') ⇒ Object
(also: #regenerate_storage_account_key_objects)
Same as regenerate_account_keys, but returns an array of StorageAccountKey objects instead.
-
#regenerate_account_keys(account_name, group = configuration.resource_group, key_name = 'key1') ⇒ Object
(also: #regenerate_storage_account_keys)
Regenerates the primary or secondary access keys for the given storage account.
Methods inherited from ResourceGroupBasedService
Methods inherited from ArmrestService
configure, #get_provider, #get_subscription, #list_resource_groups, #list_resources, #list_subscriptions, #locations, #tags, #tenants
Constructor Details
#initialize(configuration, options = {}) ⇒ StorageAccountService
Creates and returns a new StorageAccountService (SAS) instance.
9 10 11 |
# File 'lib/azure/armrest/storage_account_service.rb', line 9 def initialize(configuration, = {}) super(configuration, 'storageAccounts', 'Microsoft.Storage', ) end |
Instance Method Details
#accounts_by_name ⇒ Object
210 211 212 |
# File 'lib/azure/armrest/storage_account_service.rb', line 210 def accounts_by_name @accounts_by_name ||= list_all.each_with_object({}) { |sa, sah| sah[sa.name] = sa } end |
#create(account_name, rgroup = configuration.resource_group, options) ⇒ Object
Creates a new storage account, or updates an existing account with the specified parameters.
Note that the name of the storage account within the specified must be 3-24 alphanumeric lowercase characters.
The options available are as follows:
-
:validating Optional. Set to ‘nameAvailability’ to indicate that the account name must be checked for global availability.
-
:properties
-
:accountType The type of storage account, e.g. “Standard_GRS”.
-
-
:location Required: One of the Azure geo regions, e.g. ‘West US’.
-
:tags A hash of tags to describe the resource. You may have a maximum of 10 tags, and each key has a max size of 128 characters, and each value has a max size of 256 characters. These are optional.
Example:
sas = Azure::Armrest::StorageAccountService(config)
sas.create(
"your_storage_account",
"your_resource_group",
{
:location => "West US",
:properties => {:accountType => "Standard_ZRS"},
:tags => {:YourCompany => true}
}
)
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/azure/armrest/storage_account_service.rb', line 81 def create(account_name, rgroup = configuration.resource_group, ) validating = .delete(:validating) validate_account_name(account_name) acct = super(account_name, rgroup, ) do |url| url << "&validating=" << validating if validating end # An initial create call will return nil because the response body is # empty. In that case, make another call to get the object properties. acct = get(account_name, rgroup) unless acct acct.proxy = configuration.proxy acct.ssl_version = configuration.ssl_version acct.ssl_verify = configuration.ssl_verify acct end |
#get(name, resource_group = configuration.resource_group) ⇒ Object
Same as other resource based get methods, but also sets the proxy on the model object.
15 16 17 18 19 20 21 |
# File 'lib/azure/armrest/storage_account_service.rb', line 15 def get(name, resource_group = configuration.resource_group) super.tap do |m| m.proxy = configuration.proxy m.ssl_version = configuration.ssl_version m.ssl_verify = configuration.ssl_verify end end |
#list(resource_group = configuration.resource_group) ⇒ Object
Same as other resource based list methods, but also sets the proxy on each model object.
25 26 27 28 29 30 31 |
# File 'lib/azure/armrest/storage_account_service.rb', line 25 def list(resource_group = configuration.resource_group) super.each do |m| m.proxy = configuration.proxy m.ssl_version = configuration.ssl_version m.ssl_verify = configuration.ssl_verify end end |
#list_account_key_objects(account_name, group = configuration.resource_group) ⇒ Object Also known as: list_storage_account_key_objects
Returns a list of StorageAccountKey objects consisting of information the primary and secondary keys. This method requires an api-version string of 2016-01-01 or later, or an error is raised.
If you want a plain hash, use the list_account_keys method instead.
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/azure/armrest/storage_account_service.rb', line 125 def list_account_key_objects(account_name, group = configuration.resource_group) validate_resource_group(group) unless recent_api_version? raise ArgumentError, "unsupported api-version string '#{api_version}'" end url = build_url(group, account_name, 'listKeys') response = rest_post(url) JSON.parse(response.body)['keys'].map { |hash| StorageAccountKey.new(hash) } end |
#list_account_keys(account_name, group = configuration.resource_group) ⇒ Object Also known as: list_storage_account_keys
Returns the primary and secondary access keys for the given storage account. This method will return a hash with ‘key1’ and ‘key2’ as its keys.
If you want a list of StorageAccountKey objects, then use the list_account_key_objects method instead.
107 108 109 110 111 112 113 114 115 |
# File 'lib/azure/armrest/storage_account_service.rb', line 107 def list_account_keys(account_name, group = configuration.resource_group) validate_resource_group(group) url = build_url(group, account_name, 'listKeys') response = rest_post(url) hash = JSON.parse(response.body) parse_account_keys_from_hash(hash) end |
#list_all ⇒ Object
Same as other resource based list_all methods, but also sets the proxy on each model object.
35 36 37 38 39 40 41 |
# File 'lib/azure/armrest/storage_account_service.rb', line 35 def list_all super.each do |m| m.proxy = configuration.proxy m.ssl_version = configuration.ssl_version m.ssl_verify = configuration.ssl_verify end end |
#list_all_private_images(filter = {}) ⇒ Object
Returns a list of PrivateImage objects that are available for provisioning for all storage accounts in the current subscription.
You may optionally reduce the set of storage accounts that will be scanned by providing a filter, where the keys are StorageAccount properties.
Example:
sas.list_all_private_images(:location => 'eastus', resource_group => 'some_group')
190 191 192 193 |
# File 'lib/azure/armrest/storage_account_service.rb', line 190 def list_all_private_images(filter = {}) storage_accounts = list_all.select { |acct| filter.all? { |k, v| acct.public_send(k) == v } } get_private_images(storage_accounts) end |
#list_private_images(group = configuration.resource_group) ⇒ Object
Returns a list of PrivateImage objects that are available for provisioning for all storage accounts in the provided resource group.
The custom keys :uri and :operating_system have been added to the resulting PrivateImage objects for convenience.
Example:
sas.list_private_images(your_resource_group)
205 206 207 208 |
# File 'lib/azure/armrest/storage_account_service.rb', line 205 def list_private_images(group = configuration.resource_group) storage_accounts = list(group) get_private_images(storage_accounts) end |
#parse_uri(uri) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/azure/armrest/storage_account_service.rb', line 214 def parse_uri(uri) uri = Addressable::URI.parse(uri) host_components = uri.host.split('.') rh = { :scheme => uri.scheme, :account_name => host_components[0], :service_name => host_components[1], :resource_path => uri.path } # TODO: support other service types. return rh unless rh[:service_name] == "blob" blob_components = uri.path.split('/', 3) if blob_components[2] rh[:container] = blob_components[1] rh[:blob] = blob_components[2] else rh[:container] = '$root' rh[:blob] = blob_components[1] end return rh unless uri.query && uri.query.start_with?("snapshot=") rh[:snapshot] = uri.query.split('=', 2)[1] rh end |
#regenerate_account_key_objects(account_name, group = configuration.resource_group, key_name = 'key1') ⇒ Object Also known as: regenerate_storage_account_key_objects
Same as regenerate_account_keys, but returns an array of StorageAccountKey objects instead.
This method requires an api-version string of 2016-01-01 or later or an ArgumentError is raised.
163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/azure/armrest/storage_account_service.rb', line 163 def regenerate_account_key_objects(account_name, group = configuration.resource_group, key_name = 'key1') validate_resource_group(group) unless recent_api_version? raise ArgumentError, "unsupported api-version string '#{api_version}'" end = {'keyName' => key_name} url = build_url(group, account_name, 'regenerateKey') response = rest_post(url, .to_json) JSON.parse(response.body)['keys'].map { |hash| StorageAccountKey.new(hash) } end |
#regenerate_account_keys(account_name, group = configuration.resource_group, key_name = 'key1') ⇒ Object Also known as: regenerate_storage_account_keys
Regenerates the primary or secondary access keys for the given storage account. The key_name may be either ‘key1’ or ‘key2’. If no key name is provided, then it defaults to ‘key1’.
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/azure/armrest/storage_account_service.rb', line 143 def regenerate_account_keys(account_name, group = configuration.resource_group, key_name = 'key1') validate_resource_group(group) = {'keyName' => key_name} url = build_url(group, account_name, 'regenerateKey') response = rest_post(url, .to_json) hash = JSON.parse(response.body) parse_account_keys_from_hash(hash) end |