Class: Azure::BaseManagement::BaseManagementService
- Inherits:
-
Object
- Object
- Azure::BaseManagement::BaseManagementService
- Defined in:
- lib/azure/base_management/base_management_service.rb
Instance Method Summary collapse
-
#create_affinity_group(name, location, label, options = {}) ⇒ Object
Public: Creates a new affinity group for the specified subscription.
-
#delete_affinity_group(name) ⇒ Object
Public: Deletes an affinity group in the specified subscription.
-
#get_affinity_group(name) ⇒ Object
Public: returns the system properties associated with the specified affinity group.
-
#initialize ⇒ BaseManagementService
constructor
A new instance of BaseManagementService.
-
#list_affinity_groups ⇒ Object
Public: Gets a lists the affinity groups associated with the specified subscription.
-
#list_locations ⇒ Object
Public: Gets a list of regional data center locations from the server.
-
#update_affinity_group(name, label, options = {}) ⇒ Object
Public: updates the label and/or the description for an affinity group for the specified subscription.
- #validate_configuration ⇒ Object
Constructor Details
#initialize ⇒ BaseManagementService
Returns a new instance of BaseManagementService.
32 33 34 35 36 37 38 39 |
# File 'lib/azure/base_management/base_management_service.rb', line 32 def initialize validate_configuration certificate_key, private_key = read_management_certificate(Azure.config.management_certificate) Azure.configure do |config| config.http_certificate_key = certificate_key config.http_private_key = private_key end end |
Instance Method Details
#create_affinity_group(name, location, label, options = {}) ⇒ Object
Public: Creates a new affinity group for the specified subscription.
Attributes
-
name
- String. Affinity Group name. -
location
- String. The location where the affinity group will
be created.
-
label
- String. Name for the affinity specified as a
base-64 encoded string.
Options
Accepted key/value pairs are:
-
:description
- String. A description for the affinity group.
(optional)
See msdn.microsoft.com/en-us/library/windowsazure/gg715317.aspx
Returns: None
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/azure/base_management/base_management_service.rb', line 131 def create_affinity_group(name, location, label, = {}) if name.nil? || name.strip.empty? raise 'Affinity Group name cannot be empty' elsif list_affinity_groups.map(&:name).include?(name) raise Azure::Error::Error.new( 'ConflictError', 409, "An affinity group #{name}"\ " already exists in the current subscription." ) else validate_location(location) body = Serialization.affinity_group_to_xml(name, location, label, ) request_path = '/affinitygroups' request = ManagementHttpRequest.new(:post, request_path, body) request.call Loggerx.info "Affinity Group #{name} is created." end end |
#delete_affinity_group(name) ⇒ Object
Public: Deletes an affinity group in the specified subscription
Attributes
-
name
- String. Affinity Group name.
See msdn.microsoft.com/en-us/library/windowsazure/gg715314.aspx
Returns: None
192 193 194 195 196 197 198 199 |
# File 'lib/azure/base_management/base_management_service.rb', line 192 def delete_affinity_group(name) if affinity_group(name) request_path = "/affinitygroups/#{name}" request = ManagementHttpRequest.new(:delete, request_path) request.call Loggerx.info "Deleted affinity group #{name}." end end |
#get_affinity_group(name) ⇒ Object
Public: returns the system properties associated with the specified affinity group.
Attributes
-
name
- String. Affinity Group name.
See msdn.microsoft.com/en-us/library/windowsazure/ee460789.aspx
Returns: Azure::BaseManagement::AffinityGroup object
211 212 213 214 215 216 217 218 |
# File 'lib/azure/base_management/base_management_service.rb', line 211 def get_affinity_group(name) if affinity_group(name) request_path = "/affinitygroups/#{name}" request = ManagementHttpRequest.new(:get, request_path) response = request.call Serialization.affinity_group_from_xml(response) end end |
#list_affinity_groups ⇒ Object
Public: Gets a lists the affinity groups associated with the specified subscription.
See msdn.microsoft.com/en-us/library/windowsazure/ee460797.aspx
Returns an array of Azure::BaseManagement::AffinityGroup objects
105 106 107 108 109 110 |
# File 'lib/azure/base_management/base_management_service.rb', line 105 def list_affinity_groups request_path = '/affinitygroups' request = ManagementHttpRequest.new(:get, request_path, nil) response = request.call Serialization.affinity_groups_from_xml(response) end |
#list_locations ⇒ Object
Public: Gets a list of regional data center locations from the server
Returns an array of Azure::BaseManagement::Location objects
93 94 95 96 97 |
# File 'lib/azure/base_management/base_management_service.rb', line 93 def list_locations request = ManagementHttpRequest.new(:get, '/locations') response = request.call Serialization.locations_from_xml(response) end |
#update_affinity_group(name, label, options = {}) ⇒ Object
Public: updates the label and/or the description for an affinity group for the specified subscription.
Attributes
-
name
- String. Affinity Group name. -
label
- String. Name for the affinity specified as a
base-64 encoded string.
Options
Accepted key/value pairs are:
-
:description
- String. A description for the affinity group.
(optional)
See msdn.microsoft.com/en-us/library/windowsazure/gg715316.aspx
Returns: None
172 173 174 175 176 177 178 179 180 181 |
# File 'lib/azure/base_management/base_management_service.rb', line 172 def update_affinity_group(name, label, = {}) raise 'Label name cannot be empty' if label.nil? || label.empty? if affinity_group(name) body = Serialization.resource_to_xml(label, ) request_path = "/affinitygroups/#{name}" request = ManagementHttpRequest.new(:put, request_path, body) request.call Loggerx.info "Affinity Group #{name} is updated." end end |
#validate_configuration ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/azure/base_management/base_management_service.rb', line 41 def validate_configuration subs_id = Azure.config.subscription_id = 'Subscription ID not valid.' raise if subs_id.nil? || subs_id.empty? m_ep = Azure.config.management_endpoint = 'Management endpoint not valid.' raise if m_ep.nil? || m_ep.empty? m_cert = Azure.config.management_certificate if m_cert.is_a?(Hash) = "Management certificate hash #{m_cert} does not have key :type! If specifying a hash, you must specify :type => <:pem, :pfx or :publishsettings>!" raise unless m_cert.has_key?(:type) && %w(pem pfx publishsettings).include?(m_cert[:type].to_s) = "Management certificate hash #{m_cert} does not have the certificate data! If specifying a hash, you must specify either :data => String, :io => <IO object> or :path => <path>!" raise unless [ :data, :io, :path ].any? { |k| m_cert.has_key?(k) } unexpected_keys = m_cert.keys - [ :type, :data, :io, :path ] = "Management certificate hash #{m_cert} has unexpected keys #{unexpected_keys.join(", ")}! Only :type, :data, :io and :path are accepted values when specifying a hash." raise unless unexpected_keys.empty? if m_cert[:data] = "Management certificate :data in #{m_cert} is not a String! Must be a String." raise unless m_cert[:data].is_a?(String) end if m_cert[:io] = "Management certificate :io in #{m_cert} is not an IO object! Must be an IO object." raise unless m_cert[:io].is_a?(IO) end if m_cert[:path] = "Management certificate :path in #{m_cert} is not a String! Must be a String." raise unless m_cert[:path].is_a?(String) unless m_cert[:data] || m_cert[:io] # :path is only used to print information out if data or IO is there = "Could not read from file '#{m_cert[:path]}'." raise unless test('r', m_cert[:data]) end end else m_cert_ext = File.extname(m_cert) = "Management certificate path '#{m_cert}' must have extension .pem, .pfx or .publishsettings" raise unless %w(.pem .pfx .publishsettings).include?(m_cert_ext) = "Could not read from file '#{m_cert}'." raise unless test('r', m_cert) end end |