def create_website(cmd, name, runtime, deployment_local_git=True, deployment_user=None): runtime_values = RUNTIMES[runtime.lower()] deployment_user_password = None create_app_service_plan(cmd, resource_group_name=name, name=name, is_linux=runtime_values['is_linux'], hyper_v=False).result() webapp = create_webapp(cmd, resource_group_name=name, name=name, plan=name, runtime=runtime_values['name'], deployment_local_git=deployment_local_git) if deployment_user: deployment_user_password = uuid4() set_deployment_user(cmd, deployment_user, deployment_user_password) else: deployment_user = web_client_factory( cmd.cli_ctx).get_publishing_user().publishing_user_name site = {} site['deployment_user'] = deployment_user site[ 'deployment_password'] = deployment_user_password if deployment_user_password else '***' site['deployment_url'] = webapp.deploymentLocalGitUrl site['hostname'] = 'https://{}'.format(webapp.host_names[0]) return site
def __set_deployment_user(self): deployment_user = web_client_factory( self.__cmd.cli_ctx).get_publishing_user() # Check for existing deployment user if not deployment_user: # Create random password, set name to first 10 characters of app name self.deployment_user_password = str(uuid4()) set_deployment_user(self.__cmd, user_name=self.name[:10], password=self.deployment_user_password) self.deployment_user_name = self.name[:10] else: self.deployment_user_name = deployment_user.publishing_user_name
def __set_deployment_user(self): deployment_user = web_client_factory( self.__cmd.cli_ctx).get_publishing_user() # Check for existing deployment user if not deployment_user or not deployment_user.publishing_user_name: # Create random password, set name to base of app name logger.warning('Creating deployment user') password = str(uuid4()) user_name = self.name set_deployment_user(self.__cmd, user_name=user_name, password=password) self.deployment_user_name = user_name self.deployment_user_password = password else: self.deployment_user_name = deployment_user.publishing_user_name
def _generic_site_operation( resource_group_name, name, operation_name, slot=None, #pylint: disable=too-many-arguments extra_parameter=None, client=None): client = client or web_client_factory() m = getattr(client.web_apps, operation_name if slot is None else operation_name + '_slot') if slot is None: return (m(resource_group_name, name) if extra_parameter is None else m( resource_group_name, name, extra_parameter)) else: return (m(resource_group_name, name, slot) if extra_parameter is None else m(resource_group_name, name, extra_parameter, slot))
def create_logicapp(cmd, resource_group_name, name, storage_account, plan=None, os_type=None, consumption_plan_location=None, app_insights=None, app_insights_key=None, disable_app_insights=None, deployment_source_url=None, deployment_source_branch='master', deployment_local_git=None, docker_registry_server_password=None, docker_registry_server_user=None, deployment_container_image_name=None, tags=None): # pylint: disable=too-many-statements, too-many-branches, too-many-locals functions_version = DEFAULT_LOGICAPP_FUNCTION_VERSION runtime = None runtime_version = None if consumption_plan_location or not deployment_container_image_name: runtime = DEFAULT_LOGICAPP_RUNTIME runtime_version = DEFAULT_LOGICAPP_RUNTIME_VERSION if deployment_source_url and deployment_local_git: raise MutuallyExclusiveArgumentError( 'usage error: --deployment-source-url <url> | --deployment-local-git' ) if not plan and not consumption_plan_location: raise RequiredArgumentMissingError( "Either Plan or Consumption Plan must be specified") if consumption_plan_location and plan: raise MutuallyExclusiveArgumentError( "Consumption Plan and Plan cannot be used together") SiteConfig, Site, NameValuePair = cmd.get_models('SiteConfig', 'Site', 'NameValuePair') docker_registry_server_url = parse_docker_image_name( deployment_container_image_name) site_config = SiteConfig(app_settings=[]) logicapp_def = Site(location=None, site_config=site_config, tags=tags) client = web_client_factory(cmd.cli_ctx) plan_info = None if runtime is not None: runtime = runtime.lower() if consumption_plan_location: locations = list_consumption_locations(cmd) location = next( (loc for loc in locations if loc['name'].lower() == consumption_plan_location.lower()), None) if location is None: raise InvalidArgumentValueError( "Location is invalid. Use: az logicapp list-consumption-locations" ) logicapp_def.location = consumption_plan_location logicapp_def.kind = 'functionapp,workflowapp' # if os_type is None, the os type is windows is_linux = os_type and os_type.lower() == 'linux' else: # apps with SKU based plan if is_valid_resource_id(plan): parse_result = parse_resource_id(plan) plan_info = client.app_service_plans.get( parse_result['resource_group'], parse_result['name']) else: plan_info = client.app_service_plans.get(resource_group_name, plan) if not plan_info: raise ResourceNotFoundError( "The plan '{}' doesn't exist".format(plan)) location = plan_info.location is_linux = plan_info.reserved logicapp_def.server_farm_id = plan_info.id logicapp_def.location = location if runtime: site_config.app_settings.append( NameValuePair(name='FUNCTIONS_WORKER_RUNTIME', value=runtime)) con_string = _validate_and_get_connection_string(cmd.cli_ctx, resource_group_name, storage_account) if is_linux: logicapp_def.kind = 'functionapp,workflowapp,linux' logicapp_def.reserved = True is_consumption = consumption_plan_location is not None if not is_consumption: site_config.app_settings.append( NameValuePair(name='MACHINEKEY_DecryptionKey', value=str(hexlify( urandom(32)).decode()).upper())) if deployment_container_image_name: logicapp_def.kind = 'functionapp,workflowapp,linux,container' site_config.app_settings.append( NameValuePair(name='DOCKER_CUSTOM_IMAGE_NAME', value=deployment_container_image_name)) site_config.app_settings.append( NameValuePair(name='FUNCTION_APP_EDIT_MODE', value='readOnly')) site_config.app_settings.append( NameValuePair(name='WEBSITES_ENABLE_APP_SERVICE_STORAGE', value='false')) site_config.linux_fx_version = _format_fx_version( deployment_container_image_name) else: site_config.app_settings.append( NameValuePair(name='WEBSITES_ENABLE_APP_SERVICE_STORAGE', value='true')) if runtime not in FUNCTIONS_VERSION_TO_SUPPORTED_RUNTIME_VERSIONS[ functions_version]: raise InvalidArgumentValueError( "An appropriate linux image for runtime:'{}', " "functions_version: '{}' was not found".format( runtime, functions_version)) if deployment_container_image_name is None: site_config.linux_fx_version = _get_linux_fx_functionapp( functions_version, runtime, runtime_version) else: logicapp_def.kind = 'functionapp,workflowapp' # adding appsetting to site to make it a workflow site_config.app_settings.append( NameValuePair( name='FUNCTIONS_EXTENSION_VERSION', value=_get_extension_version_functionapp(functions_version))) site_config.app_settings.append( NameValuePair(name='AzureWebJobsStorage', value=con_string)) site_config.app_settings.append( NameValuePair(name='AzureWebJobsDashboard', value=con_string)) site_config.app_settings.append( NameValuePair( name='AzureFunctionsJobHost__extensionBundle__id', value="Microsoft.Azure.Functions.ExtensionBundle.Workflows")) site_config.app_settings.append( NameValuePair(name='AzureFunctionsJobHost__extensionBundle__version', value="[1.*, 2.0.0)")) site_config.app_settings.append( NameValuePair(name='APP_KIND', value="workflowApp")) # If plan is not consumption or elastic premium or workflow standard, we need to set always on if (consumption_plan_location is None and not is_plan_elastic_premium(cmd, plan_info) and not is_plan_workflow_standard(cmd, plan_info) and not is_plan_ASEV3(cmd, plan_info)): site_config.always_on = True # If plan is elastic premium or windows consumption, we need these app settings is_windows_consumption = consumption_plan_location is not None and not is_linux if is_plan_elastic_premium(cmd, plan_info) or is_windows_consumption: site_config.app_settings.append( NameValuePair(name='WEBSITE_CONTENTAZUREFILECONNECTIONSTRING', value=con_string)) site_config.app_settings.append( NameValuePair(name='WEBSITE_CONTENTSHARE', value=name.lower())) create_app_insights = False if app_insights_key is not None: site_config.app_settings.append( NameValuePair(name='APPINSIGHTS_INSTRUMENTATIONKEY', value=app_insights_key)) elif app_insights is not None: instrumentation_key = get_app_insights_key(cmd.cli_ctx, resource_group_name, app_insights) site_config.app_settings.append( NameValuePair(name='APPINSIGHTS_INSTRUMENTATIONKEY', value=instrumentation_key)) elif not disable_app_insights: create_app_insights = True poller = client.web_apps.begin_create_or_update(resource_group_name, name, logicapp_def) logicapp = LongRunningOperation(cmd.cli_ctx)(poller) if consumption_plan_location and is_linux: logger.warning( "Your Linux logic app '%s', that uses a consumption plan has been successfully " "created but is not active until content is published using " "Azure Portal or the Functions Core Tools.", name) else: _set_remote_or_local_git(cmd, logicapp, resource_group_name, name, deployment_source_url, deployment_source_branch, deployment_local_git) if create_app_insights: try: try_create_application_insights(cmd, logicapp) except Exception: # pylint: disable=broad-except logger.warning( 'Error while trying to create and configure an Application Insights for the Logic App. ' 'Please use the Azure Portal to create and configure the Application Insights, if needed.' ) if deployment_container_image_name: update_container_settings_functionapp(cmd, resource_group_name, name, docker_registry_server_url, deployment_container_image_name, docker_registry_server_user, docker_registry_server_password) return logicapp
def cf_plans(cli_ctx, *_): return web_client_factory(cli_ctx).app_service_plans