forked from muskan399/Python_Assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpluto_assistant.py
More file actions
469 lines (413 loc) · 17.3 KB
/
pluto_assistant.py
File metadata and controls
469 lines (413 loc) · 17.3 KB
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
import subprocess as sp
import pyttsx3
import os
import pyfiglet
#launch os function
def launchOs():
image = input("\n\t\tType the image name with version (like, unbuntu:14.04): ")
#set name for os
osname =input("\t\tSet your os name: ")
#Create new Operating System
output = sp.getstatusoutput("docker run -d -it --name {} {} ".format(osname,image))
if output[0] == 0:
os.system("tput setaf 2")
print("\t\tContainer {} successfully launched ".format(osname))
os.system("tput setaf 7")
input("press Enter Key to continue...")
def menu():
result=pyfiglet.figlet_format(" D O C K E R")
print(result)
op = input('''
\t------------------------------------------------
\t|\tPress 1: Install Docker |
\t|\tPress 2: Download an OS image |
\t|\tPress 3: See existing Images: |
\t|\tPress 4: Launch new container |
\t|\tPress 5: See all running Os |
\t|\tPress 6: See all launch Os |
\t|\tPress 7: Start or Stop container |
\t|\tPress 8: Get the docker terminal |
\t|\tPress 9: Delete an existing Image |
\t|\tPress 10: Clone an Image |
\t|\tPress 11: Remove an existing container |
\t|\tPress 12: Remove all containers |
\t|\tPress 13: Back to main menu |
\t|\tPress 14: Exit |
\t------------------------------------------------
\n\t\t>> ''')
return op
#colored success message
def success(msg):
os.system("tput setaf 2")
print("\t\t{}".format(msg))
os.system("tput setaf 7")
input("press Enter Key to continue...")
def close():
sp.getoutput("pulseaudio --start")
os.system("tput reset")
os.system("figlet 'Thank You'")
os.system("espeak-ng 'Thank you for using my services'")
exit()
#main function
def docker():
option = menu()
if option == '1':
os.system("touch /etc/yum.repos.d/docker-ce.repo")
os.system("echo '[docker]\nbaseurl =https://download.docker.com/linux/centos/7/x86_64/stable/packages/\n gpgcheck=0' > /etc/yum.repos.d/docker-ce.repo")
install = sp.getstatusoutput("yum install -y docker-ce --nobest")
print("\n{}".format(install[1]))
elif option == '2':
pullImg = sp.getstatusoutput("docker image pull {}".format(input("Enter the Image name: ")))
print(pullImg[1])
elif option == '3':
availableImages = sp.getstatusoutput("docker images ")
print("\n{}".format(availableImages[1]))
elif option == '4':
launchOs()
elif option == '5':
runningOs = sp.getstatusoutput("docker ps ")
print("\n{}".format(runningOs[1]))
elif option == '6':
launchedOs = sp.getstatusoutput("docker container ps -a")
print("\n{}".format(launchedOs[1]))
elif option == '7':
op = input('''\t\tPress 1: Start\n\t\tPress 2: Stop\n''')
if op == '1':
output = sp.getstatusoutput("docker start {} ".format(input("\t\tEnter container name: ")))
if output[0] == 0:
success("container started successfully")
elif op == '2':
output = sp.getstatusoutput("docker stop {} ".format(input("\t\tEnter container name: ")))
if output[0] == 0:
success("container stopped successfully")
elif option =='8':
print("\t\tType 'exit' for getout from docker terminal of " )
os.system("docker start {0} && tput setaf 6 && docker exec -it {0} /bin/bash ".format(input("\t\tOS name: ")))
os.system("tput setaf 7")
elif option == '9':
rmImage = input("\t\tEnter image name/id: ")
output= sp.getstatusoutput("docker rmi -f {}".format(rmImage))
if output[0] == 0:
success("Image {} removed successfully".format(rmImage))
elif option == '10':
container = input("\t\tEnter the Os name/id: ")
output = sp.getstatusoutput("docker container ps -a")
if container not in output[1]:
success("OS not found")
else:
cloneName = input("\t\tSet name to new cloned Image: ")
output = sp.getstatusoutput("docker commit {} {}".format(container,cloneName))
if output[0] == 0:
success("Os {} cloned into {} Image successfully".format(container,cloneName))
elif option == '11':
output = sp.getstatusoutput("docker rm -f {}".format(input("\t\tEnter container name: ")))
if output[0] == 0:
success("container removed succesfully")
elif option == '12':
output = sp.getstatusoutput("docker rm -f $(docker container ps -q -a)")
print(output[1])
if output[0] == 0:
success("All containers removed successfully")
os.system("clear")
return option
def hadoop():
print("------------Welcome to APACHE HADOOP SERVICES------------")
print("----You are the Client----")
while True:
os.system("clear")
print("""\n
1. Setup Hadoop Cluster
2. Get details of all slaves
3. List all files in hadoop cluster
4. Upload a file
5. Read a file
6. Remove a file
7. Back to main menu
8. Exit
""")
inp = int(input("Enter your choice: "))
if inp == 7:
text_menu()
elif inp == 8:
close()
os.system("ssh-keygen")
if inp == 1:
#Configuring Master
ip_master = input("Enter ip of master ")
os.system("ssh-copy-id -i /root/.ssh/id_rsa.pub {}".format(ip_master))
os.system("scp jdk-8u171-linux-x64.rpm {}:/".format(ip_master))
os.system("scp hadoop-1.2.1-1.x86_64.rpm {}:/".format(ip_master))
os.system("ssh {} rpm -i /jdk-8u171-linux-x64.rpm".format(ip_master))
os.system("ssh {} rpm -i /hadoop-1.2.1-1.x86_64.rpm --force".format(ip_master))
os.system("ssh {} mkdir /nn".format(ip_master))
os.system("ssh {} echo -e \"`sed -i '$d' /etc/hadoop/hdfs-site.xml`<property>\n<name>dfs.name.dir</name>\n<value>/nn</value>\n</property>\n</configuration>\" >> /etc/hadoop/hdfs-site.xml".format(ip_master))
os.system("ssh {} echo -e \"`sed -i '$d' /etc/hadoop/core-site.xml`<property>\n<name>fs.default.name</name>\n<value>hdfs://{}:9001</value>\n</property>\n</configuration>\" >> /etc/hadoop/core-site.xml".format(ip_master,ip_master))
os.system("ssh {} hadoop namenode -format".format(ip_master))
os.system("ssh {} hadoop-daemon start namenode".format(ip_master))
os.system("ssh {} systemctl stop firewalld".format(ip_master))
#Configuring Slaves
no_of_slaves = int(input("Enter how many slaves you want ?"))
for i in range(1,no_of_slaves+1):
ip_slave = input("Enter ip of slave ")
os.system("ssh-copy-id -i /root/.ssh/id_rsa.pub {}".format(ip_slave))
os.system("scp jdk-8u171-linux-x64.rpm {}:/".format(ip_slave))
os.system("scp hadoop-1.2.1-1.x86_64.rpm {}:/".format(ip_slave))
os.system("ssh {} rpm -i /jdk-8u171-linux-x64.rpm".format(ip_slave))
os.system("ssh {} rpm -i /hadoop-1.2.1-1.x86_64.rpm --force".format(ip_slave))
os.system("ssh {} mkdir /dn{}".format(ip_slave,i))
os.system("ssh {} echo -e \"`sed -i '$d' /etc/hadoop/hdfs-site.xml`<property>\n<name>dfs.data.dir</name>\n<value>/dn{}</value>\n</property>\n</configuration>\" >> /etc/hadoop/hdfs-site.xml".format(ip_slave,i))
os.system("ssh {} echo -e \"`sed -i '$d' /etc/hadoop/core-site.xml`<property>\n<name>fs.default.name</name>\n<value>hdfs://{}:9001</value>\n</property>\n</configuration>\" >> /etc/hadoop/core-site.xml".format(ip_slave,ip_master))
os.system("ssh {} hadoop-daemon start datanode".format(ip_slave))
#Configuring Client
os.system("rpm -i jdk-8u171-linux-x64.rpm")
os.system("rpm -i hadoop-1.2.1-1.x86_64.rpm")
os.system("echo -e \"`sed -i '$d' /etc/hadoop/core-site.xml`<property>\n<name>fs.default.name</name>\n<value>hdfs://{}:9001</value>\n</property>\n</configuration>\" >> /etc/hadoop/core-site.xml".format(ip_master))
elif inp == 2:
os.system("hadoop dfsadmin -report")
elif inp == 3:
os.system("hadoop fs -ls /")
elif inp == 4:
filename = input("Enter filename")
os.system("hadoop fs -put {} /".format(filename))
elif inp == 5:
filename = input("Enter filename")
os.system("hadoop fs -cat {} /".format(filename))
elif inp == 6:
filename = input("Enter filename")
os.system("hadoop fs -rm {} /".format(filename))
os.system("clear")
def text_menu():
os.system("clear")
sp.getoutput("pulseaudio --start")
os.system("tput setaf 2")
os.system("figlet 'Helper Program'")
greet='Hello I am Pluto,your technical helper'
os.system("espeak-ng 'Hello I am Pluto your technical assistant'")
print(greet)
print("-------------------------------------------Here is the menu-------------------------------------\nEnter the option number")
os.system("tput setaf 3")
print("""
1. Cloud Services
2. Docker Services
3. Hadoop Services
4. Exit
""")
os.system("tput setaf 6")
option=int(input())
os.system("clear")
if option==1:
multi_cloud()
elif option==2:
while(1):
o=docker()
if o=='13':
text_menu()
break
elif o=='14':
close()
break
elif option==3:
hadoop()
elif option==4:
close()
def multi_cloud():
os.system("clear")
while(True):
sp.getoutput("pulseaudio --start")
os.system("figlet 'Multi-Cloud Services'")
os.system("espeak-ng 'We are providing Multi Cloud services'")
print("""
1. Amazon Web Services(AWS)
2. Google Cloud Platform(GCP)
3. Go back
4. Exit
""")
os.system("tput setaf 3")
cloud_choice=int(input())
os.system("clear")
if(cloud_choice==1):
aws()
elif(cloud_choice==2):
gcp()
elif(cloud_choice==3):
text_menu()
elif(cloud_choice==4):
close()
os.system("clear")
def aws():
while(True):
sp.getoutput("pulseaudio --start")
os.system("figlet ' AWS'")
os.system("espeak-ng 'Use amazon web services'")
print("""
1. Launch Ec2 instance
2. List all the instances
3. Stop an instance
4. Start an instance
5. Terminate a instance
6. Create a S3 bucket
7. List all the buckets
8. Sync bucket with a local directory
9. Go back
10.Exit
""")
os.system("tput setaf 4")
ch=int(input())
os.system("clear")
if(ch==1):
os.system("figlet Details\n")
print("\n\nEnter the details!!\n")
os.system("espeak-ng 'Enter the details'")
print("\nOS name")
os.system("espeak-ng 'Enter the OS name'")
os_name=input()
x=sp.getstatusoutput("aws ec2 run-instances --image-id ami-026669ec456129a70 --count 1 --instance-type t2.micro --key-name os_key --security-groups default")
if(x[0]==0):
print('\nInstance Launched!!!\n')
os.system("espeak-ng 'Instance launched please check your AWS account'")
else:
print("\nSomething went wrong!!")
os.system("clear")
elif(ch==2):
os.system('aws ec2 describe-instances --query "Reservations[*].Instances[*].{Instance:InstanceId,AZ:Placement.AvailabilityZone,Name:Tags[0].Value,State:State.Name}" --output text')
print("\n\nPress 1 to go back")
e=input()
if(e==1):
multi_cloud()
elif(ch==3):
os.system("figlet Details")
os.system("espeak-ng 'Stop an instance")
os.system("figlet Details\n")
print("\n\nEnter the details!!\n")
os.system("espeak-ng 'Enter the details'")
print("\nOS name")
os.system("espeak-ng 'Enter the instance id'")
os.system('aws ec2 describe-instances --query "Reservations[*].Instances[*].{Instance:InstanceId,AZ:Placement.AvailabilityZone,Name:Tags[0].Value,State:State.Name}" --output text')
ins_id=input()
x=sp.getoutput("aws ec2 stop-instances --instance-id {0}".format(ins_id))
if(x[0]==0):
print("\nInstance Stopped!!!\n")
os.system("espeak-ng 'Instance stopped please check your AWS account'")
else:
print("\nSomething went wrong!!")
os.system("clear")
elif(ch==4):
os.system("figlet Details")
os.system("espeak-ng 'Start an instance")
os.system("figlet Details\n")
print("\n\nEnter the details!!\n")
os.system("espeak-ng 'Enter the details'")
print("\nOS name")
os.system("espeak-ng 'Enter the instance id'")
os.system('aws ec2 describe-instances --query "Reservations[*].Instances[*].{Instance:InstanceId,AZ:Placement.AvailabilityZone,Name:Tags[0].Value,State:State.Name}" --output text')
ins_id=input()
x=sp.getoutput("aws ec2 start-instances --instance-id {0}".format(ins_id))
if(x[0]==0):
print("\nInstance Started!!!\n")
os.system("espeak-ng 'Instance started please check your AWS account'")
else:
print("\nSomething went wrong!!")
os.system("clear")
elif(ch==5):
os.system("figlet Details")
os.system("espeak-ng 'Terminate an instance")
os.system("figlet Details\n")
print("\n\nEnter the details!!\n")
os.system("espeak-ng 'Enter the details'")
print("\nOS name")
os.system("espeak-ng 'Enter the instance id'")
os.system('aws ec2 describe-instances --query "Reservations[*].Instances[*].{Instance:InstanceId,AZ:Placement.AvailabilityZone,Name:Tags[0].Value,State:State.Name}" --output text')
ins_id=input()
x=sp.getstatusoutput("aws ec2 terminate-instances --instance-id {0}".format(ins_id))
if(x[0]==0):
print("\nInstance Terminated!!!\n")
os.system("espeak-ng 'Instance terminated please check your AWS account'")
else:
print("\nSomething went wrong!!")
os.system("clear")
elif(ch==6):
os.system("figlet Details\n")
print("\n\nEnter the details!!\n")
os.system("espeak-ng 'Enter the details'")
print("\nEnter the bucket name")
os.system("espeak-ng 'Enter the Bucket name(Should be unique in a region'")
os_name=input()
x=sp.getoutput('aws s3api create-bucket --bucket bucket9425 --create-bucket-configuration LocationConstraint=ap-south-1 --query {"Location:Location"} --output text')
if(x[0]==0):
print("\nBucket created!!!\n")
os.system("espeak-ng 'Bucket created please check your AWS account'")
else:
print("\nSomething went wrong!!")
os.system("clear")
elif(ch==7):
os.system("aws s3api list-buckets --query 'Buckets[*].{Name:Name,CreationDate: CreationDate}' --output text")
print("\n\nPress 1 to go back")
e=input()
if(e==1):
multi_cloud()
elif(ch==8):
os.system("figlet Details\n")
print("\n\nEnter the details!!\n")
os.system("espeak-ng 'Enter the details'")
print("\nEnter the directory path")
os.system("espeak-ng 'Enter the Directory path'")
dir_path=input()
print("\nBucket name")
os.system("aws s3api list-buckets --query 'Buckets[*].{Name:Name,CreationDate: CreationDate}' --output text")
os.system("espeak-ng 'Enter the Bucket name'")
buc_name=input()
x=sp.getstatusoutput("aws s3 sync {0} s3://{1}".format(dir_path,buc_name))
if(x[0]==0):
print("\nBucket synced!!!\n")
os.system("espeak-ng 'Bucket synced please check your AWS account'")
else:
print("\nSomething went wrong!!")
os.system("clear")
elif(ch==9):
multi_cloud()
elif(ch==10):
close()
break
os.system("clear")
def gcp():
while(True):
sp.getoutput("pulseaudio --start")
os.system("figlet ' GCP'")
os.system("espeak-ng 'Use Google Cloud Platform'")
print("""
*****Work in Progress***
1. Go back
2. Exit
""")
o=int(input())
if o==1:
multi_cloud()
else:
close()
os.system("clear")
os.system("clear")
os.system("tput setaf 4")
sp.getoutput("dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y")
sp.getoutput("yum install figlet -y")
os.system("tput bold")
os.system("figlet 'Welcome !!'")
print("Please enter the choice for communication")
print("""
1. Text
2. Voice
""")
ch=int(input())
os.system("clear")
while(True):
sp.getoutput("pulseaudio --start")
if(ch==1):
text_menu();
else:
r=sr.Recognizer()
print("Please Speak!!!!!")
with sr.Microphone() as source:
a=sp.getoutput("clear")
print(a)
audio=r.listen(source)
ins=r.recognize_google(audio)
print(ins)