def bind_domain_port(domain_id, cvm_ip, cvm_port):
sy = ApiRequest.TX_API()
sy.set_method('POST')
sy.set_uri('/v1/domains/%s/cvm_bind' % domain_id)
body = {'lanIps':[cvm_ip],'port':cvm_port}
sy.set_body(body)
result = sy.do_request()
if result:
def check_domain_info(domain_id):
sy = ApiRequest.TX_API()
sy.set_method('GET')
sy.set_uri('/v1/domains/%s' % domain_id)
result = sy.do_request()
if result:
logger.debug("Domain '%s' already bind:" % result['instanceInfo']['domain'])
for i in result['instanceInfo']['devicesList']:
logger.debug("host : %s,\tport: %s" % (i['lanIp'], i['port']))
else:
logger.error("Request Error! Please try again!")
#!/usr/bin/pythoncoding:utf-8
import ApiDomain
import time
import ApiLogger
logger = ApiLogger.logger
domains = ['s233.app100670828.qqopenapp.com']
hosts = ['10.207.252.117']
ports = ['80','8000', '8001', '8002', '8003', '8004', '8005']
logger.debug("This scripts will bind domain ports!")
raw_input("Please Enter any key to start!")
num = len(domains)
for i in range(0,num):
domain = domains[i]
host = hosts[i]
domain_id = ApiDomain.get_domain_id(domain)
print domain, domain_id, host
for port in ports:
logger.debug("bind %s port ING~~~" % port)
ApiDomain.bind_domain_port(domain_id, host, int(port))
time.sleep(20)
ApiDomain.check_domain_info(domain_id)
time.sleep(20)
logger.debug("Done!")
raw_input("Please Enter any key to exit!")
domains = ['s233.app100670828.qqopenapp.com']
hosts = ['10.207.252.117']
这里应该用字典比较好,当时写的时候就不知道怎么想的了。。后来就没改了。。写得比较弱,不过能用就好了。。