def get_node_info(): """ 获取所有的node节点信息 :return: """ if GetModel.deploy_type() == 'kvm': headers = GetModel.get_auth_header() return json.dumps({"code": 0, "data": ClearAwCloud(headers).get_node_info()}) else: return json.dumps({"code": 0, "data": Panacube().get_node()})
def push_bigdata_db(): # get_nodes() time.sleep(4) panaocs = GetModel.get_panaocs() panaocs['netmask'] = exchange_mask(panaocs['netmask']) # del panaocs['panacube_ip'] data = [ { "param_name": "bigdata", "param_value": panaocs, "description": None, "level": 1, "update_time": "0000-00-00 00:00:00.000000", "parent_id": None }, { "param_name": "panaocs", "param_value": panaocs, "description": None, "level": 1, "update_time": "0000-00-00 00:00:00.000000", "parent_id": None }, { "param_name": "node", "param_value": GetModel.get_node(), "description": None, "level": 1, "update_time": "0000-00-00 00:00:00.000000", "parent_id": None } ] if GetModel.deploy_type() == 'docker': if os.path.exists('/usr/local/udsafe/parent_bigdata_info'): node_list = os.popen("consul members | awk '{ print $1 }'").read().split('\n')[1:-1] for node in node_list: ssh_popen_1(node, del_param_name) os.system(del_param_name) for _list in data: os.system(write_db.format(_list['param_name'], json.dumps(_list['param_value']))) else: from app_projects.models.m_insert import insert_sqls, delete_sql if os.path.exists('/usr/local/udsafe/parent_bigdata_info'): delete_sql() insert_sqls(data) current_app.logger.info('写入数据配置开始') current_app.logger.info(data) current_app.logger.info('写入数据配置结束') q.put({"type": "大数据", "speed_p": "stop", "percentage": "100"})
def block(): if str(GetModel.deploy_type()) == 'kvm': if os.path.exists('/usr/local/udsafe/automatedkvm.txt'): with open('/usr/local/udsafe/automatedkvm.txt', 'r') as f: kvm_ip = f.read() return json.dumps({'ip': kvm_ip}) else: w_kvm = { 'ip': GetModel.kvm_ip() } os.system('mkdir -p /usr/local/udsafe/') with open('/usr/local/udsafe/automatedkvm.txt', 'wb') as f: f.write(GetModel.kvm_ip()) return json.dumps(w_kvm) else: return json.dumps({'ip': GetModel.panacube_ip()})
def update_storage_image(): """ 更新智能存储镜像 :return: """ q.put({ "type": "镜像上传", "size": "上传大小", "speed": "conducting", "percentage": "{}".format(generate_random(1, 6)) }) if GetModel.deploy_type() == 'kvm': awcloud = ClearAwCloud(GetModel.get_auth_header()) q.put({ "type": "镜像上传", "size": "上传大小", "speed": "conducting", "percentage": "{}".format(generate_random(17, 36)) }) image_obj = awcloud.upload_image(PathDir.image_path()) print '上传的镜像信息: %s' % image_obj image_id = image_obj['id'] q.put({ "type": "镜像上传", "size": "上传大小", "speed": "conducting", "percentage": "{}".format(generate_random(38, 52)) }) model.update_or_create('storage_img_id', image_id) q.put({ "type": "镜像上传", "size": "上传大小", "speed": "conducting", "percentage": "{}".format(generate_random(57, 78)) }) f = l = 79 while True: resp = awcloud.update_image_info(image_id) f += 4 l += 10 if l >= 90: q.put({ "type": "镜像上传", "size": "上传大小", "speed": "conducting", "percentage": "{}".format(generate_random(f, l)) }) else: f -= 2 l -= 3 q.put({ "type": "镜像上传", "size": "上传大小", "speed": "conducting", "percentage": "{}".format(generate_random(f, l)) }) if resp.get('status') != 415: if resp['code'] == '0': current_app.logger.info( 'update storage image property successful') else: current_app.logger.info( 'update storage image property fail') break else: time.sleep(2) os.system("sh {set_tag} {openstack} {id}".format( set_tag=PathDir.tag_shell_path(), openstack=PathDir.openstack(), id=image_id)) else: awcloud = ClearAwCloud(GetModel.get_auth_header()) q.put({ "type": "镜像上传", "size": "上传大小", "speed": "conducting", "percentage": "23" }) model.update_or_create('awcloud_ip', GetModel.awcloud_ip()) q.put({ "type": "镜像上传", "size": "上传大小", "speed": "conducting", "percentage": "48" }) image_id = awcloud.upload_image(PathDir.image_path()).get('id') q.put({ "type": "镜像上传", "size": "上传大小", "speed": "conducting", "percentage": "{}".format(generate_random(56, 88)) }) model.update_or_create('storage_img_id', image_id) while True: resp = awcloud.update_image_info(image_id) if resp.get('status') != 415: if resp['code'] == '0': current_app.logger.info( 'update storage image property successful') else: current_app.logger.info( 'update storage image property fail') break else: time.sleep(2) os.system("sh {set_tag} {openstack} {id}".format( set_tag=PathDir.tag_shell_path(), openstack=PathDir.openstack(), id=image_id)) from app_projects.deploy.get_config import move_storage_code storage_code_name = move_storage_code() node_list = os.popen("consul members | awk '{ print $1 }'").read().split( '\n')[1:-1] for item in node_list: os.system("scp -r /var/deploy/%s %s:/usr/local/udsafe/%s" % (storage_code_name, item, storage_code_name)) q.put({ "type": "镜像上传", "size": "上传大小", "speed": "conducting", "percentage": "{}".format(generate_random(89, 96)) })