def deploy_dedicated_function_app(parameters):
        function_app_unit = FunctionAppDeploymentUnit()
        function_app_params = \
            {'name': parameters.function_app_name,
             'resource_group_name': parameters.function_app_resource_group_name}
        function_app = function_app_unit.get(function_app_params)
        if function_app:
            return function_app

        sp_unit = AppServicePlanUnit()
        app_service_plan = sp_unit.provision_if_not_exists(parameters.service_plan)

        ai_unit = AppInsightsUnit()
        app_insights = ai_unit.provision_if_not_exists(parameters.app_insights)

        sa_unit = StorageAccountUnit()
        storage_account_id = sa_unit.provision_if_not_exists(parameters.storage_account).id
        con_string = FunctionAppUtilities.get_storage_account_connection_string(storage_account_id)

        function_app_params.update({'location': app_service_plan.location,
                                    'app_service_plan_id': app_service_plan.id,
                                    'app_insights_key': app_insights.instrumentation_key,
                                    'storage_account_connection_string': con_string})

        return function_app_unit.provision(function_app_params)
Example #2
0
    def deploy_dedicated_function_app(self, parameters):
        function_app_unit = FunctionAppDeploymentUnit()
        function_app_params = \
            {'name': parameters.functionapp_name,
             'resource_group_name': parameters.service_plan['resource_group_name']}
        function_app = function_app_unit.get(function_app_params)
        if function_app:
            return function_app

        sp_unit = AppServicePlanUnit()
        app_service_plan = sp_unit.provision_if_not_exists(
            parameters.service_plan)

        ai_unit = AppInsightsUnit()
        app_insights = ai_unit.provision_if_not_exists(parameters.app_insights)

        sa_unit = StorageAccountUnit()
        storage_account_id = sa_unit.provision_if_not_exists(
            parameters.storage_account).id
        con_string = FunctionAppUtilities.get_storage_account_connection_string(
            storage_account_id)

        function_app_params.update({
            'location':
            app_service_plan.location,
            'app_service_plan_id':
            app_service_plan.id,
            'app_insights_key':
            app_insights.instrumentation_key,
            'storage_account_connection_string':
            con_string
        })

        return function_app_unit.provision(function_app_params)
Example #3
0
    def deploy_function_app(parameters):
        function_app_unit = FunctionAppDeploymentUnit()
        function_app_params = \
            {'name': parameters.function_app_name,
             'resource_group_name': parameters.function_app_resource_group_name}
        function_app = function_app_unit.get(function_app_params)

        if function_app:
            # retrieve the type of app service plan hosting the existing function app
            session = local_session(Session)
            web_client = session.client(
                'azure.mgmt.web.WebSiteManagementClient')
            app_id = function_app.server_farm_id
            app_name = ResourceIdParser.get_resource_name(app_id)
            app_resource_group_name = ResourceIdParser.get_resource_group(
                app_id)
            app_service_plan = web_client.app_service_plans.get(
                app_resource_group_name, app_name)

            # update the sku tier to properly reflect what is provisioned in Azure
            parameters.service_plan['sku_tier'] = app_service_plan.sku.tier

            return function_app

        sp_unit = AppServicePlanUnit()
        app_service_plan = sp_unit.provision_if_not_exists(
            parameters.service_plan)

        # if only resource_id is provided, retrieve existing app plan sku tier
        parameters.service_plan['sku_tier'] = app_service_plan.sku.tier

        ai_unit = AppInsightsUnit()
        app_insights = ai_unit.provision_if_not_exists(parameters.app_insights)

        sa_unit = StorageAccountUnit()
        storage_account_id = sa_unit.provision_if_not_exists(
            parameters.storage_account).id
        con_string = FunctionAppUtilities.get_storage_account_connection_string(
            storage_account_id)

        function_app_params.update({
            'location':
            app_service_plan.location,
            'app_service_plan_id':
            app_service_plan.id,
            'app_insights_key':
            app_insights.instrumentation_key,
            'is_consumption_plan':
            FunctionAppUtilities.is_consumption_plan(parameters),
            'storage_account_connection_string':
            con_string
        })

        return function_app_unit.provision(function_app_params)
    def test_function_app_dedicated(self):
        # provision storage account
        sa_params = {
            'name': 'custodianaccount47182748',
            'location': 'westus2',
            'resource_group_name': self.rg_name
        }
        storage_unit = StorageAccountUnit()
        storage_account_id = storage_unit.provision_if_not_exists(sa_params).id
        conn_string = FunctionAppUtilities.get_storage_account_connection_string(
            storage_account_id)

        # provision app plan
        app_plan_params = {
            'name': 'cloud-custodian-test',
            'location': 'westus2',
            'resource_group_name': self.rg_name,
            'sku_tier': 'Basic',
            'sku_name': 'B1'
        }
        app_plan_unit = AppServicePlanUnit()
        app_plan = app_plan_unit.provision_if_not_exists(app_plan_params)

        # provision function app
        func_app_name = 'cc-dedicated-47182748'
        func_params = {
            'name': func_app_name,
            'location': 'westus',
            'resource_group_name': self.rg_name,
            'app_service_plan_id': app_plan.id,
            'app_insights_key': None,
            'is_consumption_plan': False,
            'storage_account_connection_string': conn_string
        }
        func_unit = FunctionAppDeploymentUnit()
        func_app = self._validate(func_unit, func_params)

        # verify settings are properly configured
        self.assertEquals(func_app.kind, 'functionapp,linux,container')
        self.assertTrue(func_app.reserved)

        wc = self.session.client('azure.mgmt.web.WebSiteManagementClient')

        site_config = wc.web_apps.get_configuration(self.rg_name,
                                                    func_app_name)
        self.assertTrue(site_config.always_on)
        self.assertEquals(site_config.linux_fx_version,
                          FUNCTION_DOCKER_VERSION)

        app_settings = wc.web_apps.list_application_settings(
            self.rg_name, func_app_name)
        self.assertIsNotNone(
            app_settings.properties['MACHINEKEY_DecryptionKey'])
    def test_function_app_dedicated(self):
        # provision storage account
        sa_params = {
            'name': 'custodianaccount47182748',
            'location': 'westus2',
            'resource_group_name': self.rg_name}
        storage_unit = StorageAccountUnit()
        storage_account_id = storage_unit.provision_if_not_exists(sa_params).id
        conn_string = FunctionAppUtilities.get_storage_account_connection_string(storage_account_id)

        # provision app plan
        app_plan_params = {
            'name': 'cloud-custodian-test',
            'location': 'westus2',
            'resource_group_name': self.rg_name,
            'sku_tier': 'Basic',
            'sku_name': 'B1'}
        app_plan_unit = AppServicePlanUnit()
        app_plan = app_plan_unit.provision_if_not_exists(app_plan_params)

        # provision function app
        func_app_name = 'cc-dedicated-47182748'
        func_params = {
            'name': func_app_name,
            'location': 'westus',
            'resource_group_name': self.rg_name,
            'app_service_plan_id': app_plan.id,
            'app_insights_key': None,
            'is_consumption_plan': False,
            'storage_account_connection_string': conn_string
        }
        func_unit = FunctionAppDeploymentUnit()
        func_app = self._validate(func_unit, func_params)

        # verify settings are properly configured
        self.assertEqual(func_app.kind, 'functionapp,linux,container')
        self.assertTrue(func_app.reserved)

        wc = self.session.client('azure.mgmt.web.WebSiteManagementClient')

        site_config = wc.web_apps.get_configuration(self.rg_name, func_app_name)
        self.assertTrue(site_config.always_on)
        self.assertEqual(site_config.linux_fx_version, FUNCTION_DOCKER_VERSION)

        app_settings = wc.web_apps.list_application_settings(self.rg_name, func_app_name)
        self.assertIsNotNone(app_settings.properties['MACHINEKEY_DecryptionKey'])
    def deploy_function_app(parameters):
        function_app_unit = FunctionAppDeploymentUnit()
        function_app_params = \
            {'name': parameters.function_app_name,
             'resource_group_name': parameters.function_app_resource_group_name}
        function_app = function_app_unit.get(function_app_params)

        if function_app:
            # retrieve the type of app service plan hosting the existing function app
            session = local_session(Session)
            web_client = session.client('azure.mgmt.web.WebSiteManagementClient')
            app_id = function_app.server_farm_id
            app_name = ResourceIdParser.get_resource_name(app_id)
            app_resource_group_name = ResourceIdParser.get_resource_group(app_id)
            app_service_plan = web_client.app_service_plans.get(app_resource_group_name, app_name)

            # update the sku tier to properly reflect what is provisioned in Azure
            parameters.service_plan['sku_tier'] = app_service_plan.sku.tier

            return function_app

        sp_unit = AppServicePlanUnit()
        app_service_plan = sp_unit.provision_if_not_exists(parameters.service_plan)

        # if only resource_id is provided, retrieve existing app plan sku tier
        parameters.service_plan['sku_tier'] = app_service_plan.sku.tier

        ai_unit = AppInsightsUnit()
        app_insights = ai_unit.provision_if_not_exists(parameters.app_insights)

        sa_unit = StorageAccountUnit()
        storage_account_id = sa_unit.provision_if_not_exists(parameters.storage_account).id
        con_string = FunctionAppUtilities.get_storage_account_connection_string(storage_account_id)

        function_app_params.update(
            {'location': app_service_plan.location,
             'app_service_plan_id': app_service_plan.id,
             'app_insights_key': app_insights.instrumentation_key,
             'is_consumption_plan': FunctionAppUtilities.is_consumption_plan(parameters),
             'storage_account_connection_string': con_string})

        return function_app_unit.provision(function_app_params)