-
Notifications
You must be signed in to change notification settings - Fork 3
/
menu.py
1027 lines (876 loc) · 31.4 KB
/
menu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import getpass
import pyfiglet
import socket
import subprocess as sp
os.system("clear")
# Contributors
os.system("tput setaf 3")
print("""
\n\tHacktober 2021 - Project Contributors
\t1. Yagyandatta Murmu (Author)
\t2. Deepak Patra
\t3. Laxman Naik
\t4. Sweta Sardar
\t5. Abhishek Dwibedy
""")
input("\nEnter To Continue...")
os.system("clear")
# Design
os.system("tput setaf 4")
title = pyfiglet.figlet_format("Hacktober", font = "epic" )
print(title)
os.system("tput setaf 2")
msg = pyfiglet.figlet_format("Welcome You", font = "digital" )
print(msg)
# Auth
passwd = getpass.getpass(" Enter Your Password : ")
if passwd != "hacktober":
print("Your password is invalid. Please try again")
exit()
where = input("Where you want to run this menu ? (local/remote) : ")
print(where)
def print_msg_box(msg, indent=1, width=None, title=None):
os.system("tput setaf 2")
"""Print message-box with optional title."""
lines = msg.split('\n')
space = " " * indent
if not width:
width = max(map(len, lines))
box = f'╔{"═" * (width + indent * 2)}╗\n' # upper_border
if title:
box += f'║{space}{title:<{width}}{space}║\n' # title
box += f'║{space}{"-" * len(title):<{width}}{space}║\n' # underscore
box += ''.join([f'║{space}{line:<{width}}{space}║\n' for line in lines])
box += f'╚{"═" * (width + indent * 2)}╝' # lower_border
print(box)
while True:
os.system("clear")
os.system("tput setaf 3")
print("\t\t\t Menu Bar")
os.system("tput setaf 7")
print("\t\t-----------------------")
msg = "press 0 : Linux Command menu\n" \
"Press 1 : Hadoop menu\n" \
"Press 2 : Docker menu\n" \
"Press 3 : Web Server menu\n" \
"Press 4 : AWS menu\n" \
"Press 5 : Exit\n"
print_msg_box(msg=msg, indent=2, title='All Services')
if where == "local":
os.system("tput setaf 1")
ch = input("Enter choice (service): ")
print(ch)
if int(ch) == 0:
while True:
os.system("clear")
os.system("tput setaf 2")
msg ="Press 1 : Check Date\n" \
"Press 2 : Check Calender\n" \
"Press 3 : Check your IP \n" \
"Press 4 : Check RAM Status \n" \
"Press 5 : Check Storage details \n" \
"press 6 : To Clear Cache\n" \
"press 7 : To Transfer File to Other Linux System\n" \
"press 8 : Query any command details\n" \
"press 9 : Go Back\n" \
"press 10 : To Exit"
print_msg_box(msg=msg, indent=2, title='Linux Command:')
os.system("tput setaf 4")
ch=input("choose your option : ")
os.system("tput setaf 3")
print(ch)
if int(ch) == 0:
exit()
elif int(ch) == 1:
os.system("date")
elif int(ch) == 2:
os.system("cal")
elif int(ch) == 3:
os.system("ifconfig")
elif int(ch) == 4:
os.system("free -m")
elif int(ch) == 5:
os.system("df -h")
elif int(ch) == 6:
os.system("echo 3 > /proc/sys/vm/drop_caches")
elif int(ch) == 7:
ip = input("Enter IP of target system : ")
user = input("Enter username : ")
src = input("Enter your source file path : ")
dest = input("Enter destination folder path where you want to copy : ")
output = getpass.getstatusoutput("scp {} {}@{}:{}".format(src, user,ip,dest))
elif int(ch) == 8:
cmd_name = input("Enter Command Name: ")
os.system(f"man {cmd_name}")
elif int(ch) == 9:
break
elif int(ch) == 10:
exit()
else:
print("Incorrect Input")
input("\nEnter To Continue...")
# Hadoop...
elif int(ch) == 1:
while True:
os.system("clear")
os.system("tput setaf 4")
msg ="Press 1 : Install Jdk and Hadoop\n" \
"Press 2 : Configure NameNode\n" \
"Press 3 : Start NameNode Service\n" \
"Press 4 : Configure DataNode\n" \
"Press 5 : Start DataNode Service\n" \
"Press 6 : Configure Client\n" \
"Press 7 : Cluster Report\n" \
"press 8 : Check SafeMode(nameNode)\n" \
"press 9 : Disable Safemode in Namenode \n" \
"press 10 : Upload a File into Cluster\n" \
"press 11 : Read the File Upload into the Cluster\n" \
"press 12 : Create a File in Cluster\n" \
"press 13 : Delete a File in Cluster\n" \
"press 14 : List Files in Cluster\n" \
"press 15 : Go Back\n" \
"press 0 : Exit.."
print_msg_box(msg=msg, indent=2, title='Hadoop Command:')
os.system("tput setaf 4")
ch=input("choose your option : ")
print(ch)
#Hadoop-installation
if int(ch) == 1:
os.system("rpm -ivh jdk-8u171-linux-x64.rpm;rpm -ivh hadoop-1.2.1-1.x86_64.rpm --force")
#namenode
elif int(ch) == 2:
os.system("rm -rf /nn")
os.system("mkdir /nn")
f=open("/etc/hadoop/hdfs-site.xml","w")
x=("""<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>dfs.name.dir</name>
<value>/nn</value>
</property>
</configuration>""")
f.write(x)
f.close
x=("""<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://0.0.0.0:9001</value>
</property>
</configuration>
""")
f=open("/etc/hadoop/core-site.xml","w")
f.write(x)
f.close
os.system('hadoop namenode -format ')
elif int(ch) == 3:
os.system('hadoop-daemon.sh start namenode')
#dataNode
elif int(ch) == 4:
os.system("rm -rf /dn")
os.system("mkdir /dn")
x=("""<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>dfs.data.dir</name>
<value>/dn</value>
</property>
</configuration>""")
f=open("/etc/hadoop/hdfs-site.xml","w")
f.write(x)
f.close
x=("""<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://192.168.43.102:9001</value>
</property>
</configuration>
""")
f=open("/etc/hadoop/core-site.xml","w")
f.write(x)
f.close
elif int(ch) == 5:
os.system("hadoop-daemon.sh start datanode")
#clint
elif int(ch) == 6:
x=("""<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://192.168.43.102:9001</value>
</property>
</configuration> """)
f=open("/etc/hadoop/core-site.xml","w")
f.write(x)
f.close
#other basic commands
elif int(ch) == 7:
os.system("hadoop dfsadmin -report | less")
elif int(ch) == 8:
os.system("hadoop dfsadmin -safemode get")
elif int(ch) == 9:
os.system("hadoop dfsadmin -safemode leave")
elif int(ch) == 10:
name = input('Enter File Name :')
os.system(f"hadoop fs -put {name}/")
elif int(ch) == 11:
name = input('Enter File Name :')
os.system(f"hadoop fs -cat {name}/")
elif int(ch) == 12:
name = input('Enter File Name :')
os.system(f"hadoop fs -touchz {name}/")
elif int(ch) == 13:
name = input('Enter File Name :')
os.system(f"hadoop fs -rm {name}/")
elif int(ch) == 14:
os.system(f"hadoop fs -ls /")
elif int(ch) == 15:
break
elif int(ch) == 0:
exit()
else:
print("Incorrect Number")
input("\ncontinue...")
#docker
elif int(ch) == 2:
while True:
os.system("clear")
os.system("tput setaf 2")
msg = "press 0 : Verify Docker is Installed or Not\n" \
"Press 1 : Install Docker\n" \
"Press 2 : Start Docker\n" \
"Press 3 : Search Docker Image\n" \
"Press 4 : List All Docker Images\n" \
"Press 5 : Pull Docker Image\n" \
"Press 6 : Launch a Container with Name\n" \
"Press 7 : List Running Docker Containers\n" \
"press 8 : Start a Container\n" \
"press 9 : Get Terminal of runing container\n" \
"press 10 : Launch GUI Software (i.e. Firefox) inside Docker Container\n" \
"press 11 : Stop a Container \n" \
"Press 12 : Delete a Container\n" \
"Press 13 : Delete an Image\n" \
"Press 14 : Delete all Container\n" \
"Press 15 : Go Back\n" \
"Press 16 : Exit.."
print_msg_box(msg=msg, indent=2, title='Docker Command:')
os.system("tput setaf 4")
ch=input("choose your option : ")
print(ch)
if int(ch) == 0:
os.system("rpm -q docker-ce")
#docker installation
elif int(ch) == 1:
os.system('yum install docker-ce')
elif int(ch) == 2:
os.system('systemctl start docker')
elif int(ch) == 3:
OS = input("Enter the docker image Name : ")
os.system(f"docker search {OS}")
elif int(ch) == 4:
os.system('docker images -a')
elif int(ch) == 5:
OS = input("Enter docker image name :")
os.system(f'docker pull -i {OS}')
elif int(ch) == 6:
NAME = input("Enter imagename and version (OSname:00.00):")
myName = input("Give a new OS name :")
os.system(f'docker run -it --name {myName} {NAME}')
elif int(ch) == 7:
os.system('docker ps')
elif int(ch) == 8:
NAME = input("Enter The OS name :")
os.system(f'docker start {NAME}')
elif int(ch) == 9:
NAME = input("Enter The OS name :")
os.system(f'docker attach {NAME}')
elif int(ch) == 10:
NAME = input("Enter The OS name :")
os.system('docker run -it --name {NAME} --env="DISPLAY" --net=host firefox:v1')
elif int(ch) == 11:
NAME = input("Enter The OS name :")
os.system(f'docker stop {NAME}')
elif int(ch) == 12:
NAME = input("Enter The OS name :")
os.system('docker rm -f {NAME}')
elif int(ch) == 13:
NAME = input("Enter The image name :")
os.system('docker rmi -f {NAME}')
elif int(ch) == 14:
os.system('docker rm `docker ps -a -q` ')
elif int(ch) == 15:
break
elif int(ch) == 16:
exit()
else:
print("Incorrect Number")
input("\nEnter To Continue...")
# webserver
elif int(ch) == 3:
while True:
os.system("clear")
os.system("tput setaf 2")
msg = "press 0 : Check Apache Web Server is Installed or Not\n" \
"Press 1 : Start Httpd Service\n" \
"Press 2 : Disable Firewall and Set Enforcing\n" \
"Press 3 : Restart Httpd Service\n" \
"Press 4 : Configure Total Webserver\n" \
"Press 5 : Go Back\n" \
"press 6 : Exit.. "
print_msg_box(msg=msg, indent=2, title='webserver Commands:')
os.system("tput setaf 4")
ch=input("choose your option : ")
print(ch)
if int(ch) == 0:
os.system("rpm -q httpd")
elif int(ch) == 1:
os.system('yum install httpd;systemctl start httpd')
elif int(ch) == 2:
os.system('systemctl stop firewalld;setenforce 0')
elif int(ch) == 3:
os.system('systemctl restart httpd')
elif int(ch) == 4:
Soc=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
IP=Soc.getsockname()[0]
T=input("\tEnter your message to preview on web :")
os.system('yum install httpd')
os.system('cd /var/www/html/')
os.system('touch web.html')
os.system(f'echo "{T}" > /var/www/html/web.html')
os.system('systemctl start httpd')
os.system('systemctl stop firewalld')
os.system('setenforce 0')
os.system(f'firefox http://"{IP}"/web.html')
elif int(ch) == 5:
break
elif int(ch) == 6:
exit()
else:
print("Incorrect Number")
input("\ncontinue...")
# AWS
elif int(ch) == 4:
while True:
os.system("clear")
os.system("tput setaf 2")
msg = "press 0 : Check if AWS-Cli is Installed or Not\n" \
"Press 1 : Create your Security Group \n" \
"Press 2 : Create your Key-Pair \n" \
"Press 3 : Launch an Instance \n" \
"Press 4 : Describe your Instance \n" \
"Press 5 : Start your Instance \n" \
"Press 6 : Stop your Instance \n" \
"Press 7 : Terminate your Instance \n" \
"Press 8 : Create an EBS Storage \n" \
"Press 9 : Attach EBS with ec2 Instance \n" \
"Press 10 : Create a S3 Bucket \n" \
"Press 11 : Create CloudFront \n" \
"Press 12 : Go Back\n" \
"press 13 : Exit.. \n"
print_msg_box(msg=msg, indent=2, title='AWS Commands:')
os.system("tput setaf 4")
ch=input("choose your option : ")
print(ch)
if int(ch) == 0:
os.system("rpm -q aws")
elif int(ch) == 1:
name = input("Enter Group Name : ")
des = input("Enter description : ")
os.system(f"aws ec2 create-security-group --group-name {name} --description '{des}' ")
elif int(ch) == 2:
name = input("Enter Key Name : ")
os.system(f'aws ec2 create-key-pair --key-name {name} --query KeyMaterial > awskey.pem --output text > {name}.pem')
elif int(ch) == 3:
while True:
os.system("clear")
os.system("tput setaf 2")
msg ="Press 0 : Want to write your own \n" \
"Press 1 : Amazon Linux 2 AMI (HVM), SSD Volume Type \n" \
"Press 2 : Red Hat Enterprise Linux 8 (HVM), SSD Volume Type \n" \
"Press 3 : SUSE Linux Enterprise Server 15 SP2 (HVM), SSD Volume Type \n" \
"Press 4 : Ubuntu Server 20.04 LTS (HVM), SSD Volume Type \n" \
"Press 5 : Microsoft Windows Server 2019 Base \n" \
"press 6 : Microsoft Windows Server 2019 Base with Containers \n"
print_msg_box(msg=msg, indent=2, title='Choose Your AMI:')
os.system("tput setaf 4")
ch=input("choose your option : ")
os.system("tput setaf 4")
print(ch)
if int(ch) == 0:
ami = input("Enter your AMI : ")
elif int(ch) == 1:
ami = "ami-0e306788ff2473ccb"
elif int(ch) == 2:
ami = "ami-0a9d27a9f4f5c0efc"
elif int(ch) == 3:
ami = "ami-0d0522ed4db1debd6"
elif int(ch) == 4:
ami = "ami-0a4a70bd98c6d6441"
elif int(ch) == 5:
ami = "ami-0994975f92b8520bc"
elif int(ch) == 6:
ami = "ami-0cc51168ed03dd131"
else:
print("Invalid choice")
os.system("clear")
os.system("tput setaf 2")
msg ="Press 0 : Write your own \n" \
"Press 1 : ap-south-1a \n" \
"Press 2 : ap-south-1b \n" \
"Press 3 : ap-south-1c \n"
print_msg_box(msg=msg, indent=2, title='Choose Your zone:')
os.system("tput setaf 4")
ch=input("Choose your Option : ")
os.system("tput setaf 4")
print(ch)
if int(ch) == 0:
subnet = input("Enter your zone : ")
elif int(ch) == 1:
subnet = "subnet-b86168d0"
elif int(ch) == 2:
subnet = "subnet-63e39c2f"
elif int(ch) == 3:
subnet = "subnet-9458d9ef"
else:
print("Invalid choice")
break
sg = input("Enter Your security group id : ")
key = input("Enter Your key-name : ")
#print(f"entered ami- {ami} and zone - {subnet} and {sg} and {key}")
os.system(f"aws ec2 run-instances --image-id {ami} --instance-type t2.micro --count 1 --subnet-id {subnet} --security-group-ids {sg} --key-name {key}")
elif int(ch) == 4:
id = input("Enter your Instance Id : ")
os.system(f"aws ec2 describe-instances --instance-ids {id}")
elif int(ch) == 5:
id = input("Enter your Instance Id : ")
os.system(f"aws ec2 start-instances --instance-ids {id}")
elif int(ch) == 6:
id = input("Enter your Instance Id : ")
os.system(f"aws ec2 stop-instances --instance-ids {id}")
elif int(ch) == 7:
id = input("Enter your Instance Id : ")
os.system(f"aws ec2 terminate-instances --instance-ids {id}")
elif int(ch) == 8:
size = input("Enter your Volume Size (in GB): ")
os.system(f"aws ec2 create-volume --availability-zone ap-south-1a --size {size}")
elif int(ch) == 9:
id = input("Enter your Volume Id : ")
ids = input("Enter your instance id : ")
os.system(f"aws ec2 attach-volume --volume-id {id} --instance-id {ids} --device /dev/sdf")
elif int(ch) == 10:
name = input("Enter the Bucket Name: ")
os.system(f"aws s3api create-bucket --bucket {name} --create-bucket-configuration LocationConstraint=ap-south-1")
elif int(ch) == 11:
name = input("Enter the Domain Name: ")
name = input("Enter the file name with extension (unknown.jpg): ")
os.system(f"aws cloudfront create-distribution --origin-domain-name {name}.s3.amazonaws.com --default-root-object {fname}")
elif int(ch) == 12:
break
elif int(ch) == 13:
exit()
else:
print("Incorrect Number")
input("\n Enter To Continue...")
elif int(ch) == 5:
exit()
elif where == "remote":
ip = input("Enter remote IP: ")
print(ip)
ch = input("Enter choice (service): ")
print(ch)
if int(ch) == 0:
while True:
os.system("clear")
os.system("tput setaf 2")
msg ="Press 1 : Check Date\n" \
"Press 2 : Check Calender\n" \
"Press 3 : Check IP\n" \
"Press 4 : Check Httpd Status\n" \
"Press 5 : Start Httpd \n" \
"press 6 : To Clear Cache\n" \
"press 7 : To Change any Command Name\n" \
"press 8 : Go Back \n" \
"press 9 : To Exit\n"
print_msg_box(msg=msg, indent=2, title='Linux Command:')
os.system("tput setaf 4")
ch=input("choose your option : ")
print(ch)
if int(ch) == 1:
os.system("ssh {} date".format(ip))
elif int(ch) == 2:
os.system("ssh {} cal".format(ip))
elif int(ch) == 3:
os.system("ssh {} ifconfig".format(ip))
elif int(ch) == 4:
os.system("ssh {} systemctl status httpd".format(ip))
elif int(ch) == 5:
os.system("ssh {} systemctl start httpd".format(ip))
elif int(ch) == 6:
os.system("ssh {} echo 3 > /proc/sys/vm/drop_caches".format(ip))
elif int(ch) == 7:
print("change name")
elif int(ch) == 8:
break
elif int(ch) == 9:
exit()
else:
print("Incorrect Number")
input("\nEnter To Continue...")
#hadoop
elif int(ch) == 1:
while True:
os.system("clear")
os.system("tput setaf 4")
msg="press 0 : To Exit\n"\
"Press 1 : Install Jdk and Hadoop\n"\
"Press 2 : Configure DataNode\n" \
"Press 3 : Configure NameNode\n" \
"Press 4 : Configure Client\n" \
"Press 5 : Check the Connected Datanodes\n" \
"press 6 : Check SafeMode in NameNode\n" \
"press 7 : Disable Safemode in Namenode\n " \
"press 8 : Upload a File into Cluster\n" \
"press 9 : Read the File Upload into the Cluster\n" \
"press 10 : Create a File in Cluster\n" \
"press 11 : Delete a File in Cluster\n" \
"press 12 : List Files in Cluster\n" \
"press 13 : Go Back..\n"
print_msg_box(msg=msg, indent=2, title='Hadoop Command:')
os.system("tput setaf 4")
ch=input("choose your option : ")
print(ch)
#Hadoop-installation
if int(ch) == 1:
os.system("ssh {} rpm -ivh jdk-8u171-linux-x64.rpm".format(ip))
os.system("ssh {} rpm -ivh hadoop-1.2.1-1.x86_64.rpm --force".format(ip))
#namenode
elif int(ch) == 2:
os.system("ssh {} rm -rf /nn".format(ip))
os.system("ssh {} mkdir /nn".format(ip))
os.system("ssh {} ".format(ip))
f=open("/etc/hadoop/hdfs-site.xml","w")
x=("""<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>dfs.name.dir</name>
<value>/nn</value>
</property>
</configuration>""")
f.write(x)
f.close
x=("""<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://0.0.0.0:9001</value>
</property>
</configuration>
""")
f=open("/etc/hadoop/core-site.xml","w")
f.write(x)
f.close
os.system("ssh {} hadoop namenode -format".format(ip))
os.system("ssh {} hadoop-daemon.sh start namenode".format(ip))
#dataNode
elif int(ch) == 3:
os.system("ssh {} rm -rf /nn".format(ip))
os.system("ssh {} mkdir /nn".format(ip))
os.system("ssh {} ".format(ip))
x=("""<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>dfs.data.dir</name>
<value>/dn</value>
</property>
</configuration>""")
f=open("/etc/hadoop/hdfs-site.xml","w")
f.write(x)
f.close
x=("""<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://192.168.43.102:9001</value>
</property>
</configuration>
""")
f=open("/etc/hadoop/core-site.xml","w")
f.write(x)
f.close
os.system("ssh {} hadoop-daemon.sh start datanode".format(ip))
#clint
elif int(ch) == 4:
os.system("ssh {} ".format(ip))
x=("""<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://192.168.43.102:9001</value>
</property>
</configuration> """)
f=open("/etc/hadoop/core-site.xml","w")
f.write(x)
f.close
#other basic commands
elif int(ch) == 5:
os.system("ssh {} hadoop dfsadmin -report | less".format(ip))
elif int(ch) == 6:
os.system("ssh {} hadoop dfsadmin -safemode get".format(ip))
elif int(ch) == 7:
os.system("ssh {} hadoop dfsadmin -safemode leave".format(ip))
elif int(ch) == 8:
name = input("Enter File Name :")
os.system("ssh {} hadoop fs -put {name}/".format(ip))
elif int(ch) == 9:
name = input('Enter File Name :')
os.system("ssh {} hadoop fs -cat {name}/".format(ip))
elif int(ch) == 10:
name = input('Enter File Name :')
os.system("ssh {} hadoop fs -touchz {name}/".format(ip))
elif int(ch) == 11:
name = input('Enter File Name :')
os.system("ssh {} hadoop fs -rm {name}/".format(ip))
elif int(ch) == 12:
os.system(f"hadoop fs -ls /")
elif int(ch) == 13:
break
elif int(ch) == 0:
exit()
else:
print("Incorrect Number")
input("\ncontinue...")
#docker
elif int(ch) == 2:
while True:
os.system("clear")
os.system("tput setaf 4")
msg = "press 0 : To Verify Docker is Installed or Not\n" \
"Press 1 : Install Docker-ce and Start the Service\n" \
"Press 2 : Check All Docker Images\n" \
"Press 3 : Pull a Docker Image and Run\n" \
"Press 4 : Check Running Docker Containers\n" \
"Press 5 : Check the Connected Datanodes\n" \
"press 6 : check safeMode in nameNode\n" \
"press 7 : disable safemode in namenode\n" \
"press 8 : Go back \n" \
"press 9 : exit..."
print_msg_box(msg=msg, indent=2, title='Docker Command:')
os.system("tput setaf 4")
ch=input("choose your option : ")
print(ch)
#Docker-installation
if int(ch) == 0:
os.system("ssh {} rpm -q docker-ce".format(ip))
#docker installation
elif int(ch) == 1:
os.system("ssh {} yum install docker-ce".format(ip))
os.system("ssh {} systemctl start docker".format(ip))
elif int(ch) == 2:
os.system("ssh {} docker images -a".format(ip))
elif int(ch) == 3:
os.system("ssh {} docker ps -a".format(ip))
elif int(ch) == 4:
os.system("ssh {} ".format(ip))
OS = input("Enter docker image name :")
os.system(f'docker load -i {OS}'.format(ip))
NAME = input("Enter imagename and version :")
os.system(f'docker run -it {NAME}'.format(ip))
elif int(ch) == 5:
os.system("ssh {} docker ps".format(ip))
else:
os.system("tput setaf 1")
print("Incorrect Number")
input("\ncontinue...")
elif int(ch) == 3:
while True:
os.system("clear")
os.system("tput setaf 2")
msg = "press 0 : Check Apache Web Server is Installed or Not\n" \
"Press 1 : Start Httpd Service\n" \
"Press 2 : Disable Firewall and Set Enforcing\n" \
"Press 3 : Restart Httpd Service\n" \
"Press 4 : Configure Total Webserver\n" \
"Press 5 : Go Back\n" \
"press 6 : Exit.. "
print_msg_box(msg=msg, indent=2, title='AWS Commands:')
os.system("tput setaf 4")
ch=input("choose your option : ")
print(ch)
if int(ch) == 0:
os.system("rpm -q httpd")
elif int(ch) == 1:
os.system('yum install httpd;systemctl start httpd'.format(ip))
elif int(ch) == 2:
os.system('systemctl stop firewalld;setenforce 0'.format(ip))
elif int(ch) == 3:
os.system('systemctl restart httpd'.format(ip))
elif int(ch) == 4:
Soc=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
IP=Soc.getsockname()[0]
T=input("\tEnter your message to preview on web :")
os.system('yum install httpd'.format(ip))
os.system('cd /var/www/html/'.format(ip))
os.system('touch web.html'.format(ip))
os.system(f'echo "{T}" > /var/www/html/web.html'.format(ip))
os.system('systemctl start httpd'.format(ip))
os.system('systemctl stop firewalld'.format(ip))
os.system('setenforce 0'.format(ip))
os.system(f'firefox http://"{IP}"/web.html'.format(ip))
elif int(ch) == 5:
break
elif int(ch) == 6:
exit()
else:
print("Incorrect Number")
input("\ncontinue...")
elif int(ch) == 4:
while True:
os.system("clear")
os.system("tput setaf 2")
msg = "press 0 : Check if AWS-Cli is Installed or Not\n" \
"Press 1 : Create your Security Group \n" \
"Press 2 : Create your Key-Pair \n" \
"Press 3 : Launch an Instance \n" \
"Press 4 : Describe your Instance \n" \
"Press 5 : Start your Instance \n" \
"Press 6 : Stop your Instance \n" \
"Press 7 : Terminate your Instance \n" \
"Press 8 : Create an EBS Storage \n" \
"Press 9 : Attach EBS with ec2 Instance \n" \
"Press 10 : Create a S3 Bucket \n" \
"Press 11 : Create CloudFront \n" \
"Press 12 : Go Back\n" \
"press 13 : Exit.. \n"
print_msg_box(msg=msg, indent=2, title='AWS Commands:')
os.system("tput setaf 4")
ch=input("choose your option : ")
print(ch)
if int(ch) == 0:
os.system("rpm -q aws".format(ip))
elif int(ch) == 1:
name = input("Enter Group Name : ")
des = input("Enter description : ")
os.system(f"aws ec2 create-security-group --group-name {name} --description '{des}' ".format(ip))
elif int(ch) == 2:
name = input("Enter Key Name : ")
os.system(f'aws ec2 create-key-pair --key-name {name} --query KeyMaterial > awskey.pem --output text > {name}.pem'.format(ip))
elif int(ch) == 3:
while True:
os.system("clear")
os.system("tput setaf 2")
msg ="Press 0 : Want to write your own \n" \
"Press 1 : Amazon Linux 2 AMI (HVM), SSD Volume Type \n" \
"Press 2 : Red Hat Enterprise Linux 8 (HVM), SSD Volume Type \n" \
"Press 3 : SUSE Linux Enterprise Server 15 SP2 (HVM), SSD Volume Type \n" \
"Press 4 : Ubuntu Server 20.04 LTS (HVM), SSD Volume Type \n" \
"Press 5 : Microsoft Windows Server 2019 Base \n" \
"press 6 : Microsoft Windows Server 2019 Base with Containers \n"
print_msg_box(msg=msg, indent=2, title='Choose Your AMI:')
os.system("tput setaf 4")
ch=input("choose your option : ")
os.system("tput setaf 4")
print(ch)
if int(ch) == 0:
ami = input("Enter your AMI : ")
elif int(ch) == 1:
ami = "ami-0e306788ff2473ccb"
elif int(ch) == 2:
ami = "ami-0a9d27a9f4f5c0efc"
elif int(ch) == 3:
ami = "ami-0d0522ed4db1debd6"
elif int(ch) == 4:
ami = "ami-0a4a70bd98c6d6441"
elif int(ch) == 5:
ami = "ami-0994975f92b8520bc"
elif int(ch) == 6:
ami = "ami-0cc51168ed03dd131"
else:
print("Invalid choice")
os.system("clear")
os.system("tput setaf 2")
msg ="Press 0 : Write your own \n" \
"Press 1 : ap-south-1a \n" \
"Press 2 : ap-south-1b \n" \
"Press 3 : ap-south-1c \n"
print_msg_box(msg=msg, indent=2, title='Choose Your zone:')
os.system("tput setaf 4")
ch=input("Choose your Option : ")
os.system("tput setaf 4")
print(ch)
if int(ch) == 0:
subnet = input("Enter your zone : ")
elif int(ch) == 1:
subnet = "subnet-b86168d0"
elif int(ch) == 2:
subnet = "subnet-63e39c2f"
elif int(ch) == 3:
subnet = "subnet-9458d9ef"
else:
print("Invalid choice")
break
sg = input("Enter Your security group id : ")
key = input("Enter Your key-name : ")
#print(f"entered ami- {ami} and zone - {subnet} and {sg} and {key}")
os.system(f"aws ec2 run-instances --image-id {ami} --instance-type t2.micro --count 1 --subnet-id {subnet} --security-group-ids {sg} --key-name {key}")
elif int(ch) == 4:
id = input("Enter your Instance Id : ")
os.system(f"aws ec2 describe-instances --instance-ids {id}".format(ip))
elif int(ch) == 5:
id = input("Enter your Instance Id : ")
os.system(f"aws ec2 start-instances --instance-ids {id}".format(ip))
elif int(ch) == 6:
id = input("Enter your Instance Id : ")
os.system(f"aws ec2 stop-instances --instance-ids {id}".format(ip))
elif int(ch) == 7:
id = input("Enter your Instance Id : ")
os.system(f"aws ec2 terminate-instances --instance-ids {id}".format(ip))
elif int(ch) == 8:
size = input("Enter your Volume Size (in GB): ")
os.system(f"aws ec2 create-volume --availability-zone ap-south-1a --size {size}".format(ip))
elif int(ch) == 9:
id = input("Enter your Volume Id : ")
ids = input("Enter your instance id : ")
os.system(f"aws ec2 attach-volume --volume-id {id} --instance-id {ids} --device /dev/sdf".format(ip))
elif int(ch) == 10:
name = input("Enter the Bucket Name: ")
os.system(f"aws s3api create-bucket --bucket {name} --create-bucket-configuration LocationConstraint=ap-south-1".format(ip))
elif int(ch) == 11:
name = input("Enter the Domain Name: ")
name = input("Enter the file name with extension (unknown.jpg): ")
os.system(f"aws cloudfront create-distribution --origin-domain-name {name}.s3.amazonaws.com --default-root-object {fname}".format(ip))
elif int(ch) == 12:
break
elif int(ch) == 13:
exit()
else:
print("Incorrect Number")
input("\n Enter To Continue...")
elif int(ch) == 5:
exit()