騰訊雲cdn更新檔案自動重新整理api添加,更新檔案并自動送出重新整理功能。
官方腳本擷取位址:https://cloud.tencent.com/document/product/228/1734
官方個人api密鑰生成下載下傳位址:https://console.cloud.tencent.com/capi
1.從上述腳本擷取位址下載下傳,我這裡下載下傳的python版,官方位址:https://mc.qcloudimg.com/static/archive/e1b2f9d047705f235d3591e4e7bc7012/python.zip
将解壓出的腳本檔案QcloudCdnTools_V2.py放在伺服器某個目錄中用于調用,我這裡放在/root/tools/scripts/下。
2.在更新腳本中添加調用api段
vi tools/scripts/change_txjn.py
#!/use/bin/env python
# -- coding:utf-8 --
import sys,os,re
if len(sys.argv) != 2:
print ‘argv Error! Usage:%s (file|statusZ) (type|txjj|txpp)’%(sysy.argv[0])
sys.exit()
GAME_DIR = ‘/data/test/xclient_unpack/launchercfg/’
START_DIR = ‘/root/tools/scripts/new_serverlist/’
STOP_DIR = ‘/root/tools/scripts/old_serverlist/’
STATUS = sys.argv[1].strip()
def jjstop():
cmd1 = “cp -p -f %s/appleaddr.dat %s”%(GAME_DIR,START_DIR)
cmd2 = “cp -p -f %s/appleaddr.dat %s”%(STOP_DIR,GAME_DIR)
os.popen(cmd1)
os.popen(cmd2)
print “::::::::::::::::::::: \n change stop ipconfig success! \n::::::::::::::::::::”
def jjstart():
cmd = “cp -rp %s/appleaddr.dat %s”%(START_DIR,GAME_DIR)
os.popen(cmd)
print “::::::::::::::::::::: \n change start ipconfig success! \n::::::::::::::::::::”
def flushtxcdn(): #api調用,這裡需要個人api密鑰SecretId和SecretKey
flushcmd = “/usr/bin/python /root/tools/scripts/QcloudCdnTools_V2.py RefreshCdnDir -u SecretId -p SecretKey –dirs http://aaa.com/ > /dev/null 2>&1”
os.popen(flushcmd)
print “::::::::::::::::::::: \n flush cdndir=http://aaa.com/ success! \n::::::::::::::::::::”
if re.search(‘start’,STATUS):
jjstart()
flushtxcdn()
elif re.search(‘stop’,STATUS):
jjstop()
flushtxcdn()
else:
print ‘Status Type Error!’
3.使用方法
[[email protected] ~]# cd tools/scripts/
[[email protected] scripts]# python change_txjn.py stop
s:::::::::::::::::::::
change stop ipconfig success!
::::::::::::::::::::
:::::::::::::::::::::
flush cdndir=http://aaa.com/ success!
::::::::::::::::::::
[[email protected] scripts]# python change_txjn.py start
:::::::::::::::::::::
change start ipconfig success!
::::::::::::::::::::
:::::::::::::::::::::
flush cdndir=http://aaa.com/ success!
::::::::::::::::::::
這裡http://aaa.com/為所需重新整理的cdn目錄,自行定義,如需有其他需求,官方參考文檔:https://cloud.tencent.com/document/api/228/1723
--binghan li