def deploy_webapp(self, app_name, group_name, service_plan, storage_account_name):
        self.log.info("Deploying Function App %s (%s) in group %s" %
                      (app_name, service_plan.location, group_name))

        site_config = SiteConfig(app_settings=[])
        functionapp_def = Site(location=service_plan.location, site_config=site_config)

        functionapp_def.kind = 'functionapp,linux'
        functionapp_def.server_farm_id = service_plan.id

        site_config.linux_fx_version = CONST_DOCKER_VERSION
        site_config.always_on = True

        app_insights_key = self.get_application_insights_key(group_name,
                                                             service_plan.app_service_plan_name)

        if app_insights_key:
            site_config.app_settings.append(
                NameValuePair('APPINSIGHTS_INSTRUMENTATIONKEY', app_insights_key))

        con_string = self.get_storage_connection_string(group_name, storage_account_name)
        site_config.app_settings.append(NameValuePair('AzureWebJobsStorage', con_string))
        site_config.app_settings.append(NameValuePair('AzureWebJobsDashboard', con_string))
        site_config.app_settings.append(NameValuePair('FUNCTIONS_EXTENSION_VERSION',
                                                      CONST_FUNCTIONS_EXT_VERSION))
        site_config.app_settings.append(NameValuePair('FUNCTIONS_WORKER_RUNTIME', 'python'))

        #: :type: azure.mgmt.web.WebSiteManagementClient
        web_client = self.local_session.client('azure.mgmt.web.WebSiteManagementClient')
        web_client.web_apps.create_or_update(group_name, app_name, functionapp_def).wait()
Exemplo n.º 2
0
    def _provision(self, params):
        site_config = SiteConfig(app_settings=[])
        functionapp_def = Site(location=params['location'], site_config=site_config)

        functionapp_def.kind = 'functionapp,linux'
        functionapp_def.server_farm_id = params['app_service_plan_id']

        site_config.linux_fx_version = CONST_DOCKER_VERSION
        site_config.always_on = True

        app_insights_key = params['app_insights_key']
        if app_insights_key:
            site_config.app_settings.append(
                azure_name_value_pair('APPINSIGHTS_INSTRUMENTATIONKEY', app_insights_key))

        con_string = params['storage_account_connection_string']
        site_config.app_settings.append(azure_name_value_pair('AzureWebJobsStorage', con_string))
        site_config.app_settings.append(azure_name_value_pair('AzureWebJobsDashboard', con_string))
        site_config.app_settings.append(azure_name_value_pair('FUNCTIONS_EXTENSION_VERSION',
                                                      CONST_FUNCTIONS_EXT_VERSION))
        site_config.app_settings.append(azure_name_value_pair('FUNCTIONS_WORKER_RUNTIME', 'python'))
        site_config.app_settings.append(
            azure_name_value_pair('MACHINEKEY_DecryptionKey',
                          FunctionAppDeploymentUnit.generate_machine_decryption_key()))

        return self.client.web_apps.create_or_update(params['resource_group_name'],
                                                     params['name'],
                                                     functionapp_def).result()
Exemplo n.º 3
0
    def _provision(self, params):
        site_config = SiteConfig(app_settings=[])
        functionapp_def = Site(location=params['location'], site_config=site_config)

        functionapp_def.kind = 'functionapp,linux'
        functionapp_def.server_farm_id = params['app_service_plan_id']

        site_config.linux_fx_version = FUNCTION_DOCKER_VERSION
        site_config.always_on = True

        app_insights_key = params['app_insights_key']
        if app_insights_key:
            site_config.app_settings.append(
                azure_name_value_pair('APPINSIGHTS_INSTRUMENTATIONKEY', app_insights_key))

        con_string = params['storage_account_connection_string']
        site_config.app_settings.append(azure_name_value_pair('AzureWebJobsStorage', con_string))
        site_config.app_settings.append(azure_name_value_pair('AzureWebJobsDashboard', con_string))
        site_config.app_settings.append(azure_name_value_pair('FUNCTIONS_EXTENSION_VERSION',
                                                              FUNCTION_EXT_VERSION))
        site_config.app_settings.append(azure_name_value_pair('FUNCTIONS_WORKER_RUNTIME', 'python'))
        site_config.app_settings.append(
            azure_name_value_pair('MACHINEKEY_DecryptionKey',
                          FunctionAppDeploymentUnit.generate_machine_decryption_key()))

        return self.client.web_apps.create_or_update(params['resource_group_name'],
                                                     params['name'],
                                                     functionapp_def).result()
Exemplo n.º 4
0
    def _provision(self, params):
        site_config = SiteConfig(app_settings=[])
        functionapp_def = Site(https_only=True,
                               client_cert_enabled=True,
                               location=params['location'],
                               site_config=site_config)

        # common function app settings
        functionapp_def.server_farm_id = params['app_service_plan_id']
        functionapp_def.reserved = True  # This implies Linux for auto-created app plans
        functionapp_def.identity = self._get_identity(params)

        # consumption app plan
        if params['is_consumption_plan']:
            functionapp_def.kind = 'functionapp,linux'
            site_config.linux_fx_version = FUNCTION_DOCKER_VERSION
        # dedicated app plan
        else:
            functionapp_def.kind = 'functionapp,linux,container'
            site_config.linux_fx_version = FUNCTION_DOCKER_VERSION
            site_config.always_on = True

        # application insights settings
        app_insights_key = params['app_insights_key']
        if app_insights_key:
            site_config.app_settings.append(
                azure_name_value_pair('APPINSIGHTS_INSTRUMENTATIONKEY',
                                      app_insights_key))

        # Don't generate pycache
        site_config.app_settings.append(
            azure_name_value_pair('PYTHONDONTWRITEBYTECODE', 1))

        # Enable server side build
        site_config.app_settings.append(
            azure_name_value_pair('ENABLE_ORYX_BUILD', 'true'))
        site_config.app_settings.append(
            azure_name_value_pair('SCM_DO_BUILD_DURING_DEPLOYMENT', 'true'))

        # general app settings
        con_string = params['storage_account_connection_string']
        site_config.app_settings.append(
            azure_name_value_pair('AzureWebJobsStorage', con_string))
        site_config.app_settings.append(
            azure_name_value_pair('FUNCTIONS_EXTENSION_VERSION',
                                  FUNCTION_EXT_VERSION))
        site_config.app_settings.append(
            azure_name_value_pair('FUNCTIONS_WORKER_RUNTIME', 'python'))

        return self.client.web_apps.begin_create_or_update(
            params['resource_group_name'], params['name'],
            functionapp_def).result()
Exemplo n.º 5
0
    def exec_module(self, **kwargs):

        for key in self.module_arg_spec:
            setattr(self, key, kwargs[key])
        if self.app_settings is None:
            self.app_settings = dict()

        try:
            resource_group = self.rm_client.resource_groups.get(self.resource_group)
        except CloudError:
            self.fail('Unable to retrieve resource group')

        self.location = self.location or resource_group.location

        try:
            function_app = self.web_client.web_apps.get(
                resource_group_name=self.resource_group,
                name=self.name
            )
            # Newer SDK versions (0.40.0+) seem to return None if it doesn't exist instead of raising CloudError
            exists = function_app is not None
        except CloudError as exc:
            exists = False

        if self.state == 'absent':
            if exists:
                if self.check_mode:
                    self.results['changed'] = True
                    return self.results
                try:
                    self.web_client.web_apps.delete(
                        resource_group_name=self.resource_group,
                        name=self.name
                    )
                    self.results['changed'] = True
                except CloudError as exc:
                    self.fail('Failure while deleting web app: {0}'.format(exc))
            else:
                self.results['changed'] = False
        else:
            kind = 'functionapp'
            linux_fx_version = None
            if self.container_settings and self.container_settings.get('name'):
                kind = 'functionapp,linux,container'
                linux_fx_version = 'DOCKER|'
                if self.container_settings.get('registry_server_url'):
                    self.app_settings['DOCKER_REGISTRY_SERVER_URL'] = 'https://' + self.container_settings['registry_server_url']
                    linux_fx_version += self.container_settings['registry_server_url'] + '/'
                linux_fx_version += self.container_settings['name']
                if self.container_settings.get('registry_server_user'):
                    self.app_settings['DOCKER_REGISTRY_SERVER_USERNAME'] = self.container_settings.get('registry_server_user')

                if self.container_settings.get('registry_server_password'):
                    self.app_settings['DOCKER_REGISTRY_SERVER_PASSWORD'] = self.container_settings.get('registry_server_password')

            if not self.plan and function_app:
                self.plan = function_app.server_farm_id

            if not exists:
                function_app = Site(
                    location=self.location,
                    kind=kind,
                    site_config=SiteConfig(
                        app_settings=self.aggregated_app_settings(),
                        scm_type='LocalGit'
                    )
                )
                self.results['changed'] = True
            else:
                self.results['changed'], function_app = self.update(function_app)

            # get app service plan
            if self.plan:
                if isinstance(self.plan, dict):
                    self.plan = "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Web/serverfarms/{2}".format(
                        self.subscription_id,
                        self.plan.get('resource_group', self.resource_group),
                        self.plan.get('name')
                    )
                function_app.server_farm_id = self.plan

            # set linux fx version
            if linux_fx_version:
                function_app.site_config.linux_fx_version = linux_fx_version

            if self.check_mode:
                self.results['state'] = function_app.as_dict()
            elif self.results['changed']:
                try:
                    new_function_app = self.web_client.web_apps.create_or_update(
                        resource_group_name=self.resource_group,
                        name=self.name,
                        site_envelope=function_app
                    ).result()
                    self.results['state'] = new_function_app.as_dict()
                except CloudError as exc:
                    self.fail('Error creating or updating web app: {0}'.format(exc))

        return self.results