<commit_before>"""
  Implementation for rebalance, add, remove, stop rebalance.
"""

import time
import os
import sys
import util_cli as util
import socket
import simplejson as json
import re
import urlparse

from usage import usage
from restclient import *
from listservers import *

# the rest commands and associated URIs for various node operations

rest_cmds = {
    'rebalance'         :'/controller/rebalance',
    'rebalance-stop'    :'/controller/stopRebalance',
    'rebalance-status'  :'/pools/default/rebalanceProgress',
    'server-add'        :'/controller/addNode',
    'server-readd'      :'/controller/reAddNode',
    'failover'          :'/controller/failOver',
    'recovery'          :'/controller/setRecoveryType',
    'cluster-init'      :'/settings/web',
    'cluster-edit'      :'/settings/web',
    'node-init'         :'/nodes/self/controller/settings',
    'setting-compaction'    :'/controller/setAutoCompaction',
    'setting-notification'  :'/settings/stats',
    'setting-autofailover'  :'/settings/autoFailover',
    'setting-alert'         :'/settings/alerts',
    'user-manage'           :'/settings/readOnlyUser',
    'group-manage'          :'/pools/default/serverGroups',
    'ssl-manage'            :'/pools/default/certificate',
    'collect-logs-start'  : '/controller/startLogsCollection',
    'collect-logs-stop'   : '/controller/cancelLogsCollection',
    'collect-logs-status' : '/pools/default/tasks',
}

server_no_remove = [
    'rebalance-stop',
    'rebalance-status',
    'server-add',
    'server-readd',
    'failover',
    'recovery',
]
server_no_add = [
    'rebalance-stop',
    'rebalance-status',
    'failover',
    'recovery',
]

# Map of operations and the HTTP methods used against the REST interface

methods = {
    'rebalance'         :'POST',
    'rebalance-stop'    :'POST',
    'rebalance-status'  :'GET',
    'eject-server'      :'POST',
    'server-add'        :'POST',
    'server-readd'      :'POST',
    'failover'          :'POST',
    'recovery'          :'POST',
    'cluster-init'      :'POST',
    'cluster-edit'      :'POST',
    'node-init'         :'POST',
    'setting-compaction'    :'POST',
    'setting-notification'  :'POST',
    'setting-autofailover'  :'POST',
    'setting-alert'         :'POST',
    'user-manage'           :'POST',
    'group-manage'          :'POST',
    'ssl-manage'            :'GET',
    'collect-logs-start'  : 'POST',
    'collect-logs-stop'   : 'POST',
    'collect-logs-status' : 'GET',
}

bool_to_str = lambda value: str(bool(int(value))).lower()

# Map of HTTP success code, success message and error message for
# handling HTTP response properly

class Node:
    SEP = ";"
    def __init__(self):
        self.rest_cmd = rest_cmds['rebalance-status']
        self.method = 'GET'
        self.debug = False
        self.server = ''
        self.port = ''
        self.user = ''
        self.password = ''
        self.ro_username = ''
        self.ro_password = ''
        self.params = {}
        self.output = 'standard'
        self.password_new = None
        self.username_new = None
        self.sa_username = None
        self.sa_password = None
        self.port_new = None
        self.per_node_quota = None
        self.data_path = None
        self.index_path = None
        self.hostname = None
        self.enable_auto_failover = None
        self.enable_notification = None
        self.autofailover_timeout = None
        self.enable_email_alert = None

        #compaction related settings
        self.compaction_db_percentage = None
        self.compaction_db_size = None
        self.compaction_view_percentage = None
        self.compaction_view_size = None
        self.compaction_period_from = None
        self.compaction_period_to = None
        self.enable_compaction_abort = None
        self.enable_compaction_parallel = None
        self.purge_interval = None

        #alert settings
        self.email_recipient = None
        self.email_sender = None
        self.email_user = None
        self.email_password = None
        self.email_host = None
        self.email_port = None
        self.email_enable_encrypt = None
        self.autofailover_node = None
        self.autofailover_max_reached = None
        self.autofailover_node_down = None
        self.autofailover_cluster_small = None
        self.alert_ip_changed = None
        self.alert_disk_space = None
        self.alert_meta_overhead = None
        self.alert_meta_oom = None
        self.alert_write_failed = None

        #group management
        self.group_name = None
        self.server_list = []
        self.from_group = None
        self.to_group = None
        self.group_rename = None

        #SSL certificate management
        self.certificate_file = None
        self.cmd = None

        self.hard_failover = None
        self.recovery_type = None
        self.recovery_buckets = None

        # Collect logs
        self.nodes = None
        self.all_nodes = None
        self.upload = False
        self.upload_host = None
        self.customer = None
        self.ticket = None

    def runCmd(self, cmd, server, port,
               user, password, opts):
        self.rest_cmd = rest_cmds[cmd]
        self.method = methods[cmd]
        self.server = server
        self.port = int(port)
        self.user = user
        self.password = password
        servers = self.processOpts(cmd, opts)
        if self.debug:
            print "INFO: servers %s" % servers

        if cmd == 'server-add' and not servers['add']:
            usage("please list one or more --server-add=HOST[:PORT];"
                  " or use -h for more help.")

        if cmd == 'server-readd' and not servers['add']:<commit_msg>MB-11777: Initialize ticket value<commit_after>"""
  Implementation for rebalance, add, remove, stop rebalance.
"""

import time
import os
import sys
import util_cli as util
import socket
import simplejson as json
import re
import urlparse

from usage import usage
from restclient import *
from listservers import *

# the rest commands and associated URIs for various node operations

rest_cmds = {
    'rebalance'         :'/controller/rebalance',
    'rebalance-stop'    :'/controller/stopRebalance',
    'rebalance-status'  :'/pools/default/rebalanceProgress',
    'server-add'        :'/controller/addNode',
    'server-readd'      :'/controller/reAddNode',
    'failover'          :'/controller/failOver',
    'recovery'          :'/controller/setRecoveryType',
    'cluster-init'      :'/settings/web',
    'cluster-edit'      :'/settings/web',
    'node-init'         :'/nodes/self/controller/settings',
    'setting-compaction'    :'/controller/setAutoCompaction',
    'setting-notification'  :'/settings/stats',
    'setting-autofailover'  :'/settings/autoFailover',
    'setting-alert'         :'/settings/alerts',
    'user-manage'           :'/settings/readOnlyUser',
    'group-manage'          :'/pools/default/serverGroups',
    'ssl-manage'            :'/pools/default/certificate',
    'collect-logs-start'  : '/controller/startLogsCollection',
    'collect-logs-stop'   : '/controller/cancelLogsCollection',
    'collect-logs-status' : '/pools/default/tasks',
}

server_no_remove = [
    'rebalance-stop',
    'rebalance-status',
    'server-add',
    'server-readd',
    'failover',
    'recovery',
]
server_no_add = [
    'rebalance-stop',
    'rebalance-status',
    'failover',
    'recovery',
]

# Map of operations and the HTTP methods used against the REST interface

methods = {
    'rebalance'         :'POST',
    'rebalance-stop'    :'POST',
    'rebalance-status'  :'GET',
    'eject-server'      :'POST',
    'server-add'        :'POST',
    'server-readd'      :'POST',
    'failover'          :'POST',
    'recovery'          :'POST',
    'cluster-init'      :'POST',
    'cluster-edit'      :'POST',
    'node-init'         :'POST',
    'setting-compaction'    :'POST',
    'setting-notification'  :'POST',
    'setting-autofailover'  :'POST',
    'setting-alert'         :'POST',
    'user-manage'           :'POST',
    'group-manage'          :'POST',
    'ssl-manage'            :'GET',
    'collect-logs-start'  : 'POST',
    'collect-logs-stop'   : 'POST',
    'collect-logs-status' : 'GET',
}

bool_to_str = lambda value: str(bool(int(value))).lower()

# Map of HTTP success code, success message and error message for
# handling HTTP response properly

class Node:
    SEP = ";"
    def __init__(self):
        self.rest_cmd = rest_cmds['rebalance-status']
        self.method = 'GET'
        self.debug = False
        self.server = ''
        self.port = ''
        self.user = ''
        self.password = ''
        self.ro_username = ''
        self.ro_password = ''
        self.params = {}
        self.output = 'standard'
        self.password_new = None
        self.username_new = None
        self.sa_username = None
        self.sa_password = None
        self.port_new = None
        self.per_node_quota = None
        self.data_path = None
        self.index_path = None
        self.hostname = None
        self.enable_auto_failover = None
        self.enable_notification = None
        self.autofailover_timeout = None
        self.enable_email_alert = None

        #compaction related settings
        self.compaction_db_percentage = None
        self.compaction_db_size = None
        self.compaction_view_percentage = None
        self.compaction_view_size = None
        self.compaction_period_from = None
        self.compaction_period_to = None
        self.enable_compaction_abort = None
        self.enable_compaction_parallel = None
        self.purge_interval = None

        #alert settings
        self.email_recipient = None
        self.email_sender = None
        self.email_user = None
        self.email_password = <PASSWORD>
        self.email_host = None
        self.email_port = None
        self.email_enable_encrypt = None
        self.autofailover_node = None
        self.autofailover_max_reached = None
        self.autofailover_node_down = None
        self.autofailover_cluster_small = None
        self.alert_ip_changed = None
        self.alert_disk_space = None
        self.alert_meta_overhead = None
        self.alert_meta_oom = None
        self.alert_write_failed = None

        #group management
        self.group_name = None
        self.server_list = []
        self.from_group = None
        self.to_group = None
        self.group_rename = None

        #SSL certificate management
        self.certificate_file = None
        self.cmd = None

        self.hard_failover = None
        self.recovery_type = None
        self.recovery_buckets = None

        # Collect logs
        self.nodes = None
        self.all_nodes = None
        self.upload = False
        self.upload_host = None
        self.customer = None
        self.ticket = ""

    def runCmd(self, cmd, server, port,
               user, password, opts):
        self.rest_cmd = rest_cmds[cmd]
        self.method = methods[cmd]
        self.server = server
        self.port = int(port)
        self.user = user
        self.password = password
        servers = self.processOpts(cmd, opts)
        if self.debug:
            print "INFO: servers %s" % servers

        if cmd == 'server-add' and not servers['add']:
            usage("please list one or more --server-add=HOST[:PORT];"
                  " or use -h for more help.")

        if cmd == 'server-readd' and not servers['add']:
{'fraction_non_alphanumeric': 0.1144546877717864, 'fraction_numerical': 0.0004348582362149939, 'mean_word_length': 2.1773970710140924, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '3028404', 'n_tokens_mistral': 3542, 'n_tokens_neox': 3408, 'n_words': 737}