def print_report(frame, explain=False): """Pretty-print the report.""" if cli.OUTPUT_FORMAT is None: if explain: frame.replace(True, ' ', inplace=True) frame.replace(False, 'X', inplace=True) dict_ = frame.to_dict(orient='split') del dict_['index'] cli.out( tabulate.tabulate(dict_['data'], dict_['columns'], tablefmt='simple')) if explain: cli.echo_green( '\nX: designates the factor that prohibits scheduling ' 'the instance on the given server') elif cli.OUTPUT_FORMAT == 'yaml': fmt = plugin_manager.load('treadmill.formatters', 'yaml') cli.out(fmt.format(frame.to_dict(orient='records'))) elif cli.OUTPUT_FORMAT == 'json': cli.out(frame.to_json(orient='records')) elif cli.OUTPUT_FORMAT == 'csv': cli.out(frame.to_csv(index=False)) else: cli.out(tabulate.tabulate(frame, frame.columns, tablefmt='simple'))
def restart_apps(apps, wait, cors_origin, krb_realm, dry_run): """Restart system apps.""" ctx = cell_admin.CellCtx(cors=cors_origin, krb_realm=krb_realm) cell_apps = cell_admin.get_apps(ctx) if not apps: apps = list(cell_apps) instance_api = instance.API(plugins=['aws-proid-env']) for appname in apps: fullname = cell_apps[appname]['fullname'] app = cell_admin.render_template(appname, ctx) count = cell_apps[appname].get('monitors') if count is None: continue cli.echo_green('Restarting app %s:', fullname) cli.out(yaml.dump(app, explicit_start=True)) if dry_run: continue for idx in range(0, count): instance_ids = instance_api.create(fullname, app, 1) for inst_id in instance_ids: cli.echo_green(inst_id) if idx <= count - 1 and wait: time.sleep(wait)
def configure_monitors(monitors, cors_origin, krb_realm, dry_run): """Configure system apps monitors.""" ctx = cell_admin.CellCtx(cors=cors_origin, krb_realm=krb_realm) cell_apps = cell_admin.get_apps(ctx) if not monitors: monitors = { appname: app['monitors'] for appname, app in cell_apps.items() if 'monitors' in app } for appname, count in monitors.items(): fullname = cell_apps[appname]['fullname'] cli.echo_green('Configuring monitor %s: %s', fullname, count) if not dry_run: masterapi.update_appmonitor(context.GLOBAL.zk.conn, fullname, int(count))
def configure_apps(apps, cors_origin, krb_realm, dry_run): """Configure system apps.""" ctx = cell_admin.CellCtx(cors=cors_origin, krb_realm=krb_realm) cell_apps = cell_admin.get_apps(ctx) if not apps: apps = list(cell_apps) admin_app = admin.Application(context.GLOBAL.ldap.conn) # For apps that need write access to LDAP. The context LDAP must have # write access because this is what we use to write manifests here. write_uri = context.GLOBAL.ldap.write_url ctx.admin_ldap_url = ','.join(write_uri) if write_uri else None # Configure apps identity groups identity_groups = cell_admin.get_identity_groups(ctx) for groupname, count in identity_groups.items(): cli.echo_green('Configuring identity group %s: %d', groupname, count) if not dry_run: masterapi.update_identity_group(context.GLOBAL.zk.conn, groupname, count) # Configure apps for appname in apps: fullname = cell_apps[appname]['fullname'] app = cell_admin.render_template(appname, ctx) cli.echo_green('Configuring app %s:', fullname) cli.out(yaml.dump(app, explicit_start=True)) if not dry_run: try: admin_app.create(fullname, app) except admin_exceptions.AlreadyExistsResult: admin_app.replace(fullname, app)
def configure_appgroups(cors_origin, krb_realm, dry_run): """Configure system app groups.""" ctx = cell_admin.CellCtx(cors=cors_origin, krb_realm=krb_realm) appgroups = cell_admin.get_appgroups(ctx) admin_app_group = admin.AppGroup(context.GLOBAL.ldap.conn) for name, data in appgroups.items(): cli.echo_green('Configuring appgroup %s: %r', name, data) if dry_run: continue try: admin_app_group.create(name, data) except admin_exceptions.AlreadyExistsResult: admin_app_group.update(name, data) existing = admin_app_group.get(name, dirty=True) group_cells = set(existing['cells']) group_cells.update([context.GLOBAL.cell]) admin_app_group.update(name, {'cells': list(group_cells)}) existing = admin_app_group.get(name, dirty=True) cli.out(existing)