lib/fog/azurerm/requests/compute/create_availability_set.rb in fog-azure-rm-0.0.4 vs lib/fog/azurerm/requests/compute/create_availability_set.rb in fog-azure-rm-0.0.5
- old
+ new
@@ -1,36 +1,31 @@
module Fog
module Compute
class AzureRM
- # This class provides the actual implemention for service calls.
+ # This class provides the actual implementation for service calls.
class Real
def create_availability_set(resource_group, name, location)
+ msg = "Creating Availability Set '#{name}' in #{location} region."
+ Fog::Logger.debug msg
+ avail_set_params = get_availability_set_properties(location)
begin
- Fog::Logger.debug "Creating Availability Set '#{name}' in #{location} region."
- avail_set_props = get_avail_set_properties(location)
- promise = @compute_mgmt_client.availability_sets.create_or_update(resource_group, name, avail_set_props)
- result = promise.value!
- Fog::Logger.debug "Availability Set #{name} created successfully."
- Azure::ARM::Compute::Models::AvailabilitySet.serialize_object(result.body)
+ availability_set = @compute_mgmt_client.availability_sets.create_or_update(resource_group, name, avail_set_params)
rescue MsRestAzure::AzureOperationError => e
- msg = "Exception creating Availability Set #{name} in Resource Group: #{resource_group}. #{e.body['error']['message']}"
- raise msg
+ raise_azure_exception(e, msg)
end
+ Fog::Logger.debug "Availability Set #{name} created successfully."
+ availability_set
end
# create the properties object for creating availability sets
- def get_avail_set_properties(location)
- avail_set_props = Azure::ARM::Compute::Models::AvailabilitySetProperties.new
- # At least two domain faults
- avail_set_props.platform_fault_domain_count = 2
- avail_set_props.platform_update_domain_count = 2
- # At this point we do not have virtual machines to include
- avail_set_props.virtual_machines = []
- avail_set_props.statuses = []
+ def get_availability_set_properties(location)
avail_set = Azure::ARM::Compute::Models::AvailabilitySet.new
+ avail_set.platform_fault_domain_count = FAULT_DOMAIN_COUNT
+ avail_set.platform_update_domain_count = UPDATE_DOMAIN_COUNT
+ avail_set.virtual_machines = []
+ avail_set.statuses = []
avail_set.location = location
- avail_set.properties = avail_set_props
avail_set
end
end
# This class provides the mock implementation for unit tests.
class Mock
@@ -40,11 +35,11 @@
'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group}/providers/Microsoft.Compute/availabilitySets/#{name}",
'name' => name,
'type' => 'Microsoft.Compute/availabilitySets',
'properties' =>
{
- 'platformUpdateDomainCount' => 2,
- 'platformFaultDomainCount' => 2
+ 'platformUpdateDomainCount' => FAULT_DOMAIN_COUNT,
+ 'platformFaultDomainCount' => FAULT_DOMAIN_COUNT
}
}
end
end
end