Ejemplo n.º 1
0
def validate_arg(opt, arg, arg_type='string'):
    if arg.startswith('-'):
        err = 'Invalid argument for opt: ' + opt + ' [' + arg + '].'
        raise CliError(err)
    if arg_type == 'integer' and not arg.isdigit():
        err = 'Invalid integer for opt: ' + opt + ' [' + arg + '].'
        raise CliError(err)
Ejemplo n.º 2
0
def node_bucket_type_list(args, cfg):
    service_url = cfg.api_url()
    if service_url is False:
        raise CliError("Riak Mesos Framework is not running.")
    if args['node'] == '':
        raise CliError('Node name must be specified')
    r = requests.get(service_url + 'clusters/' + args['cluster'] + '/nodes/' +
                     args['node'] + '/types')
    util.debug_request(args['debug_flag'], r)
    print(r.text)
    return
Ejemplo n.º 3
0
def node_bucket_type_create(args, cfg):
    service_url = cfg.api_url()
    if service_url is False:
        raise CliError("Riak Mesos Framework is not running.")
    if args['node'] == '' or args['bucket_type'] == '' or args['props'] == '':
        raise CliError('Node name, bucket-type, props must be ' 'specified')
    r = requests.post(service_url + 'clusters/' + args['cluster'] + '/nodes/' +
                      args['node'] + '/types/' + args['bucket_type'],
                      data=args['props'])
    util.debug_request(args['debug_flag'], r)
    print(r.text)
    return
Ejemplo n.º 4
0
def node_stats(args, cfg):
    service_url = cfg.scheduler_url()
    if service_url is False:
        raise CliError("Riak Mesos Framework is not running.")
    if args['node'] == '':
        raise CliError('Node name must be specified')

    r = requests.get(service_url + 'riak/nodes/' + args['node'] + '/stats')
    util.debug_request(args['debug_flag'], r)
    if r.status_code != 200:
        print('Failed to get stats, status_code: ' + str(r.status_code))
    else:
        print(r.text)
    return
Ejemplo n.º 5
0
def node_remove(args, cfg):
    service_url = cfg.api_url()
    if service_url is False:
        raise CliError("Riak Mesos Framework is not running.")
    if args['node'] == '':
        raise CliError('Node name must be specified')
    requrl = service_url + 'clusters/'
    requrl += args['cluster'] + '/nodes/' + args['node']
    if args['force_flag']:
        requrl += '?force=true'
    r = requests.delete(requrl, data='')
    util.debug_request(args['debug_flag'], r)
    print(r.text)
    return
Ejemplo n.º 6
0
def node_log_list(args, cfg):
    service_url = cfg.scheduler_url()
    if service_url is False:
        raise CliError("Riak Mesos Framework is not running.")
    if args['node'] == '':
        raise CliError('Node name must be specified')
    node_name = util.get_node_name(cfg, args['cluster'], args['debug_flag'],
                                   args['node'])
    r = requests.get(service_url + 'explore/clusters/' + args['cluster'] +
                     '/nodes/' + node_name + '/log/files')
    util.debug_request(args['debug_flag'], r)
    if r.status_code != 200:
        print('Failed to get log files, status_code: ' + str(r.status_code))
    else:
        print(r.text)
    return
Ejemplo n.º 7
0
def node(args, cfg):
    service_url = cfg.api_url()
    if service_url is False:
        raise CliError("Riak Mesos Framework is not running.")
    r = requests.get(service_url + 'clusters/' + args['cluster'] + '/nodes')
    util.debug_request(args['debug_flag'], r)
    print(r.text)
    return
Ejemplo n.º 8
0
def cluster_destroy(args, cfg):
    service_url = cfg.api_url()
    if service_url is False:
        raise CliError("Riak Mesos Framework is not running.")
    r = requests.delete(service_url + 'clusters/' + args['cluster'], data='')
    util.debug_request(args['debug_flag'], r)
    print(r.text)
    return
Ejemplo n.º 9
0
def node_add(args, cfg):
    service_url = cfg.api_url()
    if service_url is False:
        raise CliError("Riak Mesos Framework is not running.")
    for x in range(0, args['num_nodes']):
        r = requests.post(service_url + 'clusters/' + args['cluster'] +
                          '/nodes',
                          data='')
        util.debug_request(args['debug_flag'], r)
        print(r.text)
    return
Ejemplo n.º 10
0
def extract_option(args, name, default, arg_type='string'):
    val = default
    if name in args:
        index = args.index(name)
        if index + 1 < len(args):
            val = args[index + 1]
            validate_arg(name, val, arg_type)
            del args[index]
            del args[index]
        else:
            print(constants.usage)
            raise CliError('Not enough arguments for: ' + name)
    return [args, val]
Ejemplo n.º 11
0
    def run(self):
        cmd_desc = help(self.cmd)

        if self.args['help_flag'] and not cmd_desc:
            print(constants.usage)
            return 0
        elif self.args['help_flag']:
            print(cmd_desc)
            return 0

        if self.cmd == '':
            print('No commands executed')
            return
        elif self.cmd.startswith('-'):
            raise CliError('Unrecognized option: ' + self.cmd)
        elif not cmd_desc:
            raise CliError('Unrecognized command: ' + self.cmd)

        if self.cfg is None:
            raise CliError('No config file found')

        try:
            command_func_str = self.cmd.replace(' ', '_')
            command_func_str = command_func_str.replace('-', '_')
            util.debug(self.args['debug_flag'], 'Args: ' + str(self.args))
            util.debug(self.args['debug_flag'],
                       'Command Func: ' + command_func_str + '(args, cfg)')
            command_func = getattr(commands, command_func_str)
            command_func(self.args, self.cfg)
        except AttributeError as e:
            print('CliError: Unrecognized command: ' + self.cmd)
            if self.args['debug_flag']:
                traceback.print_exc()
                raise e

        return 0
Ejemplo n.º 12
0
def cluster_config_advanced(args, cfg):
    service_url = cfg.api_url()
    if service_url is False:
        raise CliError("Riak Mesos Framework is not running.")
    if args['riak_file'] == '':
        r = requests.get(service_url + 'clusters/' + args['cluster'] +
                         '/advancedConfig')
        util.debug_request(args['debug_flag'], r)
        print(r.text)
    else:
        with open(args['riak_file']) as data_file:
            r = requests.put(service_url + 'clusters/' + args['cluster'] +
                             '/advancedConfig',
                             data=data_file)
            util.debug_request(args['debug_flag'], r)
            print(r.text)
    return
Ejemplo n.º 13
0
def node_info(args, cfg):
    service_url = cfg.api_url()
    if service_url is False:
        raise CliError("Riak Mesos Framework is not running.")
    r = requests.get(service_url + 'clusters/' + args['cluster'] + '/nodes/' +
                     args['node'])
    util.debug_request(args['debug_flag'], r)
    # TODO: Parse the relevant parts of the node info
    print(r.text)
    # node_json = try_json(r.text)
    # if (node_json is not False):
    #     print('HTTP: http://' + node_json[node]['Hostname'] + ':' +
    #           str(node_json[node]['TaskData']['HTTPPort']))
    #     print('PB  : ' + node_json[node]['Hostname'] + ':' +
    #           str(node_json[node]['TaskData']['PBPort']))
    #     util.ppobj('Node: ', r.text, node, '{}')
    # else:
    #     print(r.text)
    return
Ejemplo n.º 14
0
def framework_endpoints(args, cfg):
    service_url = cfg.api_url()
    if service_url is False:
        raise CliError("Riak Mesos Framework is not running.")
    print("Framework HTTP API: " + service_url)
    return
Ejemplo n.º 15
0
def node_wait_for_service(args, cfg):
    if args['node'] == '':
        raise CliError('Node name must be specified')
    util.wait_for_node(cfg, args['cluster'], args['debug_flag'], args['node'],
                       args['timeout'])
    return