-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplicationV2.py
100 lines (71 loc) · 2.47 KB
/
ApplicationV2.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
#19.09.2018
#Version2
#APPLICATION FOR DOCKER SYSTEM
#importing reqired modules
from Tkinter import *
from paramiko import *
from Tkinter import Listbox
import paramiko
#defining main frame
sunucularhostname=[]
sunucularIP=[]
pencere=Tk()
pencere.title("Server Automation")
pencere.geometry("300x400")
#definig name of main frame
header=Label(pencere,text="MANAGE YOUR SERVERS",font=("Open Sans",15,"bold"), fg="steelblue").place(x=10,y=20)
#input and labels in main frame
host=Label(pencere,text="Host IP:").place(x=10,y=50)
hostusername=Label(pencere,text="Username:").place(x=10,y=70)
hostpasswd=Label(pencere,text="Password:").place(x=10,y=90)
IP=StringVar()
Kullaniciadi=StringVar()
Pass=StringVar()
host_entry=Entry(pencere,textvariable=IP).place(x=100,y=50)
kullaniciadi_entry=Entry(pencere,textvariable=Kullaniciadi).place(x=100,y=70)
pass_entry=Entry(pencere,textvariable=Pass,show="*").place(x=100,y=90)
#shows total server in List
toplamsunucu=StringVar()
toplam = Label(pencere, text="Total Servers:")
toplamsunucu.set(len(sunucularIP))
toplam.place(x=10, y=150)
sonuc=Label(pencere,textvariable=toplamsunucu)
sonuc.place(x=90,y=150)
#Create Function for connct button and hold IPs and hostnames in a List
def SSH(*args):
global y
PORT=22
client = SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(IP.get(), PORT, Kullaniciadi.get(),Pass.get())
stdin,stdout,stderr=client.exec_command("hostname")
output=stdout.readlines()
sunucularhostname.append(output[0])
if len(sunucularIP)==0:
sunucularIP.append(IP.get())
elif len(sunucularIP)!=0:
if IP.get() in sunucularIP:
pass
else:
sunucularIP.append(IP.get())
print sunucularIP
toplamsunucu.set(len(sunucularIP))
#client.close()
#connect and add devices to system
connect=Button(pencere,text="Connect",command=SSH).place(x=130,y=120)
# test function
def foo():
print "nice"
#create menubar assigning to main frame
my_menu=Menu(pencere,tearoff=0)
pencere.config(menu=my_menu)
devices_menu=Menu(my_menu,tearoff=0)
my_menu.add_cascade(label='Devices',menu=devices_menu)
devices_menu.add_command(label="IPlist",command=foo)
devices_menu.add_separator()
devices_menu.add_command(label="Hostnamelist",command=foo)
edit_menu=Menu(my_menu,tearoff=0)
my_menu.add_cascade(label="Edit",menu=edit_menu)
#provide connection by enter button of keyboard
pencere.bind('<Return>', SSH)
pencere.mainloop()