How to use get_nic method in lisa

Best Python code snippet using lisa_python

set_hostinfo_by_nic.py

Source:set_hostinfo_by_nic.py Github

copy

Full Screen

1#coding:utf-82#本脚本用于通过mac地址来设置ip地址3import subprocess4import re5hostname_domain='.alv.pub'6hostname={}7hostname['2']='ipa' #ipa 服务。包括ldap,dns服务。8hostname['3']='internal' #物理机 所有虚拟机都是安装在这里9hostname['4']='zabbix' #zabbix监控10hostname['5']='jenkins' #自动化流程11hostname['6']='git' #代码服务器12hostname['9']='meta' #其他虚拟机要创建的得时候,拷贝meta的盘。然后修改系统配置导入为新的虚拟机13hostname['10']='mysql_' #mysql前端14hostname['11']='mysql1'15hostname['12']='mysql2'16hostname['13']='mysql3'17hostname['20']='redis' #redis前端18hostname['21']='redis1'19hostname['22']='redis2'20hostname['23']='redis3'21hostname['30']='mongodb' #mongodb 前端22hostname['31']='mongodb1'23hostname['32']='mongodb2'24hostname['33']='mongodb3'25hostname['41']='test1'26hostname['42']='test2'27hostname['43']='test3'28hostname['44']='test4'29hostname['45']='test5'30hostname['46']='test6'31hostname['47']='test7'32hostname['48']='test8'33hostname['49']='test9'34hostname['50']='w7'35hostname['51']='w10'36hostname['52']='kali'37hostname['60']='mysql'38hostname['61']='redis'39hostname['68']='centos6u8'40hostname['74']='centos7u4'41hostname['73']='centos7u3'42hostname['81']='k8s1'43hostname['82']='k8s2'44hostname['83']='k8s3'45hostname['84']='k8s4'46hostname['90']='vpnserver'47hostname['91']='ubuntu14u4'48hostname['92']='ubuntu16u4'49hostname['93']='ubuntu18u4'50#获取mac地址51get_nic=subprocess.check_output("ip a s|grep ether|awk '{print $2}'",shell=True).split('\n')[0]52#获取mac地址最后一位53tail_1=get_nic.split(':')[-1]54#如果最后一段数的开头是0,去掉055if tail_1[0] == '0':tail_1=tail_1[1]56#获取mac地址倒数第二位57tail_2=get_nic.split(':')[-2]58#Get mac tail 3 number59tail_3=get_nic.split(':')[-2]60if tail_2 == '01':tail_1='1'+tail_161#设置ip等网络信息62sysinfo={}63sysinfo['ip']='192.168.3.%s'%tail_164sysinfo['gw']='192.168.3.3'65sysinfo['dns']='192.168.3.2'66sysinfo['dns_search']='alv.pub'67#sysinfo['nic']=subprocess.check_output("ip a s|grep state|grep -v lo|awk -F: '{print $2}'|sed 's/ //'",shell=True).split('\n')[0]68sysinfo['nic']=re.sub(r'(GENERAL.CONNECTION:\s+)','',subprocess.check_output("nmcli device show |grep -i CONNECTION|head -1",shell=True).split('\n')[0])69sysinfo['hostname']=hostname[tail_1]+hostname_domain70#设置ip地址71def set_ip_info():72 if subprocess.call('nmcli connection modify "{nic}" ipv4.method manual ipv4.addresses {ip}/24 ipv4.gateway {gw} ipv4.dns {dns} ipv4.dns-search {dns_search} autoconnect yes && nmcli con up "{nic}"'.format(**sysinfo),shell=True) == 0:73 print('IP address has heen setup ok')74 else:75 print('IP address setup failed.')76def set_hostnaem():77 if subprocess.call('hostnamectl set-hostname %s'%sysinfo['hostname'],shell=True) == 0:78 print('Hostname setup ok')79 else:80 print('Hostname setup failed.')81def main():82 set_ip_info()83 set_hostnaem()84if __name__ == '__main__':...

Full Screen

Full Screen

set_hostinfo_by_nic_10.py

Source:set_hostinfo_by_nic_10.py Github

copy

Full Screen

1#coding:utf-82#本脚本用于通过mac地址来设置ip地址3import subprocess4import re5hostname_domain='.alv.pub'6hostname={}7hostname['2']='ipa' #ipa 服务。包括ldap,dns服务。8hostname['3']='internal' #物理机 所有虚拟机都是安装在这里9hostname['4']='zabbix' #zabbix监控10hostname['5']='jenkins' #自动化流程11hostname['6']='git' #代码服务器12hostname['9']='meta' #其他虚拟机要创建的得时候,拷贝meta的盘。然后修改系统配置导入为新的虚拟机13hostname['10']='mysql_' #mysql前端14hostname['11']='mysql1'15hostname['12']='mysql2'16hostname['13']='mysql3'17hostname['20']='redis' #redis前端18hostname['21']='redis1'19hostname['22']='redis2'20hostname['23']='redis3'21hostname['30']='mongodb' #mongodb 前端22hostname['31']='mongodb1'23hostname['32']='mongodb2'24hostname['33']='mongodb3'25hostname['50']='w7'26hostname['51']='w10'27hostname['60']='mysql'28hostname['61']='redis'29hostname['68']='centos6u8'30hostname['74']='centos7u4'31hostname['73']='centos7u3'32hostname['81']='k8s1'33hostname['82']='k8s2'34hostname['83']='k8s3'35hostname['84']='k8s4'36hostname['90']='vpnserver'37#获取mac地址38get_nic=subprocess.check_output("ip a s|grep ether|awk '{print $2}'",shell=True).split('\n')[0]39#获取mac地址最后一位40tail_1=get_nic.split(':')[-1]41#如果最后一段数的开头是0,去掉042if tail_1[0] == '0':tail_1=tail_1[1]43#获取mac地址倒数第二位44tail_2=get_nic.split(':')[-2]45#Get mac tail 3 number46tail_3=get_nic.split(':')[-2]47if tail_2 == '01':tail_1='1'+tail_148#设置ip等网络信息49sysinfo={}50sysinfo['ip']='192.168.3.%s'%tail_151sysinfo['gw']='192.168.3.3'52sysinfo['dns']='192.168.3.2'53sysinfo['dns_search']='alv.pub'54#sysinfo['nic']=subprocess.check_output("ip a s|grep state|grep -v lo|awk -F: '{print $2}'|sed 's/ //'",shell=True).split('\n')[0]55sysinfo['nic']=re.sub(r'(GENERAL.CONNECTION:\s+)','',subprocess.check_output("nmcli device show |grep -i CONNECTION|head -1",shell=True).split('\n')[0])56sysinfo['hostname']=hostname[tail_1]+hostname_domain57#设置ip地址58def set_ip_info():59 if subprocess.call('nmcli connection modify "{nic}" ipv4.method manual ipv4.addresses {ip}/24 ipv4.gateway {gw} ipv4.dns {dns} ipv4.dns-search {dns_search} autoconnect yes && nmcli con up "{nic}"'.format(**sysinfo),shell=True) == 0:60 print('IP address has heen setup ok')61 else:62 print('IP address setup failed.')63def set_hostnaem():64 if subprocess.call('hostnamectl set-hostname %s'%sysinfo['hostname'],shell=True) == 0:65 print('Hostname setup ok')66 else:67 print('Hostname setup failed.')68def main():69 set_ip_info()70 set_hostnaem()71if __name__ == '__main__':...

Full Screen

Full Screen

tests_helpers.py

Source:tests_helpers.py Github

copy

Full Screen

...3class HelperTestCase(TestCase):4 siret = "123456789000"5 def test_get_siren(self):6 self.assertEqual(get_siren(self.siret), "123456789")7 def test_get_nic(self):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful