Ejemplo n.º 1
0
def create_blueprint(name, bpname=None, wait=True):
    """create_blueprint(name, bpname=None)

    Create a blueprint from an application.

    The *name* argument must be an application whose VMs are either all in
    the STOPPED or in the STARTED state.  The *bpname* argument is the name
    of the blueprint. If the blueprint name is not specified, a new unique name
    will be allocated.

    The return value of this function is the name of the blueprint that was
    created.
    """
    app = cache.get_application(name=name)
    if app is None:
        error.raise_error("Application `{0}` does not exist.", name)
    state = application.get_application_state(app)
    if state not in ('STOPPED', 'STARTED'):
        error.raise_error('Application `{0}` is currently in state {1}.\n'
                          'Can only save when STOPPED or STARTED.',
                          name, state)
    if bpname is None:
        bpname = new_blueprint_name('bp-{0}'.format(name))
    bp = application.create_blueprint(bpname, app)
    if wait:
        bp = application.wait_until_blueprint_is_in_state(bp, 'DONE')
    return application.appdef_from_app(bp)
Ejemplo n.º 2
0
def get_blueprints():
    """get_blueprints()

    Return a list of all blueprints.
    """
    blueprints = []
    for bp in cache.get_blueprints():
        bp = cache.get_blueprint(bp['id'])
        blueprints.append(application.appdef_from_app(bp))
    return blueprints
Ejemplo n.º 3
0
def get_applications():
    """get_applications()

    Return a list containing all applications.
    """
    applications = []
    for app in cache.get_applications():
        app = cache.get_application(app['id'])
        applications.append(application.appdef_from_app(app))
    return applications
Ejemplo n.º 4
0
def get_blueprint(name):
    """get_blueprint(name)

    Lookup the blueprint *name*.

    If the blueprint exists, return the blueprint definition for it. The
    format is the same as the application definition that created the blueprint
    with some operational fields removed.
    """
    bp = cache.get_blueprint(name=name)
    if not bp:
        return
    return application.appdef_from_app(bp)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
def get_application(name):
    """get_application(name)
    
    Lookup the application *name*.

    If the application exists, return the application definition for it. The
    application is be a dictionary with string keys describing the application.
    If the application is not found, return None.

    .. seealso::
       See :ref:`application-ref` for the possible keys in the application
       definition dictionary.
    """
    app = cache.get_application(name=name)
    if app is None:
        return
    return application.appdef_from_app(app)