示例#1
0
def check_ssh_authorization(host, ssh_name, ssh_passwd):
    try:
        if ':' in host:
            host = host.split(':')[0]
        logger.debug('ssh_host:%s' % host)
        SSHConnection(host, 22, ssh_name, ssh_passwd)
        return True
    except:
        logger.error('【SSH】登陆FlexSafe Server失败,请检查【SSH】用户账号、密码、IP是否正确!')
        return False
示例#2
0
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重启完成-----")
示例#3
0
def exec_rollback():
    try:
        ssh = SSHConnection(host, 22, ssh_name, ssh_passwd)
    except:
        logger.error('未知错误')
        sys.exit(1)

    ssh.put(localpath, remotepath + '/' + tar_name)
    logger.info('正在执行还原操作...')
    logger.info('正在执行还原操作...')
    logger.info('正在执行还原操作...')
    ssh.exec_command(
        'cd /home/{ssh_name}/;'
        'tar -zxvf {tar_name}; '
        'cd rollback;'
        ' sudo bash iso_rollback.sh'.format(ssh_name=ssh_name,
                                            tar_name=tar_name), ssh_passwd)
示例#4
0
def del_archieve():
    # 只考虑share_path为/flexsafe/data/volume的情况
    logger.info('正在删除存档文件')
    share_path = '/flexsafe/data/volume/'
    share_names = excuseSQL(host, ssh_account, 'flexsafe', '''SELECT share_name FROM flexsafe.archive_dir;''')
    ssh = SSHConnection(host, 22, ssh_account[0], ssh_account[1])
    options = {
        'webdav_hostname': "http://%s/remote.php/webdav" % host,
        'webdav_login': "******",
        'webdav_password': "******"
    }
    client = wc.Client(options)
    for share_name in share_names:
        print(client.clean('%s/' % share_name))
        ssh.exec_command('sudo chattr -R -i %s%s/*' % (share_path, share_name), ssh_account[1])
        ssh.exec_command('sudo rm -fr %s%s' % (share_path, share_name), ssh_account[1])

    logger.info('正在清空Flexsafe存档相关表【archive_dir】')
    excuseSQL(host, ssh_account, 'flexsafe', '''TRUNCATE TABLE archive_dir;''')
示例#5
0
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}; '
    'cd pvl;'
    ' sudo bash pvl.sh'.format(ssh_name=ssh_name, tar_name=tar_name),
    ssh_passwd)
示例#6
0
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))

from loguru import logger

from flexsafe_utils.SSHConnection import SSHConnection
from flexsafe_utils.common import ssh_login, get_current_time, parse_ip

print('''
功能:

    1.自动与172.16.71.180服务器同步时间。
    
''')
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)
    logger.debug('get_current_time:' + get_current_time())
    ssh.exec_command("sudo date -s '{}';".format(get_current_time()), ssh_passwd)
    logger.info('设置成功,【%s】当前时间为【%s】' % (host, get_current_time()))
except:
    logger.error('未知错误')
    sys.exit(1)
示例#7
0
    def mvFiles(self, ssh_name, ssh_passwd, confirm):
        localpath = [license_path, licenseLib_path]
        remotepath = '/home/%s/' % ssh_name
        if ssh_name == 'root':
            remotepath = '/root/'
        try:
            ssh = SSHConnection(parse_ip(self.input_ip), 22, ssh_name, ssh_passwd)
        except:
            logger.error('未知错误')
            logger.info('ssh_name:' + ssh_name)
            logger.info('ssh_passwd:' + ssh_passwd)
            logger.info('host:' +parse_ip(self.input_ip))
            sys.exit(1)
        for i in localpath:
            logger.info("-----正在上传【%s】至Flexsafe....-----" % i)
            logger.debug('remotepath:' + remotepath + str(i).split('/')[-1])
            ssh.put(i, remotepath + str(i).split('/')[-1])
        ssh.exec_command('cd /home/%s/;sudo mv license libLicenseConfig.so /usr/lib/jni/' % ssh_name, ssh_passwd)

        if confirm == '0' or confirm == '':
            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失败,请手动重启!')
                    os._exit(0)
        if confirm == '1':
            ssh.exec_command('sudo reboot', ssh_passwd)

        # 检查Jetty状态
        http_url = 'http://' + parse_ip(self.input_ip)
        if ':' not in self.input_ip:
            http_url = 'http://' + parse_ip(self.input_ip) + ':8080'
        check_jetty(http_url, 200)
示例#8
0
文件: tt.py 项目: luka9527/Lukas_proj
import sys

sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
from loguru import logger

from flexsafe_utils.SSHConnection import SSHConnection
from flexsafe_utils.common import ssh_login

host = '172.16.71.168'
ssh_info = ssh_login(host)
ssh_name = ssh_info[0]
ssh_passwd = ssh_info[1]

host_name = '172.16.71.168'
cfback_passwd = 'cfbackup'

try:
    ssh = SSHConnection(host, 22, ssh_name, ssh_passwd)
except:
    logger.error('未知错误')
    sys.exit(1)
local_dir_name = 'bak_configure'
current_dir = os.path.dirname(os.path.abspath(__file__))
localpath = os.path.join(current_dir, local_dir_name)
ssh.put(localpath, '/home/cfservice/' + local_dir_name)
# ssh.exec_command('cd /home/{ssh_name}/;'
#                  'sudo rm -fr /root/.ssh;'
#                  'sudo tar -zxvf {tar_name} -C /root/; '
#                  .format(ssh_name=ssh_name, tar_name=tar_name, host_name=host_name, cfback_passwd=cfback_passwd),
#                  ssh_passwd)
示例#9
0
from flexsafe_utils.SSHConnection import SSHConnection

from flexsafe_utils.common import flexsafe_login, config_mail, enable_clock, add_cloud_backup, ssh_login, \
    get_current_time, enable_special_control, parse_ip

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)
    logger.debug('get_current_time:' + get_current_time())
    ssh.exec_command("sudo date -s '{}';".format(get_current_time()), ssh_passwd)
except:
    logger.error('未知错误')
    sys.exit(1)

authorization = flexsafe_login(host)[0]
print('''
功能:

    1.配置邮箱服务器。
    2.开启【加锁功能】、【专用管控功能】。
    3.配置【阿里云】备份服务器。
    4.配置【亚马逊】备份服务器。
    5.配置本地备份服务器。