Best Python code snippet using avocado_python
PA-menu.py
Source:PA-menu.py
...61 if(ssh == ""):62 #local system63 64 if task == '1':65 output = sp.getstatusoutput("nautilus &")66 elif task == '2':67 file = input("If you want to open a file then enter 'file name' else 'press enter' : ")68 output =sp.getstatusoutput("gedit {} &".format(file) )69 elif task == '3':70 output =sp.getstatusoutput("firefox &")71 elif task == '4':72 file = input("Enter file path which you want to open : ")73 rc = os.system("vim {}".format(file))74 if(rc == 0):75 output=(0,"")76 elif task == '5':77 output =sp.getstatusoutput("gnome-terminal &")78 elif task == '6':79 output =sp.getstatusoutput("gnome-control-center &")80 elif task == '7':81 output =sp.getstatusoutput("rhythmbox &")82 elif task == '8':83 output =sp.getstatusoutput("gnome-calculator &")84 elif task == '9':85 output =sp.getstatusoutput("cheese &")86 elif task == '10':87 output =sp.getstatusoutput("totem &")88 elif task == '11':89 output =sp.getstatusoutput("evolution -c mails &")90 elif task == '12':91 output =sp.getstatusoutput("evolution -c calender &")92 elif task == '13':93 output =sp.getstatusoutput("evolution -c contacts &")94 elif task == '14':95 output =sp.getstatusoutput("date")96 elif task == '15':97 output =sp.getstatusoutput("fdisk -l")98 elif task == '16':99 output =sp.getstatusoutput("lsblk")100 print(output[1])101 output =sp.getstatusoutput("df -h")102 elif task == '17':103 software = input("Enter package/software name about which you want to query : ")104 output =sp.getstatusoutput("rpm -q {}".format(software))105 elif task == '18':106 link = input("Enter link to download : ")107 output =sp.getstatusoutput("yum install {}".format(link))108 elif task == '19':109 software = input("Enter package/software name which you want to install : ")110 os.system("yum install {}".format(software))111 ouput = output =sp.getstatusoutput("rpm -q {}".format(software))112 elif task == '20':113 status = input("Enter [start / stop / enable / disable / status] according to your requirement : ")114 service = input("Enter service name : ")115 output =sp.getstatusoutput("systemctl {} {}".format(status,service))116 output =sp.getstatusoutput("systemctl status {}".format(service))117 elif task == '21':118 output =sp.getstatusoutput("free -m")119 elif task == '22':120 domain = input("Enter domain name : ")121 output =sp.getstatusoutput("nslookup {}".format(domain))122 elif task == '23':123 print("Present directory :")124 os.system("pwd")125 output =sp.getstatusoutput("ls")126 elif task == '24':127 folder = input("Enter folder path : ")128 output =sp.getstatusoutput("cd {}".format(folder))129 elif task == '25':130 content = input("What do you want to delete [file / folder] : ")131 path = input("Enter {} path which you want to delete : ".format(content))132 if(content == 'folder'):133 output =sp.getstatusoutput("rm -rf {}".format(path))134 else:135 output =sp.getstatusoutput("rm {}".format(path))136 elif task == '26':137 output =sp.getstatusoutput("netstat -tnlp")138 elif task == '27':139 ip = input("Enter IP or domain name to which you want to check connectivity : ")140 output =sp.getstatusoutput("ping -c 4 {}".format(ip))141 elif task == '28':142 output =sp.getstatusoutput("nmcli")143 elif task == '29':144 output =sp.getstatusoutput("nmcli connection show")145 elif task == '30':146 card = input("Enter your ethernet card name : ")147 status = input("Enter ['up' for on and 'down' for off] as per requirement : ")148 output =sp.getstatusoutput("nmcli connection {} {}".format(status,card))149 elif task == '31':150 output =sp.getstatusoutput("ifconfig")151 elif task == '32':152 ip = input("Enter IP of system to which you want to send file : ")153 user = input("Enter username to to which you want to send file : ")154 src = input("Enter your source file path which you want to send : ")155 dest = input("Enter destination folder path where you want to copy : ")156 output =sp.getstatusoutput("scp {} {}@{}:{}".format(src, user,ip,dest))157158 elif task == '33':159 software = input("Enter package/software name which you want to uninstall : ")160 rc = os.system("yum remove {}".format(software))161 if(rc == 0):162 output = (0, "Successfully removed!!")163164 elif task == '34':165 print("Configuring yum. please Wait!!!")166 output = sp.getstatusoutput("yum install --nogpgcheck https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm")167 os.system("yum repolist")168169170 elif task == '35':171 break;172173 else:174 print("Invalid Choice!!! Try Again")175 os.system("sleep 1")176 continue177178 if output[0] == 0:179 os.system("tput setaf 2")180 print("Task successfully completed !!")181 os.system("tput setaf 7")182 print(output[1])183 else:184 os.system("tput setaf 5")185 print("Oops !! Some error occurred : {}".format(output[1]))186187 os.system("tput setaf 6")188 input("'Press enter' to continue :")189 os.system("tput setaf 7")190 191 else:192193 #remote system194195 if task == '1':196 output = sp.getstatusoutput("{} -X nautilus".format(ssh))197 elif task == '2':198 file = input("If you want to open a file then enter 'file name' else 'press enter' : ")199 output =sp.getstatusoutput("{} -X 'gedit {}'".format(ssh,file))200 elif task == '3':201 output =sp.getstatusoutput("{} -X firefox".format(ssh))202 elif task == '4':203 file = input("Enter file path which you want to open : ")204 rc = os.system("{} 'vim {}'".format(ssh,file))205 if(rc == 0):206 output=(0,"")207 elif task == '5':208 output =sp.getstatusoutput("{} -X gnome-terminal".format(ssh))209 elif task == '6':210 output =sp.getstatusoutput("{} -X gnome-control-center".format(ssh))211 elif task == '7':212 output =sp.getstatusoutput("{} -X rhythmbox".format(ssh))213 elif task == '8':214 output =sp.getstatusoutput("{} -X gnome-calculator".format(ssh))215 elif task == '9':216 output =sp.getstatusoutput("{} -X cheese".format(ssh))217 elif task == '10':218 output =sp.getstatusoutput("{} -X totem".format(ssh))219 elif task == '11':220 output =sp.getstatusoutput("{} -X evolution -c mails".format(ssh))221 elif task == '12':222 output =sp.getstatusoutput("{} -X evolution -c calender".format(ssh))223 elif task == '13':224 output =sp.getstatusoutput("{} -X evolution -c contacts".format(ssh))225 elif task == '14':226 output =sp.getstatusoutput("{} date".format(ssh))227 elif task == '15':228 output =sp.getstatusoutput("{} 'fdisk -l'".format(ssh))229 elif task == '16':230 output =sp.getstatusoutput("{} lsblk".format(ssh))231 print(output[1])232 output =sp.getstatusoutput("{} 'df -h'".format(ssh))233 elif task == '17':234 software = input("Enter package/software name about which you want to query : ")235 output =sp.getstatusoutput("{} 'rpm -q {}'".format(ssh,software))236 elif task == '18':237 link = input("Enter link to download : ")238 output =sp.getstatusoutput("{} 'yum install {}'".format(ssh,link))239 elif task == '19':240 software = input("Enter package/software name which you want to install : ")241 os.system("{} 'yum install {}'".format(ssh,software))242 ouput = output =sp.getstatusoutput("{} 'rpm -q {}'".format(ssh,software))243 elif task == '20':244 status = input("Enter [start / stop / enable / disable / status] according to your requirement : ")245 service = input("Enter service name : ")246 output =sp.getstatusoutput("{} systemctl {} {}".format(ssh,status,service))247 output =sp.getstatusoutput("{} systemctl status {}".format(ssh,service))248 elif task == '21':249 output =sp.getstatusoutput("{} free -m".format(ssh))250 elif task == '22':251 domain = input("Enter domain name : ")252 output =sp.getstatusoutput("{} 'nslookup {}'".format(ssh,domain))253 elif task == '23':254 print("Present directory :")255 os.system("{} pwd".format(ssh))256 output =sp.getstatusoutput("{} ls".format(ssh))257 elif task == '24':258 folder = input("Enter folder path : ")259 output =sp.getstatusoutput("{} 'cd {}'".format(ssh,folder))260 elif task == '25':261 content = input("What do you want to delete [file / folder] : ")262 path = input("Enter {} path which you want to delete : ".format(content))263 if(content == 'folder'):264 output =sp.getstatusoutput("{} 'rm -rf {}'".format(ssh,path))265 else:266 output =sp.getstatusoutput("{} 'rm {}'".format(ssh,path))267 elif task == '26':268 output =sp.getstatusoutput("{} 'netstat -tnlp'".format(ssh))269 elif task == '27':270 ip = input("Enter IP or domain name to which you want to check connectivity : ")271 output =sp.getstatusoutput("{} 'ping -c 4 {}'".format(ssh,ip))272 elif task == '28':273 output =sp.getstatusoutput("{} nmcli".format(ssh))274 elif task == '29':275 output =sp.getstatusoutput("{} 'nmcli connection show'".format(ssh))276 elif task == '30':277 card = input("Enter your ethernet card name : ")278 status = input("Enter ['up' for on and 'down' for off] as per requirement : ")279 output =sp.getstatusoutput("{} 'nmcli connection {} {}'".format(ssh,status,card))280 elif task == '31':281 output =sp.getstatusoutput("{} ifconfig".format(ssh))282 elif task == '32':283 ip = input("Enter IP of system to which you want to send file : ")284 user = input("Enter username to to which you want to send file : ")285 src = input("Enter your source file path which you want to send : ")286 dest = input("Enter destination folder path where you want to copy : ")287 output =sp.getstatusoutput("{} 'scp {} {}@{}:{}'".format(ssh,src, user,ip,dest))288289 elif task == '33':290 software = input("Enter package/software name which you want to uninstall : ")291 rc = os.system("{} yum remove {}".format(ssh,software))292 if(rc == 0):293 output = (0, "Successfully removed!!")294295 elif task == '34':296 print("Configuring yum. please Wait!!!")297 output = sp.getstatusoutput("{} 'yum install --nogpgcheck https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm'".format(ssh))298 os.system("{} 'yum repolist'".format(ssh))299300301302 elif task == '35':303 break;304305 else:306 print("Invalid Choice!!! Try Again")307 os.system("sleep 1")308 continue309310 if output[0] == 0:311 os.system("tput setaf 2")312 print("Task successfully completed !!")313 os.system("tput setaf 7")314 print(output[1])315 else:316 os.system("tput setaf 5")317 print("Oops !! Some error occurred : {}".format(output[1]))318319 os.system("tput setaf 6")320 input("'Press enter' to continue :")321 os.system("tput setaf 7")322 323324325326def staticpartitions(ssh):327328 while True :329330 os.system("clear")331 os.system("tput setaf 3")332 print("\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~ Welcome to our Partition menu ~~~~~~~~~~~~~~~~~~~~~~~~~~\n")333 os.system("tput setaf 6")334 menu="""335 \t\tPress 1 :To see all disks available336 \t\tPress 2 :To see info of all existing partitions and their mount points337 \t\tPress 3 :To create a static partition338 \t\tPress 4 :To delete a Partition339 \t\tPress 5 :To go back to main menu or exit from this menu\n"""340 print(menu)341 os.system("tput setaf 7")342 task = input("Enter your choice : ")343344 if(ssh == ""):345 #local system346347 if task == '1':348 output = sp.getstatusoutput("fdisk -l")349 elif task == '2':350 output =sp.getstatusoutput("lsblk")351 print(output[1])352 output =sp.getstatusoutput("df -h")353 elif task == '3':354 dname =input ("Enter disk name in which you want to create partition : ")355 mountpt = input("Enter a folder path to which you want to link partition : ")356 os.system("tput setaf 3")357 print("Enter 'n' to create new partition")358 print(" Select Partition type as ['p' for primary / 'e' for extended] : ")359 print("Enter 'w' to save changes after creating partition.")360 os.system("tput setaf 7")361 os.system("fdisk {}".format(dname))362 print(os.system("lsblk"))363 pname = input("Enter partition name created : ")364 output = sp.getstatusoutput("mkfs.ext4 {}".format(pname))365 print(output[1],"\n") 366 if(output[0] == 0):367 os.system("mkdir {}".format(mountpt))368 output = sp.getstatusoutput("mount {} {}".format(pname,mountpt))369 info = sp.getstatusoutput("df -h")370 print(info[1])371 372 373 elif task == '4':374 dname =input ("Enter disk name in which you want to delete partition : ")375 pname = input("Enter partition name to be deleted : ")376 output = sp.getstatusoutput("umount {}".format(pname))377 os.system("tput setaf 3")378 print("Enter 'd' to delete partition")379 print("Enter 'w' to save changes after deleting partition.")380 os.system("tput setaf 7")381 if(output[0] == 0):382 os.system("fdisk {}".format(dname))383 output = sp.getstatusoutput("lsblk")384385 elif task == '5':386 break;387 else:388 print("Invalid Choice!!! Try Again")389 os.system("sleep 1")390 continue391392 else:393 #Remote system394 if task == '1':395 output = sp.getstatusoutput("{} 'fdisk -l'".format(ssh))396 elif task == '2':397 output =sp.getstatusoutput("{} lsblk".format(ssh))398 print(output[1])399 output =sp.getstatusoutput("{} 'df -h'".format(ssh))400 elif task == '3':401 dname =input ("Enter disk name in which you want to create partition : ")402 mountpt = input("Enter a folder path to which you want to link partition : ")403 os.system("tput setaf 3")404 print("Enter 'n' to create new partition")405 print(" Select Partition type as ['p' for primary / 'e' for extended] : ")406 print("Enter 'w' to save changes after creating partition.")407 os.system("tput setaf 7")408 os.system("{} 'fdisk {}'".format(sshdname))409 print(os.system("{} lsblk".format(ssh)))410 pname = input("Enter partition name created : ")411 output = sp.getstatusoutput("{} 'mkfs.ext4 {}'".format(ssh,pname))412 print(output[1],"\n") 413 if(output[0] == 0):414 os.system("{} 'mkdir {}'".format(ssh,mountpt))415 output = sp.getstatusoutput("{} 'mount {} {}'".format(ssh,pname,mountpt))416 info = sp.getstatusoutput("{} 'df -h'".format(ssh))417 print(info[1])418 419 420 elif task == '4':421 dname =input ("Enter disk name in which you want to delete partition : ")422 pname = input("Enter partition name to be deleted : ")423 output = sp.getstatusoutput("{} 'umount {}'".format(ssh,pname))424 os.system("tput setaf 3")425 print("Enter 'd' to delete partition")426 print("Enter 'w' to save changes after deleting partition.")427 os.system("tput setaf 7")428 if(output[0] == 0):429 os.system("{} 'fdisk {}'".format(ssh,dname))430 output = sp.getstatusoutput("{} lsblk".format(ssh))431432 elif task == '5':433 break;434 else:435 print("Invalid Choice!!! Try Again")436 os.system("sleep 1")437 continue438439 if output[0] == 0:440 os.system("tput setaf 2")441 print("Task successfully completed !!")442 os.system("tput setaf 7")443 print(output[1])444 else:445 os.system("tput setaf 5")446 print("Oops !! Some error occurred : {}".format(output[1]))447448 os.system("tput setaf 6")449 input("'Press enter' to continue :")450 os.system("tput setaf 7")451452453def lvm(ssh):454455 while True :456457458 os.system("clear")459 os.system("tput setaf 3")460 print("\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~ Welcome to our LVM menu ~~~~~~~~~~~~~~~~~~~~~~~~~~\n")461 os.system("tput setaf 6")462 menu="""463 \t\tPress 1 :To see all disks available464 \t\tPress 2 :To see info of all existing virtual group465 \t\tPress 3 :To see info of a existing virtual group466 \t\tPress 4 :To see info of lv partition467 \t\tPress 5 :To see info of all partitions with their mount points\n468 \t\tPress 6 :To create virtual group469 \t\tPress 7 :To create an lv partition470 \t\tPress 8 :To resize a lv partition471 \t\tPress 9 :To remove a virtual group472 \t\tPress 10 :To delete a Partition473 \t\tPress 11 :To go back to main menu or exit from this menu\n"""474 print(menu)475 os.system("tput setaf 7")476 task = input("Enter your choice : ")477478 if ssh == "":479 #local system480481 if task == '1':482 output = sp.getstatusoutput("fdisk -l")483 elif task == '2':484 output = sp.getstatusoutput("vgdisplay")485486 elif task == '3':487 vgname = input("Enter virtual group name : ")488 output = sp.getstatusoutput("vgdisplay {}".format(vgname))489490 elif task == '4':491 vgname = input("Enter virtual group name : ")492 lvname = input("Enter logical volume name : ")493 output = sp.getstatusoutput("lvdisplay {}/{}".format(vgname,lvname))494495 elif task == '5':496 output = sp.getstatusoutput("df -h")497498 elif task == '6':499 vgname=input("Enter virtual group name : ")500 num = input("Enter number of physical volume you want to add : ") 501 num = int(num)502 disks = [input("Enter disk {} name : ".format(i)) for i in range(num)]503 print("disks")504 s = " "505 s = s.join(disks)506 os.system("pvcreate {}".format(s))507 output = sp.getstatusoutput("vgcreate {} {}".format(vgname,s))508 info = sp.getstatusoutput("vgdisplay {}".format(vgname))509 print(info[1])510511 elif task == '7':512513 vgname =input ("Enter vgname in which you want to create partition : ")514 lvname = input("Enter Logical volume name : ")515 size = input("Enter size of lv [K,M,G,T,P,E] : ")516 mountpt = input("Enter a folder path to which you want to link partition : ")517 output = sp.getstatusoutput("lvcreate -n {} --size {} {} ".format(lvname,size,vgname))518 print(output[1],"\n")519 if(output[0] == 0):520 output = sp.getstatusoutput("mkfs.ext4 /dev/{}/{}".format(vgname,lvname))521 print(output[1],"\n") 522 if(output[0] == 0):523 os.system("mkdir {}".format(mountpt))524 output = sp.getstatusoutput("mount /dev/{}/{} {}".format(vgname,lvname,mountpt))525 info = sp.getstatusoutput("lvdisplay {}/{}".format(vgname,lvname))526 print(info[1])527528529 elif task == '8':530531 vgname =input ("Enter virtual group name in which logicl volume partition is present : ")532 lvname =input ("Enter logival volume name : ")533 option =input("Enter 'R' to reduce and 'E' to extend size : ")534 size =input ("Enter final size [K,M,G,T,P,E] you want to achieve after extend/reduce : ")535 if option == 'R':536 mountpt = sp.getoutput("findmnt -n -o TARGET /dev/{}/{}".format(vgname,lvname))537 output = sp.getstatusoutput("umount /dev/{}/{}".format(vgname,lvname))538 print(output[1],"\n")539 if(output[0] == 0):540 x = os.system("e2fsck -f /dev/{}/{}".format(vgname,lvname))541 output = sp.getstatusoutput("resize2fs /dev/{}/{} {}".format(vgname,lvname,size))542 print(output[1],"\n")543 if(output[0] == 0):544 print("Enter y if you want to continue else enter n")545 output = sp.getstatusoutput("lvreduce -L {} /dev/{}/{}".format(size,vgname,lvname))546 if(output[0] == 0):547 output=sp.getstatusoutput("mount /dev/{}/{} {}".format(vgname,lvname,mountpt))548 549550 elif option == 'E':551 output = sp.getstatusoutput("lvextend -L {} /dev/{}/{}".format(size,vgname,lvname))552 if(output[0] == 0):553 output = sp.getstatusoutput("resize2fs /dev/{}/{}".format(vgname,lvname))554 info = sp.getstatusoutput("lvdisplay {}/{}".format(vgname,lvname))555 print(info[1])556557 elif task == '9':558 vgname =input("Enter virtual group name which you wish to delete : ")559 output = sp.getstatusoutput("vgchange -a n {}".format(vgname))560 if(output[0] == 0):561 output = sp.getstatusoutput("vgremove {}".format(vgname))562563 elif task == '10':564 vgname =input("Enter virtual group name of which logical volume is a part : ")565 lvname =input("Enter logical volume name which you wish to delete : ")566 output = sp.getstatusoutput("umount /dev/{}/{}".format(vgname,lvname))567 if(output[0] == 0):568 output = sp.getstatusoutput("lvremove -y /dev/{}/{}".format(vgname,lvname))569570 elif(task == '11'):571 break;572573 else:574 print("Invalid Choice!!! Try Again")575 os.system("sleep 1")576 continue577578 if output[0] == 0:579 os.system("tput setaf 2")580 print("Task successfully completed !!")581 os.system("tput setaf 7")582 print(output[1])583 else:584 os.system("tput setaf 5")585 print("Oops !! Some error occurred : {}".format(output[1]))586587 os.system("tput setaf 6")588 input("'Press enter' to continue :")589 os.system("tput setaf 7")590591 else:592 #remote sys593 if task == '1':594 output = sp.getstatusoutput("{} 'fdisk -l'".format(ssh))595 elif task == '2':596 output = sp.getstatusoutput("{} vgdisplay".format(ssh))597598 elif task == '3':599 vgname = input("Enter virtual group name : ")600 output = sp.getstatusoutput("{} 'vgdisplay {}'".format(ssh,vgname))601602 elif task == '4':603 vgname = input("Enter virtual group name : ")604 lvname = input("Enter logical volume name : ")605 output = sp.getstatusoutput("{} 'lvdisplay {}/{}'".format(ssh,vgname,lvname))606607 elif task == '5':608 output = sp.getstatusoutput("{} 'df -h'".format(ssh))609610 elif task == '6':611 vgname=input("Enter virtual group name : ")612 num = input("Enter number of physical volume you want to add : ") 613 num = int(num)614 disks = [input("Enter disk {} name : ".format(i)) for i in range(num)]615 print("disks")616 s = " "617 s = s.join(disks)618 os.system("{} 'pvcreate {}'".format(ssh,s))619 output = sp.getstatusoutput("{} 'vgcreate {} {}' ".format(ssh,vgname,s))620 info = sp.getstatusoutput("{} 'vgdisplay {}' ".format(ssh,vgname))621 print(info[1])622623 elif task == '7':624625 vgname =input ("Enter vgname in which you want to create partition : ")626 lvname = input("Enter Logical volume name : ")627 size = input("Enter size of lv [K,M,G,T,P,E] : ")628 mountpt = input("Enter a folder path to which you want to link partition : ")629 output = sp.getstatusoutput("{} 'lvcreate -n {} --size {} {}'' ".format(ssh,lvname,size,vgname))630 print(output[1],"\n")631 if(output[0] == 0):632 output = sp.getstatusoutput("{} 'mkfs.ext4 /dev/{}/{}'".format(ssh,vgname,lvname))633 print(output[1],"\n") 634 if(output[0] == 0):635 os.system("{} 'mkdir {}'".format(ssh,mountpt))636 output = sp.getstatusoutput("{} 'mount /dev/{}/{} {}'".format(ssh,vgname,lvname,mountpt))637 info = sp.getstatusoutput("{} 'lvdisplay {}/{}'".format(ssh,vgname,lvname))638 print(info[1])639640641 elif task == '8':642643 vgname =input ("Enter virtual group name in which logicl volume partition is present : ")644 lvname =input ("Enter logival volume name : ")645 option =input("Enter 'R' to reduce and 'E' to extend size : ")646 size =input ("Enter final size [K,M,G,T,P,E] you want to achieve after extend/reduce : ")647 if option == 'R':648 mountpt = sp.getoutput("{} 'findmnt -n -o TARGET /dev/{}/{}'".format(ssh,vgname,lvname))649 output = sp.getstatusoutput("{} umount /dev/{}/{}'".format(ssh,vgname,lvname))650 print(output[1],"\n")651 if(output[0] == 0):652 x = os.system("{} 'e2fsck -f /dev/{}/{}'".format(ssh,vgname,lvname))653 output = sp.getstatusoutput("{} 'resize2fs /dev/{}/{} {}'".format(ssh,vgname,lvname,size))654 print(output[1],"\n")655 if(output[0] == 0):656 print("Enter y if you want to continue else enter n")657 output = sp.getstatusoutput("{} 'lvreduce -L {} /dev/{}/{}'".format(ssh,size,vgname,lvname))658 if(output[0] == 0):659 output=sp.getstatusoutput("{} 'mount /dev/{}/{} {}'".format(ssh,vgname,lvname,mountpt))660 661662 elif option == 'E':663 output = sp.getstatusoutput("{} 'lvextend -L {} /dev/{}/{}'".format(ssh,size,vgname,lvname))664 if(output[0] == 0):665 output = sp.getstatusoutput("{} 'resize2fs /dev/{}/{}'".format(ssh,vgname,lvname))666 info = sp.getstatusoutput("{} 'lvdisplay {}/{}'".format(ssh,vgname,lvname))667 print(info[1])668669 elif task == '9':670 vgname =input("Enter virtual group name which you wish to delete : ")671 output = sp.getstatusoutput("{} 'vgchange -a n {}'".format(ssh,vgname))672 if(output[0] == 0):673 output = sp.getstatusoutput("{} 'vgremove {}'".format(ssh,vgname))674675 elif task == '10':676 vgname =input("Enter virtual group name of which logical volume is a part : ")677 lvname =input("Enter logical volume name which you wish to delete : ")678 output = sp.getstatusoutput("{} 'umount /dev/{}/{}'".format(ssh,vgname,lvname))679 if(output[0] == 0):680 output = sp.getstatusoutput("{} 'lvremove -y /dev/{}/{}'".format(ssh,vgname,lvname))681682 elif(task == '11'):683 break;684685 else:686 print("Invalid Choice!!! Try Again")687 os.system("sleep 1")688 continue689690 if output[0] == 0:691 os.system("tput setaf 2")692 print("Task successfully completed !!")693 os.system("tput setaf 7")694 print(output[1])695 else:696 os.system("tput setaf 5")697 print("Oops !! Some error occurred : {}".format(output[1]))698699 os.system("tput setaf 6")700 input("'Press enter' to continue :")701 os.system("tput setaf 7")702 703704 705706707708def hadoop(ssh,user,rsip):709710 while True:711712 os.system("clear")713 os.system("tput setaf 3")714 print("\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~ Welcome to our hadoop menu ~~~~~~~~~~~~~~~~~~~~~~~~~~\n")715 os.system("tput setaf 6")716 menu = """717 \t\tPress 1 : Configure system as Namenode / Datanode718 \t\tPress 2 : Start Namenode / Datanode719 \t\tPress 3 : Configure system as Client720 \t\tPress 4 : See Cluster Information\n721 \t\tPress 5 : Client Operation : Upload File 722 \t\tPress 6 : Client Operation : Read File723 \t\tPress 7 : Client Operation : Create an Empty file724 \t\tPress 8 : Client Operation : Delete a file725 \t\tPress 9 : Client Operation : list all contents in Cluster726 \t\tPress 10 : Stop Namenode / Datanode727 \t\tPress 11 : To go back to main menu or exit from this menu\n"""728729 print(menu)730731 os.system("tput setaf 7")732 task = input("\t\t\tWhat do you want to do ? : ")733734 if ssh == "":735 #local736737 if(task == '1'):738 node = input("Enter 'master'/'slave' if you want to configure as 'namenode' / 'datanode' : ")739 folder = input("Enter datanode / namenode folder path : ")740 ip = input("Enter namenode IP address : ")741 sp.getstatusoutput("mkdir {}".format(folder))742743 #hdfs-site configure744 htree = ET.parse("/etc/hadoop/hdfs-site.xml")745 hroot = htree.getroot()746 if(len(hroot) == 0):747 hp = ET.SubElement(hroot, 'property')748 else:749 hp = hroot[0]750 if(len(hp) == 0):751 hn = ET.SubElement(hp, 'name')752 hv = ET.SubElement(hp,'value')753 else:754 hn = hp[0]755 hv = hp[1]756757 758759 #core-site configure760 ctree = ET.parse("/etc/hadoop/core-site.xml")761 croot = ctree.getroot()762 if len(croot == 0):763 cp = ET.SubElement(croot, 'property')764 else:765 cp = croot[0]766 if(len(cp) == 0):767 cn = ET.SubElement(cp, 'name')768 cv = ET.SubElement(cp,'value')769 else:770 cn = cp[0]771 cv = cp[1]772773 774 cn.text = "fs.default.name"775 cv.text = "hdfs://{}:9001".format(ip)776777 ctree.write("/etc/hadoop/core-site.xml",pretty_print=True)778779 if node == 'master':780 hn.text = "dfs.name.dir"781 hv.text = folder782 htree.write("/etc/hadoop/hdfs-site.xml",pretty_print=True)783784 print("Namenode configured !!!")785 print("Enter password to start Namenode folder formatting....")786787 rc = os.system("hadoop namenode -format")788 if(rc == 0):789 output = sp.getstatusoutput("hadoop-daemon.sh start namenode")790 else:791 hn.text = "dfs.data.dir"792 hv.text = folder793 htree.write("/etc/hadoop/hdfs-site.xml",pretty_print=True)794 output = sp.getstatusoutput("hadoop-daemon.sh start datanode")795 796797 elif(task == '2'):798 node = input("Enter 'master'/'slave' if you want to start 'namenode' / 'datanode' ")799 if(node == 'master'):800 output = sp.getstatusoutput("hadoop-daemon.sh start namenode")801 else:802 output = sp.getstatusoutput("hadoop-daemon.sh start datanode")803804 elif(task =='3'):805 ip = input("Enter namenode IP address : ")806 ctree = ET.parse("/etc/hadoop/core-site.xml")807 croot = ctree.getroot()808 if(len(croot) == 0):809 cp = ET.SubElement(croot, 'property')810 else:811 cp = croot[0]812 if(len(cp) == 0):813 cn = ET.SubElement(cp, 'name')814 cv = ET.SubElement(cp,'value')815 else:816 cn = cp[0]817 cv = cp[1]818819 820 cn.text = "fs.default.name"821 cv.text = "hdfs://{}:9001".format(ip)822823 elif(task == '4'):824 output = sp.getstatusoutput("hadoop dfsadmin -report | less")825826 elif(task == '5'):827 file = input("Enter path of the file which you want to upload : ")828 print("Uploading may take several seconds... Please be patient!!")829 output = sp.getstatusoutput("hadoop fs -put {} /".format(file))830831832 elif(task == '6'):833 file = input("Enter path of file which you want to read: ")834 output = sp.getstatusoutput("hadoop fs -cat {}".format(file))835836 elif(task == '7'):837 file = input("Enter file path with name which you want to create (eg - /<foldername>/<filename>) : ")838 output = sp.getstatusoutput("hadoop fs -touchz {}".format(file))839840 elif(task == '8'):841 file = input("Enter path of file which you want to remove from cluster : ")842 output = sp.getstatusoutput("hadoop fs -rm {}".format(file))843844 elif(task =='9'):845 output = sp.getstatusoutput("hadoop fs -ls /")846847 elif(task == '10'):848 node = input("Enter 'master'/'slave' if you want to stop 'namenode' / 'datanode' ")849 if(node == 'master'):850 output = sp.getstatusoutput("hadoop-daemon.sh stop namenode")851 else:852 output = sp.getstatusoutput("hadoop-daemon.sh stop datanode")853854 elif(task == '11'):855 break;856857 else:858 print("Invalid Option!!")859 os.system("sleep 2")860 continue861862 if output[0] == 0:863 os.system("tput setaf 2")864 print("Task successfully completed !!")865 os.system("tput setaf 7")866 print(output[1])867 else:868 os.system("tput setaf 5")869 print("Oops !! Some error occurred : {}".format(output[1]))870871 os.system("tput setaf 6")872 input("'Press enter' to continue :")873 os.system("tput setaf 7")874875 else:876 #remote sys877 if(task == '1'):878 node = input("Enter 'master'/'slave' if you want to configure as 'namenode' / 'datanode' : ")879 folder = input("Enter datanode / namenode folder path : ")880 ip = input("Enter namenode IP address : ")881 print("Enter password to create namenode folder....")882 sp.getstatusoutput("{} 'mkdir {}'".format(ssh,folder))883884 #hdfs-site configure885 sp.getstatusoutput("touch hdfs-site.xml")886 sp.getstatusoutput("echo '<configuration>\n</configuration>' > hdfs-site.xml")887 htree = ET.parse("hdfs-site.xml")888 hroot = htree.getroot()889 890 hp = ET.SubElement(hroot, 'property')891 hn = ET.SubElement(hp, 'name')892 hv = ET.SubElement(hp,'value')893 894895 896897 #core-site configure898 sp.getstatusoutput("touch core-site.xml")899 sp.getstatusoutput("echo '<configuration>\n</configuration>' > core-site.xml")900 ctree = ET.parse("core-site.xml")901 croot = ctree.getroot()902 903 cp = ET.SubElement(croot, 'property')904 cn = ET.SubElement(cp, 'name')905 cv = ET.SubElement(cp,'value')906907 print("Enter password to configure hadoop files....")908 sp.getstatusoutput("{} 'rm /etc/hadoop/hdfs-site.xml /etc/hadoop/core-site.xml'".format(ssh))909 910 911 cn.text = "fs.default.name"912 cv.text = "hdfs://{}:9001".format(ip)913914915 ctree.write("core-site.xml",pretty_print=True)916 sp.getstatusoutput("scp core-site.xml {}@{}:/etc/hadoop/".format(user,rsip))917918 if node == 'master':919 hn.text = "dfs.name.dir"920 hv.text = folder921 htree.write("hdfs-site.xml",pretty_print=True)922 sp.getstatusoutput("scp hdfs-site.xml {}@{}:/etc/hadoop/".format(user,rsip))923 print("Namenode configured !!!")924 print("Enter password to start Namenode folder formatting....")925926927 rc = os.system("{} 'hadoop namenode -format'".format(ssh))928 if(rc== 0):929 output = sp.getstatusoutput("{} 'hadoop-daemon.sh start namenode'".format(ssh))930 else:931 hn.text = "dfs.data.dir"932 hv.text = folder933 htree.write("hdfs-site.xml",pretty_print=True)934 sp.getstatusoutput("scp hdfs-site.xml {}@{}:/etc/hadoop/".format(user,rsip))935 output = sp.getstatusoutput("{} 'hadoop-daemon.sh start datanode'".format(ssh))936937 sp.getstatusoutput("rm hdfs-site.xml")938 sp.getstatusoutput("rm core-site.xml")939 940941 elif(task == '2'):942 node = input("Enter 'master'/'slave' if you want to start 'namenode' / 'datanode' ")943 if(node == 'master'):944 output = sp.getstatusoutput("{} hadoop-daemon.sh start namenode".format(ssh))945 else:946 output = sp.getstatusoutput("{} hadoop-daemon.sh start datanode".format(ssh))947948 elif(task =='3'):949 ip = input("Enter namenode IP address : ")950951 sp.getstatusoutput("touch core-site.xml")952 sp.getstatusoutput("echo '<configuration>\n</configuration>' > core-site.xml")953 sp.getstatusoutput("{} 'rm /etc/hadoop/core-site.xml'".format(ssh))954 ctree = ET.parse("core-site.xml")955 croot = ctree.getroot()956 957 cp = ET.SubElement(croot, 'property')958 cn = ET.SubElement(cp, 'name')959 cv = ET.SubElement(cp,'value')960 961962 cn.text = "fs.default.name"963 cv.text = "hdfs://{}:9001".format(ip)964 ctree.write("core-site.xml",pretty_print=True)965966 output =sp.getstatusoutput("scp core-site.xml {}@{}:/etc/hadoop/".format(user,rsip))967 sp.getstatusoutput("rm core-site.xml")968969 elif(task == '4'):970 output = sp.getstatusoutput("{} 'hadoop dfsadmin -report | less'".format(ssh))971972 elif(task == '5'):973 file = input("Enter path of the file which you want to upload : ")974 print("Uploading may take several seconds... Please be patient!!")975 output = sp.getstatusoutput("{} 'hadoop fs -put {} /'".format(ssh,file))976977978 elif(task == '6'):979 file = input("Enter path of file which you want to read: ")980 output = sp.getstatusoutput("{} 'hadoop fs -cat {}'".format(ssh,file))981982 elif(task == '7'):983 file = input("Enter file path with name which you want to create (eg - /<foldername>/<filename>) : ")984 output = sp.getstatusoutput("{} 'hadoop fs -touchz {}'".format(ssh,file))985986 elif(task == '8'):987 file = input("Enter path of file which you want to remove from cluster : ")988 output = sp.getstatusoutput("{} 'hadoop fs -rm {}'".format(ssh,file))989990 elif(task =='9'):991 output = sp.getstatusoutput("{} 'hadoop fs -ls /'".format(ssh))992993 elif(task == '10'):994 node = input("Enter 'master'/'slave' if you want to stop 'namenode' / 'datanode' ")995 if(node == 'master'):996 output = sp.getstatusoutput("{} hadoop-daemon.sh stop namenode".format(ssh))997 else:998 output = sp.getstatusoutput("{} hadoop-daemon.sh stop datanode".format(ssh))9991000 elif(task == '11'):1001 break;10021003 else:1004 print("Invalid Option!!")1005 os.system("sleep 2")1006 continue10071008 if output[0] == 0:1009 os.system("tput setaf 2")1010 print("Task successfully completed !!")1011 os.system("tput setaf 7")1012 print(output[1])1013 else:1014 os.system("tput setaf 5")1015 print("Oops !! Some error occurred : {}".format(output[1]))10161017 os.system("tput setaf 6")1018 input("'Press enter' to continue :")1019 os.system("tput setaf 7")10201021def aws(ssh):10221023 10241025 while True:10261027 os.system("clear")1028 os.system("tput setaf 3")1029 print("\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~ Welcome to our AWS menu ~~~~~~~~~~~~~~~~~~~~~~~~~~\n")1030 os.system("tput setaf 6")10311032 mainmenu="""1033 \t\tPress 1 : Login to aws account1034 \t\tPress 2 : Create key pair1035 \t\tPress 3 : Create security group1036 \t\tPress 4 : Add inbound rules1037 \t\tPress 5 : Launch EC2 instance1038 \t\tPress 6 : Create EBS volume1039 \t\tPress 7 : Attach EBS to EC2 instance1040 \t\tPress 8 : Create S3 bucket1041 \t\tPress 9: Launch Distribution1042 \t\tPress 10: Shows all existing EC2 instances1043 \t\tPress 11: Shows all existing key-pairs1044 \t\tPress 12: Shows all existing security-groups1045 \t\tPress 13: To stop instance1046 \t\tPress 14: To start existing instance1047 \t\tPress 15: To change the bucket permission 1048 \t\tPress 16: To upload image in S3 bucket1049 \t\tPress 17 :To go back to main menu or exit from this menu\n"""1050 print(mainmenu)10511052 os.system("tput setaf 7")1053 task = input("Enter your choice : ")1054 1055 if ssh == "":1056 #local sys10571058 if task == '1':1059 rc=os.system("aws configure")1060 if(rc == 0):1061 output=(0,'Login Successful')10621063 elif task == '2':1064 keyname = input("Enter Key name : ")1065 output = sp.getstatusoutput("aws ec2 create-key-pair --key-name {}".format(keyname))1066 elif task == '3':1067 grpname = input("Enter Security group name : ")1068 description = input("Give Description of your security group : ")1069 output = sp.getstatusoutput("aws ec2 create-security-group --group-name {} --description {} --vpc-id vpc-c62ecead".format(grpname,description))1070 elif task == '4':1071 grpid = input("Enter groyp id : ")1072 protocol = input("Enter protocol you want to add : ")1073 port = input("Enter port number : ")1074 output = sp.getstatusoutput("aws ec2 authorize-security-group-ingress --group-id {} --protocol {} --port {} --cidr 0.0.0.0/0".format(grpid,protocol,port))1075 elif task == '5':1076 image = input("Enter image id : ")1077 instance = input("Enter instance-type : ")1078 count = input("Enter no.of instance you want to launch : ")1079 sgid = input("Enter security group id : ")1080 keyname = input("Enter Key name : ")10811082 output = sp.getstatusoutput("aws ec2 run-instances --image-id {} --instance-type {} --count {} --security-groups {} --key-name {}".format(image,instance,count,sgid,keyname))1083 elif task == '6':1084 size = input("Enter size of youe ebs volume : ")1085 az = input("Enter availability-zone in which you want to create volume : ")1086 ebsname = input("Enter a name which you want to give to your volume : ")1087 output = sp.getstatusoutput("aws ec2 create-volume --volume-type gp2 --size {} --availability-zone {} --tag-specifications 'ResourceType=volume,Tags=['{'Key=name,Value= {}}]'".format(size,az,ebsname))1088 elif task == '7':1089 print("Before attaching EBS volume to an instance make sure your EBS volume and instance are in the same availability zone")1090 instance = input("Enter instance-id to which you want to attach: ")1091 volid = input("Enter volume-id which you want to attach : ")1092 output = sp.getstatusoutput("aws ec2 attach-volume --volume-id {} --instance-id {} --device /dev/sdf".format(volid,instance))1093 elif task == '8':1094 bucketname = input("Enter bucket name : ")1095 region = input("Enter region in which you want to create bucket : ")1096 output = sp.getstatusoutput("aws s3 mb s3://{} --region {}".format(bucketname,region))1097 elif task == '9':1098 bucketname = input("Enter bucket name : ")1099 output = sp.getstatusoutput("aws cloudfront create-distribution --origin-domain-name {}.s3.amazonaws.com".format(bucketname))1100 elif task == '10':1101 output = sp.getstatusoutput("aws ec2 describe-instances")1102 elif task == '11':1103 output = sp.getstatusoutput("aws ec2 describe-key-pairs")1104 elif task == '12':1105 output = sp.getstatusoutput("aws ec2 describe-security-groups")1106 elif task == '13':1107 instance = input("Enter the instance id which you want to stop: ")1108 output = sp.getstatusoutput("aws ec2 stop-instances --instance-ids {}".format(instance))11091110 elif task == '14':1111 instance = input("Enter the instance id which you want to start: ")1112 output = sp.getstatusoutput("aws ec2 start-instances --instance-ids {}".format(instance))1113 elif task == '15':1114 b_name = input("Enter bucket name: ")1115 img_name = input("Enter image file name: ")1116 permission = input("Enter permission you want to give eg.,public-read: ")1117 ouput = sp.getstatusoutput("aws s3api put-object-acl --bucket {} --key {} --acl {}".format(b_name,img_name,permission))11181119 elif task == '16':1120 img_path = input("Enter the complete path of the image you want to upload: ")1121 b_name = input("Enter name of the bucket: ")1122 output = sp.getstatusoutput("aws s3 sync \"{}\" s3\:\/\/{}\ ".format(img_path,b_name))11231124 elif task == '17':1125 break;11261127 else:1128 print("Invalid Option!!")1129 os.system("sleep 1")1130 continue11311132 if output[0] == 0:1133 os.system("tput setaf 2")1134 print("Task successfully completed !!")1135 os.system("tput setaf 7")1136 print(output[1])1137 else:1138 os.system("tput setaf 5")1139 print("Oops !! Some error occurred : {}".format(output[1]))11401141 os.system("tput setaf 6")1142 input("'Press enter' to continue :")1143 os.system("tput setaf 7")11441145 else:1146 #remote1147 if task == '1':1148 rc=os.system("{} 'aws configure'".format(ssh))1149 if(rc == 0):1150 output=(0,'Login Successful')11511152 elif task == '2':1153 keyname = input("Enter Key name : ")1154 output = sp.getstatusoutput("{} 'aws ec2 create-key-pair --key-name {}'".format(ssh,keyname))1155 elif task == '3':1156 grpname = input("Enter Security group name : ")1157 description = input("Give Description of your security group : ")1158 output = sp.getstatusoutput("{} 'aws ec2 create-security-group --group-name {} --description {} --vpc-id vpc-c62ecead'".format(ssh,grpname,description))1159 elif task == '4':1160 grpid = input("Enter groyp id : ")1161 protocol = input("Enter protocol you want to add : ")1162 port = input("Enter port number : ")1163 output = sp.getstatusoutput("{} 'aws ec2 authorize-security-group-ingress --group-id {} --protocol {} --port {} --cidr 0.0.0.0/0'".format(ssh,grpid,protocol,port))1164 elif task == '5':1165 image = input("Enter image id : ")1166 instance = input("Enter instance-type : ")1167 count = input("Enter no.of instance you want to launch : ")1168 sgid = input("Enter security group id : ")1169 keyname = input("Enter Key name : ")11701171 output = sp.getstatusoutput("{} 'aws ec2 run-instances --image-id {} --instance-type {} --count {} --security-groups {} --key-name {}'".format(ssh,image,instance,count,sgid,keyname))1172 elif task == '6':1173 size = input("Enter size of youe ebs volume : ")1174 az = input("Enter availability-zone in which you want to create volume : ")1175 ebsname = input("Enter a name which you want to give to your volume : ")1176 output = sp.getstatusoutput("{} 'aws ec2 create-volume --volume-type gp2 --size {} --availability-zone {} --tag-specifications \'ResourceType=volume,Tags=[\'{\'Key=name,Value= {}}]\''".format(ssh,size,az,ebsname))1177 elif task == '7':1178 print("Before attaching EBS volume to an instance make sure your EBS volume and instance are in the same availability zone")1179 instance = input("Enter instance-id to which you want to attach: ")1180 volid = input("Enter volume-id which you want to attach : ")1181 output = sp.getstatusoutput("{} 'aws ec2 attach-volume --volume-id {} --instance-id {} --device /dev/sdf'".format(ssh,volid,instance))1182 elif task == '8':1183 bucketname = input("Enter bucket name : ")1184 region = input("Enter region in which you want to create bucket : ")1185 output = sp.getstatusoutput("{} 'aws s3 mb s3://{} --region {}'".format(ssh,bucketname,region))1186 elif task == '9':1187 bucketname = input("Enter bucket name : ")1188 output = sp.getstatusoutput("{} 'aws cloudfront create-distribution --origin-domain-name {}.s3.amazonaws.com'".format(ssh,bucketname))1189 elif task == '10':1190 output = sp.getstatusoutput("{} 'aws ec2 describe-instances'".format(ssh))1191 elif task == '11':1192 output = sp.getstatusoutput("{} 'aws ec2 describe-key-pairs'".format(ssh))1193 elif task == '12':1194 output = sp.getstatusoutput("{} 'aws ec2 describe-security-groups'".format(ssh))11951196 elif task == '13':1197 instance = input("Enter the instance id which you want to stop: ")1198 output = sp.getstatusoutput("{} 'aws ec2 stop-instances --instance-ids {}'".format(ssh,instance))11991200 elif task == '14':1201 instance = input("Enter the instance id which you want to start: ")1202 output = sp.getstatusoutput("{} 'aws ec2 start-instances --instance-ids {}'".format(ssh,instance))1203 elif task == '15':1204 b_name = input("Enter bucket name: ")1205 img_name = input("Enter image file name: ")1206 permission = input("Enter permission you want to give eg.,public-read: ")1207 ouput = sp.getstatusoutput("{} 'aws s3api put-object-acl --bucket {} --key {} --acl {}'".format(ssh,b_name,img_name,permission))12081209 elif task == '16':1210 img_path = input("Enter the complete path of the image you want to upload: ")1211 b_name = input("Enter name of the bucket: ")1212 output = sp.getstatusoutput("{} 'aws s3 sync \"{}\" s3\:\/\/{}\ '".format(ssh,img_path,b_name))1213 elif task == '17':1214 break;12151216 else:1217 print("Invalid Option!!")1218 os.system("sleep 1")1219 continue12201221 if output[0] == 0:1222 os.system("tput setaf 2")1223 print("Task successfully completed !!")1224 os.system("tput setaf 7")1225 print(output[1])1226 else:1227 os.system("tput setaf 5")1228 print("Oops !! Some error occurred : {}".format(output[1]))12291230 os.system("tput setaf 6")1231 input("'Press enter' to continue :")1232 os.system("tput setaf 7")123312341235123612371238def docker(ssh):1239 rc= sp.getstatusoutput("systemctl status docker")1240 if(rc != 0):1241 rc= sp.getstatusoutput("systemctl start docker")1242 if(rc == 0):1243 print("Docker running successfully!!")12441245 while True :12461247 os.system("clear")1248 os.system("tput setaf 3")1249 print("\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~ Welcome to our DOCKER menu ~~~~~~~~~~~~~~~~~~~~~~~~~~\n")1250 os.system("tput setaf 6")1251 menu="""1252 \t\tPress 1 :To install docker1253 1254 \t\tPress 2 :To download a docker image1255 \t\tPress 3 :To see docker images available1256 \t\tPress 4 :To launch a docker container1257 \t\tPress 5 :To start a container\n1258 \t\tPress 6 :To stop a container1259 \t\tPress 7 :To attach to container1260 \t\tPress 8 :To remove a docker container1261 \t\tPress 9 :To remove all conatiners1262 \t\tPress 10 :To see info of all running containers1263 \t\tPress 11 :To see info of all existing containers1264 \t\tPress 12 :To see logs of a container1265 \t\tPress 13 :To see logs of all container1266 \t\tPress 14 :To see all info about the container1267 \t\tPress 15 :To search for docker images12681269 \t\tPress 16 :To go back to main menu or exit from this menu\n"""1270 print(menu)1271 os.system("tput setaf 7")1272 task = input("Enter your choice : ")12731274 if ssh == {}:127512761277 if(task == '1'):1278 os.system("touch /etc/yum.repos.d/docker-ce.repo".format(ssh))1279 output = sp.getstatusoutput("echo '[docker]\nbaseurl = https://download.docker.com/linux/centos/7/x86_64/stable/Packages/\ngpgcheck=0' > /etc/yum.repos.d/docker-ce.repo")1280 if(output[0] == 0):1281 output = sp.getstatusoutput("yum install docker-ce --nobest")1282 os.system("docker info")12831284 elif(task == '2'):1285 image = input("Enter docker image name : ")1286 output = sp.getstatusoutput("docker pull {}".format(image))1287 elif(task == '3'):1288 output = sp.getstatusoutput("docker images")1289 elif(task == '4'):1290 image = input("Enter docker image name as (<image_name>:<version>) : ")1291 cname = input("Enter container name : ")1292 print("Enter 'exit' to exit container")1293 rc = os.system("docker run -it --name {} {}".format(cname,image))1294 if rc == 0:1295 output = (0,"")1296 elif(task == '5'):1297 cname = input("Enter container name : ")1298 output = sp.getstatusoutput("docker start {}".format(cname))1299 elif(task == '6'):1300 cname = input("Enter container name : ")1301 output = sp.getstatusoutput("docker stop {}".format(cname))1302 elif(task == '7'):1303 cname = input("Enter container name : ")1304 print("Enter 'exit' to exit container")1305 rc = os.system("docker attach {}".format(cname))1306 if rc == 0:1307 output = (0,"")1308 elif(task == '8'):1309 cname = input("Enter container name : ")1310 output = sp.getstatusoutput("docker rm {}".format(cname))1311 elif(task == '9'):1312 output = sp.getstatusoutput("docker rm -f `docker ps -a -q`")1313 elif(task == '10'):1314 output = sp.getstatusoutput("docker ps")1315 elif(task == '11'):1316 output = sp.getstatusoutput("docker ps -a")1317 elif(task == '12'):1318 cname = input("Enter container name : ")1319 output = sp.getstatusoutput("docker logs {}".format(cname))1320 elif(task == '13'):1321 output = sp.getstatusoutput("docker logs")1322 elif(task == '14'):1323 cname = input("Enter container name : ")1324 output = sp.getstatusoutput("docker inspect {}".format(cname))1325 elif(task == '15'):1326 image = input("Enter docker image name which you wanr to search: ")1327 output = sp.getstatusoutput("docker search {}".format(image))13281329 elif task == '16':1330 break;13311332 else:1333 print("Invalid Option!!")1334 os.system("sleep 1")1335 continue13361337 if output[0] == 0:1338 os.system("tput setaf 2")1339 print("Task successfully completed !!")1340 os.system("tput setaf 7")1341 print(output[1])1342 else:1343 os.system("tput setaf 5")1344 print("Oops !! Some error occurred : {}".format(output[1]))13451346 os.system("tput setaf 6")1347 input("'Press enter' to continue :")1348 os.system("tput setaf 7")13491350 else:13511352 if(task == '1'):1353 os.system("{} 'touch /etc/yum.repos.d/docker-ce.repo'".format(ssh))1354 output = sp.getstatusoutput("{} \'echo '[docker]\nbaseurl = https://download.docker.com/linux/centos/7/x86_64/stable/Packages/\ngpgcheck=0' > /etc/yum.repos.d/docker-ce.repo\'".format(ssh))1355 if(output[0] == 0):1356 output = sp.getstatusoutput("{} 'yum install docker-ce --nobest'".format(ssh))1357 os.system("{} 'docker info'".format(ssh))13581359 elif(task == '2'):1360 image = input("Enter docker image name : ")1361 output = sp.getstatusoutput("{} 'docker pull {}'".format(ssh,image))1362 elif(task == '3'):1363 output = sp.getstatusoutput("{} 'docker images'".format(ssh))1364 elif(task == '4'):1365 image = input("Enter docker image name as (<image_name>:<version>) : ")1366 cname = input("Enter container name : ")1367 print("Enter 'exit' to exit container")1368 rc = os.system("{} 'docker run -it --name {} {}'".format(ssh,cname,image))1369 if rc == 0:1370 output = (0,"")1371 elif(task == '5'):1372 cname = input("Enter container name : ")1373 output = sp.getstatusoutput("{} 'docker start {}'".format(ssh,cname))1374 elif(task == '6'):1375 cname = input("Enter container name : ")1376 output = sp.getstatusoutput("{} 'docker stop {}'".format(ssh,cname))1377 elif(task == '7'):1378 cname = input("Enter container name : ")1379 print("Enter 'exit' to exit container")1380 rc = os.system("{} 'docker attach {}'".format(ssh,cname))1381 if rc == 0:1382 output = (0,"")1383 elif(task == '8'):1384 cname = input("Enter container name : ")1385 output = sp.getstatusoutput("{} 'docker rm {}'".format(ssh,cname))1386 elif(task == '9'):1387 output = sp.getstatusoutput("{} 'docker rm -f `docker ps -a -q`'".format(ssh))1388 elif(task == '10'):1389 output = sp.getstatusoutput("{} docker ps".format(ssh))1390 elif(task == '11'):1391 output = sp.getstatusoutput("{} 'docker ps -a'".format(ssh))1392 elif(task == '12'):1393 cname = input("Enter container name : ")1394 output = sp.getstatusoutput("{} 'docker logs {}'".format(ssh,cname))1395 elif(task == '13'):1396 output = sp.getstatusoutput("{} 'docker logs'".format(ssh))1397 elif(task == '14'):1398 cname = input("Enter container name : ")1399 output = sp.getstatusoutput("{} 'docker inspect {}'".format(ssh,cname))1400 elif(task == '15'):1401 image = input("Enter docker image name which you wanr to search: ")1402 output = sp.getstatusoutput("{} 'docker search {}'".format(ssh,image))14031404 elif task == '16':1405 break;14061407 else:1408 print("Invalid Option!!")1409 os.system("sleep 1")1410 continue14111412 if output[0] == 0:1413 os.system("tput setaf 2")1414 print("Task successfully completed !!")1415 os.system("tput setaf 7")1416 print(output[1])1417 else:1418 os.system("tput setaf 5")1419 print("Oops !! Some error occurred : {}".format(output[1]))14201421 os.system("tput setaf 6")1422 input("'Press enter' to continue :")1423 os.system("tput setaf 7")142414251426 142714281429def server(ssh):14301431 while True:14321433 os.system("clear")1434 os.system("tput setaf 3")1435 print("\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~ Welcome to our Server menu ~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n\n")1436 print("Before Configuring webserver, configure yum once if not configured : Press 5")1437 os.system("tput setaf 6")14381439 mainmenu="""1440 \t\tPress 1 : Configure Apache Web Server on linux1441 \t\tPress 2 : Start Apache Web Server on linux1442 \t\tPress 3 : Host webpage Apache Web Server1443 \t\tPress 4 : Configure yum repository1444 \t\tPress 5:To go back to main menu or exit from this menu\n"""1445 print(mainmenu)14461447 os.system("tput setaf 7")1448 task = input("Enter your choice : ")14491450 14511452 if ssh =="":1453 #local sys1454 if task == '1':14551456 print("Installing httpd software... Be patient!!")1457 rc = os.system("yum install httpd")1458 if(rc == 0):1459 webpage = input("Enter webpage file path which you want to host: ")1460 os.system("cp {} /var/www/html".format(webpage))1461 output = sp.getstatusoutput("systemctl start httpd")14621463 elif task == '2':1464 output = sp.getstatusoutput("systemctl start httpd")1465 output = sp.getstatusoutput("systemctl status httpd")14661467 elif task == '3':1468 webpage = input("Enter webpage file path which you want to host: ")1469 os.system("cp {} /var/www/html".format(webpage))1470 ouput = (0, "WEBPAGE hosted!!!")14711472 elif task == '4':1473 print("Configuring yum. please Wait!!!")1474 output = sp.getstatusoutput("yum install --nogpgcheck https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm")1475 os.system(" yum repolist")147614771478 elif task == '5':1479 break;14801481 else:1482 print("Invalid Option!!")1483 os.system("sleep 1")1484 continue14851486 if output[0] == 0:1487 os.system("tput setaf 2")1488 print("Task successfully completed !!")1489 print("Web Server configured!! Services started successfully !!! ")1490 os.system("tput setaf 7")1491 print(output[1])1492 else:1493 os.system("tput setaf 5")1494 print("Oops !! Some error occurred : {}".format(output[1]))14951496 os.system("tput setaf 6")1497 input("'Press enter' to continue :")1498 os.system("tput setaf 7")14991500 else:1501 #remote sys1502 if task == '1':15031504 print("Installing httpd software... Be patient!!")1505 rc = os.system("{} 'yum install httpd'".format(ssh))1506 print("Installing httpd software... Be patient!!")1507 if(rc== 0):1508 webpage = input("Enter webpage file path which you want to host: ")1509 os.system("{} 'cp {} /var/www/html'".format(ssh,webpage))1510 output = sp.getstatusoutput("{} 'systemctl start httpd'".format(ssh))15111512 elif task == '2':1513 output = sp.getstatusoutput("{} systemctl start httpd".format(ssh))1514 output = sp.getstatusoutput("{} systemctl status httpd".format(ssh))15151516 elif task == '3':1517 webpage = input("Enter webpage file path which you want to host: ")1518 os.system("{} 'cp {} /var/www/html'".format(ssh,webpage))1519 ouput = (0, "WEBPAGE hosted!!!")15201521 elif task == '4':1522 print("Configuring yum. please Wait!!!")1523 output = sp.getstatusoutput("{} 'yum install --nogpgcheck https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm'".format(ssh))1524 os.system("{} 'yum repolist'".format(ssh))152515261527 elif task == '5':1528 break;15291530 else:1531 print("Invalid Option!!")1532 os.system("sleep 1")1533 continue15341535 if output[0] == 0:1536 os.system("tput setaf 2")1537 print("Task successfully completed !!")
...
hadoop1copy.py
Source:hadoop1copy.py
1#!/usr/bin/python22import commands3p = raw_input("enter the password : ")4ip=commands.getstatusoutput("hostname -i")[1]5xy=ip.split(".")6ipv=commands.getstatusoutput(" nmap -n -sP {0}.{1}.{2}.0-100|grep report | awk '{{print $5}}'".format(xy[0],xy[1],xy[2]) )[1].split("\n")7ram_list=[]8hdd_list=[]9ca=commands.getstatusoutput("echo {} > /ip.txt".format(ipv))10def see_ram(r):11 if r==ip:12 s=commands.getstatusoutput("free -m | grep Mem | awk '{{print $4}}'")13 return s[1]14 else:15 s=commands.getstatusoutput("sshpass -p {0} ssh -o StrictHostKeyChecking=no root@{1} free -m | grep Mem | awk '{{print $4}}'".format(p,r))16 #print s[1]17 18 return s[1]19def max_ram():20 c=see_ram(i)21 ram_list.append(c)22 #maxram=max(ram_list)23def see_hdd(h):24 if h==ip:25 s=commands.getstatusoutput(" df -l / | grep /dev/mapper/ | awk '{{print $4}}'")26 return s[1]27 else:28 s=commands.getstatusoutput("sshpass -p {0} ssh -o StrictHostKeyChecking=no root@{1} df -l / | grep /dev/mapper/ | awk '{{print $4}}'".format(p,h))29 #print s[1]30 31 return s[1]32def max_hdd():33 c=see_hdd(i)34 hdd_list.append(c)35 # maxhdd=max(hdd_list)36for i in ipv:37 38 39 see_ram(i)40 max_ram()41 see_hdd(i)42 max_hdd()43#KNOWING THE IP44ram_list=[int(i) for i in ram_list] 45print ram_list46hdd_list=[int(i) for i in hdd_list] 47print hdd_list48print ipv49maxram=max(ram_list)50maxhdd=max(hdd_list)51jobtracker_index=ram_list.index(maxram)52namenode_index=hdd_list.index(maxhdd)53jt=ipv[jobtracker_index]54nn=ipv[namenode_index] 55ab=commands.getstatusoutput("echo {} > /jt.txt".format(jt))56ba=commands.getstatusoutput("echo {} > /nn.txt".format(nn))57print jt58print nn59def installing(n):60 jdk=commands.getstatusoutput("sshpass -p {} ssh -o StrictHostKeyChecking=no root@{} rpm -q jdk".format(p,n))61 hadoop=commands.getstatusoutput("sshpass -p {} ssh -o StrictHostKeyChecking=no root@{} rpm -q hadoop".format(p,n))62 if jdk[0]==0:63 64 print "jdk installed at "+n65 else:66 print "installing jdk at"+n67 s1=commands.getstatusoutput("sshpass -p {} ssh -o StrictHostKeyChecking=no root@{} yum install jdk -y".format(p,n))68 69 if hadoop[0]==0:70 print "hadoop already at "+n71 else :72 commands.getstatusoutput("sshpass -p {} scp -o StrictHostKeyChecking=no /root/Desktop/hadoop-1.2.1-1.x86_64.rpm root@{}:/root/Desktop/".format(p,n))73 commands.getstatusoutput("sshpass -p {} ssh -o StrictHostKeyChecking=no root@{} rpm -ivh /root/Desktop/hadoop-1.2.1-1.x86_64.rpm --replacefiles".format(p,n))74def jps(k):75 name=commands.getstatusoutput("sshpass -p {} ssh -o StrictHostKeyChecking=no root@{} rpm -q jdk".format(p,k))76 j=commands.getstatusoutput("sshpass -p {0} ssh -o StrictHostKeyChecking=no root@{1} /usr/java/{2}/bin/jps | grep node".format(p,k,name[1]))77 return j78def setting_nn(r):79 80 commands.getstatusoutput("sshpass -p {} scp -o StrictHostKeyChecking=no /root/Desktop/writtingnode root@{}:/".format(p,r))81 commands.getstatusoutput("sshpass -p {} scp -o StrictHostKeyChecking=no /jt.txt root@{}:/".format(p,r))82 commands.getstatusoutput("sshpass -p {} scp -o StrictHostKeyChecking=no /nn.txt root@{}:/".format(p,r))83 commands.getstatusoutput("sshpass -p {} scp -o StrictHostKeyChecking=no /ip.txt root@{}:/".format(p,r))84 commands.getstatusoutput("sshpass -p {} ssh -o StrictHostKeyChecking=no root@{} python /writtingnode".format(p,r))85 commands.getstatusoutput("sshpass -p {} ssh -o StrictHostKeyChecking=no root@{} hadoop namenode -format".format(p,r))86 commands.getstatusoutput("sshpass -p {} ssh -o StrictHostKeyChecking=no root@{} hadoop-daemon.sh start namenode".format(p,r))87 print "namenode is set"88 #commands.getstatusoutput("sshpass -p {} ssh root@{} /usr/java/jdk/bin/jps".format(p,r))89def setting_dn_tt(t):90 91 commands.getstatusoutput("sshpass -p {} scp -o StrictHostKeyChecking=no /root/Desktop/writtingnode root@{}:/".format(p,t))92 commands.getstatusoutput("sshpass -p {} scp -o StrictHostKeyChecking=no /jt.txt root@{}:/".format(p,r))93 commands.getstatusoutput("sshpass -p {} scp -o StrictHostKeyChecking=no /nn.txt root@{}:/".format(p,r))94 commands.getstatusoutput("sshpass -p {} scp -o StrictHostKeyChecking=no /ip.txt root@{}:/".format(p,r))95 commands.getstatusoutput("sshpass -p {} ssh -o StrictHostKeyChecking=no root@{} python /writtingnode ".format(p,t))96 commands.getstatusoutput("sshpass -p {} ssh -o StrictHostKeyChecking=no root@{} hadoop-daemon.sh start datanode".format(p,t))97 commands.getstatusoutput("sshpass -p {} ssh -o StrictHostKeyChecking=no root@{} hadoop-daemon.sh start tasktracker".format(p,t))98 print "datanode is set"99 #commands.getstatusoutput("sshpass -p {} ssh root@{} /usr/java/jdk/bin/jps".format(p,t))100 101 102def setting_jt(g):103 104 commands.getstatusoutput("sshpass -p {} scp -o StrictHostKeyChecking=no /root/Desktop/writtingnode root@{}:/".format(p,g))105 commands.getstatusoutput("sshpass -p {} scp -o StrictHostKeyChecking=no /jt.txt root@{}:/".format(p,r))106 commands.getstatusoutput("sshpass -p {} scp -o StrictHostKeyChecking=no /nn.txt root@{}:/".format(p,r))107 commands.getstatusoutput("sshpass -p {} scp -o StrictHostKeyChecking=no /ip.txt root@{}:/".format(p,r))108 commands.getstatusoutput("sshpass -p {} ssh -o StrictHostKeyChecking=no root@{} python /writtingnode ".format(p,g))109 commands.getstatusoutput("sshpass -p {} ssh -o StrictHostKeyChecking=no root@{} hadoop-daemon.sh start jobtracker".format(p,g))110 print "jt is set"111 #commands.getstatusoutput("sshpass -p {} ssh root@{} /usr/java/jdk/bin/jps".format(p,g))112for i in ipv:113 installing(i)114 if i==nn:115 setting_nn(i)116 if i==jt:117 setting_jt(i)118 else:...
pico_register_readout.py
Source:pico_register_readout.py
...3# Written by Pontus Petersson (pontus.pson@gmail.com)4# Version 1: 2015-10-165import commands6# RTC data7year = commands.getstatusoutput("i2cget -y 1 0x6A 6")8month = commands.getstatusoutput("i2cget -y 1 0x6A 5")9day = commands.getstatusoutput("i2cget -y 1 0x6A 4")10dow = commands.getstatusoutput("i2cget -y 1 0x6A 3")11hour = commands.getstatusoutput("i2cget -y 1 0x6A 2")12min = commands.getstatusoutput("i2cget -y 1 0x6A 1")13sec = commands.getstatusoutput("i2cget -y 1 0x6A 0")14ccf = commands.getstatusoutput("i2cget -y 1 0x6A 7")15days_of_the_week = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']16YEAR = "20" + year[1][2:]17MONTH = month[1][2:]18DAY = day[1][2:]19DOW = days_of_the_week[int(dow[1][3:])-1]20HOUR = hour[1][2:]21MIN = min[1][2:]22SEC = sec[1][2:]23CCF = ccf[1][2:]24print("--- RTC data ---")25print(YEAR+"-"+MONTH+"-"+DAY+" "+DOW+" "+HOUR+":"+MIN+":"+SEC+" /"+CCF+"\n")26# Status registers27mode = commands.getstatusoutput("i2cget -y 1 0x69 0")28batlevel_1 = commands.getstatusoutput("i2cget -y 1 0x69 2")29batlevel_2 = commands.getstatusoutput("i2cget -y 1 0x69 1")30rpilevel_1 = commands.getstatusoutput("i2cget -y 1 0x69 4")31rpilevel_2 = commands.getstatusoutput("i2cget -y 1 0x69 3")32tmpcels = commands.getstatusoutput("i2cget -y 1 0x69 12")33powering_modes = ['RPi', 'Bat']34MODE = powering_modes[int(mode[1][2:])-1]35BATLEVEL = batlevel_1[1][3:]+"."+batlevel_2[1][2:]+" V"36RPILEVEL = rpilevel_1[1][3:]+"."+rpilevel_2[1][2:]+" V"37TMPCELS = tmpcels[1][2:]+" "+unichr(176)+"C"38print("--- Status registers --- ")39print("Mode\t\tBat_lvl\t\tRPi_lvl\t\tTemp")40print(MODE+"\t\t"+BATLEVEL+"\t\t"+RPILEVEL+"\t\t"+TMPCELS+"\n")41# Module commands42version = commands.getstatusoutput("i2cget -y 1 0x6B 0")43error_code = commands.getstatusoutput("i2cget -y 1 0x6B 1")44rpi_serror_1 = commands.getstatusoutput("i2cget -y 1 0x6B 3")45rpi_serror_2 = commands.getstatusoutput("i2cget -y 1 0x6B 2")46bat_serror_1 = commands.getstatusoutput("i2cget -y 1 0x6B 5")47bat_serror_2 = commands.getstatusoutput("i2cget -y 1 0x6B 4")48tmp_serror_1 = commands.getstatusoutput("i2cget -y 1 0x6B 7")49tmp_serror_2 = commands.getstatusoutput("i2cget -y 1 0x6B 6")50sta_counter = commands.getstatusoutput("i2cget -y 1 0x6B 8")51fssd_batime = commands.getstatusoutput("i2cget -y 1 0x6B 9")52lprsta = commands.getstatusoutput("i2cget -y 1 0x6B 10")53btto = commands.getstatusoutput("i2cget -y 1 0x6B 11")54led_blue = commands.getstatusoutput("i2cget -y 1 0x6B 12")55led_red = commands.getstatusoutput("i2cget -y 1 0x6B 13")56buzmode = commands.getstatusoutput("i2cget -y 1 0x6B 14")57fanmode = commands.getstatusoutput("i2cget -y 1 0x6B 15")58fanspeed = commands.getstatusoutput("i2cget -y 1 0x6B 16")59xbmc = commands.getstatusoutput("i2cget -y 1 0x6B 23")60fssd_tout = commands.getstatusoutput("i2cget -y 1 0x6B 24")61status = ['OFF', 'ON']62buz_fan_modes = ['Disabled', 'Enabled', 'Automatic', 'Unknown']63fan_speeds = ['0', '100', '25', '50', '75']64VERSION = version[1][2:]65ERROR_CODE = '{0:08b}'.format(int(error_code[1][2:]))66RPI_SERROR = rpi_serror_1[1][3:]+"."+rpi_serror_2[1][2:]+" V"67BAT_SERROR = bat_serror_1[1][3:]+"."+bat_serror_2[1][2:]+" V"68TMP_SERROR = tmp_serror_1[1][2:]+"."+tmp_serror_2[1][2:]+" "+unichr(176)+"C"69STA_COUNTER = int(sta_counter[1], 16)70FSSD_BATIME = int(fssd_batime[1], 16)71LPRSTA = int(lprsta[1], 16)72BTTO = int(btto[1], 16)73LED_BLUE = status[int(led_blue[1][3:])]74LED_RED = status[int(led_red[1][3:])]...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!