Class: Azure::StorageAccounts

Inherits:
Object
  • Object
show all
Includes:
AzureUtility
Defined in:
lib/azure/service_management/storageaccount.rb

Instance Method Summary collapse

Methods included from AzureUtility

#error_from_response_xml, #xml_content

Constructor Details

#initialize(connection) ⇒ StorageAccounts

Returns a new instance of StorageAccounts.



22
23
24
# File 'lib/azure/service_management/storageaccount.rb', line 22

def initialize(connection)
  @connection=connection
end

Instance Method Details

#allObject



43
44
45
# File 'lib/azure/service_management/storageaccount.rb', line 43

def all
  self.load.values
end

#clear_unattachedObject



69
70
71
72
73
74
# File 'lib/azure/service_management/storageaccount.rb', line 69

def clear_unattached
  self.all.each do |storage|
    next unless storage.attached == false
    @connection.query_azure('storageaccounts/' + storage.name, 'delete')
  end
end

#create(params) ⇒ Object



65
66
67
68
# File 'lib/azure/service_management/storageaccount.rb', line 65

def create(params)
  storage = StorageAccount.new(@connection)
  storage.create(params)
end

#delete(name) ⇒ Object



76
77
78
79
80
81
# File 'lib/azure/service_management/storageaccount.rb', line 76

def delete(name)
  if self.exists?(name)
      servicecall = "storageservices/" + name
    @connection.query_azure(servicecall, "delete") 
  end
end

#exists?(name) ⇒ Boolean

first look up local cache if we have already loaded list.

Returns:

  • (Boolean)


48
49
50
51
# File 'lib/azure/service_management/storageaccount.rb', line 48

def exists?(name)
  return @azure_storage_accounts.key?(name) if @azure_storage_accounts
  self.exists_on_cloud?(name)
end

#exists_on_cloud?(name) ⇒ Boolean

Look up on cloud and not local cache

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
62
63
# File 'lib/azure/service_management/storageaccount.rb', line 54

def exists_on_cloud?(name)
  ret_val = @connection.query_azure("storageservices/#{name}")
  error_code, error_message = error_from_response_xml(ret_val) if ret_val
  if ret_val.nil? || error_code.length > 0
    Chef::Log.warn 'Unable to find storage account:' + error_message + ' : ' + error_message if ret_val
    false
  else
    true
  end
end

#load(force_load = false) ⇒ Object

force_load should be true when there is something in local cache and we want to reload first call is always load.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/azure/service_management/storageaccount.rb', line 27

def load(force_load = false)
  if not @azure_storage_accounts || force_load
    @azure_storage_accounts = begin
      azure_storage_accounts = Hash.new
      responseXML = @connection.query_azure('storageservices')
      servicesXML = responseXML.css('StorageServices StorageService')
      servicesXML.each do |serviceXML|
        storage = StorageAccount.new(@connection).parse(serviceXML)
        azure_storage_accounts[storage.name] = storage
      end
      azure_storage_accounts
    end
  end
  @azure_storage_accounts
end