MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / ModifyCloudServer

Method ModifyCloudServer

class/database.py:463–517  ·  view source on GitHub ↗

@name 修改远程服务器 @author hwliang<2021-01-10> @param id 远程服务器ID @param db_host 服务器地址 @param db_port 数据库端口 @param db_user 用户名 @param db_password 数据库密码 @param db_ps 数

(self, get)

Source from the content-addressed store, hash-verified

461 return public.returnMsg(False, '删除失败: {}'.format(result))
462
463 def ModifyCloudServer(self, get):
464 ''&#x27;
465 @name 修改远程服务器
466 @author hwliang<2021-01-10>
467 @param id<int> 远程服务器ID
468 @param db_host<string> 服务器地址
469 @param db_port<port> 数据库端口
470 @param db_user<string> 用户名
471 @param db_password<string> 数据库密码
472 @param db_ps<string> 数据库备注
473 @return dict
474 ''&#x27;
475 if not hasattr(get, 'id'):
476 return public.returnMsg(False, '参数传递错误,请重试!')
477 if not hasattr(get, 'db_host'):
478 return public.returnMsg(False, '参数传递错误,请重试!')
479 if not hasattr(get, 'db_port'):
480 return public.returnMsg(False, '参数传递错误,请重试!')
481 if not hasattr(get, 'db_user'):
482 return public.returnMsg(False, '参数传递错误,请重试!')
483 if not hasattr(get, 'db_password'):
484 return public.returnMsg(False, '参数传递错误,请重试!')
485 if not hasattr(get, 'db_ps'):
486 return public.returnMsg(False, '参数传递错误,请重试!')
487
488 id = int(get.id)
489 get.db_port = int(get.db_port)
490 db_find = public.M('database_servers').where("id=? AND LOWER(db_type)=LOWER('mysql')", (id,)).find()
491 if not db_find: return public.returnMsg(False, '指定远程服务器不存在!')
492 _modify = False
493 if db_find['db_host'] != get.db_host or db_find['db_port'] != get.db_port:
494 _modify = True
495 if public.M('database_servers').where("db_host=? AND db_port=? AND LOWER(db_type)=LOWER('mysql')", (get.db_host, get.db_port)).count():
496 return public.returnMsg(False, '指定服务器已存在: [{}:{}]'.format(get.db_host, get.db_port))
497
498 if db_find['db_user'] != get.db_user or db_find['db_password'] != get.db_password:
499 _modify = True
500
501 if _modify:
502 res = self.CheckCloudDatabase(get)
503 if isinstance(res, dict): return res
504
505 pdata = {
506 'db_host': get.db_host,
507 'db_port': get.db_port,
508 'db_user': get.db_user,
509 'db_password': get.db_password,
510 'ps': public.xssencode2(get.db_ps.strip())
511 }
512
513 result = public.M("database_servers").where('id=?', (id,)).update(pdata)
514 if isinstance(result, int):
515 public.WriteLog('数据库管理', '修改远程MySQL服务器[{}:{}]'.format(get.db_host, get.db_port))
516 return public.returnMsg(True, '修改成功!')
517 return public.returnMsg(False, '修改失败: {}'.format(result))
518
519 def AddCloudDatabase(self, get):
520 ''&#x27;

Callers

nothing calls this directly

Calls 8

CheckCloudDatabaseMethod · 0.95
returnMsgMethod · 0.80
findMethod · 0.45
whereMethod · 0.45
MMethod · 0.45
countMethod · 0.45
formatMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected