def launch_appliance(name, cloud_version_config, credentials, app_config, user_data, task_id=None): """Call the appropriate app handler and initiate the app launch process.""" try: LOG.debug("Launching appliance %s", name) handler = util.import_class( cloud_version_config.application_version.backend_component_name)() provider = domain_model.get_cloud_provider(cloud_version_config.cloud, credentials) cloud_config = util.serialize_cloud_config(cloud_version_config) launch_result = handler.launch_app(provider, Task(launch_appliance), name, cloud_config, app_config, user_data) # Schedule a task to migrate result one hour from now migrate_launch_task.apply_async([launch_appliance.request.id], countdown=3600) return launch_result except SoftTimeLimitExceeded: launch_appliance.update_state(state="FAILURE", meta={ "exc_message": "Task time limit exceeded; " "stopping the task." }) raise Ignore # This keeps the custom state set above
def create(self, validated_data): name = validated_data.get("name") cloud = validated_data.get("target_cloud") version = validated_data.get("application_version") cloud_version_config = models.ApplicationVersionCloudConfig.objects.get( application_version=version.id, cloud=cloud.slug) default_config = json.loads(cloud_version_config.default_launch_config) request = self.context.get('view').request credentials = view_helpers.get_credentials(cloud, request) try: handler = util.import_class(version.backend_component_name)() app_config = validated_data.get("config_app", {}) merged_config = jsonmerge.merge(default_config, app_config) final_ud_config = handler.process_app_config( name, cloud_version_config, credentials, merged_config) async_result = tasks.launch_appliance.delay( name, cloud_version_config, credentials, merged_config, final_ud_config) del validated_data['application'] del validated_data['config_app'] validated_data['owner_id'] = request.user.id validated_data['application_config'] = json.dumps(merged_config) validated_data['celery_task_id'] = async_result.task_id return super(DeploymentSerializer, self).create(validated_data) except serializers.ValidationError as ve: raise ve except Exception as e: raise serializers.ValidationError({"error": str(e)})
def launch_appliance(name, cloud_version_config, credentials, app_config, user_data, task_id=None): handler = util.import_class(cloud_version_config.application_version.backend_component_name)() result = handler.launch_app(launch_appliance, name, cloud_version_config, credentials, app_config, user_data) deployment = models.ApplicationDeployment.objects.get(celery_task_id=launch_appliance.request.id) deployment.task_result = json.dumps(result) deployment.save() return result
def _get_app_handler(deployment): """ Retrieve app-specific handler for a deployment. :rtype: :class:`.AppPlugin` :return: An instance of the handler class corresponding to the deployment app. """ cloud = deployment.target_cloud cloud_version_config = models.ApplicationVersionCloudConfig.objects.get( application_version=deployment.application_version.id, cloud=cloud.slug) return util.import_class( cloud_version_config.application_version.backend_component_name)()
def launch_appliance(name, cloud_version_config, credentials, app_config, user_data, task_id=None): handler = util.import_class( cloud_version_config.application_version.backend_component_name)() result = handler.launch_app(launch_appliance, name, cloud_version_config, credentials, app_config, user_data) deployment = models.ApplicationDeployment.objects.get( celery_task_id=launch_appliance.request.id) deployment.task_result = json.dumps(result) deployment.save() return result
def launch_appliance(name, cloud_version_config, credentials, app_config, user_data, task_id=None): """Call the appropriate app handler and initiate the app launch process.""" handler = util.import_class( cloud_version_config.application_version.backend_component_name)() launch_result = handler.launch_app(launch_appliance, name, cloud_version_config, credentials, app_config, user_data) # Schedule a task to migrate result one hour from now migrate_task_result.apply_async([launch_appliance.request.id], countdown=3600) return launch_result
def create(self, validated_data): """ Create a new ApplicationDeployment object. Called automatically by the DRF following a POST request. """ name = validated_data.get("name") cloud = validated_data.get("target_cloud") version = validated_data.get("application_version") cloud_version_config = models.ApplicationVersionCloudConfig.objects.get( application_version=version.id, cloud=cloud.slug) default_combined_config = cloud_version_config.compute_merged_config() request = self.context.get('view').request provider = view_helpers.get_cloud_provider(self.context.get('view'), cloud_id=cloud.slug) credentials = view_helpers.get_credentials(cloud, request) try: handler = util.import_class(version.backend_component_name)() app_config = validated_data.get("config_app", {}) merged_config = jsonmerge.merge(default_combined_config, app_config) cloud_config = util.serialize_cloud_config(cloud_version_config) final_ud_config = handler.process_app_config( provider, name, cloud_config, merged_config) sanitised_app_config = handler.sanitise_app_config(merged_config) async_result = tasks.launch_appliance.delay( name, cloud_version_config, credentials, merged_config, final_ud_config) del validated_data['application'] del validated_data['config_app'] validated_data['owner_id'] = request.user.id validated_data['application_config'] = json.dumps(merged_config) app_deployment = super(DeploymentSerializer, self).create(validated_data) self.log_usage(cloud_version_config, app_deployment, sanitised_app_config, request.user) models.ApplicationDeploymentTask.objects.create( action=models.ApplicationDeploymentTask.LAUNCH, deployment=app_deployment, celery_id=async_result.task_id) return app_deployment except serializers.ValidationError as ve: raise ve except Exception as e: raise serializers.ValidationError({"error": str(e)})
def launch_appliance(name, cloud_version_config, credentials, app_config, user_data, task_id=None): """Call the appropriate app handler and initiate the app launch process.""" try: LOG.debug("Launching appliance %s", name) handler = util.import_class( cloud_version_config.application_version.backend_component_name)() provider = domain_model.get_cloud_provider(cloud_version_config.cloud, credentials) cloud_config = util.serialize_cloud_config(cloud_version_config) launch_result = handler.launch_app(provider, Task(launch_appliance), name, cloud_config, app_config, user_data) # Schedule a task to migrate result one hour from now migrate_launch_task.apply_async([launch_appliance.request.id], countdown=3600) return launch_result except SoftTimeLimitExceeded: launch_appliance.update_state( state="FAILURE", meta={"exc_message": "Task time limit exceeded; " "stopping the task."}) raise Ignore # This keeps the custom state set above