Ejemplo n.º 1
0
 def update_target_db(self, request):
     pk = request.data.get('id')
     instance = DbConf.objects.get(pk=pk)
     params = {
         'db': instance.name,
         'host': instance.host,
         'port': instance.port,
         'user': instance.user,
         'password': prpcrypt.decrypt(instance.password)
     }
     self.conn_database(params)
     return res.get_ret()
Ejemplo n.º 2
0
Archivo: mixins.py Proyecto: zy14/see
 def check(self, request):
     ret = res.get_ret()
     request_data = request.data
     check_type = request_data.get('check_type')
     if check_type == 'inception_conn':
         sub_cmd = "inception get variables"
         cmd = self.get_cmd(sub_cmd)
     else:
         params = {}
         if check_type == 'inception_backup':
             self.conf.read(self.file_path)
             password = self.conf.get('inception',
                                      'inception_remote_system_password')
             params = request_data
             params['password'] = password
             params['db'] = 'inception'
         elif check_type == 'update_target_db':
             db_id = request_data.get('id')
             instance = Dbconf.objects.get(id=db_id)
             params = {
                 'db': instance.name,
                 'host': instance.host,
                 'port': instance.port,
                 'user': instance.user,
                 'password': prpcrypt.decrypt(instance.password)
             }
         elif check_type == 'create_target_db':
             params = request_data
         cmd = self.get_mysql_conn(params)
     popen = subprocess.Popen(cmd,
                              shell=True,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
     lines = popen.stdout.readlines()
     last_item = lines[-1].decode('gbk') if len(lines) > 0 else ''
     if self.error_tag in last_item.lower():
         ret['status'] = -1
         ret['data'] = last_item
     return ret
Ejemplo n.º 3
0
 def get_db_conf(self, user, password, host, port, actiontype):
     password = prpcrypt.decrypt(password)
     return '--user={}; --password={}; --host={}; --port={}; {};'.format(
         user, password, host, port, actiontype)