k8s-node自动挂存储(python)
#!/usr/bin/env python
# _*_ coding:utf-8 _*_
# Author:Mzk
import paramiko
glusterfs01 = '1xxx'
glusterfs02 = '1xxx'
mkdir_path = '/data01'
view = ('''\033[32m
-------------------------------
1 View Glusterfs Server Gv List
2 Node Mount All
3 Node Umount All
-------------------------------\033[0m
''')
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
list_gl_vg = []
class vg_glusterfs(object):
def __init__(self,hostname,password):
self.hostname = hostname
self.password = password
ssh.connect(hostname=self.hostname,port=22,username='root',password=self.password)
def view_volume(self):
ssh.connect(hostname=self.hostname,port=22,username='root',password=self.password)
stdin,stdout,stderr = ssh.exec_command("ls %s "%(mkdir_path),get_pty=True )
result = stdout.read()
print(result.decode().strip())
def vg_list(self):
ssh.connect(hostname=self.hostname,port=22,username='root',password=self.password)
stdin,stdout,stderr = ssh.exec_command("ls %s "%(mkdir_path),get_pty=True )
result = stdout.read()
print(result.decode().strip())
list_vg = result.decode().strip().split()
for i in list_vg:
list_gl_vg.append(i)
def node_mount(self):
ssh.connect(hostname=self.hostname,port=22,username='root',password=self.password)
for i in list_gl_vg:
stdin,stdout,stderr = ssh.exec_command("mount -t glusterfs %s:/%s /data01/%s"%(glusterfs01,i,i),get_pty=True )
stdout.read()
print("\033[32mNode Mount OK!\033[0m")
def node_umount(self):
ssh.connect(hostname=self.hostname,port=22,username='root',password=self.password)
for i in list_gl_vg:
stdin,stdout,stderr = ssh.exec_command("umount -t glusterfs %s:/%s /data01/%s"%(glusterfs01,i,i),get_pty=True )
stdout.read()
print("\033[32mNode Umount OK!!!\033[0m")
node243 = vg_glusterfs('1xxx','Sxxx')
node244 = vg_glusterfs('1xxx','Sxxx')
node245 = vg_glusterfs('1xxx','Sxxx')
gluster02 = vg_glusterfs('1xxx','Sxxx')
gluster01 = vg_glusterfs('1xxx','Sxxx')
while 1:
print(view)
user_input = input("Please input number(1,2,3),(q)quit->>").strip().replace(' ','')
if user_input =='q':
ssh.close()
break
elif user_input =='2':
gluster01.vg_list()
node243.node_mount()
node244.node_mount()
node245.node_mount()
ssh.close()
continue
elif user_input =='3':
gluster01.vg_list()
node243.node_umount()
node244.node_umount()
node245.node_umount()
ssh.close()
continue
elif user_input == '1':
gluster01.view_volume()
ssh.close()
continue
ssh.close()

浙公网安备 33010602011771号