Ejemplo n.º 1
0
 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))
Ejemplo n.º 2
0
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()))
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
 def configure(instance):
     """View app instance configuration"""
     scheduled = masterapi.get_app(context.GLOBAL.zk.conn, instance)
     cli.out(formatter(scheduled))
Ejemplo n.º 5
0
 def _list():
     """List allocations."""
     restapi = context.GLOBAL.admin_api(ctx.get('api'))
     response = restclient.get(restapi, '/tenant/')
     cli.out(alloc_formatter(response.json()))
Ejemplo n.º 6
0
 def list_users(path):
     """List IAM users.
     """
     iam_conn = awscontext.GLOBAL.iam
     users = iamclient.list_users(iam_conn, path)
     cli.out(formatter(users))
Ejemplo n.º 7
0
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')))
Ejemplo n.º 8
0
    def get(path):
        """REST GET request."""
        response = restclient.get(ctx['api'], path)

        formatter = cli.make_formatter(None)
        cli.out(formatter(response.json()))
Ejemplo n.º 9
0
    def delete(path):
        """REST DELETE request."""
        response = restclient.delete(ctx['api'], path)

        formatter = cli.make_formatter(None)
        cli.out(formatter(response.json()))
Ejemplo n.º 10
0
 def _list():
     """List out App Group entries"""
     restapi = context.GLOBAL.admin_api()
     response = restclient.get(restapi, _REST_PATH)
     cli.out(formatter(response.json()))
Ejemplo n.º 11
0
 def list_ipa():
     """List users.
     """
     ipa_client = awscontext.GLOBAL.ipaclient
     users = usermanager.list_users(ipa_client=ipa_client)
     cli.out(formatter(users))
Ejemplo n.º 12
0
 def _list():
     """List security groups"""
     ec2_conn = awscontext.GLOBAL.ec2
     secgroups = ec2client.list_secgroups(ec2_conn)
     cli.out(formatter(secgroups))
Ejemplo n.º 13
0
 def _test_count(self, urls, name):
     """Checks {name} srv records count > 0."""
     cli.out('%s: %r' % (name, urls))
     self.assertTrue(len(urls) > 0)
Ejemplo n.º 14
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))
Ejemplo n.º 15
0
 def running():
     """List running applications"""
     for app in sorted(context.GLOBAL.zk.conn.get_children(z.RUNNING)):
         cli.out(app)
Ejemplo n.º 16
0
 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()))
Ejemplo n.º 17
0
 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)
Ejemplo n.º 18
0
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)
Ejemplo n.º 19
0
 def _list():
     """List configured tenants"""
     admin_tnt = context.GLOBAL.admin.tenant()
     cli.out(formatter(admin_tnt.list({})))
Ejemplo n.º 20
0
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)
Ejemplo n.º 21
0
 def _list():
     """List configured app monitors"""
     restapi = context.GLOBAL.cell_api(ctx['api'])
     response = restclient.get(restapi, _REST_PATH)
     cli.out(formatter(response.json()))
Ejemplo n.º 22
0
 def _list():
     """List configured tenants"""
     admin_tnt = admin.Tenant(context.GLOBAL.ldap.conn)
     cli.out(formatter(admin_tnt.list({})))
Ejemplo n.º 23
0
 def _list():
     """List configured allocations"""
     admin_alloc = admin.Allocation(context.GLOBAL.ldap.conn)
     cli.out(formatter(admin_alloc.list({})))
Ejemplo n.º 24
0
    def _list():
        """List the configured cells."""
        restapi = context.GLOBAL.admin_api(ctx.get('api'))

        cli.out(cell_formatter(restclient.get(restapi, '/cell/').json()))
Ejemplo n.º 25
0
 def _list():
     """List instances"""
     ec2_conn = awscontext.GLOBAL.ec2
     instances = ec2client.list_instances(ec2_conn)
     cli.out(formatter(instances))
Ejemplo n.º 26
0
    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()))
Ejemplo n.º 27
0
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))
Ejemplo n.º 28
0
 def scheduled():
     """List scheduled applications"""
     for app in sorted(context.GLOBAL.zk.conn.get_children(z.SCHEDULED)):
         cli.out(app)
Ejemplo n.º 29
0
 def _list():
     """Displays master servers"""
     admin_cell = admin.Cell(context.GLOBAL.ldap.conn)
     cells = admin_cell.list({})
     cli.out(formatter(cells))
Ejemplo n.º 30
0
 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))