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 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_config(vr, app_list, squad_list): tmpl = { 'app': '', 'version': '', 'proc_name': '', 'size': '', 'squad': '', # TODO: Add config options } info = { 'NOTES': 'Use the URL when copying vlaues.', 'available apps': {app.name: app.resource_uri for app in app_list}, 'available squads': {squad.name: squad.resource_uri for squad in squad_list}, } footer = dump_yaml(info) return edit_yaml(dump_yaml(tmpl), footer)
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 swarm(names, dry_run): """Swarm an existing swarm. The swarm command allows swarming more than one swarm as defined by the `names` argument. The names can be passed directly in the command. $ rapt swarm myapp-production-web myapp-production-workers The `names` can also be passed in via stdin. For eaxmple: $ rapt swarms | grep myapp | rapt swarm This will open a YAML file where each swarm's settings can be edited. Only those swarms that have been edited will be reswarmed. After the swarms have been triggered, the events for those swarms will be printed. The script will exit when the events have finished or there has been a failure in one of swarms. """ vr = get_vr() swarms = load_swarms(vr, names or stdin()) configs = {str(swarm.name): swarm.config for swarm in swarms} if not configs: click.echo('No configs found') return new_config = edit_yaml(dump_yaml(configs)) if not new_config: click.echo('No changes to the config. Exiting...') return event_handlers = [] for swarm in swarms: config = new_config[swarm.name] if config != swarm.config: click.echo('Updating swarms with: %s' % config) if not dry_run: doc = swarm.obj.dispatch(**config) event_handlers.append(swarm_id_handler(doc['swarm_id'])) click.echo('Swarmed %s!' % swarm.name) if event_handlers: click.echo('Watching for events. Hit C-c to exit') for event in filtered_events(vr, event_handlers): click.echo(event)
def deploy(build_config, app_name, release, proc, config_name, hostname, port): """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 = { 'release': release or '', 'proc': proc or '', 'config_name': config_name or '', 'hostname': hostname or '', 'port': port or '', } vr = get_vr() # Do we use some pre-canned yaml? if build_config: config = load_yaml(build_config[0]) # How about some command line flags elif release and proc and config_name and hostname: 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: release = get_release(config, vr) # TODO: Get VR returning some value. release.deploy(config['hostname'], config['port'], config['proc'], config['config_name']) click.echo('Watching for events. Hit C-c to exit') for event in filtered_events(vr, forever=True): click.echo(event)
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)