def option_1(): net_thread = Process(target=waiting_spin_procesor_bar, args=('Configuring bridge network ....', 0.1)) net_thread.daemon = True net_thread.start() #check net-tools status, output = utils_cmd.cmd_status_output(cmd='which ifconfig', verbose=False) if status: utils_cmd.cmd_status_output(cmd='yum install -y net-tools', verbose=False) #setup bridge nic_status = utils_cmd.cmd_output('ip addr | grep %s' % get_host_ip(), verbose=False) nic_name = nic_status.split(" ")[-1].strip('\n') connection = utils_cmd.cmd_output( 'nmcli device show %s | grep GENERAL.CONNECTION' % nic_name, verbose=False) conid = re.split(r'\s{2,}', connection)[-1].strip('\n') utils_cmd.cmd_output( 'nmcli con add type bridge ifname switch con-name switch stp no', verbose=False) utils_cmd.cmd_output('nmcli con modify \'%s\' master switch' % conid, verbose=False) utils_cmd.cmd_output('nmcli con up \'%s\'' % conid, verbose=False) if utils_cmd.cmd_output('[ $? -ne 1 ]', verbose=False): print('NetworkManager Command failed') #write configuration file utils_cmd.cmd_output( 'echo \"#!/bin/sh\nswitch=switch\nip link set \$1 up\n' 'ip link set dev \$1 master \${switch}\n' 'ip link set \${switch} type bridge forward_delay 0\n' 'ip link set \${switch} type bridge stp_state 0\" > /etc/qemu-ifup', verbose=False) utils_cmd.cmd_output( 'echo \"#!/bin/sh\nswitch=switch\nip link set \$1 down\n' 'ip link set dev \$1 nomaster\" > /etc/qemu-ifdown', verbose=False) utils_cmd.cmd_output('chmod a+rx /etc/qemu-if*', verbose=False) bridge_ip = get_switch_ip() net_thread.terminate() sys.stdout.write('\b') sys.stdout.flush() print(color.yellow('Done')) print(color.green('The bridge IP: %s' % bridge_ip))
def install_qemu_package(nvr): found = False download_file = os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'downloads') if os.path.exists(download_file): for pkg in os.listdir(download_file): if pkg == (nvr + '.' + machine()): found = True break if found: utils_cmd.cmd_output('yum remove -y qemu-*') utils_cmd.cmd_output('cd %s;yum install -y *' % (os.path.join(download_file, pkg))) else: download_dir, ret = utils_brew.brew_download_rpms(rpm_nvr=nvr, arch=machine()) if not ret: return False utils_cmd.cmd_output('yum remove -y qemu-*') utils_cmd.cmd_output('cd %s;yum install -y *' % download_dir) else: download_dir, ret = utils_brew.brew_download_rpms(rpm_nvr=nvr, arch=machine()) if not ret: return False utils_cmd.cmd_output('yum remove -y qemu-*') utils_cmd.cmd_output('cd %s;yum install -y *' % download_dir) s, o = utils_cmd.cmd_status_output('/usr/libexec/qemu-kvm --version') print(o) if s != 0: print(color.red('Failed to install qemu package.')) return False else: return True
def install_brew(verbose=True): status, output = utils_cmd.cmd_status_output(cmd='which brew') if verbose: print(output) if status: rel_ver = utils_cmd.cmd_output( cmd='cat /etc/redhat-release | ' 'grep -oE \'[0-9]+\.[0-9]+\'| cut -d\'.\' -f1', verbose=False) status, output = utils_cmd.cmd_status_output('yum install -y brewkoji') if verbose: print(output) if status: print(color.red('Failed to install \"brewkoji\"')) print( color.red( 'Please get rcm-tools-rhel-%s-server.repo by manual.' % rel_ver.rstrip())) sys.exit(1)
def _create_backstore(): status, output = utils_cmd.cmd_status_output( 'targetcli /backstores/fileio/ create file_or_dev=/home/osd%s ' 'name=osd%s size=%sM'% (exist_lun, exist_lun, image_size2), verbose=False) if status !=0: net_thread.terminate() sys.stdout.write('\b') sys.stdout.flush() print(color.yellow('Done')) print(color.red('Command Error: %s.' % output)) else: return True
def brew_download_rpms(rpm_nvr, arch=None, verbose=True): download_file = os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'downloads') if not os.path.exists(download_file): os.mkdir(download_file) if arch: dir_rpm = os.path.join(download_file, (rpm_nvr + '.' + arch)) else: dir_rpm = os.path.join(download_file, rpm_nvr) if not os.path.exists(dir_rpm): os.mkdir(dir_rpm) brew_download_cmd = 'cd %s; brew download-build' % dir_rpm brew_download_cmd += ' --arch=%s' % arch brew_download_cmd += ' ' + ' --noprogress ' + rpm_nvr status, output = utils_cmd.cmd_status_output(cmd=brew_download_cmd) if verbose: print(output) if status: utils_cmd.cmd_output('rm -rf %s' % dir_rpm, verbose=False) print(color.red('Failed to download \"%s\" package.' % rpm_nvr)) return dir_rpm, False return dir_rpm, True
def option_3(): s, o = utils_cmd.cmd_status_output('which ceph') if s: pack_list = [] rel_ver = utils_cmd.cmd_output(cmd='cat /etc/redhat-release | ' 'grep -oE \'[0-9]+\.[0-9]+\'| ' 'cut -d\'.\' -f1', verbose=False) lttng_ust_list = utils_brew.brew_search('lttng-ust') leaste_lttng_ust = sorted([ lttng_ust for lttng_ust in lttng_ust_list if re.match(r'^lttng-ust-\d.*\.el%s$' % rel_ver.strip('\n'), lttng_ust) ])[-1] print(leaste_lttng_ust) pack_list.append(leaste_lttng_ust) python_flask_list = utils_brew.brew_search('python-flask') leaste_python_flask = sorted([ python_flask for python_flask in python_flask_list if re.match(r'^python-flask-\d.*\.el%s' % rel_ver.strip('\n'), python_flask) ])[-1] print(leaste_python_flask) pack_list.append(leaste_python_flask) python_werkzeug_list = utils_brew.brew_search('python-werkzeug') leaste_python_werkzeug = sorted([ python_werkzeug for python_werkzeug in python_werkzeug_list if re.match(r'^python-werkzeug-\d.*\.el%s' % rel_ver.strip('\n'), python_werkzeug) ])[-1] print(leaste_python_werkzeug) pack_list.append(leaste_python_werkzeug) python_itsdangerous_list = utils_brew.brew_search( 'python-itsdangerous') leaste_python_itsdangerous = sorted([ python_itsdangerous for python_itsdangerous in python_itsdangerous_list if re.match( r'^python-itsdangerous-\d.*\.el%s' % rel_ver.strip('\n'), python_itsdangerous) ])[-1] print(leaste_python_itsdangerous) pack_list.append(leaste_python_itsdangerous) userspace_rcu_list = utils_brew.brew_search('userspace-rcu') leaste_userspace_rcu = sorted([ userspace_rcu for userspace_rcu in userspace_rcu_list if re.match(r'^userspace-rcu-\d.*\.el%s' % rel_ver.strip('\n'), userspace_rcu) ])[-1] print(leaste_userspace_rcu) pack_list.append(leaste_userspace_rcu) ceph_list = utils_brew.brew_search('ceph') leaste_ceph = sorted([ ceph for ceph in ceph_list if re.match(r'^ceph-\d.*\.el%scp$' % rel_ver.strip('\n'), ceph) ])[-1] print(leaste_ceph) pack_list.append(leaste_ceph) for pak in pack_list: download_dir, ret = utils_brew.brew_download_rpms(rpm_nvr=pak, arch=machine()) if not ret: print( color.red('Please check package NVR or ' 'search it before download.'))