def go(self): """ used : go to server """ username = self.config['username'] password = self.config['password'] key_file = self.config['key_file'] paramiko_log = recursiveSearchFile(project_abdir, '*paramiko.log')[0] paramiko.util.log_to_file(paramiko_log) s = paramiko.SSHClient() s.load_system_host_keys() s.set_missing_host_key_policy(paramiko.AutoAddPolicy()) #go to server try: if key_file == '' and (username != '' and password != ''): s.connect(self.ip_domain, self.port, username, password) elif key_file != '': key = paramiko.RSAKey.from_private_key_file(key_file) s.connect(self.ip_domain, self.port, username, pkey=key) else: error_msg = "[action]:get paramikoconfig " \ "[status]:FAIL" \ "[Errorcode]:paramikoconfig error" \ "[ip_domain]:{ip_domain}" \ "[port]:{port}" \ "[username]:{username}" \ "[password]:{password}" \ "[key_file]:{key_file}".format(ip_domain=self.ip_domain, port=self.port, username=username, password=password, key_file=key_file) logger.error(error_msg) return 'paramikoconfig error' exec_info = "[action]:go to server" \ "[status]:OK" \ "[ip_domain]:{ip_domain}" \ "[port]:{port}".format(ip_domain=self.ip_domain, port=self.port) logger.info(exec_info) return s except Exception, e: error_msg = "[action]:go to server" \ "[status]:FAIL" \ "[Errorcode]:{e}" \ "[ip_domain]:{ip_domain}" \ "[port]:{port}".format(ip_domain=self.ip_domain, port=self.port, e=e) logger.info(error_msg)
Created on 2017-8-29 @module: material trace @used: get material component """ from . import api from flask import request, jsonify, Response import json from Backend.utils.MyFILE import project_abdir, recursiveSearchFile from Backend.utils.MyLOG import MyLog logConfig = recursiveSearchFile(project_abdir, '*logConfig.ini')[0] mylog = MyLog(logConfig, 'material_trace_old.py') logger = mylog.outputLog() from Backend.utils.MyCONN import MySQL import configparser config = configparser.ConfigParser() colConfig = recursiveSearchFile(project_abdir, '*metaConfig.ini')[0] config.read(colConfig) from Backend.app.views import auth __all__ = ['materialtrace'] __author__ = 'zhihao'