设置容器日志切割 @param get: @return:
(self, get)
| 1369 | return public.returnMsg(True, e) |
| 1370 | |
| 1371 | def docker_split(self, get): |
| 1372 | """ |
| 1373 | 设置容器日志切割 |
| 1374 | @param get: |
| 1375 | @return: |
| 1376 | """ |
| 1377 | try: |
| 1378 | client = self.docker_client(self._url) |
| 1379 | if not client: |
| 1380 | return public.returnMsg(True, 'docker连接失败') |
| 1381 | containers = client.containers |
| 1382 | clist = [i.attrs for i in containers.list(all=True)] |
| 1383 | name = [dp.rename(i['Name'][1:]) for i in clist if i['Id'] == get.pid] |
| 1384 | if name: |
| 1385 | name = name[0] |
| 1386 | else: |
| 1387 | name = '' |
| 1388 | if not hasattr(get, 'type'): |
| 1389 | return public.returnMsg(False, '参数错误,请传入:type') |
| 1390 | if not public.M('sqlite_master').where('type=? AND name=?', ('table', 'docker_log_split')).count(): |
| 1391 | public.M('docker_log_split').execute('''CREATE TABLE IF NOT EXISTS docker_log_split ( |
| 1392 | id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 1393 | name text default '', |
| 1394 | pid text default '', |
| 1395 | log_path text default '', |
| 1396 | split_type text default '', |
| 1397 | split_size INTEGER default 0, |
| 1398 | split_hour INTEGER default 2, |
| 1399 | split_minute INTEGER default 0, |
| 1400 | save INTEGER default 180)''', ()) |
| 1401 | if get.type == 'add': |
| 1402 | if "log_path" not in get or not get.log_path: |
| 1403 | return public.returnMsg(False, '容器日志目录不存在,无法设置日志切割!') |
| 1404 | |
| 1405 | if not (hasattr(get, 'pid') and hasattr(get, 'log_path') and |
| 1406 | hasattr(get, 'split_type') and hasattr(get, 'split_size') and |
| 1407 | hasattr(get, 'split_minute') and |
| 1408 | hasattr(get, 'split_hour') and hasattr(get, 'save')): |
| 1409 | return public.returnMsg(False, '参数错误') |
| 1410 | data = { |
| 1411 | 'name': name, |
| 1412 | 'pid': get.pid, |
| 1413 | 'log_path': get.log_path, |
| 1414 | 'split_type': get.split_type, |
| 1415 | 'split_size': get.split_size, |
| 1416 | 'split_hour': get.split_hour, |
| 1417 | 'split_minute': get.split_minute, |
| 1418 | 'save': get.save |
| 1419 | } |
| 1420 | if public.M('docker_log_split').where('pid=?', (get.pid,)).count(): |
| 1421 | id = public.M('docker_log_split').where('pid=?', (get.pid,)).select() |
| 1422 | public.M('docker_log_split').delete(id[0]['id']) |
| 1423 | public.M('docker_log_split').insert(data) |
| 1424 | return public.returnMsg(True, "开启成功!") |
| 1425 | elif get.type == 'del': |
| 1426 | id = public.M('docker_log_split').where('pid=?', (get.pid,)).getField('id') |
| 1427 | public.M('docker_log_split').where('id=?', (id,)).delete() |
| 1428 | return public.returnMsg(True, "关闭成功!") |
nothing calls this directly
no test coverage detected