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

Method AddBaseCloudServer

class/databaseModel/base.py:280–320  ·  view source on GitHub ↗

@name 添加远程服务器 @author hwliang<2021-01-10> @param db_host 服务器地址 @param db_port 数据库端口 @param db_user 用户名 @param db_password 数据库密码 @param db_ps 数据库备注 @param type 数据库类型,mysql/sqlserver/sqlite

(self, get)

Source from the content-addressed store, hash-verified

278 return p.model(get)
279
280 def AddBaseCloudServer(self, get):
281 """
282 @name 添加远程服务器
283 @author hwliang<2021-01-10>
284 @param db_host<string> 服务器地址
285 @param db_port<port> 数据库端口
286 @param db_user<string> 用户名
287 @param db_password<string> 数据库密码
288 @param db_ps<string> 数据库备注
289 @param type<string> 数据库类型,mysql/sqlserver/sqlite
290 @return dict
291 """
292
293 arrs = ['db_host', 'db_port', 'db_user', 'db_password', 'db_ps', 'type']
294 if get.type == 'redis': arrs = ['db_host', 'db_port', 'db_password', 'db_ps', 'type']
295
296 cRet = self.check_cloud_args(get, arrs)
297 if not cRet['status']: return cRet
298
299 get['db_name'] = None
300 res = self.check_cloud_database(get)
301 if isinstance(res, dict): return res
302
303 if public.M('database_servers').where('db_host=? AND db_port=?', (get['db_host'], get['db_port'])).count():
304 return public.returnMsg(False, '指定服务器已存在: [{}:{}]'.format(get['db_host'], get['db_port']))
305 get['db_port'] = int(get['db_port'])
306 pdata = {
307 'db_host': get['db_host'],
308 'db_port': int(get['db_port']),
309 'db_user': get['db_user'],
310 'db_password': get['db_password'],
311 'db_type': get['type'],
312 'ps': public.xssencode2(get['db_ps'].strip()),
313 'addtime': int(time.time())
314 }
315 result = public.M("database_servers").insert(pdata)
316
317 if isinstance(result, int):
318 public.WriteLog('数据库管理', '添加远程MySQL服务器[{}:{}]'.format(get['db_host'], get['db_port']))
319 return public.returnMsg(True, '添加成功!')
320 return public.returnMsg(False, '添加失败: {}'.format(result))
321
322 def GetBaseCloudServer(self, get):
323 ''&#x27;

Callers 3

AddCloudServerMethod · 0.80
AddCloudServerMethod · 0.80
AddCloudServerMethod · 0.80

Calls 9

check_cloud_argsMethod · 0.95
check_cloud_databaseMethod · 0.95
returnMsgMethod · 0.80
timeMethod · 0.80
countMethod · 0.45
whereMethod · 0.45
MMethod · 0.45
formatMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected