Ejemplo n.º 1
0
def buildpack():
    tmpl = {
        'repo_url': '',
        'repo_type': ['git', 'hg'],
        'description': '',
        'order': 0,
    }

    vr = get_vr()

    info = {
        'available buildpacks': [
            bp.repo_url for bp in query('buildpack', vr)
        ]
    }

    config = edit_yaml(dump_yaml(tmpl),
                       dump_yaml(info))

    click.echo('Creating buildpack with following config:\n')
    click.echo(pformat(config))
    click.echo()

    if click.confirm('Create buildpack?'):
        bp = models.Buildpack(vr, config)
        bp.create()
        click.echo('Create %s %s!' % (bp.repo_url, bp.resource_uri))
Ejemplo n.º 2
0
def get_release(config, vr):
    # We need to make sure we have the release
    results = query('Release', vr, {'compiled_name': config['release']})
    if not results:
        click.echo('%s is not a valid release name' % config['release'])
        sys.exit(RESOURCE_MISSING)
    return results.pop()
Ejemplo n.º 3
0
    def test_query_returns_objects(self):
        vr = MagicMock()
        vr.query.return_value = [{'name': 'foo'}]
        obj = query('App', vr).next()

        assert isinstance(obj, App)
        assert obj.name == 'foo'
Ejemplo n.º 4
0
    def test_query_returns_objects(self):
        vr = MagicMock()
        vr.query.return_value = [{'name': 'foo'}]
        obj = query('App', vr).next()

        assert isinstance(obj, App)
        assert obj.name == 'foo'
Ejemplo n.º 5
0
Archivo: app.py Proyecto: yougov/rapt
def app():
    tmpl = {
        'name': '',
        'repo': '',
        'repo_type': [
            'git', 'hg',
        ],
    }

    vr = get_vr()

    info = {
        'current_apps': [app.name for app in query('App', vr)],
    }

    config = edit_yaml(dump_yaml(tmpl), dump_yaml(info))

    config = validate(config)
    click.echo('Creating new app with the following config:')
    click.echo(pformat(config))
    click.echo()

    if click.confirm('Add app?'):
        app = models.App(vr, config)
        app.create()
        click.echo('Added %s!' % app.name)
Ejemplo n.º 6
0
def apps():
    """List apps."""

    vr = get_vr()

    # add filters if we need to be...
    for i, app in enumerate(query('App', vr)):
        click.echo(app.name)
Ejemplo n.º 7
0
def ingredients(name):
    """List builds.
    """
    vr = get_vr()

    q = {}
    if name:
        q['name'] = name

    # add filters if we need to be...
    for i, ingredient in enumerate(query('Ingredient', vr, q)):
        click.echo(ingredient.name)
Ejemplo n.º 8
0
def ingredients(name):
    """List builds.
    """
    vr = get_vr()

    q = {}
    if name:
        q['name'] = name

    # add filters if we need to be...
    for i, ingredient in enumerate(query('Ingredient', vr, q)):
        click.echo(ingredient.name)
Ejemplo n.º 9
0
def swarms(app_name, config_name, proc_name):
    vr = get_vr()
    q = {
        'app__name__icontains': app_name,
        'config_name': config_name,
        'proc_name': proc_name,
    }

    q = {k: v for k, v in q.items() if v}

    for swarm in query('Swarm', vr, q):
        click.echo(swarm.name)
Ejemplo n.º 10
0
Archivo: build.py Proyecto: yougov/rapt
def build(build_config, app_name=None, tag=None):
    """Trigger new a build.

    The `build_config` is a YAML file with the require fields
    necessary to do the build. If no build_config is provided, your
    $EDITOR will be opened with a template that can be used to
    configure the build.
    """
    tmpl = {
        'app': str(app_name) or '',
        'tag': str(tag) or '',
        'os_image': ''
    }
    vr = get_vr()

    # grab our images and apps to validate them.
    images = query('OSImage', vr)
    apps = query('App', vr)

    # Do we use some pre-canned yaml?
    if build_config:
        config = load_yaml(build_config[0])

    # How about some command line flags
    elif app_name and tag:
        config = tmpl

    # No? We'll use our template and editor
    else:
        config = edit_yaml(dump_yaml(tmpl))

    # We have a config so we'll actually do stuff
    if config:
        config = validate(config, apps, images)
        build = models.Build(vr, config)
        build.assemble()

        click.echo('Watching for events. Hit C-c to exit')
        for event in filtered_events(vr, forever=True):
            click.echo(event)
Ejemplo n.º 11
0
Archivo: swarm.py Proyecto: yougov/rapt
def swarm(config):
    """Add a new swarm."""
    vr = get_vr()

    apps = query('App', vr)
    squads = query('Squad', vr)

    if config:
        config = load_yaml(config[0])

    config = config or get_config(vr, apps, squads)

    if config:
        config = validate(config, squads, apps)
        click.echo('Creating swarm with following config:\n\n')
        click.echo(dump_yaml(config))
        click.echo()
        click.echo()

        if click.confirm('Add the swarm?', default=True):
            swarm = models.Swarm(vr, config)
            swarm.create()
            click.echo('Swarm %s created!' % (swarm.name))
Ejemplo n.º 12
0
Archivo: build.py Proyecto: yougov/rapt
def build(build_config, app_name=None, tag=None):
    """Trigger new a build.

    The `build_config` is a YAML file with the require fields
    necessary to do the build. If no build_config is provided, your
    $EDITOR will be opened with a template that can be used to
    configure the build.
    """
    tmpl = {'app': str(app_name) or '', 'tag': str(tag) or '', 'os_image': ''}
    vr = get_vr()

    # grab our images and apps to validate them.
    images = query('OSImage', vr)
    apps = query('App', vr)

    # Do we use some pre-canned yaml?
    if build_config:
        config = load_yaml(build_config[0])

    # How about some command line flags
    elif app_name and tag:
        config = tmpl

    # No? We'll use our template and editor
    else:
        config = edit_yaml(dump_yaml(tmpl))

    # We have a config so we'll actually do stuff
    if config:
        config = validate(config, apps, images)
        build = models.Build(vr, config)
        build.assemble()

        click.echo('Watching for events. Hit C-c to exit')
        for event in filtered_events(vr, forever=True):
            click.echo(event)
Ejemplo n.º 13
0
def releases(app_name, limit):
    """List releases and print the compiled name.

    The `compiled_name` includes the app, build version and app hash.
    """
    vr = get_vr()

    q = {
        'build__app__name': app_name,
    }

    # add filters if we need to be...
    for i, release in enumerate(query('Release', vr, q)):
        click.echo(release.compiled_name)
        if i == limit:
            return
Ejemplo n.º 14
0
def builds(app_name, limit):
    """List builds.
    """
    vr = get_vr()

    q = {
        'app__name': app_name,
    }

    # add filters if we need to be...
    for i, build in enumerate(query('Build', vr, q)):
        if not build.file:
            click.echo('[failed] %s %s' % (build.resource_uri, build.app))
        else:
            click.echo(build.file)
        if i == limit:
            return
Ejemplo n.º 15
0
Archivo: swarm.py Proyecto: yougov/rapt
def load_swarms(vr, names):
    """Return an ordered of swarms."""
    swarms = []
    for name in names:
        try:
            app_name, config_name, proc_name = name.split('-')
        except ValueError:
            click.echo('Invalid swarm name %s' % name)
            sys.exit(3)

        q = {
            'app__name': app_name,
            'config_name': config_name,
            'proc_name': proc_name
        }

        swarm = query('Swarm', vr, q).next()
        handlers = swarm_event_handler(swarm, vr.username)
        swarms.append(SwarmInfo(name, swarm, swarm_config(swarm), handlers))
    return swarms
Ejemplo n.º 16
0
def buildpack():
    tmpl = {
        'repo_url': '',
        'repo_type': ['git', 'hg'],
        'description': '',
        'order': 0,
    }

    vr = get_vr()

    info = {
        'available buildpacks': [bp.repo_url for bp in query('buildpack', vr)]
    }

    config = edit_yaml(dump_yaml(tmpl), dump_yaml(info))

    click.echo('Creating buildpack with following config:\n')
    click.echo(pformat(config))
    click.echo()

    if click.confirm('Create buildpack?'):
        bp = models.Buildpack(vr, config)
        bp.create()
        click.echo('Create %s %s!' % (bp.repo_url, bp.resource_uri))
Ejemplo n.º 17
0
def ingredient(name, read):
    """View a complete ingredient config."""
    vr = get_vr()
    q = {'name': name}
    ingredient = query('Ingredient', vr, q).next()

    doc = {
        'config': load_yaml(ingredient.config_yaml),
        'env': load_yaml(ingredient.env_yaml),
    }

    if read:
        click.echo(dump_yaml(doc))
        return

    config = edit_yaml(dump_yaml(doc))

    if not config:
        click.echo('No changes')
        return

    ingredient.config_yaml = dump_yaml(config['config'])
    ingredient.env_yaml = dump_yaml(config['env'])
    ingredient.save()
Ejemplo n.º 18
0
def ingredient(name, read):
    """View a complete ingredient config."""
    vr = get_vr()
    q = {'name': name}
    ingredient = query('Ingredient', vr, q).next()

    doc = {
        'config': load_yaml(ingredient.config_yaml),
        'env': load_yaml(ingredient.env_yaml),
    }

    if read:
        click.echo(dump_yaml(doc))
        return

    config = edit_yaml(dump_yaml(doc))

    if not config:
        click.echo('No changes')
        return

    ingredient.config_yaml = dump_yaml(config['config'])
    ingredient.env_yaml = dump_yaml(config['env'])
    ingredient.save()
Ejemplo n.º 19
0
    def test_query_valid_models(self):
        result = query('NotARealModel', Mock())

        # NOTE: We have to actually consume the result in order to get an
        #       error.
        assert pytest.raises(Exception, result.next)
Ejemplo n.º 20
0
 def test_query_returns_iterable(self):
     vr = MagicMock()
     result = query('App', vr)
     assert hasattr(result, 'next')
Ejemplo n.º 21
0
    def test_query_valid_models(self):
        result = query('NotARealModel', Mock())

        # NOTE: We have to actually consume the result in order to get an
        #       error.
        assert pytest.raises(Exception, result.next)
Ejemplo n.º 22
0
 def test_query_returns_iterable(self):
     vr = MagicMock()
     result = query('App', vr)
     assert hasattr(result, 'next')