添加keys 发布接口

This commit is contained in:
pengtao 2019-11-05 14:23:43 +08:00
parent fdc40c8c8f
commit 9d1c3114f6

View File

@ -2,6 +2,7 @@
from ops.mmysql import MysqlBase
from ops.mansible import AnsibleAPI
from ops.mlog import define_logger
from ops.common import run_cmd
import logging
import datetime
import os
@ -29,10 +30,9 @@ class DeployKeys:
def run(self):
svn_path, ipadr = self.get_config()
if svn_path:
key_path = f"{svn_path}/keys"
if ipadr:
args = dict()
tar_file = self.build_svn_tar(key_path)
tar_file = self.build_svn_tar()
if tar_file:
hostfile = self.build_hostfile()
args['hostfile'] = hostfile
@ -57,7 +57,6 @@ class DeployKeys:
mydb = MysqlBase(**dbargs)
data = mydb.query(sql)
ip_addr = list()
pdb.set_trace()
if data:
for line in data:
try:
@ -70,31 +69,32 @@ class DeployKeys:
return (svn_path, ip_addr)
def build_svn_tar(self, svn_path):
def build_svn_tar(self):
try:
log.info("svn export config start")
s = svn.remote.RemoteClient(svn_path)
if self.svn_paths:
shutil.rmtree(self.svn_paths)
s.export(self.svn_paths, force=True)
log.info("svn export config success")
pdb.set_trace()
cmd = f"cd {self.svn_paths} && svn up"
status, output = run_cmd(cmd)
if status:
log.info("svn export config success")
else:
raise Exception("update svn failed!")
except Exception:
log.error(f"get remote {self.project} svn failed", exc_info=True)
else:
log.info("tarfile {0} config to tar.gz start".format(self.project))
tar = tarfile.open(self.svn_paths + '.tar.gz', 'w:gz')
os.chdir(self.svn_paths)
project_paths = os.path.join(self.svn_paths, self.project)
tar = tarfile.open(project_paths + '.tar.gz', 'w:gz')
os.chdir(self.project_paths)
for f in os.listdir(self.svn_paths):
tar.add(f)
tar.close()
# 判断是否有生成tar包
list_dir = os.listdir(self.svn_base)
list_dir = os.listdir(project_paths)
tar_files = list()
for i in list_dir:
if i == "{0}.tar.gz".format(self.project) and os.path.isfile(os.path.join(self.basedir, i)):
tar_files.append(os.path.join(self.basedir, i))
if i == "{0}.tar.gz".format(self.project) and os.path.isfile(os.path.join(project_paths, i)):
tar_files.append(os.path.join(project_paths, i))
if len(tar_files) == 1:
log.info("tarfile {0} config to tar.gz success".format(self.project))
return tar_files
@ -111,6 +111,7 @@ class DeployKeys:
return host_files
def ansible_deploy(self, args):
pdb.set_trace()
an = AnsibleAPI(args['hostfile'])
data = {'dest_filename': 'x', 'source': 'x', 'project': 'x'}
resule = an.run_playbook('deploy_keys.yml', **data)