Authored by chunhua.zhang

Merge branch 'wap-node-activity' into 'master'

支持containers的IP地址获取



See merge request !85
... ... @@ -13,6 +13,7 @@ from jinja2 import Environment, FileSystemLoader
import collections
import time
import sys
import get_iplist
# clone deploy project to local
HOME = os.path.expanduser("~")
... ... @@ -26,7 +27,7 @@ call("git clone --recursive git@git.yoho.cn:yohoops/auto_deploy.git %s" % PATH
# get iptables info from git files.
azs_mappings = {"qcloud": "az1", "aws": "aws", "t6": "t6"}
azs_mappings = {"qcloud": "az1", "aws": "aws", "t6": "t6", "containers": "containers"}
host_group = { "nginx": "java-nginx",
"yoho_gateway": "java-gateway",
"yoho_users": "java-users",
... ... @@ -62,26 +63,43 @@ host_group = { "nginx": "java-nginx",
"yoho_reviewed": "java-review",
"yoho_message_controller": "java-messagecontroller"
}
containers_host_group = { "media-containers": "media-containers",
"web-containers": "web-containers",
"yoho-java-container": "yoho-java-container",
"yoho-ops-container": "yoho-ops-container"
}
# all available zone groups
all_groups = {}
ClusterIds = {"yoho-java-container": "cls-rzb97zht","yoho-ops-container": "cls-gscif1o5","media-containers": "cls-qzkxrhg7","web-containers": "cls-ro6kl3cp"}
for _az in azs_mappings.keys():
groups = {}
all_groups[azs_mappings[_az]] = groups
file = open(os.path.join(PATH, "scripts/iptable/", _az, "app-iptable.sh"), 'r')
for line in file:
for deploy_prj_name in host_group.keys():
if line.strip().startswith(deploy_prj_name + "_" + _az):
g_hosts = []
groups[host_group[deploy_prj_name]] = g_hosts
i_1 = line.index("(")
i_2 = line.index(")")
sub = line[i_1 + 1 : i_2]
for user_ip in sub.split("master@"):
if user_ip.strip() != '':
g_hosts.append(user_ip.strip())
file.close()
if _az == "containers":
for line in ClusterIds.keys():
for deploy_prj_name in containers_host_group.keys():
if line == deploy_prj_name:
g_hosts = []
groups[containers_host_group[deploy_prj_name]] = g_hosts
result = get_iplist.ip_inqure(ClusterIds[line])
ip_s = result['data']['data']['nodes']
for ip in ip_s:
g_hosts.append(ip['lanIp'].strip())
else:
file = open(os.path.join(PATH, "scripts/iptable/", _az, "app-iptable.sh"), 'r')
for line in file:
for deploy_prj_name in host_group.keys():
if line.strip().startswith(deploy_prj_name + "_" + _az):
g_hosts = []
groups[host_group[deploy_prj_name]] = g_hosts
i_1 = line.index("(")
i_2 = line.index(")")
sub = line[i_1 + 1 : i_2]
for user_ip in sub.split("master@"):
if user_ip.strip() != '':
g_hosts.append(user_ip.strip())
file.close()
print("get all inventory info success. \n")
print(all_groups)
... ...
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import json
import commands
import sys,os
reload(sys)
sys.setdefaultencoding('utf8')
base_dir=os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
base_dir = base_dir + "/playbooks/module_utils"
sys.path.append(base_dir)
from qcloud_api import QcloudApi
# 获取SecretId和SecretKey值
def get_secrets():
(status, output) = commands.getstatusoutput(
'curl -s -H "X-Vault-Token: s.0pbNAI6Oy94m2svlEFBadl74" -X GET http://10.66.107.2:8200/v1/yoho/ops/qcloud')
result = {}
result['status'] = status
if status == 0:
output = json.loads(output)
result['data'] = output['data']
return result
# 调用腾讯云查询集群节点列表接口 ( DescribeClusterInstances ) 获取容器集群节点内网IP
def ip_inqure(clusterId):
ret = {}
URLS = 'ccs.api.qcloud.com/v2/index.php'
try:
datas = get_secrets()
if datas['status'] != 0:
ret["code"] = datas['status']
ret["err"] = "未获取到正确的SecretId和SecretKey值"
else:
SecretId = datas['data']['SecretId'].encode('utf-8')
SecretKey = datas['data']['SecretKey'].encode('utf-8')
ips_query = QcloudApi(secretId=SecretId, secretKey=SecretKey)
ip_list = ips_query.do_query(params={'Action': 'DescribeClusterInstances', 'clusterId': clusterId, 'Region': 'ap-beijing'}, req_url=URLS)
if ip_list['code'] == 0:
ret['code'] = 0
ret["data"] = ip_list
else:
ret['code'] = ip_list['code']
except Exception,e:
ret["code"] = 500
ret["err"] = e.message
return ret
... ...
# inventory file for containers
# auto generated at {{time_now}}
{% extends "java-services.j2" %}
... ...