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))
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()
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'
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)
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)
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)
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)
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)
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))
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)
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
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
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
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))
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()
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)
def test_query_returns_iterable(self): vr = MagicMock() result = query('App', vr) assert hasattr(result, 'next')