<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
  listservers class

  This class implements methods that will list servers within a
  membase cluster

"""

import pprint
from membase_info import *
from restclient import *


class Listservers:

    def __init__(self):
        """
      constructor
    """

        self.rest_cmd = '/pools/default'
        self.method = 'GET'
        self.debug = False

    def runCmd(
        self,
        cmd,
        server,
        port,
        user,
        password,
        opts,
        ):

        output= 'default'
        for (o, a) in opts:
            if o in  ('-o', '--output'):
                output = a
            if o in  ('-d', '--debug'):
                self.debug = 1

        data = self.getData(server,port)
        if (output == 'json'):
            print data
        else:
            print 'List of servers within the server %s:%s' % (server, port)
            self.printNodes(self.getNodes(data))


    def getData(self,
                server,
                port):
        """
        get the raw json output from the server
    """

        self.rest = RestClient(cluster, port, {'debug':self.debug})
        response = self.rest.sendCmd(self.method, self.rest_cmd)

        if response.status == 200:
            data = response.read()
        else:
            data = '"Error! ' + response.status + response.reason + '"'

        return data

    def getNodes(self, data):
        """
        deserialize the raw json output and return just the nodes
    """

        json = self.rest.getJson(data)
        #pp = pprint.PrettyPrinter(indent=4)
        #pp.pprint(json['nodes'])
        return json['nodes']

    def printNodes(self, nodes):
        """
        print the nodes
    """

        for node in nodes:
            print '\t%s\t%s\t%s' % (node['hostname'],
                node['otpNode'], node['status' ])
<commit_msg>Fixed wrongly named variable to correct name in listservers<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
  listservers class

  This class implements methods that will list servers within a
  membase cluster

"""

import pprint
from membase_info import *
from restclient import *


class Listservers:

    def __init__(self):
        """
      constructor
    """

        self.rest_cmd = '/pools/default'
        self.method = 'GET'
        self.debug = False

    def runCmd(
        self,
        cmd,
        server,
        port,
        user,
        password,
        opts,
        ):

        output= 'default'
        for (o, a) in opts:
            if o in  ('-o', '--output'):
                output = a
            if o in  ('-d', '--debug'):
                self.debug = 1

        data = self.getData(server,port)
        if (output == 'json'):
            print data
        else:
            print 'List of servers within the server %s:%s' % (server, port)
            self.printNodes(self.getNodes(data))


    def getData(self,
                server,
                port):
        """
        get the raw json output from the server
    """

        self.rest = RestClient(server, port, {'debug':self.debug})
        response = self.rest.sendCmd(self.method, self.rest_cmd)

        if response.status == 200:
            data = response.read()
        else:
            data = '"Error! ' + response.status + response.reason + '"'

        return data

    def getNodes(self, data):
        """
        deserialize the raw json output and return just the nodes
    """

        json = self.rest.getJson(data)
        #pp = pprint.PrettyPrinter(indent=4)
        #pp.pprint(json['nodes'])
        return json['nodes']

    def printNodes(self, nodes):
        """
        print the nodes
    """

        for node in nodes:
            print '\t%s\t%s\t%s' % (node['hostname'],
                node['otpNode'], node['status' ])

{'fraction_non_alphanumeric': 0.12297401595060457, 'fraction_numerical': 0.0030872137895549268, 'mean_word_length': 1.6111484217595702, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1249522', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1108, 'n_words': 312}