Beispiel #1
0
    def deploy_template(self):
        """
        Deploy the targeted template and parameters
        :param module: Ansible module containing the validated configuration for the deployment template
        :param client: resource management client for azure
        :param conn_info: connection info needed
        :return:
        """

        deploy_parameter = DeploymentProperties()
        deploy_parameter.mode = self.deployment_mode
        if not self.parameters_link:
            deploy_parameter.parameters = self.parameters
        else:
            deploy_parameter.parameters_link = ParametersLink(
                uri=self.parameters_link
            )
        if not self.template_link:
            deploy_parameter.template = self.template
        else:
            deploy_parameter.template_link = TemplateLink(
                uri=self.template_link
            )

        params = ResourceGroup(location=self.location, tags=self.tags)

        try:
            self.rm_client.resource_groups.create_or_update(self.resource_group_name, params)
        except CloudError as exc:
            self.fail("Resource group create_or_update failed with status code: %s and message: %s" %
                      (exc.status_code, exc.message))
        try:
            result = self.rm_client.deployments.create_or_update(self.resource_group_name,
                                                                 self.deployment_name,
                                                                 deploy_parameter)

            deployment_result = self.get_poller_result(result)
            if self.wait_for_deployment_completion:
                while deployment_result.properties.provisioning_state not in ['Canceled', 'Failed', 'Deleted',
                                                                              'Succeeded']:
                    time.sleep(self.wait_for_deployment_polling_period)
                    deployment_result = self.rm_client.deployments.get(self.resource_group_name, self.deployment_name)
        except CloudError as exc:
            failed_deployment_operations = self._get_failed_deployment_operations(self.deployment_name)
            self.log("Deployment failed %s: %s" % (exc.status_code, exc.message))
            self.fail("Deployment failed with status code: %s and message: %s" % (exc.status_code, exc.message),
                      failed_deployment_operations=failed_deployment_operations)

        if self.wait_for_deployment_completion and deployment_result.properties.provisioning_state != 'Succeeded':
            self.log("provisioning state: %s" % deployment_result.properties.provisioning_state)
            failed_deployment_operations = self._get_failed_deployment_operations(self.deployment_name)
            self.fail('Deployment failed. Deployment id: %s' % deployment_result.id,
                      failed_deployment_operations=failed_deployment_operations)

        return deployment_result
Beispiel #2
0
    def deploy_template(self):
        """
        Deploy the targeted template and parameters
        :param module: Ansible module containing the validated configuration for the deployment template
        :param client: resource management client for azure
        :param conn_info: connection info needed
        :return:
        """

        deploy_parameter = DeploymentProperties(self.deployment_mode)
        if not self.parameters_link:
            deploy_parameter.parameters = self.parameters
        else:
            deploy_parameter.parameters_link = ParametersLink(
                uri=self.parameters_link
            )
        if not self.template_link:
            deploy_parameter.template = self.template
        else:
            deploy_parameter.template_link = TemplateLink(
                uri=self.template_link
            )

        params = ResourceGroup(location=self.location, tags=self.tags)

        try:
            self.rm_client.resource_groups.create_or_update(self.resource_group_name, params)
        except CloudError as exc:
            self.fail("Resource group create_or_update failed with status code: %s and message: %s" %
                      (exc.status_code, exc.message))
        try:
            result = self.rm_client.deployments.create_or_update(self.resource_group_name,
                                                                 self.deployment_name,
                                                                 deploy_parameter)

            deployment_result = None
            if self.wait_for_deployment_completion:
                deployment_result = self.get_poller_result(result)
                while deployment_result.properties is None or deployment_result.properties.provisioning_state not in ['Canceled', 'Failed', 'Deleted',
                                                                              'Succeeded']:
                    time.sleep(self.wait_for_deployment_polling_period)
                    deployment_result = self.rm_client.deployments.get(self.resource_group_name, self.deployment_name)
        except CloudError as exc:
            failed_deployment_operations = self._get_failed_deployment_operations(self.deployment_name)
            self.log("Deployment failed %s: %s" % (exc.status_code, exc.message))
            self.fail("Deployment failed with status code: %s and message: %s" % (exc.status_code, exc.message),
                      failed_deployment_operations=failed_deployment_operations)

        if self.wait_for_deployment_completion and deployment_result.properties.provisioning_state != 'Succeeded':
            self.log("provisioning state: %s" % deployment_result.properties.provisioning_state)
            failed_deployment_operations = self._get_failed_deployment_operations(self.deployment_name)
            self.fail('Deployment failed. Deployment id: %s' % deployment_result.id,
                      failed_deployment_operations=failed_deployment_operations)

        return deployment_result
Beispiel #3
0
def deploy_template(module, client, conn_info):
    """
    Deploy the targeted template and parameters
    :param module: Ansible module containing the validated configuration for the deployment template
    :param client: resource management client for azure
    :param conn_info: connection info needed
    :return:
    """

    deployment_name = conn_info["deployment_name"]
    group_name = conn_info["resource_group_name"]

    deploy_parameter = DeploymentProperties()
    deploy_parameter.mode = "Complete"

    if module.params.get('parameters_link') is None:
        deploy_parameter.parameters = module.params.get('parameters')
    else:
        parameters_link = ParametersLink(
            uri=module.params.get('parameters_link'))
        deploy_parameter.parameters_link = parameters_link

    if module.params.get('template_link') is None:
        deploy_parameter.template = module.params.get('template')
    else:
        template_link = TemplateLink(uri=module.params.get('template_link'))
        deploy_parameter.template_link = template_link

    params = ResourceGroup(location=module.params.get('location'),
                           tags=module.params.get('tags'))
    try:
        client.resource_groups.create_or_update(group_name, params)
        result = client.deployments.create_or_update(group_name,
                                                     deployment_name,
                                                     deploy_parameter)
        return result.result()  # Blocking wait, return the Deployment object
    except CloudError as e:
        module.fail_json(
            msg='Deploy create failed with status code: %s and message: "%s"' %
            (e.status_code, e.message))
def deploy_template(module, client, conn_info):
    """
    Deploy the targeted template and parameters
    :param module: Ansible module containing the validated configuration for the deployment template
    :param client: resource management client for azure
    :param conn_info: connection info needed
    :return:
    """

    deployment_name = conn_info["deployment_name"]
    group_name = conn_info["resource_group_name"]

    deploy_parameter = DeploymentProperties()
    deploy_parameter.mode = "Complete"

    if module.params.get('parameters_link') is None:
        deploy_parameter.parameters = module.params.get('parameters')
    else:
        parameters_link = ParametersLink(
            uri = module.params.get('parameters_link')
        )
        deploy_parameter.parameters_link = parameters_link

    if module.params.get('template_link') is None:
        deploy_parameter.template = module.params.get('template')
    else:
        template_link = TemplateLink(
            uri = module.params.get('template_link')
        )
        deploy_parameter.template_link = template_link

    params = ResourceGroup(location=module.params.get('location'), tags=module.params.get('tags'))
    try:
        client.resource_groups.create_or_update(group_name, params)
        result = client.deployments.create_or_update(group_name, deployment_name, deploy_parameter)
        return result.result() # Blocking wait, return the Deployment object
    except CloudError as e:
        module.fail_json(msg='Deploy create failed with status code: %s and message: "%s"' % (e.status_code, e.message))
Beispiel #5
0
def deploy_template(module, client, conn_info):
    """
    Deploy the targeted template and parameters
    :param module: Ansible module containing the validated configuration for the deployment template
    :param client: resource management client for azure
    :param conn_info: connection info needed
    :return:
    """

    deployment_name = conn_info["deployment_name"]
    group_name = conn_info["resource_group_name"]

    deploy_parameter = DeploymentProperties()
    deploy_parameter.mode = module.params.get('deployment_mode')

    if module.params.get('parameters_link') is None:
        deploy_parameter.parameters = module.params.get('parameters')
    else:
        parameters_link = ParametersLink(
            uri=module.params.get('parameters_link'))
        deploy_parameter.parameters_link = parameters_link

    if module.params.get('template_link') is None:
        deploy_parameter.template = module.params.get('template')
    else:
        template_link = TemplateLink(uri=module.params.get('template_link'))
        deploy_parameter.template_link = template_link

    params = ResourceGroup(location=module.params.get('location'),
                           tags=module.params.get('tags'))
    try:
        client.resource_groups.create_or_update(group_name, params)
        result = client.deployments.create_or_update(group_name,
                                                     deployment_name,
                                                     deploy_parameter)
        deployment_result = result.result(
        )  # Blocking wait, return the Deployment object
        if module.params.get('wait_for_deployment_completion'):
            while not deployment_result.properties.provisioning_state in [
                    'Canceled', 'Failed', 'Deleted', 'Succeeded'
            ]:
                deployment_result = client.deployments.get(
                    group_name, deployment_name)
                time.sleep(
                    module.params.get('wait_for_deployment_polling_period'))

        if deployment_result.properties.provisioning_state == 'Succeeded':
            return deployment_result

        failed_deployment_operations = get_failed_deployment_operations(
            module, client, group_name, deployment_name)
        module.fail_json(
            msg='Deployment failed. Deployment id: %s' %
            (deployment_result.id),
            failed_deployment_operations=failed_deployment_operations)
    except CloudError as e:
        failed_deployment_operations = get_failed_deployment_operations(
            module, client, group_name, deployment_name)
        module.fail_json(
            msg='Deploy create failed with status code: %s and message: "%s"' %
            (e.status_code, e.message),
            failed_deployment_operations=failed_deployment_operations)