<commit_before>from fabric.api import *
from fabric.context_managers import env
from distutils.version import LooseVersion

from fabfile.config import *
from fabfile.tasks.install import pkg_install
from fabfile.tasks.upgrade import upgrade_compute_node
from fabfile.utils.host import get_env_passwords, hstr_to_ip,\
              get_control_host_string, get_bgp_md5
from fabfile.utils.multitenancy import get_mt_opts
from fabfile.tasks.provision import prov_analytics_node
from fabfile.tasks.provision import prov_config_node
from fabfile.tasks.provision import prov_database_node
from fabfile.tasks.provision import prov_control_bgp_node
from fabfile.utils.install import get_vrouter_kmod_pkg
from fabfile.utils.host import *
from fabfile.utils.fabos import *
from fabric.contrib.files import exists

issu_process_bash_file="issu_process.sh" 
issu_process_bash_path="/opt/contrail/utils/issu_process.sh"

@task
@roles('compute')
def issu_contrail_switch_collector_in_compute():
    """Migrate the contrail compute nodes to new collector."""
    execute("issu_contrail_switch_collector_in_compute_node", env.host_string)

@task
def issu_contrail_switch_collector_in_compute_node(*args):
    for host in args:
        collector_list = ''
        with settings(host_string=host):
            for i in range(0, len(env.roledefs['collector'])):
                collector_list += "%s:8086 " %(hstr_to_ip(get_control_host_string(env.roledefs['collector'][i])))
            with settings(warn_only=True):
                file_list = sudo('ls /etc/contrail/contrail-tor-agent*')
            if file_list.succeeded:
                file_list = file_list.split()
            else:
                file_list = []
            file_list.append('/etc/contrail/contrail-vrouter-agent.conf')
            for cfile in file_list:
                run('openstack-config --set %s DEFAULT collectors "%s"' % (cfile, collector_list))
            run('openstack-config --set /etc/contrail/contrail-vrouter-nodemgr.conf COLLECTOR server_list "%s"' % (collector_list))

@task
@roles('compute')
def issu_contrail_switch_compute(discovery_ip):
    """Migrate the contrail compute nodes to new discovery."""
    execute("issu_contrail_switch_compute_node", discovery_ip, env.host_string)

@task
def issu_contrail_switch_compute_node(discovery_ip, *args):
    """Usage: fab issu_contrail_switch_compute_node:<new_discovery_ip>,root@1.1.1.4..."""
    for host in args:
        with settings(host_string=host):
            put('%s' %(issu_process_bash_path), '/tmp/%s' %(issu_process_bash_file), use_sudo=True)
            sudo("chmod 777 /tmp/%s" %(issu_process_bash_file))
            sudo("source /tmp/%s;issu_contrail_switch_compute_node %s" %(issu_process_bash_file, discovery_ip))
@task
@roles('compute')
def issu_contrail_prepare_compute():
    """Prepare compute nodes for upgrade"""
    execute("issu_contrail_prepare_compute_node", env.host_string)

@task
def issu_contrail_prepare_compute_node(*args):<commit_msg>Adding a fab task to revert the collectors addition change to vrouter conf files<commit_after>from fabric.api import *
from fabric.context_managers import env
from distutils.version import LooseVersion

from fabfile.config import *
from fabfile.tasks.install import pkg_install
from fabfile.tasks.upgrade import upgrade_compute_node
from fabfile.utils.host import get_env_passwords, hstr_to_ip,\
              get_control_host_string, get_bgp_md5
from fabfile.utils.multitenancy import get_mt_opts
from fabfile.tasks.provision import prov_analytics_node
from fabfile.tasks.provision import prov_config_node
from fabfile.tasks.provision import prov_database_node
from fabfile.tasks.provision import prov_control_bgp_node
from fabfile.utils.install import get_vrouter_kmod_pkg
from fabfile.utils.host import *
from fabfile.utils.fabos import *
from fabric.contrib.files import exists

issu_process_bash_file="issu_process.sh" 
issu_process_bash_path="/opt/contrail/utils/issu_process.sh"

@task
@roles('compute')
def issu_contrail_switch_collector_in_compute():
    """Migrate the contrail compute nodes to new collector."""
    execute("issu_contrail_switch_collector_in_compute_node", env.host_string)

@task
def issu_contrail_switch_collector_in_compute_node(*args):
    for host in args:
        collector_list = ''
        with settings(host_string=host):
            for i in range(0, len(env.roledefs['collector'])):
                collector_list += "%s:8086 " %(hstr_to_ip(get_control_host_string(env.roledefs['collector'][i])))
            with settings(warn_only=True):
                file_list = sudo('ls /etc/contrail/contrail-tor-agent*')
            if file_list.succeeded:
                file_list = file_list.split()
            else:
                file_list = []
            file_list.append('/etc/contrail/contrail-vrouter-agent.conf')
            for cfile in file_list:
                run('openstack-config --set %s DEFAULT collectors "%s"' % (cfile, collector_list))
            run('openstack-config --set /etc/contrail/contrail-vrouter-nodemgr.conf COLLECTOR server_list "%s"' % (collector_list))


@task
@roles('compute')
def issu_contrail_switch_collector_in_compute_revert():
    """Revert the Migrate of the contrail compute nodes to new collector."""
    execute("issu_contrail_switch_collector_in_compute_node_revert", env.host_string)

@task
def issu_contrail_switch_collector_in_compute_node_revert(*args):
    for host in args:
        with settings(host_string=host, warn_only=True):
            file_list = sudo('ls /etc/contrail/contrail-tor-agent*')
            if file_list.succeeded:
                file_list = file_list.split()
            else:
                file_list = []
            file_list.append('/etc/contrail/contrail-vrouter-agent.conf')
            for cfile in file_list:
                run('openstack-config --del %s DEFAULT collectors' % (cfile))
            run('openstack-config --del /etc/contrail/contrail-vrouter-nodemgr.conf COLLECTOR server_list')

@task
@roles('compute')
def issu_contrail_switch_compute(discovery_ip):
    """Migrate the contrail compute nodes to new discovery."""
    execute("issu_contrail_switch_compute_node", discovery_ip, env.host_string)

@task
def issu_contrail_switch_compute_node(discovery_ip, *args):
    """Usage: fab issu_contrail_switch_compute_node:<new_discovery_ip>,root@1.1.1.4..."""
    for host in args:
        with settings(host_string=host):
            put('%s' %(issu_process_bash_path), '/tmp/%s' %(issu_process_bash_file), use_sudo=True)
            sudo("chmod 777 /tmp/%s" %(issu_process_bash_file))
            sudo("source /tmp/%s;issu_contrail_switch_compute_node %s" %(issu_process_bash_file, discovery_ip))
@task
@roles('compute')
def issu_contrail_prepare_compute():
    """Prepare compute nodes for upgrade"""
    execute("issu_contrail_prepare_compute_node", env.host_string)

@task
def issu_contrail_prepare_compute_node(*args):
{'fraction_non_alphanumeric': 0.10175590097869891, 'fraction_numerical': 0.003742084052964882, 'mean_word_length': 4.109558823529412, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3490620', 'n_tokens_mistral': 2283, 'n_tokens_neox': 2203, 'n_words': 432}