def restart_jetty(): ssh_account = ssh_login(host) ssh_name = ssh_account[0] ssh_passwd = ssh_account[1] try: ssh = SSHConnection(host, 22, ssh_name, ssh_passwd) except: logger.error('ssh登录失败') sys.exit(1) if ssh_name != 'root': ls = 'sudo ls /etc/init.d/ | grep jetty' jetty_v = ssh.exec_command(ls, ssh_passwd).decode('utf-8').split('\r\n')[2] logger.info("-----正在重启Jetty....-----") logger.debug('jetty_v:' + jetty_v) ssh.exec_command('sudo service %s restart' % jetty_v, ssh_passwd) else: try: ssh.exec_command('service jettydr restart', ssh_passwd) ssh.exec_command('service jettyd restart', ssh_passwd) except: logger.error('重启Jetty失败,请手动重启!') logger.warning("-----所有操作完成,请等待Jetty重启完成-----")
current_dir = os.path.dirname(os.path.abspath(__file__)) tar_name = 'pvl.tar.gz' localpath = os.path.join(current_dir, tar_name) remotepath = '/home/cfservice/' print(''' 功能: 1.自动fdisk划盘 2.自动lvm划分逻辑卷 ''') input_ip = input('请输入FlexSafe Server IP:172.16.') host = parse_ip(input_ip) logger.info("服务器IP:【%s】" % host) ssh_info = ssh_login(host) ssh_name = ssh_info[0] ssh_passwd = ssh_info[1] try: ssh = SSHConnection(host, 22, ssh_name, ssh_passwd) except: logger.error('未知错误') sys.exit(1) ssh.exec_command( 'cd /home/{ssh_name}/;' 'rm -fr ./pvl ./pvl.tar.gz'.format(ssh_name=ssh_name), ssh_passwd) ssh.put(localpath, remotepath + '/' + tar_name) logger.info('正在远程执行脚本,请稍等...') ssh.exec_command( 'cd /home/{ssh_name}/;' 'tar -zxvf {tar_name}; '
if __name__ == '__main__': logger.remove() logger.add(sys.stdout, level="INFO") print(''' 执行步骤: 1.使用默认的SSH账号【cfservice】和密码【cfzoom2016】尝试连接FlexServer,若失败,提示用户进行输入; 2.下载FlexServer的KeyGen文件; 3.通过KeyGen查找License Server上MySQL的license记录,若存在,则进行删除; 4.读取License配置文件【conf.cfg】,请求License Server将license文件发送至邮箱【[email protected]】; 5.读取LibLicense配置文件【conf.cfg】,请求并获取到【libLicenseConfig.so】文件; 6.模拟登陆邮箱【[email protected]】,或取到附件【license】; 7.SSH登陆FlexServer,将license、libLicenseConfig.so移动至路径【/usr/lib/jni】; 8.提供后续操作选项:重启Jetty、重启服务器; ''') f = FlexSafe() confirm = input('''请输入操作选项(默认为0): 0---->重启Jetty; 1---->重启服务器; ''') ssh_account = ssh_login(parse_ip(f.input_ip)) f.get_keygen_text() f.getLibLicense() f.clear_license() f.applyLicense() f.downloadLicenseFromMail() f.mvFiles(ssh_account[0], ssh_account[1], confirm)
import webdav.client as wc from flexsafe_utils.common import flexsafe_login, split_list, ssh_login, excuseSQL import json from loguru import logger from requests import session print(''' 主要功能: 1.快速删除所有【用户】、【用户组及项目组】、【共享目录】、【存档目录】 ''') input_ip = input('请输入FlexSafe Server IP:172.16.') host = '172.16.' + input_ip ssh_account = ssh_login('172.16.' + input_ip) authorization = flexsafe_login(host)[0] header = { "Host": host, "Connection": "keep-alive", "Accept": "application/json, text/plain, */*", "Authorization": authorization, "channel": "1", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8", } # 删除除了staff所有组(包括项目组) def delete_sub_group(g_id):