Class: Azure::StorageManagement::StorageManagementService

Inherits:
BaseManagementService
  • Object
show all
Defined in:
lib/azure/storage_management/storage_management_service.rb

Overview

Provides Storage Management API

Instance Method Summary collapse

Constructor Details

#initializeStorageManagementService

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 Windows 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)

Returns None



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/azure/storage_management/storage_management_service.rb', line 99

def (name, options = {})
  raise 'Name not specified' if !name || name.class != String || name.empty?
  if (name)
    Loggerx.warn "Storage Account #{name} already exists. Skipped..."
  else
    Loggerx.info "Creating Storage Account #{name}."
    body = Serialization.storage_services_to_xml(name, options)
    request_path = '/services/storageservices'
    request = 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 Windows Azure.

Attributes

  • name - String. Storage account name.

Returns: None



156
157
158
159
160
161
162
163
# File 'lib/azure/storage_management/storage_management_service.rb', line 156

def (name)
  Loggerx.info "Deleting Storage Account #{name}."
  request_path = "/services/storageservices/#{name}"
  request = ManagementHttpRequest.new(:delete, request_path)
  request.call
rescue Exception => e
  e.message
end

#get_storage_account(name) ⇒ Object

Public: Checks to see if the specified storage account is available

Attributes

  • name - String. Storage account name.

Returns: A boolean value indicating whether the storage account exists. If true, the storage account exists. If false, the storage account does not exist.



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/azure/storage_management/storage_management_service.rb', line 44

def (name)
  return false if name.nil?
  flag = false
  storage_accounts = list_storage_accounts
  storage_accounts.each do |storage|
    if storage.name == name
      flag = true
      break
    end
  end
  flag
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/windowsazure/ee460802.aspx

Returns the storage account



66
67
68
69
70
71
# File 'lib/azure/storage_management/storage_management_service.rb', line 66

def (name)
  request_path = "/services/storageservices/#{name}"
  request = ManagementHttpRequest.new(:get, request_path, nil)
  response = request.call
  Serialization.storage_services_from_xml(response).first
end

#list_storage_accountsObject

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 = ManagementHttpRequest.new(:get, request_path, nil)
  response = request.call
  Serialization.storage_services_from_xml(response)
end

#update_storage_account(name, options = {}) ⇒ Object

Public: Updates an existing storage account in Windows 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. 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 wheter 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)

Returns None Fails with RuntimeError if invalid options specified



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/azure/storage_management/storage_management_service.rb', line 136

def (name, options = {})
  if  name
    Loggerx.info "Account '#{name}' exists, updating..."
    body = Serialization.storage_update_to_xml options
    request_path = "/services/storageservices/#{name}"
    request = ManagementHttpRequest.new(:put, request_path, body)
    request.call
  else
    Loggerx.warn "Storage Account '#{name}' does not exist. Skipped..."
  end
end