Class: Armrest::Services::StorageAccount

Inherits:
Base
  • Object
show all
Defined in:
lib/armrest/services/storage_account.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Api::Settings

#client_id, #client_secret, #endpoint, #group, #location, #resource, #subscription_id, #tenant_id

Methods included from Api::HandleResponse

#load_json, #ok?

Methods included from Logging

#default_logger, #logger, #logger=

Constructor Details

This class inherits a constructor from Armrest::Services::Base

Instance Method Details

#check_name_availability(attrs = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/armrest/services/storage_account.rb', line 5

def check_name_availability(attrs={})
  name = attrs[:name]
  path = "subscriptions/#{subscription_id}/providers/Microsoft.Storage/checkNameAvailability"
  attrs = {
    name: name,
    type: "Microsoft.Storage/storageAccounts",
  }
  res = api.post(path, attrs)
  load_json(res)
end

#create(attrs = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/armrest/services/storage_account.rb', line 19

def create(attrs={})
  name = attrs.delete(:name)
  # https://docs.microsoft.com/en-us/rest/api/storagerp/storage-accounts/create#request-body
  attrs[:kind] ||= "StorageV2"
  attrs[:location] ||= location
  attrs[:sku] ||= {
    name: "Standard_RAGRS", # default according to az storage account create --help
    tier: "Standard",
  }
  attrs[:properties] ||= {
    allow_blob_public_access: false
  }
  path = "subscriptions/#{subscription_id}/resourceGroups/#{group}/providers/Microsoft.Storage/storageAccounts/#{name}"
  resp = api.put(path, attrs)
end