a
This commit is contained in:
commit
974c3c394e
23
.gitignore
vendored
Normal file
23
.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
*.pyc
|
||||
*.log
|
||||
*.old
|
||||
.idea/
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
._*
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
Icon?
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
.pem
|
||||
test_*
|
||||
*.pid
|
||||
*.log.*
|
||||
.DS_Store
|
||||
.vscode/settings.json
|
||||
.gitignore
|
||||
.DS_Store
|
||||
*.txt
|
||||
*.csv
|
||||
|
4
.idea/encodings.xml
generated
Normal file
4
.idea/encodings.xml
generated
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
|
||||
</project>
|
7
.idea/misc.xml
generated
Normal file
7
.idea/misc.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavaScriptSettings">
|
||||
<option name="languageLevel" value="ES6" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (venv)" project-jdk-type="Python SDK" />
|
||||
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/ops_interface.iml" filepath="$PROJECT_DIR$/.idea/ops_interface.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
12
.idea/ops_interface.iml
generated
Normal file
12
.idea/ops_interface.iml
generated
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="TestRunnerService">
|
||||
<option name="projectConfiguration" value="Nosetests" />
|
||||
<option name="PROJECT_TEST_RUNNER" value="Nosetests" />
|
||||
</component>
|
||||
</module>
|
BIN
config/__pycache__/__init__.cpython-37.pyc
Normal file
BIN
config/__pycache__/__init__.cpython-37.pyc
Normal file
Binary file not shown.
BIN
config/__pycache__/config.cpython-37.pyc
Normal file
BIN
config/__pycache__/config.cpython-37.pyc
Normal file
Binary file not shown.
BIN
data_channel/__pycache__/__init__.cpython-37.pyc
Normal file
BIN
data_channel/__pycache__/__init__.cpython-37.pyc
Normal file
Binary file not shown.
BIN
data_channel/__pycache__/gamelog_external.cpython-37.pyc
Normal file
BIN
data_channel/__pycache__/gamelog_external.cpython-37.pyc
Normal file
Binary file not shown.
BIN
data_channel/__pycache__/mp2shushu.cpython-37.pyc
Normal file
BIN
data_channel/__pycache__/mp2shushu.cpython-37.pyc
Normal file
Binary file not shown.
@ -2,8 +2,8 @@
|
||||
#被mp系统调用,用于同步(第三方传递日志需要)appkey到gamelog的相应配置文件
|
||||
import requests
|
||||
import logging
|
||||
from ops.mansible import AnsibleAPI
|
||||
from ops.mmysql import MysqlBase
|
||||
from myops.mansible import AnsibleAPI
|
||||
from myops.mmysql import MysqlBase
|
||||
import time
|
||||
from config.config import args
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import requests
|
||||
import logging
|
||||
#from ops.ss_virtual_create import SS_Virtual_command
|
||||
|
||||
import json
|
||||
log = logging.getLogger(__name__)
|
||||
import pdb
|
||||
@ -103,7 +103,7 @@ class SS_Virtual_command:
|
||||
class Mp2shushu():
|
||||
def __init__(self, gameid, channel):
|
||||
self.mp_url = f"http://10.10.5.4:2333/api/open/promotion/co-list?channelid={channel}&gameid={gameid}"
|
||||
self.filename = "/data/git/ops_interface/ops/csv/2001_b_n.csv"
|
||||
self.filename = "/data/git/ops_interface/myops/csv/2001_b_n.csv"
|
||||
|
||||
def get_ad_list(self):
|
||||
r = requests.get(self.mp_url)
|
||||
|
43
data_channel/produce_ss_csv.py
Normal file
43
data_channel/produce_ss_csv.py
Normal file
@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import pdb
|
||||
import requests
|
||||
|
||||
|
||||
def get_mp_interface(gameid, channelid):
|
||||
base_url = "http://10.10.5.4:2333/api/open/cfg/all?"
|
||||
key = "name-table"
|
||||
url = f"{base_url}channelid={channelid}&gameid={gameid}&key={key}"
|
||||
r = requests.get(url)
|
||||
if r.status_code == requests.codes.ok:
|
||||
return r.json().get('result')
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
class ProduceSSCsv:
|
||||
def __init__(self):
|
||||
# self.base_path = "/data/git/ops_interface/myops/csv"
|
||||
self.base_path = "/tmp"
|
||||
self.gameid_list = [1004, 1001, 2001, 1011,2002]
|
||||
self.channelid = 6001
|
||||
|
||||
def write2csv(self, data):
|
||||
filename = f"{self.base_path}/all__button_name.csv"
|
||||
with open(filename, 'w') as f:
|
||||
f.write("button_name,button_name_cn\n")
|
||||
print(data)
|
||||
for key, values in data.items():
|
||||
f.write(f"{key},{values}\n")
|
||||
|
||||
|
||||
def run(self):
|
||||
all = dict()
|
||||
for gameid in self.gameid_list:
|
||||
data = get_mp_interface(gameid, self.channelid)
|
||||
all.update(data)
|
||||
self.write2csv(all)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pp = ProduceSSCsv()
|
||||
pp.run()
|
@ -34,7 +34,7 @@ class SS_Virtual_command:
|
||||
|
||||
|
||||
def upload_gameid(self):
|
||||
filename = "/data/git/ops_interface/ops/csv/gameid.csv"
|
||||
filename = "/data/git/ops_interface/myops/csv/gameid.csv"
|
||||
projectId = int(19)
|
||||
createParam = {"commonHeader": {"projectId": 19},
|
||||
"mainColumn": {"property": {"columnName": "gameid", "tableType": 0}},
|
||||
@ -54,7 +54,7 @@ class SS_Virtual_command:
|
||||
|
||||
|
||||
def upload_2001_b_n(self):
|
||||
filename = "/data/git/ops_interface/ops/csv/2001_b_n.csv"
|
||||
filename = "/data/git/ops_interface/myops/csv/2001_b_n.csv"
|
||||
projectId = int(22)
|
||||
createParam = {"commonHeader": {"projectId": 22},
|
||||
"mainColumn": {"property": {"columnName": "#vp@b_n", "tableType": 0, "subTableType": "vprop_sql"}},
|
||||
@ -73,7 +73,7 @@ class SS_Virtual_command:
|
||||
return False
|
||||
|
||||
def upload_1004_button_name(self):
|
||||
filename = "/data/git/ops_interface/ops/csv/1004_button_name.csv"
|
||||
filename = "/data/git/ops_interface/myops/csv/1004_button_name.csv"
|
||||
projectId = int(19)
|
||||
createParam = {"commonHeader": {"projectId": 19},
|
||||
"mainColumn": {"property": {"columnName": "#vp@button_name", "tableType": 0, "subTableType": "vprop_sql"}},
|
144
deploy/deploy_keys.py
Normal file
144
deploy/deploy_keys.py
Normal file
@ -0,0 +1,144 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# python3 deploy_keys.py cloud_php
|
||||
# python3 deploy_keys.py loginserver_php
|
||||
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
|
||||
import tarfile
|
||||
import svn
|
||||
import shutil
|
||||
import pdb
|
||||
define_logger("/data/logs/ops/deploy_keys.log")
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
dbargs = dict()
|
||||
dbargs['host'] = '10.10.3.5'
|
||||
dbargs['user'] = 'ops'
|
||||
dbargs['pswd'] = 'deploy2018'
|
||||
dbargs['db'] = 'ywplatform'
|
||||
|
||||
|
||||
class DeployKeys:
|
||||
def __init__(self, project):
|
||||
self.env='prod'
|
||||
self.project = project
|
||||
self.svn_base = f"/data/publish/svn/{self.env}"
|
||||
self.svn_paths = f"{self.svn_base}/{self.project}"
|
||||
|
||||
|
||||
|
||||
def run(self):
|
||||
if not os.path.isdir(self.svn_paths):
|
||||
self.svn_paths = f"/data/publish/svn/{self.env}/global/{self.project}"
|
||||
svn_path, ipadr = self.get_config()
|
||||
if ipadr:
|
||||
args = dict()
|
||||
tar_file = self.build_svn_tar()
|
||||
if tar_file:
|
||||
hostfile = self.build_hostfile(ipadr)
|
||||
args['hostfile'] = hostfile
|
||||
args['tar_file'] = tar_file[0]
|
||||
if self.ansible_deploy(args):
|
||||
return True
|
||||
else:
|
||||
log.error(f"tar file no found with {self.project}")
|
||||
return False
|
||||
else:
|
||||
raise Exception(f"{self.project} config not found in manager table!")
|
||||
|
||||
|
||||
def get_config(self):
|
||||
sql = f"""SELECT
|
||||
config_address,
|
||||
run_server
|
||||
FROM
|
||||
`deploy_projectmanage`
|
||||
WHERE
|
||||
project_name="{self.project}"
|
||||
and env='{self.env}'"""
|
||||
|
||||
mydb = MysqlBase(**dbargs)
|
||||
data = mydb.query(sql)
|
||||
ip_addr = list()
|
||||
if data:
|
||||
for line in data:
|
||||
try:
|
||||
svn_path = line[0]
|
||||
ip_addr.append(line[1])
|
||||
except Exception:
|
||||
log.error(f"split {self.project} config failed", exc_info=True)
|
||||
svn_path = None
|
||||
|
||||
return (svn_path, ip_addr)
|
||||
|
||||
|
||||
def build_svn_tar(self):
|
||||
try:
|
||||
log.info("svn export config start")
|
||||
cmd = f"cd {self.svn_paths} && svn cleanup && svn up && tar zcvf keys.tar.gz keys "
|
||||
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)
|
||||
|
||||
# project_paths = os.path.join(self.svn_paths, self.project)
|
||||
# tar = tarfile.open(self.svn_paths + '.tar.gz', 'w:gz')
|
||||
# os.chdir(self.svn_paths)
|
||||
# key_dirs = os.path.join(self.svn_paths, "keys")
|
||||
# for f in os.listdir(key_dirs):
|
||||
# tar.add(f)
|
||||
# tar.close()
|
||||
|
||||
# 判断是否有生成tar包
|
||||
list_dir = os.listdir(self.svn_paths)
|
||||
tar_files = list()
|
||||
for i in list_dir:
|
||||
if i.split('.')[-1] == "gz" and os.path.isfile(os.path.join(self.svn_paths, i)):
|
||||
tar_files.append(os.path.join(self.svn_paths, i))
|
||||
if len(tar_files) == 1:
|
||||
log.info("tarfile {0} config to tar.gz success".format(self.project))
|
||||
return tar_files
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def build_hostfile(self, ip_addr):
|
||||
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
host_files = f"/tmp/host_{now}"
|
||||
with open(host_files, 'w') as f:
|
||||
for line in ip_addr:
|
||||
f.writelines(line + '\n')
|
||||
return host_files
|
||||
|
||||
def ansible_deploy(self, args):
|
||||
an = AnsibleAPI(args['hostfile'])
|
||||
tar_files = args['tar_file'].split('/')[-1]
|
||||
data = {'dest_filename': tar_files, 'source': args['tar_file'], 'project': self.project}
|
||||
resule = an.run_playbook('deploy_keys.yml', **data)
|
||||
if not (resule['failed'] or resule['unreachable']):
|
||||
log.info(f"deploy keys with {self.project} success!")
|
||||
return True
|
||||
else:
|
||||
log.error(f"{self.project} deploy keys failed,{resule}", exc_info=True)
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
projects = ['loginserver_php', 'cloud_php']
|
||||
for project in projects:
|
||||
dk = DeployKeys(project)
|
||||
if not dk.run():
|
||||
msg = f"deploy {project} failed"
|
||||
log.error(msg, exc_info=True)
|
||||
raise Exception(msg)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
11
deploy/deploy_keys.yml
Normal file
11
deploy/deploy_keys.yml
Normal file
@ -0,0 +1,11 @@
|
||||
- hosts: all
|
||||
tasks:
|
||||
|
||||
- name: rsync deploy file
|
||||
copy: src={{ source }} dest=/data/apps/{{ project }}/{{ dest_filename }}
|
||||
|
||||
- name: back old config file
|
||||
shell: "rsync -avcp /data/apps/{{ project }}/keys /data/apps/{{ project }}/keys.old"
|
||||
|
||||
- name: decomp file
|
||||
shell: "cd /data/apps/{{ project }} && tar zxvf {{ dest_filename }} "
|
1
mp2ss.sh
Normal file
1
mp2ss.sh
Normal file
@ -0,0 +1 @@
|
||||
curl "http://10.10.3.16:6500/webapp/index.php?c=Ops&a=mp2ss"
|
1
myops/__init__.py
Normal file
1
myops/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# -*- coding: utf-8 -*-
|
103
myops/ss_virtual_create.py
Normal file
103
myops/ss_virtual_create.py
Normal file
@ -0,0 +1,103 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from urllib.parse import unquote, quote, urlencode
|
||||
|
||||
def my_quote(data):
|
||||
if isinstance(data, dict):
|
||||
return urlencode(data)
|
||||
elif isinstance(data, str):
|
||||
return quote(data)
|
||||
|
||||
|
||||
class SS_Virtual_command:
|
||||
def __init__(self):
|
||||
self.ss_virtual_url = "http://10.10.3.14:8993/v1/ta/meta/prop/virtual/dict/create"
|
||||
self.method = "post"
|
||||
self.loginName = "root"
|
||||
self.password = "kingsome2016"
|
||||
|
||||
def run_cmd(self, cmd):
|
||||
import subprocess
|
||||
msg = "Starting run: %s " % cmd
|
||||
print("run_cmd {0}".format(msg))
|
||||
cmdref = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
||||
output, error_info = cmdref.communicate()
|
||||
if cmdref.returncode != 0:
|
||||
if isinstance(error_info, list) or isinstance(error_info, tuple):
|
||||
error_info = error_info[0]
|
||||
msg = "RUN %s ERROR,error info: %s" % (cmd, error_info)
|
||||
print(f"{msg},error output={output}")
|
||||
return False
|
||||
else:
|
||||
print(f"Run Success,output was {output}")
|
||||
return True
|
||||
|
||||
|
||||
def upload_gameid(self):
|
||||
filename = "/data/git/ops_interface/myops/csv/gameid.csv"
|
||||
projectId = int(19)
|
||||
createParam = {"commonHeader": {"projectId": 19},
|
||||
"mainColumn": {"property": {"columnName": "gameid", "tableType": 0}},
|
||||
"columns": [{"property": {"columnName": "gameid", "columnDesc": "主键ID", "selectType": "string"}},
|
||||
{"property": {"columnName": "gameid_china", "columnDesc": "游戏名称", "selectType": "string"}}]}
|
||||
|
||||
body = {"projectId": projectId, "createParam": createParam, "loginName": self.loginName,
|
||||
"password": self.password}
|
||||
quote_body = my_quote(body)
|
||||
|
||||
cmd = f"curl --header 'Accept: application/json' --form 'file=@{filename}' '{self.ss_virtual_url}?{quote_body}'"
|
||||
print(cmd)
|
||||
if self.run_cmd(cmd):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def upload_2001_b_n(self):
|
||||
filename = "/data/git/ops_interface/myops/csv/2001_b_n.csv"
|
||||
projectId = int(22)
|
||||
createParam = {"commonHeader": {"projectId": 22},
|
||||
"mainColumn": {"property": {"columnName": "#vp@b_n", "tableType": 0, "subTableType": "vprop_sql"}},
|
||||
"columns": [{"property": {"columnName": "b_n", "columnDesc": "跳转appid", "selectType": "string"}},
|
||||
{"property": {"columnName": "b_n_china", "columnDesc": "跳转中文名", "selectType": "string"}}]}
|
||||
|
||||
body = {"projectId": projectId, "createParam": createParam, "loginName": self.loginName,
|
||||
"password": self.password}
|
||||
quote_body = my_quote(body)
|
||||
|
||||
cmd = f"curl --header 'Accept: application/json' --form 'file=@{filename}' '{self.ss_virtual_url}?{quote_body}'"
|
||||
print(cmd)
|
||||
if self.run_cmd(cmd):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def upload_1004_button_name(self):
|
||||
filename = "/data/git/ops_interface/myops/csv/1004_button_name.csv"
|
||||
projectId = int(19)
|
||||
createParam = {"commonHeader": {"projectId": 19},
|
||||
"mainColumn": {"property": {"columnName": "#vp@button_name", "tableType": 0, "subTableType": "vprop_sql"}},
|
||||
"columns": [{"property": {"columnName": "button_name", "columnDesc": "点击按钮属性", "selectType": "string"}},
|
||||
{"property": {"columnName": "button_name_cn", "columnDesc": "点击按钮属性(中文)", "selectType": "string"}}]}
|
||||
|
||||
body = {"projectId": projectId, "createParam": createParam, "loginName": self.loginName,
|
||||
"password": self.password}
|
||||
quote_body = my_quote(body)
|
||||
|
||||
cmd = f"curl --header 'Accept: application/json' --form 'file=@{filename}' '{self.ss_virtual_url}?{quote_body}'"
|
||||
print(cmd)
|
||||
if self.run_cmd(cmd):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
ss = SS_Virtual_command()
|
||||
#ss.upload_gameid()
|
||||
#ss.upload_2001_b_n()
|
||||
ss.upload_1004_button_name()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
27
web.py
27
web.py
@ -1,20 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# ops 通用接口
|
||||
# myops 通用接口
|
||||
# python web.py --port=6013
|
||||
import tornado.ioloop
|
||||
import tornado.web
|
||||
import tornado.options
|
||||
from tornado import gen
|
||||
|
||||
from ops.mylog import define_logger
|
||||
from myops.mylog import define_logger
|
||||
import logging
|
||||
|
||||
from config.config import *
|
||||
import pdb
|
||||
from data_channel.gamelog_external import Build_Gamelog_Config
|
||||
from data_channel.mp2shushu import Mp2shushu
|
||||
|
||||
define_logger("/data/logs/ops/ops_interface.log")
|
||||
from deploy.deploy_keys import DeployKeys
|
||||
define_logger("/data/logs/myops/ops_interface.log")
|
||||
log = logging.getLogger(__name__)
|
||||
tornado.options.define("port", default=interface_port, type=int, help="run server on the given port.")
|
||||
|
||||
@ -27,13 +27,24 @@ class DispatchHandler(tornado.web.RequestHandler):
|
||||
self._selfgamelogexternal()
|
||||
elif self.get_query_argument('c') == 'Ops' and self.get_query_argument('a') == 'mp2ss':
|
||||
yield self._selfmp2ss()
|
||||
elif self.get_query_argument('c') == 'Deploy' and self.get_query_argument('a') == 'keys':
|
||||
yield self._selfdeploykeys()
|
||||
else:
|
||||
self.write("pls check args!")
|
||||
|
||||
@gen.coroutine
|
||||
def post(self):
|
||||
if self.get_query_argument('c') == 'Ops' and self.get_query_argument('a') == 'upJumpRecording':
|
||||
self._selfupJumpRecording()
|
||||
# @gen.coroutine
|
||||
# def post(self):
|
||||
# if self.get_query_argument('c') == 'Ops' and self.get_query_argument('a') == 'upJumpRecording':
|
||||
# self._selfupJumpRecording()
|
||||
|
||||
def _selfdeploykeys(self):
|
||||
try:
|
||||
project = self.get_query_argument('project')
|
||||
dk = DeployKeys(project)
|
||||
dk.run()
|
||||
except Exception:
|
||||
log.error(f"deploy keys with {project} failed", exc_info=True)
|
||||
|
||||
|
||||
def _selfgamelogexternal(self):
|
||||
try:
|
||||
|
Loading…
x
Reference in New Issue
Block a user