def demo_exec(): mongo=mongodb.mongo_opreate() list_exec=resolve_xml_ovs.get_xml_host_exec() execute_list=[] for exec_info in list_exec: docker_info=mongo.display_tpl_condition("docker_info",{"name":exec_info["docker_list"][0]}) if docker_info==[]: print "找不到列表:",exec_info["docker_list"],"内的容器!" continue execute={ "host":docker_info[0]["host_ip"], "version":docker_info[0]["version"], "docker_list":exec_info["docker_list"], #待执行容器名 "cmd":exec_info["command"], #待执行命令 "docker_num":exec_info["docker_num"] } execute_list.append(execute) task_list={ "id":srand(), "operate":{ "type":"execute", #操作类型 "operation":execute_list #具体操作字典 }, "state":"" } return task_list
def demo_del(filename='del.xml'): mongo = mongodb.mongo_opreate() list_ovs = resolve_xml_ovs.get_xml_del(filename) list_del = [] for ovs_del in list_ovs: docker = mongo.display_tpl_condition("docker_info", {"link_ovs": ovs_del}) docker_list = [{ "version": one["version"], "name": one["docker_id"], "host": one["host_ip"] } for one in docker] list_del.extend(docker_list) task_list = { "id": srand(), "operate": { "type": "delete", #操作类型 "operation": { "ovs_list": list_ovs, "docker_list": list_del } }, "state": "" } return task_list
def demo_exec(filename='exec.xml'): mongo = mongodb.mongo_opreate() list_exec = resolve_xml_ovs.get_xml_host_exec(filename) execute_list = [] for exec_info in list_exec: docker_info = mongo.display_tpl_condition( "docker_info", {"name": exec_info["docker_list"][0]}) if docker_info == []: print "找不到列表:", exec_info["docker_list"], "内的容器!" continue execute = { "host": docker_info[0]["host_ip"], "version": docker_info[0]["version"], "docker_list": exec_info["docker_list"], #待执行容器名 "cmd": exec_info["command"], #待执行命令 "docker_num": exec_info["docker_num"] } execute_list.append(execute) task_list = { "id": srand(), "operate": { "type": "execute", #操作类型 "operation": execute_list #具体操作字典 }, "state": "" } return task_list
def demo_create(filename='ovs.xml'): #测试使用,正式版删除 # ip_start={ # "start":"10.0.0.0" # } mongo = mongodb.mongo_opreate() mongo.save_tpl_dic(ip_start, "ip_start") #建立对象 test = ip_distribution.ip_distribution() example = scheduler.scheduler() #获取列表 list_ovs, list_relation = resolve_xml_ovs.get_xml_ovs(filename) list_host = resolve_xml_ovs.get_xml_host_conf() list_ovs_new = test.distribution_ovs(list_ovs) operation, list_ovs_new_new, ovs_link = example.docker_scheduler( list_ovs_new, list_host, list_relation) #构建任务字典 task_list = { "id": srand(), "ovs_link": list_relation, "ovs_tube_link": ovs_link, "ovs_list": list_ovs_new_new, "host_list": list_host, "operate": operation, "state": "" } return task_list
def demo_create(filename='ovs.xml'): #测试使用,正式版删除 # ip_start={ # "start":"10.0.0.0" # } mongo=mongodb.mongo_opreate() mongo.save_tpl_dic(ip_start,"ip_start") #建立对象 test=ip_distribution.ip_distribution() example=scheduler.scheduler() #获取列表 list_ovs,list_relation=resolve_xml_ovs.get_xml_ovs(filename) list_host=resolve_xml_ovs.get_xml_host_conf() list_ovs_new=test.distribution_ovs(list_ovs) operation,list_ovs_new_new,ovs_link=example.docker_scheduler(list_ovs_new,list_host,list_relation) #构建任务字典 task_list={ "id":srand(), "ovs_link":list_relation, "ovs_tube_link":ovs_link, "ovs_list":list_ovs_new_new, "host_list":list_host, "operate":operation, "state":"" } return task_list
def demo_recover_ip(): ip_start={ "start":"10.0.0.0" } mongo=mongodb.mongo_opreate() mongo.del_tpl(ip_start,{}) mongo.save_tpl_dic(ip_start,"ip_start")
def __init__(self,types=True): self.mongo=mongodb.mongo_opreate() if types==True: while True: try: self.start_ip=self.mongo.display_tpl("ip_start")[0]['start'] break except: print traceback.format_exc() time.sleep(0.5) print "无法获取初始ip!" self.mongo.del_tpl("ip_start",{})
def __init__(self, types=True): self.mongo = mongodb.mongo_opreate() if types == True: while True: try: self.start_ip = self.mongo.display_tpl( "ip_start")[0]['start'] break except: print traceback.format_exc() time.sleep(0.5) print "无法获取初始ip!" self.mongo.del_tpl("ip_start", {})
def demo_del(): mongo=mongodb.mongo_opreate() list_ovs=resolve_xml_ovs.get_xml_del() list_del=[] for ovs_del in list_ovs: docker=mongo.display_tpl_condition("docker_info",{"link_ovs":ovs_del}) docker_list=[{"version":one["version"],"name":one["docker_id"],"host":one["host_ip"]} for one in docker] list_del.extend(docker_list) task_list={ "id":srand(), "operate":{ "type":"delete", #操作类型 "operation":{ "ovs_list":list_ovs, "docker_list":list_del } }, "state":"" } return task_list
def __init__(self): self.ip_solve = ip_distribution.ip_distribution() self.mongo = mongodb.mongo_opreate()
def __init__(self): self.ip_solve = ip_distribution.ip_distribution(types=False) self.mongo = mongodb.mongo_opreate()
def __init__(self): self.list_host = resolve_xml_ovs.get_xml_host_conf() self.mongo=mongodb.mongo_opreate()
# ovs["OVS_IP"]=start_ip_ovs # ovs["OVS_Start_Ip"]=start_ip_ovs # ovs["OVS_End_Ip"]=end_ip_ovs # ovs["OVS_Mask"]=mask_ovs # ovs["OVS_BroadCast"]=end_ip_ovs # else: # start_ip_ovs,end_ip_ovs,mask_ovs,next_ip=self.distribution_subnet(next_ip,10) # ovs["OVS_IP"]=start_ip_ovs # ovs["OVS_Start_Ip"]=start_ip_ovs # ovs["OVS_End_Ip"]=end_ip_ovs # ovs["OVS_Mask"]=mask_ovs # ovs["OVS_BroadCast"]=end_ip_ovs # list_result.append(ovs) # return list_result if __name__ == '__main__': ip_start={ "start":"10.0.0.0" } mongo=mongodb.mongo_opreate() mongo.save_tpl_dic(ip_start,"ip_start") test=ip_distribution() list_ovs,list_relation=resolve_xml_ovs.get_xml_ovs() print test.distribution_ovs(list_ovs)
# for ovs in list_ovs: # if ovs["OVS_Docker_Num"]!=0: # start_ip_ovs,end_ip_ovs,mask_ovs,next_ip=self.distribution_subnet(next_ip,ovs["OVS_Docker_Num"]) # ovs["OVS_IP"]=start_ip_ovs # ovs["OVS_Start_Ip"]=start_ip_ovs # ovs["OVS_End_Ip"]=end_ip_ovs # ovs["OVS_Mask"]=mask_ovs # ovs["OVS_BroadCast"]=end_ip_ovs # else: # start_ip_ovs,end_ip_ovs,mask_ovs,next_ip=self.distribution_subnet(next_ip,10) # ovs["OVS_IP"]=start_ip_ovs # ovs["OVS_Start_Ip"]=start_ip_ovs # ovs["OVS_End_Ip"]=end_ip_ovs # ovs["OVS_Mask"]=mask_ovs # ovs["OVS_BroadCast"]=end_ip_ovs # list_result.append(ovs) # return list_result if __name__ == '__main__': ip_start = {"start": "10.0.0.0"} mongo = mongodb.mongo_opreate() mongo.save_tpl_dic(ip_start, "ip_start") test = ip_distribution() list_ovs, list_relation = resolve_xml_ovs.get_xml_ovs() print test.distribution_ovs(list_ovs)