def _test_is_up(self, url, name): """Test {name} - {url} is up.""" del name cli.out(' Server up : {}'.format(url)) host, port = _to_hostport(url) self.assertTrue(chk.connect(host, port))
def _show_instance(apis, instance_id): """Show instance manifest.""" url = '/instance/%s' % urllib_parse.quote(instance_id) response = restclient.get(apis, url) cli.out(_APP_FORMATTER(response.json()))
def _show_list(apis, match, states, finished=False, partition=None): """Show list of instnces in given state.""" state = _get_state(apis, match, finished, partition) names = [item['name'] for item in state if item['state'] in states] for name in names: cli.out(name)
def configure(instance): """View app instance configuration""" scheduled = masterapi.get_app(context.GLOBAL.zk.conn, instance) cli.out(formatter(scheduled))
def _list(): """List allocations.""" restapi = context.GLOBAL.admin_api(ctx.get('api')) response = restclient.get(restapi, '/tenant/') cli.out(alloc_formatter(response.json()))
def list_users(path): """List IAM users. """ iam_conn = awscontext.GLOBAL.iam users = iamclient.list_users(iam_conn, path) cli.out(formatter(users))
def _print(frame, formatter): """Print data frame based on cli options.""" if cli.OUTPUT_FORMAT == 'csv': cli.out(frame.to_csv()) else: cli.out(formatter(frame.to_dict(orient='records')))
def get(path): """REST GET request.""" response = restclient.get(ctx['api'], path) formatter = cli.make_formatter(None) cli.out(formatter(response.json()))
def delete(path): """REST DELETE request.""" response = restclient.delete(ctx['api'], path) formatter = cli.make_formatter(None) cli.out(formatter(response.json()))
def _list(): """List out App Group entries""" restapi = context.GLOBAL.admin_api() response = restclient.get(restapi, _REST_PATH) cli.out(formatter(response.json()))
def list_ipa(): """List users. """ ipa_client = awscontext.GLOBAL.ipaclient users = usermanager.list_users(ipa_client=ipa_client) cli.out(formatter(users))
def _list(): """List security groups""" ec2_conn = awscontext.GLOBAL.ec2 secgroups = ec2client.list_secgroups(ec2_conn) cli.out(formatter(secgroups))
def _test_count(self, urls, name): """Checks {name} srv records count > 0.""" cli.out('%s: %r' % (name, urls)) self.assertTrue(len(urls) > 0)
def _test_is_ok(self, url, name): """Test {name} - {url} is healthy.""" del name cli.out(' Server healthy : {}'.format(url)) self.assertTrue(chk.url_check(url))
def running(): """List running applications""" for app in sorted(context.GLOBAL.zk.conn.get_children(z.RUNNING)): cli.out(app)
def configure(name): """Display details of the server.""" restapi = context.GLOBAL.admin_api(ctx.get('api')) cli.out( server_formatter( restclient.get(restapi, '/server/{}'.format(name)).json()))
def stopped(): """List stopped applications""" running = set(context.GLOBAL.zk.conn.get_children(z.RUNNING)) scheduled = set(context.GLOBAL.zk.conn.get_children(z.SCHEDULED)) for app in sorted(running - scheduled): cli.out(app)
def _run(apis, count, manifest, memory, cpu, disk, tickets, service, restart_limit, restart_interval, endpoint, appname, command): """Run Treadmill app.""" # too many branches # # pylint: disable=R0912 app = {} if manifest: with open(manifest, 'rb') as fd: app = yaml.load(fd.read()) if endpoint: app['endpoints'] = [{ 'name': name, 'port': port } for name, port in endpoint] if tickets: app['tickets'] = tickets if command: if not service: # Take the basename of the command, always assume / on all # platforms. service = command[0].split('/')[-1] services_dict = {svc['name']: svc for svc in app.get('services', [])} if service: if service not in services_dict: services_dict[service] = { 'name': service, 'restart': { 'limit': restart_limit, 'interval': restart_interval, } } if command: services_dict[service]['command'] = ' '.join(list(command)) if services_dict: app['services'] = list(services_dict.values()) if app: # Ensure defaults are set. if 'memory' not in app: app['memory'] = _DEFAULT_MEM if 'disk' not in app: app['disk'] = _DEFAULT_DISK if 'cpu' not in app: app['cpu'] = _DEFAULT_CPU # Override if requested. if memory is not None: app['memory'] = str(memory) if disk is not None: app['disk'] = str(disk) if cpu is not None: app['cpu'] = str(cpu) url = '/instance/' + appname if count: url += '?count=%d' % count response = restclient.post(apis, url, payload=app) for instance_id in response.json()['instances']: cli.out(instance_id)
def _list(): """List configured tenants""" admin_tnt = context.GLOBAL.admin.tenant() cli.out(formatter(admin_tnt.list({})))
def _run(apis, count, manifest, memory, cpu, disk, tickets, service, restart_limit, restart_interval, endpoint, debug, debug_services, appname, command): """Run Treadmill app.""" # too many branches # # pylint: disable=R0912 app = {} if manifest: with io.open(manifest, 'rb') as fd: app = yaml.load(stream=fd) if endpoint: app['endpoints'] = [{ 'name': name, 'port': port } for name, port in endpoint] if tickets: app['tickets'] = tickets if command: if not service: # Take the basename of the command, always assume / on all # platforms. service = os.path.basename(shlex.split(command[0])[0]) services_dict = {svc['name']: svc for svc in app.get('services', [])} if service: if service not in services_dict: services_dict[service] = { 'name': service, 'restart': { 'limit': restart_limit, 'interval': restart_interval, } } if command: services_dict[service]['command'] = ' '.join(list(command)) if services_dict: app['services'] = list(six.itervalues(services_dict)) if app: # Ensure defaults are set. if 'memory' not in app: app['memory'] = _DEFAULT_MEM if 'disk' not in app: app['disk'] = _DEFAULT_DISK if 'cpu' not in app: app['cpu'] = _DEFAULT_CPU # Override if requested. if memory is not None: app['memory'] = str(memory) if disk is not None: app['disk'] = str(disk) if cpu is not None: app['cpu'] = str(cpu) url = '/instance/' + appname query = {} if count: query['count'] = count if debug: query['debug'] = 'true' if debug_services: query['debug_services'] = ','.join(debug_services) if query: url = '{}?{}'.format(url, urllib_parse.urlencode(query)) response = restclient.post(apis, url, payload=app) for instance_id in response.json()['instances']: cli.out(instance_id)
def _list(): """List configured app monitors""" restapi = context.GLOBAL.cell_api(ctx['api']) response = restclient.get(restapi, _REST_PATH) cli.out(formatter(response.json()))
def _list(): """List configured tenants""" admin_tnt = admin.Tenant(context.GLOBAL.ldap.conn) cli.out(formatter(admin_tnt.list({})))
def _list(): """List configured allocations""" admin_alloc = admin.Allocation(context.GLOBAL.ldap.conn) cli.out(formatter(admin_alloc.list({})))
def _list(): """List the configured cells.""" restapi = context.GLOBAL.admin_api(ctx.get('api')) cli.out(cell_formatter(restclient.get(restapi, '/cell/').json()))
def _list(): """List instances""" ec2_conn = awscontext.GLOBAL.ec2 instances = ec2client.list_instances(ec2_conn) cli.out(formatter(instances))
def configure(name): """Display the details of a cell.""" restapi = context.GLOBAL.admin_api(ctx.get('api')) cli.out( cell_formatter(restclient.get(restapi, '/cell/%s' % name).json()))
def _show_state(apis, match=None, finished=False, partition=None): """Show cell state.""" state = _get_state(apis, match, finished, partition) cli.out(_STATE_FORMATTER(state))
def scheduled(): """List scheduled applications""" for app in sorted(context.GLOBAL.zk.conn.get_children(z.SCHEDULED)): cli.out(app)
def _list(): """Displays master servers""" admin_cell = admin.Cell(context.GLOBAL.ldap.conn) cells = admin_cell.list({}) cli.out(formatter(cells))
def _list(): """List App Group entries""" admin_app_group = admin.AppGroup(context.GLOBAL.ldap.conn) app_group_entries = admin_app_group.list({}) cli.out(formatter(app_group_entries))