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