Exemplo n.º 1
0
def update(ctx, update_id, temp_blueprint_id, deployments_to_update, force,
           auto_correct_types, reevaluate_active_statuses, **_):
    """Execute deployment update for all the given deployments_to_update.

    :param update_id: plugins update ID.
    :param temp_blueprint_id: temporary blueprint ID that should be used for
    this workflow only.
    :param deployments_to_update: deployments to perform the update on, using
    the temp blueprint ID provided.
    :param force: force update (i.e. even if the blueprint is used to create
    components).
    :param auto_correct_types: update deployments with auto_correct_types flag,
     which will attempt to cast inputs to the types defined by the blueprint.
    :reevaluate_active_statuses: reevaluate deployment updates states based on
    relevant executions statuses.
    """
    def get_wait_for_execution_message(execution_id):
        return 'Deployment update has failed with execution ID: ' \
               '{0}.'.format(execution_id)

    ctx.logger.info('Executing update_plugin system workflow with flags: '
                    'force={0}, auto_correct_types={1}'.format(
                        force, auto_correct_types))

    client = get_rest_client()
    for dep in deployments_to_update:
        ctx.send_event('Executing deployment update for deployment '
                       '{}...'.format(dep))
        try:
            execution_id = client.deployment_updates \
                .update_with_existing_blueprint(
                    deployment_id=dep,
                    blueprint_id=temp_blueprint_id,
                    skip_install=True,
                    skip_uninstall=True,
                    skip_reinstall=True,
                    force=force,
                    auto_correct_types=auto_correct_types,
                    reevaluate_active_statuses=reevaluate_active_statuses) \
                .execution_id
        except CloudifyClientError:
            execution_id = None
            execution_status = ExecutionState.FAILED
        else:
            wait_for(client.executions.get, execution_id, 'status',
                     lambda x: x in ExecutionState.END_STATES, RuntimeError,
                     get_wait_for_execution_message(execution_id))
            execution_status = client.executions.get(execution_id).status

        msg = f'Deployment update of deployment {dep} {execution_status}. ' \
            f'Plugins update ID {update_id}.'
        if execution_id:
            msg += f' Execution ID {execution_id}.'
        ctx.send_event(msg)

    ctx.send_event('Finalizing plugins update...')
    client.plugins_update.finalize_plugins_update(update_id)
Exemplo n.º 2
0
 def _wait_for_execution(self, execution, timeout=900):
     # Poll for execution status until execution ends
     error_msg = 'execution of operation {0} for deployment {1} timed out' \
         .format(execution.workflow_id, execution.deployment_id)
     return wait_for(self.client.executions.get, execution.id, 'status',
                     lambda x: x in ExecutionState.END_STATES,
                     TimeoutException, error_msg, timeout)
Exemplo n.º 3
0
 def _wait_for_successful_state(self, depup_id):
     error_msg = 'deployment update {0} failed to commit'.format(depup_id)
     return wait_for(self.client.deployment_updates.get,
                     depup_id,
                     'state',
                     lambda x: x == STATES.SUCCESSFUL,
                     TimeoutException,
                     error_msg)
Exemplo n.º 4
0
def update(ctx, update_id, temp_blueprint_id, deployments_to_update, **_):
    """Execute deployment update for all the given deployments_to_update.

    :param update_id: plugins update ID.
    :param temp_blueprint_id: temporary blueprint ID that should be used for
    this workflow only.
    :param deployments_to_update: deployments to perform the update on, using
    the temp blueprint ID provided.
    """

    def get_wait_for_execution_message(execution_id):
        return 'Deployment update has failed with execution ID: ' \
               '{0}.'.format(execution_id)

    client = get_rest_client()
    for dep in deployments_to_update:
        ctx.send_event('Executing deployment update for deployment '
                       '{}...'.format(dep))
        execution_id = client.deployment_updates \
            .update_with_existing_blueprint(deployment_id=dep,
                                            blueprint_id=temp_blueprint_id,
                                            skip_install=True,
                                            skip_uninstall=True,
                                            skip_reinstall=True) \
            .execution_id

        wait_for(client.executions.get,
                 execution_id,
                 'status',
                 lambda x: x in ExecutionState.END_STATES,
                 RuntimeError,
                 get_wait_for_execution_message(execution_id))
        execution_status = client.executions.get(execution_id).status
        if execution_status in (ExecutionState.FAILED,
                                ExecutionState.CANCELLED):
            raise RuntimeError("Deployment update of deployment {0} with "
                               "execution ID {1} failed, stopped this "
                               "plugins update (id="
                               "'{2}').".format(dep, execution_id, update_id))

    ctx.send_event('Finalizing plugins update...')
    client.plugins_update.finalize_plugins_update(update_id)