Esempio n. 1
0
def get_cloud_provider(view, cloud_id=None):
    """
    Returns a cloud provider for the current user. The relevant
    cloud is discovered from the view and the credentials are retrieved
    from the request or user profile. Return ``None`` if no credentials were
    retrieved.
    """
    return cb_view_helpers.get_cloud_provider(view, cloud_id)
Esempio n. 2
0
def get_cloud_provider(view, cloud_id=None):
    """
    Returns a cloud provider for the current user. The relevant
    cloud is discovered from the view and the credentials are retrieved
    from the request or user profile. Return ``None`` if no credentials were
    retrieved.
    """
    return cb_view_helpers.get_cloud_provider(view, cloud_id)
Esempio n. 3
0
    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_app_config = jsonmerge.merge(default_combined_config,
                                                app_config)
            cloud_config = util.serialize_cloud_config(cloud_version_config)
            final_ud_config = handler.validate_app_config(
                provider, name, cloud_config, merged_app_config)
            sanitised_app_config = handler.sanitise_app_config(
                merged_app_config)
            async_result = tasks.create_appliance.delay(
                name, cloud_version_config.pk, credentials, merged_app_config,
                final_ud_config)

            del validated_data['application']
            if 'config_app' in validated_data:
                del validated_data['config_app']
            validated_data['owner_id'] = request.user.id
            validated_data['application_config'] = json.dumps(
                merged_app_config)
            validated_data['credentials_id'] = credentials.get('id') or None
            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":
                "An exception creating a deployment of %s: %s)" %
                (version.backend_component_name, e)
            })
Esempio n. 4
0
    def get_saved_clusters(self, obj):
        """
        Fetch a list of saved CloudMan clusters from AWS.

        This only fetches saved clusters that used AWS since it appears that
        was the only place this feature was actively used.
        """
        provider = view_helpers.get_cloud_provider(self.context.get('view'))
        if provider.PROVIDER_ID != ProviderList.AWS:
            return []
        # Since we're only working with the AWS, there's no need to specify
        # the cloud argument as it defaults to AWS in BioBlend.
        cml = CloudManLauncher(provider.a_key, provider.s_key, None)
        return cml.get_clusters_pd().get('clusters', [])