コード例 #1
0
def cleanup_repo_node(*args):
    '''Remove existing repos in given node'''
    for host_string in args:
        with settings(host_string=host_string):
            os_type = detect_ostype().lower()
            with hide('everything'):
                ts = sudo("date '+%s'")
            if os_type == 'ubuntu':
                org_repo_file = '/etc/apt/sources.list'
                bck_repo_file = '/etc/apt/sources.list.%s.contrail' % ts
                print 'Backup Original sources.list (%s) as (%s)' % (
                    org_repo_file, bck_repo_file)
                sudo('mv %s %s' % (org_repo_file, bck_repo_file))
                print 'Create an empty sources.list'
                sudo('touch /etc/apt/sources.list')
                sudo('echo >> /etc/apt/sources.list')
                sudo('chmod 644 /etc/apt/sources.list')
                sudo('apt-get update')
            elif os_type in ['centos', 'redhat', 'centoslinux']:
                with cd('/etc/yum.repos.d/'):
                    with settings(warn_only=True):
                        with hide('everything'):
                            repo_files = run('ls -1 *.repo').split('\r\n')
                        print 'Backup Original repo files with timestamp'
                        for repo_file in repo_files:
                            sudo('mv %s %s.%s.contrail' % (repo_file,
                                 repo_file, ts))
                        sudo('yum clean all')
コード例 #2
0
def restore_repo_node(*args, **kwargs):
    '''Remove existing repos in given node'''
    merge = kwargs.get('merge', True)
    pattern = re.compile(r'\.[\d]+\.contrail$')
    for host_string in args:
        with settings(host_string=host_string, warn_only=True):
            os_type = detect_ostype().lower()
            if os_type == 'ubuntu':
                dirname = '/etc/apt'
                update_cmd = 'apt-get update'
            else:
                dirname = '/etc/yum.repos.d/'
                update_cmd = 'yum clean all'

            with cd(dirname):
                repo_files = sudo("find . -maxdepth 1 -regextype sed \
                                          -regex '.*/*[0-9]*\.contrail'")
                repo_files = repo_files.split('\r\n')
                restore_map = [(repo_file, pattern.sub('', repo_file)) \
                                  for repo_file in repo_files]
                for original, restore_file in restore_map:
                    sudo('cp %s %s.oldbckup' % (original, original))
                    if merge == True:
                        sudo('cat %s >> %s' % (original, restore_file))
                    else:
                        sudo('mv %s %s' % (original, restore_file))
                    sudo('chmod 644 %s' % restore_file)
                sudo(update_cmd)
コード例 #3
0
def cleanup_repo_node(*args):
    '''Remove existing repos in given node'''
    for host_string in args:
        with settings(host_string=host_string):
            os_type = detect_ostype().lower()
            with hide('everything'):
                ts = sudo("date '+%s'")
            if os_type == 'ubuntu':
                org_repo_file = '/etc/apt/sources.list'
                bck_repo_file = '/etc/apt/sources.list.%s.contrail' % ts
                print 'Backup Original sources.list (%s) as (%s)' % (
                    org_repo_file, bck_repo_file)
                sudo('mv %s %s' % (org_repo_file, bck_repo_file))
                print 'Create an empty sources.list'
                sudo('touch /etc/apt/sources.list')
                sudo('echo >> /etc/apt/sources.list')
                sudo('chmod 644 /etc/apt/sources.list')
                sudo('apt-get update')
            elif os_type in ['centos', 'redhat']:
                with cd('/etc/yum.repos.d/'):
                    with settings(warn_only=True):
                        with hide('everything'):
                            repo_files = run('ls -1 *.repo').split('\r\n')
                        print 'Backup Original repo files with timestamp'
                        for repo_file in repo_files:
                            sudo('mv %s %s.%s.contrail' % (repo_file,
                                 repo_file, ts))
                        sudo('yum clean all')
コード例 #4
0
def detach_vrouter_node(*args):
    """Detaches one/more compute node from the existing cluster."""
    cfgm_host = get_control_host_string(env.roledefs['cfgm'][0])
    cfgm_host_password = get_env_passwords(env.roledefs['cfgm'][0])
    cfgm_ip = hstr_to_ip(cfgm_host)
    nova_compute = "openstack-nova-compute"

    for host_string in args:
        with settings(host_string=host_string, warn_only=True):
            sudo("service supervisor-vrouter stop")
            if detect_ostype() in ['ubuntu']:
                nova_compute = "nova-compute"
            mode = get_mode(host_string)
            if (mode == 'vcenter'):
                nova_compute = ""
            if (nova_compute != ""):
                sudo("service %s stop" % nova_compute)
            compute_hostname = sudo("hostname")
        with settings(host_string=env.roledefs['cfgm'][0],
                      pasword=cfgm_host_password):
            sudo(
                "python /opt/contrail/utils/provision_vrouter.py --host_name %s --host_ip %s --api_server_ip %s --oper del %s"
                % (compute_hostname, host_string.split('@')[1], cfgm_ip,
                   get_mt_opts()))
    execute("restart_control")
コード例 #5
0
def stop_zookeeper():
    stop_cmd = "/usr/lib/zookeeper/bin/zkServer.sh stop"
    if detect_ostype() in ['ubuntu']:
        stop_cmd = "/usr/share/zookeeper/bin/zkServer.sh stop"
    with settings(warn_only=True):
        if sudo("service zookeeper stop").failed:
            sudo(stop_cmd)
コード例 #6
0
def restart_zookeeper():
    restart_cmd = "/usr/lib/zookeeper/bin/zkServer.sh restart"
    if detect_ostype() in ['ubuntu']:
        restart_cmd = "/usr/share/zookeeper/bin/zkServer.sh restart"
    with settings(warn_only=True):
        if sudo("service zookeeper restart").failed:
            sudo(restart_cmd)
コード例 #7
0
def restart_zookeeper():
    restart_cmd = "/usr/lib/zookeeper/bin/zkServer.sh restart"
    if detect_ostype() in ['ubuntu']:
        restart_cmd = "/usr/share/zookeeper/bin/zkServer.sh restart"
    with settings(warn_only=True):
        if sudo("service zookeeper restart").failed:
            sudo(restart_cmd)
コード例 #8
0
def stop_zookeeper():
    stop_cmd = "/usr/lib/zookeeper/bin/zkServer.sh stop"
    if detect_ostype() in ['ubuntu']:
        stop_cmd = "/usr/share/zookeeper/bin/zkServer.sh stop"
    with settings(warn_only=True):
        if sudo("service zookeeper stop").failed:
            sudo(stop_cmd)
コード例 #9
0
def config_rabbitmq():
    rabbit_hosts = []
    rabbit_conf = '/etc/rabbitmq/rabbitmq.config'
    if len(env.roledefs['rabbit']) <= 1 and detect_ostype() == 'redhat':
        print "CONFIG_RABBITMQ: Skip creating rabbitmq.config for Single node setup"
        return
    for host_string in env.roledefs['rabbit']:
        with settings(host_string=host_string,
                      password=env.passwords[host_string]):
            host_name = sudo('hostname -s') + ctrl
        rabbit_hosts.append("\'rabbit@%s\'" % host_name)
    rabbit_hosts = ', '.join(rabbit_hosts)
    rabbitmq_config_template = rabbitmq_config
    if len(env.roledefs['rabbit']) == 1:
        rabbitmq_config_template = rabbitmq_config_single_node
    rabbitmq_configs = rabbitmq_config_template.template.safe_substitute({
        '__control_intf_ip__':
        hstr_to_ip(get_control_host_string(env.host_string)),
        '__rabbit_hosts__':
        rabbit_hosts,
    })
    tmp_fname = "/tmp/rabbitmq_%s.config" % env.host_string
    cfg_file = open(tmp_fname, 'w')
    cfg_file.write(rabbitmq_configs)
    cfg_file.close()
    put(tmp_fname, "/etc/rabbitmq/rabbitmq.config", use_sudo=True)
    local("rm %s" % (tmp_fname))
コード例 #10
0
def restore_repo_node(*args, **kwargs):
    '''Remove existing repos in given node'''
    merge = kwargs.get('merge', True)
    pattern = re.compile(r'\.[\d]+\.contrail$')
    for host_string in args:
        with settings(host_string=host_string, warn_only=True):
            os_type = detect_ostype().lower()
            if os_type == 'ubuntu':
                dirname = '/etc/apt'
                update_cmd = 'apt-get update'
            else:
                dirname = '/etc/yum.repos.d/'
                update_cmd = 'yum clean all'

            with cd(dirname):
                repo_files = sudo("find . -maxdepth 1 -regextype sed \
                                          -regex '.*/*[0-9]*\.contrail'")
                repo_files = repo_files.split('\r\n')
                restore_map = [(repo_file, pattern.sub('', repo_file)) \
                                  for repo_file in repo_files]
                for original, restore_file in restore_map:
                    sudo('cp %s %s.oldbckup' % (original, original))
                    if merge == True:
                        sudo('cat %s >> %s' % (original, restore_file)) 
                    else:
                        sudo('mv %s %s' % (original, restore_file))
                    sudo('chmod 644 %s' % restore_file)
                sudo(update_cmd)
コード例 #11
0
def restart_openstack_compute():
    """Restarts the contrail openstack compute service."""
    if 'tsn' in env.roledefs.keys() and env.host_string in env.roledefs['tsn']:
        return
    if detect_ostype() in ['ubuntu']:
        sudo('service nova-compute restart')
        return
    sudo('service openstack-nova-compute restart')
コード例 #12
0
def install_pkg(pkgs):
    ostype = detect_ostype()
    for pkg in pkgs:
        with settings(warn_only = True):
            if ostype in [ 'fedora','centos' ]:
                run("yum -y install %s" % (pkg))
            elif ostype in ['ubuntu']:
                run("DEBIAN_FRONTEND=noninteractive apt-get -y --force-yes install %s" %(pkg))
コード例 #13
0
def install_pkg(pkgs):
    ostype = detect_ostype()
    for pkg in pkgs:
        with settings(warn_only=True):
            if ostype in ["fedora", "centos", "redhat", "centoslinux"]:
                sudo("yum -y install %s" % (pkg))
            elif ostype in ["ubuntu"]:
                sudo("DEBIAN_FRONTEND=noninteractive apt-get -y --force-yes install %s" % (pkg))
コード例 #14
0
def verify_openstack():
    if detect_ostype() in ['ubuntu']:
        verify_service("keystone")
    else:
        verify_service("openstack-keystone")
    output = run("source /etc/contrail/openstackrc; keystone tenant-list")
    if 'error' in output:
        raise OpenStackSetupError(output)
コード例 #15
0
def verify_openstack():
    if detect_ostype() in ['Ubuntu']:
        verify_service("keystone")
    else:
        verify_service("openstack-keystone")
    output = run("source /etc/contrail/openstackrc; keystone tenant-list")
    if 'error' in output:
        raise OpenStackSetupError(output)
コード例 #16
0
def is_ceilometer_provision_supported(use_install_repo=False):
    supported = is_ceilometer_supported(use_install_repo)
    if not supported:
        return False
    # Not supported on redhat
    os_type = detect_ostype()
    if os_type == 'redhat':
        return False
    return supported
コード例 #17
0
ファイル: ha.py プロジェクト: sajuptpm/contrail-fabric-utils
def fix_wsrep_cluster_address():
    openstack_host_list = [get_control_host_string(openstack_host) for openstack_host in env.roledefs['openstack']]
    galera_ip_list = [hstr_to_ip(galera_host) for galera_host in openstack_host_list]
    with settings(host_string=env.roledefs['openstack'][0], password=env.passwords[env.roledefs['openstack'][0]]):
        wsrep_conf = '/etc/mysql/my.cnf'
        if detect_ostype() in ['Ubuntu']:
            wsrep_conf = '/etc/mysql/conf.d/wsrep.cnf'
        run('sed -ibak "s#wsrep_cluster_address=.*#wsrep_cluster_address=gcomm://%s:4567#g" %s' %
              (':4567,'.join(galera_ip_list), wsrep_conf))
コード例 #18
0
def is_ceilometer_compute_provision_supported():
    supported = is_ceilometer_supported()
    if not supported:
        return False
    # Not supported on redhat
    os_type = detect_ostype()
    if os_type == 'redhat':
        return False
    return supported
コード例 #19
0
def is_ceilometer_compute_provision_supported():
    supported = is_ceilometer_supported()
    if not supported:
        return False
    # Not supported on redhat
    os_type = detect_ostype()
    if os_type == 'redhat':
        return False
    return supported
コード例 #20
0
def is_ceilometer_provision_supported(use_install_repo=False):
    supported = is_ceilometer_supported(use_install_repo)
    if not supported:
        return False
    # Not supported on redhat
    os_type = detect_ostype()
    if os_type == 'redhat':
        return False
    return supported
コード例 #21
0
ファイル: ha.py プロジェクト: hkumarmk/contrail-fabric-utils
def fix_wsrep_cluster_address():
    openstack_host_list = [get_control_host_string(openstack_host) for openstack_host in env.roledefs['openstack']]
    galera_ip_list = [hstr_to_ip(galera_host) for galera_host in openstack_host_list]
    with settings(host_string=env.roledefs['openstack'][0], password=get_env_passwords(env.roledefs['openstack'][0])):
        wsrep_conf = '/etc/mysql/my.cnf'
        if detect_ostype() in ['ubuntu']:
            wsrep_conf = '/etc/mysql/conf.d/wsrep.cnf'
        sudo('sed -ibak "s#wsrep_cluster_address=.*#wsrep_cluster_address=gcomm://%s:4567#g" %s' %
              (':4567,'.join(galera_ip_list), wsrep_conf))
コード例 #22
0
def restart_openstack_node(*args):
    """Restarts the contrail openstack services in once openstack node. USAGE:fab restart_openstack_node:[email protected],[email protected]"""
    openstack_services = ['httpd', 'memcached', 'supervisor-openstack']
    if detect_ostype() in ['ubuntu']:
        openstack_services = ['memcached', 'supervisor-openstack']

    for host_string in args:
        with settings(host_string=host_string):
            for svc in openstack_services:
                sudo('service %s restart' % svc)
コード例 #23
0
def start_glance():
    """Start keystone  services :fab start_keystone"""
    host = env.host_string
    openstack_services = ['glance-api','glance-registry']
    if detect_ostype() in ['Ubuntu']:
        openstack_services = ['glance-api','glance-registry']

    with settings(host_string=host):
        for svc in openstack_services:
            run('service %s start' % svc)
コード例 #24
0
def stop_keystone():
    """Stop keystone  services :fab stop_keystone"""
    host = env.host_string
    openstack_services = ['keystone']
    if detect_ostype() in ['Ubuntu']:
        openstack_services = ['keystone']

    with settings(host_string=host):
        for svc in openstack_services:
            run('service %s stop' % svc)
コード例 #25
0
def restart_openstack_node(*args):
    """Restarts the contrail openstack services in once openstack node. USAGE:fab restart_openstack_node:[email protected],[email protected]"""
    openstack_services = [ 'httpd', 'memcached', 'supervisor-openstack']
    if detect_ostype() in ['ubuntu']:
        openstack_services = ['memcached', 'supervisor-openstack']

    for host_string in args:
        with  settings(host_string=host_string):
            for svc in openstack_services:
                sudo('service %s restart' % svc)
コード例 #26
0
def install_pkg(pkgs):
    ostype = detect_ostype()
    for pkg in pkgs:
        with settings(warn_only=True):
            if ostype in ['fedora', 'centos', 'redhat', 'centoslinux']:
                sudo("yum -y install %s" % (pkg))
            elif ostype in ['ubuntu']:
                sudo(
                    "DEBIAN_FRONTEND=noninteractive apt-get -y --force-yes install %s"
                    % (pkg))
コード例 #27
0
def restart_openstack_compute():
    """Restarts the contrail openstack compute service."""
    if 'tsn' in env.roledefs.keys() and env.host_string in env.roledefs['tsn']:
        return
    if get_orchestrator() == 'vcenter':
        return
    if detect_ostype() in ['ubuntu']:
        sudo('service nova-compute restart')
        return
    sudo('service openstack-nova-compute restart')
コード例 #28
0
def restart_cfgm_node(*args):
    """Restarts the contrail config services in once cfgm node. USAGE:fab restart_cfgm_node:[email protected],[email protected]"""
    for host_string in args:
        with  settings(host_string=host_string):
            run('supervisorctl -s http://localhost:9004 restart contrail-config-nodemgr')
            if detect_ostype() not in ['Ubuntu']:
                run('service ifmap restart')
            run('supervisorctl -s http://localhost:9004 restart contrail-api:0')
            run('supervisorctl -s http://localhost:9004 restart contrail-discovery:0')
            run('service contrail-schema restart')
            run('service contrail-svc-monitor restart')
コード例 #29
0
def start_nova():
    """Start nova services :fab stop_nova"""
    host = env.host_string
    openstack_services = ['nova-api', 'nova-scheduler',
                          'nova-conductor']
    if detect_ostype() in ['Ubuntu']:
        openstack_services = ['nova-api', 'nova-scheduler', 'nova-conductor']

    with settings(host_string=host):
        for svc in openstack_services:
            run('service %s start' % svc)
コード例 #30
0
def install_pkg(pkgs, container=None):
    ostype = detect_ostype(container=container)
    for pkg in pkgs:
        with settings(warn_only = True):
            if ostype in ['fedora', 'centos', 'redhat', 'centoslinux']:
                cmd = "yum -y install %s" % (pkg)
            elif ostype in ['ubuntu']:
                cmd = "DEBIAN_FRONTEND=noninteractive apt-get -y --force-yes install %s" %(pkg)
            if container:
                run_in_container(container, cmd)
            else:
                sudo(cmd)
コード例 #31
0
def upgrade_compute_node(from_rel, pkg, *args, **kwargs):
    """Upgrades compute pkgs in one or list of nodes. USAGE:fab upgrade_compute_node:[email protected],[email protected]"""
    for host_string in args:
        with settings(host_string=host_string):
            execute('install_pkg_node', pkg, host_string)
            execute('create_install_repo_node', host_string)
            pkg_install(['contrail-setup'])
            configure_nova = kwargs.get('configure_nova', 'yes')
            manage_nova_compute = kwargs.get('manage_nova_compute', 'yes')

            if (env.host_string in get_tsn_nodes() or
                get_orchestrator() == 'vcenter'):
                manage_nova_compute='no'

            # Identify packages to upgrade
            cmd = frame_vnc_compute_cmd(
                      host_string, 'upgrade-vnc-compute',
                      configure_nova=configure_nova,
                      manage_nova_compute=manage_nova_compute)
            if ('vcenter_compute' in env.roledefs and 
                    env.host_string in env.roledefs['vcenter_compute']):
                pkgs = get_vcenter_compute_pkgs() 
                roles = ['vcenter_compute']
            else:
                pkgs = get_compute_pkgs(manage_nova_compute=manage_nova_compute)
                if (getattr(env, 'interface_rename', True) and
                    detect_ostype() not in ['ubuntu', 'redhat']):
                    pkgs.append('contrail-interface-name')
                if LooseVersion(from_rel) <= LooseVersion('3.2.0.0'):
                    dist, version, extra = get_linux_distro()
                    if version == '14.04':
                       if 'contrail-vrouter-3.13.0-40-generic' in pkgs:
                          pkgs.remove('contrail-vrouter-3.13.0-40-generic')
                       if 'contrail-vrouter-3.13.0-85-generic' in pkgs:
                          pkgs.remove('contrail-vrouter-3.13.0-85-generic')
                       if 'contrail-vrouter-3.13.0-100-generic' in pkgs:
                          pkgs.remove('contrail-vrouter-3.13.0-100-generic')
                       if 'contrail-vrouter-3.13.0-106-generic' in pkgs:
                          pkgs.remove('contrail-vrouter-3.13.0-106-generic')
                       pkgs.append('contrail-vrouter-3.13.0-106-generic')
                # Identify roles of this node.
                roles = ['compute']
                if env.host_string in get_tsn_nodes():
                   roles.append('tsn')
                if env.host_string in get_toragent_nodes():
                   roles.append('toragent')

            cmd += ' -P %s' % ' '.join(pkgs)
            cmd += ' -F %s' % from_rel
            cmd += ' -T %s' % get_release()
            cmd += ' -R %s' % ' '.join(roles)
            sudo(cmd)
コード例 #32
0
ファイル: misc.py プロジェクト: Juniper/contrail-fabric-utils
def replace_vrouter_ko():
    """Replaces the vrouter kernal module with upgraded version."""
    os_type = detect_ostype()
    if os_type in ['ubuntu']:
        cmd = "ls /opt/contrail/contrail_install_repo/contrail-vrouter-$(uname -r)*"
        out = sudo(cmd, warn_only=True)
        #No change in Kernel version so no need to reboot the box.
        if out.succeeded:
            execute('replace_vrouter_ko_node', env.host_string)
        else:
            execute("reboot_node", 'yes', env.host_string)
    else:
        execute("reboot_node", 'yes', env.host_string)
コード例 #33
0
def restart_database_node(*args):
    """Restarts the contrail database services in once database node. USAGE:fab restart_database_node:[email protected],[email protected]"""
    for host_string in args:
        with settings(host_string=host_string):
            execute('zoolink_node', host_string)
            zoo_svc = 'contrail-zookeeper'
            if detect_ostype() in ['Ubuntu']:
                zoo_svc = 'zookeeper'
            run('service %s restart' % zoo_svc)

    for host_string in args:
        with settings(host_string=host_string):
            run('service supervisord-contrail-database restart')
コード例 #34
0
def replace_vrouter_ko():
    """Replaces the vrouter kernal module with upgraded version."""
    os_type = detect_ostype()
    if os_type in ['ubuntu']:
        cmd = "ls /opt/contrail/contrail_install_repo/contrail-vrouter-$(uname -r)*"
        out = sudo(cmd, warn_only=True)
        #No change in Kernel version so no need to reboot the box.
        if out.succeeded:
            execute('replace_vrouter_ko_node', env.host_string)
        else:
            execute("reboot_node", 'yes', env.host_string)
    else:
        execute("reboot_node", 'yes', env.host_string)
コード例 #35
0
def restart_database_node(*args):
    """Restarts the contrail database services in once database node. USAGE:fab restart_database_node:[email protected],[email protected]"""
    for host_string in args:
        with  settings(host_string=host_string):
            execute('zoolink_node', host_string)
            zoo_svc = 'contrail-zookeeper'
            if detect_ostype() in ['Ubuntu']:
                zoo_svc = 'zookeeper'
            run('service %s restart' % zoo_svc)

    for host_string in args:
        with  settings(host_string=host_string):
            run('service supervisord-contrail-database restart')
コード例 #36
0
def is_ceilometer_compute_provision_supported():
    supported = is_ceilometer_supported()
    if not supported:
        return False
    # Orchestrator should be openstack
    orchestrator = get_orchestrator()
    if orchestrator != 'openstack':
        return False
    # Not supported on redhat
    os_type = detect_ostype()
    if os_type == 'redhat':
        return False
    return supported
コード例 #37
0
def install_test_repo_node(*args):
    '''Installs test repo in given node'''
    for host_string in args:
        with settings(host_string=host_string):
            os_type = detect_ostype().lower()
            if os_type in ['ubuntu']:
                print 'No test-repo availabe'
            if os_type in ['centos']:
                print 'No test-repo availabe'
            if os_type in ['redhat']:
                put('fabfile/contraillabs/repo/el7_test.repo',
                    '/etc/yum.repos.d/contrail_test.repo')
                run('yum clean all')
コード例 #38
0
def is_ceilometer_compute_provision_supported():
    supported = is_ceilometer_supported()
    if not supported:
        return False
    # Orchestrator should be openstack
    orchestrator = get_orchestrator()
    if orchestrator != 'openstack':
        return False
    # Not supported on redhat
    os_type = detect_ostype()
    if os_type == 'redhat':
        return False
    return supported
コード例 #39
0
def install_test_repo_node(*args):
    '''Installs test repo in given node'''
    for host_string in args:
        with settings(host_string=host_string):
            os_type = detect_ostype().lower()
            if os_type in ['ubuntu']:
                print 'No test-repo availabe'
            if os_type in ['centos']:
                print 'No test-repo availabe'
            if os_type in ['redhat']:
                put('fabfile/contraillabs/repo/el7_test.repo',
                    '/etc/yum.repos.d/contrail_test.repo')
                run('yum clean all')
コード例 #40
0
def start_nova_openstack_compute():
    """Start the contrail openstack compute service."""
    tsn_nodes = []
    tor_nodes = []
    host = env.host_string
    if 'tsn' in env.roledefs:
        tsn_nodes = env.roledefs['tsn']
    if 'toragent' in env.roledefs:
        tor_nodes = env.roledefs['toragent']
    if host not in (tsn_nodes and tor_nodes):
        if detect_ostype() in ['ubuntu']:
            sudo('service nova-compute start')
            return
        sudo('service openstack-nova-compute start')
コード例 #41
0
def start_nova_openstack_compute():
    """Start the contrail openstack compute service."""
    tsn_nodes = []
    tor_nodes = []
    host = env.host_string
    if 'tsn' in env.roledefs:
        tsn_nodes = env.roledefs['tsn']
    if 'toragent' in env.roledefs:
        tor_nodes = env.roledefs['toragent']
    if host not in (tsn_nodes and tor_nodes) :
        if detect_ostype() in ['ubuntu']:
            sudo('service nova-compute start')
            return
        sudo('service openstack-nova-compute start')
コード例 #42
0
def verify_cluster_status(retry='yes'):

    # Retry a few times, as rabbit-mq can fail intermittently when trying to
    # connect to AMQP server. Total wait time here is atmost a minute.
    rabbitmq_up = False
    for i in range(0, 6):
        with settings(warn_only=(retry == 'yes')):
            status = sudo("service rabbitmq-server status")
        if 'running' in status.lower():
            rabbitmq_up = True
            break
        elif retry == 'no':
            return False
        time.sleep(10)
    if not rabbitmq_up:
        return False

    rabbitmq_up = False
    for i in range(0, 6):
        with settings(warn_only=(retry == 'yes')):
            output = sudo("rabbitmqctl cluster_status")
        running_nodes = re.compile(r"running_nodes,\[([^\]]*)")
        match = running_nodes.search(output)
        if match:
            rabbitmq_up = True
            break
        elif retry == 'no':
            return False
        time.sleep(10)
    if not rabbitmq_up:
        return False

    clustered_nodes = match.group(1).split(',')
    clustered_nodes = [node.strip(' \n\r\'') for node in clustered_nodes]

    rabbit_nodes = []
    for host_string in env.roledefs['rabbit']:
        with settings(host_string=host_string):
            if len(env.roledefs['rabbit']) <= 1 and detect_ostype(
            ) == 'redhat':
                print "Skip verifying /etc/rabbitmq/rabbitmq.config for Single node setup"
            elif not files.exists("/etc/rabbitmq/rabbitmq.config"):
                return False
            host_name = sudo('hostname -s') + ctrl
            rabbit_nodes.append('rabbit@%s' % host_name)
    for rabbit_node in rabbit_nodes:
        if rabbit_node not in clustered_nodes:
            print "RabbitMQ cluster doesnt list %s in running_nodes" % env.host_string
            return False
    return True
コード例 #43
0
def is_ceilometer_supported(use_install_repo=False):
    # Ceilometer should be enabled
    enable_ceilometer = get_enable_ceilometer()
    if not enable_ceilometer:
        return False
    # Orchestrator should be openstack
    orchestrator = get_orchestrator()
    if orchestrator != 'openstack':
        return False
    os_type = detect_ostype()
    if os_type in ['redhat', 'ubuntu']:
        return True
    else:
        return False
コード例 #44
0
def is_ceilometer_supported(use_install_repo=False):
    # Ceilometer should be enabled
    enable_ceilometer = get_enable_ceilometer()
    if not enable_ceilometer:
        return False
    # Orchestrator should be openstack
    orchestrator = get_orchestrator()
    if orchestrator != 'openstack':
        return False
    os_type = detect_ostype()
    if os_type in ['redhat', 'ubuntu']:
        return True
    else:
        return False
コード例 #45
0
def verify_cluster_status(retry='yes'):

    # Retry a few times, as rabbit-mq can fail intermittently when trying to
    # connect to AMQP server. Total wait time here is atmost a minute.
    rabbitmq_up = False
    for i in range(0, 6):
        with settings(warn_only=True):
            status = sudo("service rabbitmq-server status")
        if 'running' in status.lower():
            rabbitmq_up = True
            break
        elif retry == 'no':
            return False
        time.sleep(10)
    if not rabbitmq_up:
        return False

    rabbitmq_up = False
    for i in range(0, 6):
        with settings(warn_only=True):
            output = sudo("rabbitmqctl cluster_status")
        running_nodes = re.compile(r"running_nodes,\[([^\]]*)")
        match = running_nodes.search(output)
        if match:
            rabbitmq_up = True
            break
        elif retry == 'no':
            return False
        time.sleep(10)
    if not rabbitmq_up:
        return False

    clustered_nodes = match.group(1).split(',')
    clustered_nodes = [node.strip(' \n\r\'') for node in clustered_nodes]

    rabbit_nodes = []
    for host_string in env.roledefs['rabbit']:
        with settings(host_string=host_string):
            if len(env.roledefs['rabbit']) <= 1 and detect_ostype() == 'redhat':
                print "Skip verifying /etc/rabbitmq/rabbitmq.config for Single node setup"
            elif not files.exists("/etc/rabbitmq/rabbitmq.config"):
                return False
            host_name = sudo('hostname -s') + ctrl
            rabbit_nodes.append('rabbit@%s' % host_name)
    for rabbit_node in rabbit_nodes:
        if rabbit_node not in clustered_nodes:
            print "RabbitMQ cluster doesnt list %s in running_nodes" % env.host_string
            return False
    return True
コード例 #46
0
ファイル: ha.py プロジェクト: skiranh/contrail-fabric-utils
def setup_cmon_schema():
    """Task to configure cmon schema in the openstack nodes to monitor galera cluster"""
    if len(env.roledefs['openstack']) <= 1:
        print "Single Openstack cluster, skipping cmon schema  setup."
        return

    openstack_host_list = [get_control_host_string(openstack_host)\
                           for openstack_host in env.roledefs['openstack']]
    galera_ip_list = [hstr_to_ip(galera_host)\
                      for galera_host in openstack_host_list]
    internal_vip = get_openstack_internal_vip()

    mysql_token = sudo("cat /etc/contrail/mysql.token")
    pdist = detect_ostype()
    if pdist in ['ubuntu']:
        mysql_svc = 'mysql'
    elif pdist in ['centos', 'redhat']:
        mysql_svc = 'mysqld'
    # Create cmon schema
    sudo('mysql -u root -p%s -e "CREATE SCHEMA IF NOT EXISTS cmon"' %
         mysql_token)
    sudo('mysql -u root -p%s < /usr/local/cmon/share/cmon/cmon_db.sql' %
         mysql_token)
    sudo('mysql -u root -p%s < /usr/local/cmon/share/cmon/cmon_data.sql' %
         mysql_token)

    # insert static data
    sudo(
        'mysql -u root -p%s -e "use cmon; insert into cluster(type) VALUES (\'galera\')"'
        % mysql_token)

    host_list = galera_ip_list + ['localhost', '127.0.0.1', internal_vip]
    # Create cmon user
    for host in host_list:
        mysql_cmon_user_cmd = 'mysql -u root -p%s -e "CREATE USER \'cmon\'@\'%s\' IDENTIFIED BY \'cmon\'"' % (
            mysql_token, host)
        with settings(hide('everything'), warn_only=True):
            sudo(mysql_cmon_user_cmd)

    mysql_cmd = "mysql -uroot -p%s -e" % mysql_token
    # Grant privilages for cmon user.
    for host in host_list:
        sudo(
            '%s "GRANT ALL PRIVILEGES on *.* TO cmon@%s IDENTIFIED BY \'cmon\' WITH GRANT OPTION"'
            % (mysql_cmd, host))
    # Restarting mysql in all openstack nodes
    for host_string in env.roledefs['openstack']:
        with settings(host_string=host_string):
            sudo("service %s restart" % mysql_svc)
コード例 #47
0
def restart_openstack_node(*args):
    """Restarts the contrail openstack services in once openstack node. USAGE:fab restart_openstack_node:[email protected],[email protected]"""
    openstack_services = ['rabbitmq-server', 'httpd', 'memcached', 'openstack-nova-api',
                          'openstack-nova-scheduler', 'openstack-nova-cert',
                          'openstack-nova-consoleauth', 'openstack-nova-novncproxy',
                          'openstack-nova-conductor', 'openstack-nova-compute']
    if detect_ostype() in ['Ubuntu']:
        openstack_services = ['rabbitmq-server', 'memcached', 'nova-api',
                              'nova-scheduler', 'glance-api',
                              'glance-registry', 'keystone',
                              'nova-conductor', 'cinder-api', 'cinder-scheduler']

    for host_string in args:
        with  settings(host_string=host_string):
            for svc in openstack_services:
                run('service %s restart' % svc)
コード例 #48
0
def is_ceilometer_supported():
    # Ceilometer should be enabled
    enable_ceilometer = get_enable_ceilometer()
    if not enable_ceilometer:
        return False
    # Currently supported only on ubuntu icehouse
    os_type = detect_ostype()
    openstack_sku = get_openstack_sku()
    if os_type in ['redhat'] and \
            openstack_sku in ['icehouse']:
        return True
    elif os_type in ['ubuntu'] and \
            openstack_sku in ['icehouse', 'juno']:
        return True
    else:
        return False
コード例 #49
0
def is_ceilometer_supported():
    # Ceilometer should be enabled
    enable_ceilometer = get_enable_ceilometer()
    if not enable_ceilometer:
        return False
    # Currently supported only on ubuntu icehouse
    os_type = detect_ostype()
    openstack_sku = get_openstack_sku()
    if os_type in ['redhat'] and \
            openstack_sku in ['icehouse']:
        return True
    elif os_type in ['ubuntu'] and \
            openstack_sku in ['icehouse', 'juno']:
        return True
    else:
        return False
コード例 #50
0
def detach_vrouter_node(*args):
    """Detaches one/more compute node from the existing cluster."""
    cfgm_host = get_control_host_string(env.roledefs['cfgm'][0])
    cfgm_host_password = env.passwords[env.roledefs['cfgm'][0]]
    cfgm_ip = hstr_to_ip(cfgm_host)
    nova_compute = "openstack-nova-compute"
    if detect_ostype() in ['ubuntu']:
        nova_compute = "nova-compute"

    for host_string in args:
        compute_hostname = socket.gethostbyaddr(hstr_to_ip(host_string))[0].split('.')[0]
        with settings(host_string=host_string, warn_only=True):
            sudo("service supervisor-vrouter stop")
            sudo("service %s stop" % nova_compute)
        with settings(host_string=cfgm_host, pasword=cfgm_host_password):
            sudo("python /opt/contrail/utils/provision_vrouter.py --host_name %s --host_ip %s --api_server_ip %s --oper del" %
                (compute_hostname, host_string.split('@')[1], cfgm_ip))
    execute("restart_control")
コード例 #51
0
def upgrade_compute_node(from_rel, pkg, *args, **kwargs):
    """Upgrades compute pkgs in one or list of nodes. USAGE:fab upgrade_compute_node:[email protected],[email protected]"""
    for host_string in args:
        with settings(host_string=host_string):
            execute("install_pkg_node", pkg, host_string)
            execute("create_install_repo_node", host_string)
            pkg_install(["contrail-setup"])
            configure_nova = kwargs.get("configure_nova", "yes")
            manage_nova_compute = kwargs.get("manage_nova_compute", "yes")

            if env.host_string in get_tsn_nodes() or get_orchestrator() == "vcenter":
                manage_nova_compute = "no"

            # Identify packages to upgrade
            cmd = frame_vnc_compute_cmd(
                host_string,
                "upgrade-vnc-compute",
                configure_nova=configure_nova,
                manage_nova_compute=manage_nova_compute,
            )
            if "vcenter_compute" in env.roledefs and env.host_string in env.roledefs["vcenter_compute"]:
                pkgs = get_vcenter_compute_pkgs()
                roles = ["vcenter_compute"]
            else:
                pkgs = get_compute_pkgs(manage_nova_compute=manage_nova_compute)
                if getattr(env, "interface_rename", True) and detect_ostype() not in ["ubuntu", "redhat"]:
                    pkgs.append("contrail-interface-name")
                if LooseVersion(from_rel) <= LooseVersion("3.0.2.0"):
                    dist, version, extra = get_linux_distro()
                    if version == "14.04" and "contrail-vrouter-3.13.0-40-generic" in pkgs:
                        pkgs.remove("contrail-vrouter-3.13.0-40-generic")
                        pkgs.append("contrail-vrouter-3.13.0-85-generic")
                # Identify roles of this node.
                roles = ["compute"]
                if env.host_string in get_tsn_nodes():
                    roles.append("tsn")
                if env.host_string in get_toragent_nodes():
                    roles.append("toragent")

            cmd += " -P %s" % " ".join(pkgs)
            cmd += " -F %s" % from_rel
            cmd += " -T %s" % get_release()
            cmd += " -R %s" % " ".join(roles)
            sudo(cmd)
コード例 #52
0
def setup_cmon_schema():
    """Task to configure cmon schema in the openstack nodes to monitor galera cluster"""
    if len(env.roledefs['openstack']) <= 1:
        print "Single Openstack cluster, skipping cmon schema  setup."
        return

    openstack_host_list = [get_control_host_string(openstack_host)\
                           for openstack_host in env.roledefs['openstack']]
    galera_ip_list = [hstr_to_ip(galera_host)\
                      for galera_host in openstack_host_list]
    internal_vip = get_openstack_internal_vip()

    mysql_token = run("cat /etc/contrail/mysql.token")
    pdist = detect_ostype()
    if pdist in ['Ubuntu']:
        mysql_svc = 'mysql'
    elif pdist in ['centos', 'redhat']:
        mysql_svc = 'mysqld'
    # Create cmon schema
    run('mysql -u root -p%s -e "CREATE SCHEMA IF NOT EXISTS cmon"' % mysql_token)
    run('mysql -u root -p%s < /usr/local/cmon/share/cmon/cmon_db.sql' % mysql_token)
    run('mysql -u root -p%s < /usr/local/cmon/share/cmon/cmon_data.sql' % mysql_token)

    # insert static data
    run('mysql -u root -p%s -e "use cmon; insert into cluster(type) VALUES (\'galera\')"' % mysql_token)

    host_list = galera_ip_list + ['localhost', '127.0.0.1', internal_vip]
    # Create cmon user
    for host in host_list:
        mysql_cmon_user_cmd = 'mysql -u root -p%s -e "CREATE USER \'cmon\'@\'%s\' IDENTIFIED BY \'cmon\'"' % (
                               mysql_token, host)
        with settings(hide('everything'),warn_only=True):
            run(mysql_cmon_user_cmd)

    mysql_cmd =  "mysql -uroot -p%s -e" % mysql_token
    # Grant privilages for cmon user.
    for host in host_list:
        run('%s "GRANT ALL PRIVILEGES on *.* TO cmon@%s IDENTIFIED BY \'cmon\' WITH GRANT OPTION"' %
               (mysql_cmd, host))
    # Restarting mysql in all openstack nodes
    for host_string in env.roledefs['openstack']:
        with settings(host_string=host_string):
            run("service %s restart" % mysql_svc)
コード例 #53
0
def detach_vrouter_node(*args):
    """Detaches one/more compute node from the existing cluster."""
    cfgm_host = get_control_host_string(env.roledefs['cfgm'][0])
    cfgm_host_password = env.passwords[env.roledefs['cfgm'][0]]
    cfgm_ip = hstr_to_ip(cfgm_host)
    nova_compute = "openstack-nova-compute"
    if detect_ostype() in ['ubuntu']:
        nova_compute = "nova-compute"

    for host_string in args:
        compute_hostname = socket.gethostbyaddr(
            hstr_to_ip(host_string))[0].split('.')[0]
        with settings(host_string=host_string, warn_only=True):
            sudo("service supervisor-vrouter stop")
            sudo("service %s stop" % nova_compute)
        with settings(host_string=cfgm_host, pasword=cfgm_host_password):
            sudo(
                "python /opt/contrail/utils/provision_vrouter.py --host_name %s --host_ip %s --api_server_ip %s --oper del"
                % (compute_hostname, host_string.split('@')[1], cfgm_ip))
    execute("restart_control")
コード例 #54
0
ファイル: ha.py プロジェクト: sajuptpm/contrail-fabric-utils
def fix_memcache_conf_node(*args):
    """Increases the memcached memory to 2048 and listen address to mgmt ip. USAGE:fab fix_memcache_conf_node:[email protected],[email protected]"""
    memory = '2048'
    for host_string in args:
        listen_ip = hstr_to_ip(env.host_string)
        with settings(host_string=host_string, warn_only=True):
            if detect_ostype() == 'Ubuntu':
                memcache_conf='/etc/memcached.conf'
                if run('grep "\-m " %s' % memcache_conf).failed:
                    #Write option to memcached config file
                    run('echo "-m %s" >> %s' % (memory, memcache_conf))
                else:
                    run("sed -i -e 's/\-m.*/\-m %s/' %s" % (memory, memcache_conf))
                if run('grep "\-l " %s' % memcache_conf).failed:
                    #Write option to memcached config file
                    run('echo "-l %s" >> %s' % (listen_ip, memcache_conf))
                else:
                    run("sed -i -e 's/\-l.*/\-l %s/' %s" % (listen_ip, memcache_conf))
            else:
                memcache_conf='/etc/sysconfig/memcached'
コード例 #55
0
def restart_openstack_node(*args):
    """Restarts the contrail openstack services in once openstack node. USAGE:fab restart_openstack_node:[email protected],[email protected]"""
    openstack_services = [
        'rabbitmq-server', 'httpd', 'memcached', 'openstack-nova-api',
        'openstack-nova-scheduler', 'openstack-nova-cert',
        'openstack-nova-consoleauth', 'openstack-nova-novncproxy',
        'openstack-nova-conductor', 'openstack-nova-compute'
    ]
    openstack_services = ['httpd', 'memcached', 'supervisor-openstack']
    if detect_ostype() in ['Ubuntu']:
        openstack_services = [
            'rabbitmq-server', 'memcached', 'nova-api', 'nova-scheduler',
            'glance-api', 'glance-registry', 'keystone', 'nova-conductor',
            'cinder-api', 'cinder-scheduler'
        ]
        openstack_services = ['memcached', 'supervisor-openstack']

    for host_string in args:
        with settings(host_string=host_string):
            for svc in openstack_services:
                run('service %s restart' % svc)
コード例 #56
0
def install_test_repo_node(*args):
    '''Installs test repo in given node'''
    for host_string in args:
        with settings(host_string=host_string):
            os_type = detect_ostype().lower()
            os_type, version, extra = get_linux_distro()
            if os_type in ['ubuntu']:
                if 'trusty' in extra:
                    put('fabfile/contraillabs/repo/trusty_test.repo',
                        '/etc/apt/sources.list.d/')
                if 'xenial' in extra:
                    put('fabfile/contraillabs/repo/xenial_test.repo',
                        '/etc/apt/sources.list.d/')
                sudo('apt-get update')
            if os_type in ['centos', 'centoslinux']:
                put('fabfile/contraillabs/repo/centos_el7_test.repo',
                    '/etc/yum.repos.d/contrail_test.repo')
                run('yum clean all')
            if os_type in ['redhat']:
                put('fabfile/contraillabs/repo/el7_test.repo',
                    '/etc/yum.repos.d/contrail_test.repo')
                run('yum clean all')
コード例 #57
0
def verfiy_zookeeper(*zoo_nodes):
    zookeeper_status = {}
    for host_string in zoo_nodes:
        with settings(host_string=host_string, warn_only=True):
            status_cmd = "/usr/lib/zookeeper/bin/zkServer.sh status"
            if detect_ostype() in ['ubuntu']:
                status_cmd = "/usr/share/zookeeper/bin/zkServer.sh status"
            retries = 5
            for i in range(retries):
                status = sudo(status_cmd)
                if 'not running' in status:
                    status = 'notrunning'
                elif 'No such file' in status:
                    status = 'notinstalled'
                elif 'Error contacting service' not in status:
                    break
                sleep(2)
            for stat in ['leader', 'follower', 'standalone']:
                if stat in status:
                    status = stat
                    break
            zookeeper_status.update({host_string: status})
    return zookeeper_status
コード例 #58
0
def restart_ntp_node():
    ostype = detect_ostype()
    if ostype in ['ubuntu']:
        sudo("service ntp restart", warn_only=True)
    else:
        sudo("service ntpd restart", warn_only=True)