Beispiel #1
0
def manage_appliance(self, action, deployment, credentials):
    """
    Perform supplied action on this app.

    @type action: ``str``
    @param action: Accepted values are ``restart`` or ``delete``. Invoking
                   the ``delete`` action, if successful, will also mark the
                   supplied ``deployment`` as ``archived`` in the database.
    """
    LOG.debug("Performing %s on deployment %s", action, deployment.name)
    handler = _get_app_handler(deployment)
    dpl = _serialize_deployment(deployment)
    provider = domain_model.get_cloud_provider(deployment.target_cloud,
                                               credentials)
    if action.lower() == 'restart':
        result = handler.restart(provider, dpl)
    elif action.lower() == 'delete':
        result = handler.delete(provider, dpl)
        if result is True:
            deployment.archived = True
            deployment.save()
    else:
        LOG.error("Unrecognized action: %s. Acceptable values are 'delete' "
                  "or 'restart'", action)
        return None
    # Schedule a task to migrate results right after task completion
    # Do this as a separate task because until this task completes, we
    # cannot obtain final status or traceback.
    migrate_task_result.apply_async([self.request.id],
                                    countdown=1)
    return result
Beispiel #2
0
def health_check(self, deployment_id, credentials):
    """
    Check the health of the supplied deployment.

    Conceptually, the health check can be as elaborate as the deployed
    appliance supports via a custom implementation. At the minimum, and
    by default, the health reflects the status of the cloud instance by
    querying the cloud provider.
    """
    try:
        deployment = models.ApplicationDeployment.objects.get(pk=deployment_id)
        log.debug("Checking health of deployment %s", deployment.name)
        plugin = _get_app_plugin(deployment)
        dpl = _serialize_deployment(deployment)
        provider = domain_model.get_cloud_provider(deployment.target_cloud,
                                                   credentials)
        result = plugin.health_check(provider, dpl)
    except Exception as e:
        msg = "Health check failed: %s" % str(e)
        log.error(msg)
        raise Exception(msg) from e
    finally:
        # We only keep the two most recent health check task results so delete
        # any older ones
        signals.health_check.send(sender=None, deployment=deployment)
    # Schedule a task to migrate results right after task completion
    # Do this as a separate task because until this task completes, we
    # cannot obtain final status or traceback.
    migrate_task_result.apply_async([self.request.id], countdown=1)
    return result
Beispiel #3
0
def delete_appliance(self, deployment_id, credentials):
    """
    Deletes this appliances
    If successful, will also mark the supplied ``deployment`` as
    ``archived`` in the database.
    """
    try:
        deployment = models.ApplicationDeployment.objects.get(pk=deployment_id)
        log.debug("Performing delete on deployment %s", deployment.name)
        plugin = _get_app_plugin(deployment)
        dpl = _serialize_deployment(deployment)
        provider = domain_model.get_cloud_provider(deployment.target_cloud,
                                                   credentials)
        result = plugin.delete(provider, dpl)
        if result is True:
            deployment.archived = True
            deployment.save()
    except Exception as e:
        msg = "Delete task failed: %s" % str(e)
        log.error(msg)
        raise Exception(msg) from e
    # Schedule a task to migrate results right after task completion
    # Do this as a separate task because until this task completes, we
    # cannot obtain final status or traceback.
    migrate_task_result.apply_async([self.request.id], countdown=1)
    return result
Beispiel #4
0
def manage_appliance(self, action, deployment, credentials):
    """
    Perform supplied action on this app.

    @type action: ``str``
    @param action: Accepted values are ``restart`` or ``delete``.
    """
    LOG.debug("Performing %s on deployment %s", action, deployment.name)
    handler = _get_app_handler(deployment)
    dpl = _serialize_deployment(deployment)
    provider = domain_model.get_cloud_provider(deployment.target_cloud,
                                               credentials)
    if action.lower() == 'restart':
        result = handler.restart(provider, dpl)
    elif action.lower() == 'delete':
        result = handler.delete(provider, dpl)
    else:
        LOG.error("Unrecognized action: %s. Acceptable values are 'delete' "
                  "or 'restart'", action)
        return None
    # Schedule a task to migrate results right after task completion
    # Do this as a separate task because until this task completes, we
    # cannot obtain final status or traceback.
    migrate_task_result.apply_async([self.request.id],
                                    countdown=1)
    return result
Beispiel #5
0
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
Beispiel #6
0
def restart_appliance(self, deployment_id, credentials):
    """
    Restarts this appliances
    """
    try:
        deployment = models.ApplicationDeployment.objects.get(pk=deployment_id)
        log.debug("Performing restart on deployment %s", deployment.name)
        plugin = _get_app_plugin(deployment)
        dpl = _serialize_deployment(deployment)
        provider = domain_model.get_cloud_provider(deployment.target_cloud,
                                                   credentials)
        result = plugin.restart(provider, dpl)
    except Exception as e:
        msg = "Restart task failed: %s" % str(e)
        log.error(msg)
        raise Exception(msg) from e
    # Schedule a task to migrate results right after task completion
    # Do this as a separate task because until this task completes, we
    # cannot obtain final status or traceback.
    migrate_task_result.apply_async([self.request.id], countdown=1)
    return result
Beispiel #7
0
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
Beispiel #8
0
def health_check(self, deployment, credentials):
    """
    Check the health of the supplied deployment.

    Conceptually, the health check can be as elaborate as the deployed
    appliance supports via a custom implementation. At the minimum, and
    by default, the health reflects the status of the cloud instance by
    querying the cloud provider.
    """
    LOG.debug("Checking health of deployment %s", deployment.name)
    handler = _get_app_handler(deployment)
    dpl = _serialize_deployment(deployment)
    provider = domain_model.get_cloud_provider(deployment.target_cloud,
                                               credentials)
    result = handler.health_check(provider, dpl)
    # We only keep the two most recent health check task results so delete
    # any older ones
    signals.health_check.send(sender=None, deployment=deployment)
    # Schedule a task to migrate results right after task completion
    # Do this as a separate task because until this task completes, we
    # cannot obtain final status or traceback.
    migrate_task_result.apply_async([self.request.id], countdown=1)
    return result
Beispiel #9
0
def health_check(self, deployment, credentials):
    """
    Check the health of the supplied deployment.

    Conceptually, the health check can be as elaborate as the deployed
    appliance supports via a custom implementation. At the minimum, and
    by default, the health reflects the status of the cloud instance by
    querying the cloud provider.
    """
    LOG.debug("Checking health of deployment %s", deployment.name)
    handler = _get_app_handler(deployment)
    dpl = _serialize_deployment(deployment)
    provider = domain_model.get_cloud_provider(deployment.target_cloud,
                                               credentials)
    result = handler.health_check(provider, dpl)
    # We only keep the two most recent health check task results so delete
    # any older ones
    signals.health_check.send(sender=None, deployment=deployment)
    # Schedule a task to migrate results right after task completion
    # Do this as a separate task because until this task completes, we
    # cannot obtain final status or traceback.
    migrate_task_result.apply_async([self.request.id], countdown=1)
    return result
Beispiel #10
0
def create_appliance(name, cloud_version_config_id, credentials, app_config,
                     user_data):
    """Call the appropriate app plugin and initiate the app launch process."""
    try:
        log.debug("Creating appliance %s", name)
        cloud_version_conf = models.ApplicationVersionCloudConfig.objects.get(
            pk=cloud_version_config_id)
        plugin = util.import_class(
            cloud_version_conf.application_version.backend_component_name)()
        provider = domain_model.get_cloud_provider(cloud_version_conf.cloud,
                                                   credentials)
        cloud_config = util.serialize_cloud_config(cloud_version_conf)
        # TODO: Add keys (& support) for using existing, user-supplied hosts
        provider_config = {
            'cloud_provider': provider,
            'cloud_config': cloud_config,
            'cloud_user_data': user_data
        }
        log.info("Provider_config: %s", provider_config)
        log.info(
            "Creating app %s with the follwing app config: %s \n and "
            "cloud config: %s", name, app_config, provider_config)
        deploy_result = plugin.deploy(name, Task(create_appliance), app_config,
                                      provider_config)
        # Schedule a task to migrate result one hour from now
        migrate_launch_task.apply_async([create_appliance.request.id],
                                        countdown=3600)
        return deploy_result
    except SoftTimeLimitExceeded:
        msg = "Create appliance task time limit exceeded; stopping the task."
        log.warning(msg)
        raise Exception(msg)
    except Exception as exc:
        msg = "Create appliance task failed: %s" % str(exc)
        log.error(msg)
        raise Exception(msg) from exc