lib/fog/azurerm/requests/resources/create_deployment.rb in fog-azure-rm-0.0.4 vs lib/fog/azurerm/requests/resources/create_deployment.rb in fog-azure-rm-0.0.5
- old
+ new
@@ -2,43 +2,47 @@
module Resources
class AzureRM
# This class provides the actual implemention for service calls.
class Real
def create_deployment(resource_group, deployment_name, template_link, parameters_link)
+ Fog::Logger.debug "Creating Deployment: #{deployment_name} in Resource Group: #{resource_group}"
+ deployment = create_deployment_object(template_link, parameters_link)
begin
- Fog::Logger.debug "Creating Deployment: #{deployment_name} in Resource Group: #{resource_group}"
- deployment = Azure::ARM::Resources::Models::Deployment.new
- deployment_properties = Azure::ARM::Resources::Models::DeploymentProperties.new
+ @rmc.deployments.validate(resource_group, deployment_name, deployment)
+ deployment = @rmc.deployments.create_or_update(resource_group, deployment_name, deployment)
+ Fog::Logger.debug "Deployment: #{deployment_name} in Resource Group: #{resource_group} created successfully."
+ deployment
+ rescue MsRestAzure::AzureOperationError => e
+ raise Fog::AzureRm::OperationError.new(e)
+ end
+ end
- template_link_obj = Azure::ARM::Resources::Models::TemplateLink.new
- template_link_obj.uri = template_link
+ private
- parameters_link_obj = Azure::ARM::Resources::Models::ParametersLink.new
- parameters_link_obj.uri = parameters_link
+ def create_deployment_object(template_link, parameters_link)
+ deployment = Azure::ARM::Resources::Models::Deployment.new
+ deployment_properties = Azure::ARM::Resources::Models::DeploymentProperties.new
- deployment_properties.template_link = template_link_obj
- deployment_properties.parameters_link = parameters_link_obj
- deployment_properties.mode = 'Incremental'
+ template_link_obj = Azure::ARM::Resources::Models::TemplateLink.new
+ template_link_obj.uri = template_link
- deployment.properties = deployment_properties
+ parameters_link_obj = Azure::ARM::Resources::Models::ParametersLink.new
+ parameters_link_obj.uri = parameters_link
- @rmc.deployments.validate(resource_group, deployment_name, deployment)
- promise = @rmc.deployments.create_or_update(resource_group, deployment_name, deployment)
- result = promise.value!
- Fog::Logger.debug "Deployment: #{deployment_name} in Resource Group: #{resource_group} created successfully."
- Azure::ARM::Resources::Models::DeploymentExtended.serialize_object(result.body)
- rescue MsRestAzure::AzureOperationError => e
- msg = "Exception creating Deployment: #{deployment_name} in Resource Group: #{resource_group}. #{e.body['error']['message']}"
- raise msg
- end
+ deployment_properties.template_link = template_link_obj
+ deployment_properties.parameters_link = parameters_link_obj
+ deployment_properties.mode = 'Incremental'
+
+ deployment.properties = deployment_properties
+ deployment
end
end
# This class provides the mock implementation
class Mock
def create_deployment(resource_group, deployment_name, template_link, parameters_link)
- {
+ deployment = {
id: "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group}/providers/microsoft.resources/deployments/#{deployment_name}",
name: deployment_name,
properties: {
templateLink: {
uri: template_link,
@@ -81,9 +85,11 @@
resourceType: 'namespace1/resourcetype2',
resourceName: 'resourcename2'
}]
}
}
+ result_mapper = Azure::ARM::Resources::Models::DeploymentExtended.mapper
+ @rmc.deserialize(result_mapper, deployment, 'result.body')
end
end
end
end
end