Ejemplo n.º 1
0
def start_application(name, wait=True, show_progress=True, timeout=1200):
    """start_application(name, wait=True, show_progress=True, timeout=1200)

    Start up an application.

    The *name* argument must be the name of an application. If *wait* is
    nonzero, then this function will wait until the application is up and its
    VMs are accessible via ssh. If *show_progress* is nonzero then a progress
    bar is shown.  The *timeout* argument specifies the timeout in seconds.
    The default timeout is 20 minutes. Application startup times vary greatly
    between clouds, and whether or not the application has already been
    published.

    This method will start all VMs in the application that are in the 'STOPPED'
    state. If *wait* is nonzero, then all VMs must either be in the 'STOPPED'
    state (in which case they will get started), in the 'STARTED' state (in
    which case there is nothing to do), or in a state that will eventually
    transition to 'STARTED' state (currently 'STARTING' and 'PUBLISHING'). If a
    VM is in another state, then no action is taken and an exception is raised,
    because this call would just timeout without the ability to complete.

    This function has no return value, and raises an exception in case of an
    error.
    """
    app = cache.get_application(name=name)
    if app is None:
        error.raise_error("Application `{0}` does not exist.", name)
    app = application.start_application(app)
    if wait:
        state = application.get_application_state(app)
        if state not in application.vm_reuse_states:
            error.raise_error("Cannot wait for app in state '{0}'.", state)
        vms = set((vm['name'] for vm in app['vms']))
        with env.let(quiet=not show_progress):
            application.wait_for_application(app, vms, timeout)
Ejemplo n.º 2
0
def create_application(name=None, blueprint=None, vms=None, cloud=None,
                       region=None, wait=True, show_progress=True):
    """create_application(name=None, blueprint=None, vms=None, cloud=None, \
            region=None, wait=True, show_progress=True)

    Create a new application.

    If *blueprint* is specified, then it must be the name of a blueprint from
    which the application is created. If *blueprint* is not specified, then an
    application will be created from scratch in which case *vms* needs to be
    specified containing a list of the VM definitions. The VM definitions are
    dictionaries containing string keys describing the VM. The arguments
    *cloud* and *region* specify which cloud and region to publish the
    application to.  If these are not specified, the application is published
    to the lowest cost cloud that fits the VM definitions. If *wait* is
    nonzero, then this function will wait until the application is started up
    and its VMs are accessible via ssh.  If *show_progress* is nonzero, then a
    progress bar is shown.

    The return value of this function is the application definition of the
    application that was created. In case of an error, an exception is raised.

    .. seealso::
       See :ref:`vm-ref` for the possible keys in a VM definition dictionary.
    """
    if blueprint:
        bp = cache.get_blueprint(name=blueprint)
        if bp is None:
            error.raise_error('Blueprint `{0}` not found.', blueprint)
        if name is None:
            name = new_application_name(bp['name'])
    else:
        if name is None:
            name = new_application_name()
    appdef = { 'name': name }
    if vms:
        appdef['vms'] = vms
    if blueprint:
        appdef['blueprint'] = blueprint
    manif = { 'applications': [appdef],
              'defaults': { 'vms': { 'smp': 1, 'memory': 2048 } } }
    manifest.check_manifest(manif)
    manifest.percolate_defaults(manif)
    manifest.check_manifest_entities(manif)
    app = application.create_new_application(appdef, False)
    app = application.publish_application(app, cloud, region)
    if wait:
        vms = set((vm['name'] for vm in app['vms']))
        with env.let(quiet=not show_progress):
            app = application.wait_for_application(app, vms)
    return application.appdef_from_app(app)