示例#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))
示例#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()))
示例#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)
示例#4
0
 def configure(instance):
     """View app instance configuration"""
     scheduled = masterapi.get_app(context.GLOBAL.zk.conn, instance)
     cli.out(formatter(scheduled))
示例#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()))
示例#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))
示例#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')))
示例#8
0
    def get(path):
        """REST GET request."""
        response = restclient.get(ctx['api'], path)

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

        formatter = cli.make_formatter(None)
        cli.out(formatter(response.json()))
示例#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()))
示例#11
0
 def list_ipa():
     """List users.
     """
     ipa_client = awscontext.GLOBAL.ipaclient
     users = usermanager.list_users(ipa_client=ipa_client)
     cli.out(formatter(users))
示例#12
0
 def _list():
     """List security groups"""
     ec2_conn = awscontext.GLOBAL.ec2
     secgroups = ec2client.list_secgroups(ec2_conn)
     cli.out(formatter(secgroups))
示例#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)
示例#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))
示例#15
0
 def running():
     """List running applications"""
     for app in sorted(context.GLOBAL.zk.conn.get_children(z.RUNNING)):
         cli.out(app)
示例#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()))
示例#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)
示例#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)
示例#19
0
 def _list():
     """List configured tenants"""
     admin_tnt = context.GLOBAL.admin.tenant()
     cli.out(formatter(admin_tnt.list({})))
示例#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)
示例#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()))
示例#22
0
 def _list():
     """List configured tenants"""
     admin_tnt = admin.Tenant(context.GLOBAL.ldap.conn)
     cli.out(formatter(admin_tnt.list({})))
示例#23
0
 def _list():
     """List configured allocations"""
     admin_alloc = admin.Allocation(context.GLOBAL.ldap.conn)
     cli.out(formatter(admin_alloc.list({})))
示例#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()))
示例#25
0
 def _list():
     """List instances"""
     ec2_conn = awscontext.GLOBAL.ec2
     instances = ec2client.list_instances(ec2_conn)
     cli.out(formatter(instances))
示例#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()))
示例#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))
示例#28
0
 def scheduled():
     """List scheduled applications"""
     for app in sorted(context.GLOBAL.zk.conn.get_children(z.SCHEDULED)):
         cli.out(app)
示例#29
0
 def _list():
     """Displays master servers"""
     admin_cell = admin.Cell(context.GLOBAL.ldap.conn)
     cells = admin_cell.list({})
     cli.out(formatter(cells))
示例#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))