def post(self): remotion_data = self.get_argument("remotion_data", None) remotion_data = json.loads(remotion_data) des_ip = remotion_data[0] des_port = NodeInfo.get_node_port(des_ip)[0][0] myswarm = Myswarm() for row in remotion_data[1:]: if des_ip == row[0]: continue conf_dict = dict() src_ip = str(row[0]) src_port = NodeInfo.get_node_port(src_ip)[0][0] cont_id = row[1] cont_name = row[2] temp = myswarm.detail_container(src_ip, src_port, cont_id) conf_dict['OpenStdin'] = temp['Config']['OpenStdin'] conf_dict['Tty'] = temp['Config']['Tty'] conf_dict['Cmd'] = temp['Config']['Cmd'] conf_dict['Image'] = PRIVATE_REGISTRY + cont_name conf_dict['Name'] = cont_name conf_dict['Hostname'] = cont_name.replace("/", "") conf_dict['HostConfig'] = dict() conf_dict['HostConfig']['CpuPeriod'] = temp['HostConfig'][ 'CpuPeriod'] conf_dict['HostConfig']['CpuQuota'] = temp['HostConfig'][ 'CpuQuota'] conf_dict['HostConfig']['CpuShares'] = temp['HostConfig'][ 'CpuShares'] conf_dict['HostConfig']['Memory'] = temp['HostConfig']['Memory'] thr = threading.Thread(target=myswarm.remotion_container, args=(src_ip, src_port, cont_id, cont_name, des_ip, des_port, conf_dict)) thr.start()
def get(self, *args, **kwargs): node_ip = self.get_argument('node_ip', None) action = self.get_argument('action', None) if node_ip is None or action is None: self.redirect("/nodemanage?active=2") elif action == "delete": del_status = NodeInfo.delete_node(node_ip) self.redirect("/nodemanage?active=2&del_status=True") elif action == "update": update_dict = dict() update_dict['node_ip'] = self.get_argument('node_ip', None) update_dict['node_name'] = self.get_argument('node_name', None) update_dict['node_port'] = self.get_argument('node_port', None) update_dict['node_cpus'] = self.get_argument('node_cpus', None) update_dict['node_mem'] = self.get_argument('node_mem', None) update_dict['node_imgs'] = self.get_argument('node_imgs', None) update_dict['node_state'] = self.get_argument('node_state', None) update_dict['node_cons'] = self.get_argument('node_cons', None) update_dict['node_os'] = self.get_argument('node_os', None) update_dict['node_ks'] = self.get_argument('node_ks', None) update_dict['node_ds'] = self.get_argument('node_ds', None) update_dict['node_group'] = self.get_argument( 'node_group', None) #node_group获取是的它的ID值 update_dict['user_group'] = self.get_argument( 'user_group', None) #user_group获取是的它的ID值 temp_list = NodeInfo.get_group_list() self.render("node/node_modify.html", node_data=update_dict, group_list=temp_list)
def post(self, *args, **kwargs): result = {} result['name'] = self.get_argument("nodename") result['nodeip'] = self.get_argument('nodeip') result['nodeport'] = self.get_argument('nodeport') result['cpus'] = self.get_argument('cpus') result['memory'] = self.get_argument('memory') result['image'] = self.get_argument('image') result['state'] = self.get_argument('state') result['nodegroup'] = self.get_argument('nodegroup') result['container'] = self.get_argument('container') result['osversion'] = self.get_argument('osversion') result['kernelversion'] = self.get_argument('kernelversion') result['dockerversion'] = self.get_argument('dockerversion') print(result) ret = all(result) if ret: message = NodeCheck.check_node(result['name'], result['nodeip']) print(message) if not message: NodeInfo.insert_node_info(result) self.redirect('/main') else: self.redirect('/nodeadd') else: self.redirect('/nodeadd')
def get(self, *args, **kwargs): node_ip = self.get_argument('node_ip', None) get_all_node = self.get_argument('get_all_node', None) if node_ip is None and get_all_node is None: self.write("Something Wrong") return elif get_all_node: """ 直接点击Director中的Container查看所有容器管理时 """ node_list = NodeInfo.get_all_node( ) # ((127.0.0.1, ), (192.168.180.128, )) myswarm = Myswarm() con_data_list = list() ip_list = list() for ip in node_list: node_ip = ip[0] ip_list.append(node_ip) node_port = NodeInfo.get_node_port(node_ip)[0][0] con_data_list.append( [ip[0], myswarm.container_list(node_ip, node_port)]) self.render('node/cont_list.html', con_data=con_data_list, node_ip=ip_list) else: node_port = NodeInfo.get_node_port(node_ip)[0][0] myswarm = Myswarm() con_data = myswarm.container_list(node_ip, node_port) self.render('node/node_add.html', con_data=con_data, node_ip=node_ip)
def get(self, *args, **kwargs): con_id = self.get_argument('con_id', 'none') if con_id == 'none': con_data = NodeInfo.con_usage_info() else: con_data = NodeInfo.get_con_usage_modify(con_id) con_data_handled = DataManage.manage_con_usage_info(con_data) self.render("node/con_list.html", name=template_variables, con_data=con_data_handled)
def _update_node(self): node_data = NodeInfo.node_info() myswarm = Myswarm() for line in node_data: node_ip = line[2] node_port = line[3] if myswarm.ping_port(node_ip, node_port) == 1: continue else: node_info = myswarm.node_list(node_ip, node_port) NodeInfo.node_info_update(node_info, node_ip)
def post(self, *args, **kwargs): action = self.get_argument('action', None) if action is None: self.write("Sorry you submitted the data incorrectly ...") elif action == 'update': update_dict = dict() update_dict['node_ip'] = self.get_argument('node_ip', None) update_dict['node_name'] = self.get_argument('node_name', None) update_dict['node_port'] = self.get_argument('node_port', None) update_dict['node_cpus'] = self.get_argument('node_cpus', None) update_dict['node_mem'] = self.get_argument('node_mem', None) update_dict['node_imgs'] = self.get_argument('node_imgs', None) update_dict['node_state'] = self.get_argument('node_state', None) update_dict['node_cons'] = self.get_argument('node_cons', None) update_dict['node_os'] = self.get_argument('node_os', None) update_dict['node_ks'] = self.get_argument('node_ks', None) update_dict['node_ds'] = self.get_argument('node_ds', None) update_dict['node_group_id'] = self.get_argument( 'node_group_id', None) update_dict['node_group'] = self.get_argument('node_group', None) update_dict['user_group_id'] = self.get_argument( 'user_group_id', None) update_dict['user_group'] = self.get_argument('user_group', None) upd_status = NodeInfo.update_node(update_dict) self.redirect("/nodemanage?active=2&update_status=True")
def post(self, *args, **kwargs): json_ret = json.loads(json_data[0]) node_ip = self.get_argument('node_ip', 'None') if node_ip == 'None': print("There is no node ip") return port_ret = NodeInfo.get_node_port(node_ip) if len(port_ret) < 1: print("There is no port of the node") return else: node_port = port_ret[0][0] con_dict = {} for key in [ 'Cmd', 'Image', 'CpuPeriod', 'CpuQuota', 'CpuShares', 'Memory' ]: con_dict[key] = self.get_argument(key.lower()) if key == 'Cmd' and con_dict[key] != "": json_ret[key] = con_dict[key].split() elif key == 'Image' and con_dict[key] != "": json_ret[key] = con_dict[key] elif con_dict[key] != "": json_ret['HostConfig'][key] = int(con_dict[key]) myswarm = Myswarm() json_ret['Name'] = str(uuid.uuid4())[0:13] json_ret['Hostname'] = json_ret['Name'] container_id = myswarm.create_container(node_ip, node_port, json_ret) if not container_id: print("Can not create the Container") return ret = myswarm.start_container(node_ip, node_port, container_id) self.redirect("/contlist?active=3&get_all_node=True&res=%s" % ret)
def get(self, *args, **kwargs): node_ip = self.get_argument("node_ip") node_port = NodeInfo.get_node_port(node_ip)[0][0] self.render('node/image_pull.html', node_ip=node_ip, node_port=node_port, search_data=dict())
def get(self, *args, **kwargs): #加载界面之前,更新节点状态 node_status_check = online_check() node_status_check.trigger() node_data = NodeInfo.node_info(status=None) node_data_handled = DataManageAjax.status_list(node_data) print(node_data_handled) self.write(json.dumps(node_data_handled)) #准备联合datatable后台分页做的,因为失败,废弃 # class pag(BaseHandler): # def get(self,*args,**kwargs): # data = self.get_argument('aodata') # data= json.loads(data) # print (data) # for i in data: # if i['name'] == "sEcho": # sEcho = i['value'] # elif i['name'] == "iDisplayStart": # iDisplayStart = i['value'] # elif i['name'] == "iDisplayLength": # iDisplayLength = i['value'] # node_info = NodeInfo.node_info(status=all) # # # node_info = [{'id':1,'name':2,'age':3,'con':4}] # data = { # "draw": 1, # "recordsTotal": 57, # "recordsFiltered": 57, # "data": [[1,2,3]] # } # # self.write(json.dumps(data))
def get(self, *args, **kwargs): con_id = self.get_argument('con_id') con_data = NodeInfo.get_con_usage_modify(con_id) con_data_handled = DataManage.manage_con_usage_info(con_data) self.render("node/con_modify.html", name=template_variables, single_con_usage_data=con_data_handled)
def prepare_data(username): node_group_id, user_group_id = NodeInfo.user_access(username)[0] node_list = NodeInfo.node_list(node_group_id, user_group_id) # (((ip,port),(ip,port))) myswarm = Myswarm() image_data = list() ip_list = list() for ip, port in node_list: img_data = myswarm.show_images(ip, port) if image_data is None: # 当节点不能连接时,避免报错,但不能消除等待连接超时 continue image_data.append(dict()) image_data[-1]['name'] = ip ip_list.append(ip) format_data = DataManage.image_list(img_data) # 列表套字典的形式 image_data[-1]['value'] = len(format_data) return image_data, ip_list
def get(self, *args, **kwargs): username = self.get_secure_cookie(COOKIE_NAME).decode() node_group_id, user_group_id = NodeInfo.user_access(username)[0] node_list = NodeInfo.node_list( node_group_id, user_group_id) # (((ip,port),(ip,port))) myswarm = Myswarm() image_data = list() for ip, port in node_list: image_data.append(dict()) image_data[-1]['node_ip'] = ip image_data[-1]['node_port'] = port img_data = myswarm.show_images(ip, port) if img_data is None: # 测试数据时会添加不存在的节点,避免出错,但不能避免连接超时等待 image_data.pop() continue format_data = DataManage.image_list(img_data) # 列表套字典的形式 image_data[-1]['images'] = format_data self.render('node/image_list.html', image_data=image_data, node_ip=node_list)
def get(self, *args, **kwargs): threads = [] node_update = threading.Thread(target=self._update_node) threads.append(node_update) node_pass = threading.Thread(target=self._get_pass) threads.append(node_pass) for t in threads: t.setDaemon(True) t.start() node_data = NodeInfo.node_info() node_data_handled = DataManage.manage_node_info(node_data) self.render("node/node_list.html", node_data=node_data_handled)
def get(self, *args, **kwargs): node_ip = self.get_argument('node_ip', None) if node_ip is None: self.write("Something Wrong") return else: node_port = NodeInfo.get_node_port(node_ip)[0][0] myswarm = Myswarm() images_data = myswarm.images_list(node_ip, node_port) self.render('node/cont_create.html', node_ip=node_ip, images=images_data)
def get(self, *args, **kwargs): node_ip = self.get_argument('node_ip', None) print(node_ip) if node_ip is None: self.write("Something Wrong") return else: node_port = NodeInfo.get_node_port(node_ip)[0][0] myswarm = Myswarm() con_data = myswarm.container_list(node_ip, node_port) self.render('node/rightnode.html', con_data=con_data, node_ip=node_ip)
def scope_of_data(self): ''' 返回每个数据范围要显示的这页的数据 :return: ''' start = (self.cur_page - 1) * self.data_num #比如当前也是5-1 * 每页显示数据8 那么数据就是32 end = self.cur_page * self.data_num #比如当前页是5 * 每页显示数据8 那么数据就是40 #show = self.total_data[start:end] #把起始位置和结束位置传到数据库取这一段的数据 show = NodeInfo.con_usage_info( start, end=self.data_num) #这里end-1是数据库limit的语法从0开始的 print(start, end, '---', len(show)) return show
def post(self, *args, **kwargs): con_dic = dict() for key in ['con_id', 'con_desc', 'con_app', 'user_name']: con_dic[key] = self.get_argument(key) con_ret = NodeInfo.set_con_usage_modify(con_dic) if con_ret == 0: url_cmd = ("<script language='javascript'>window.location.href='" + "/conmanage?con_id=" + str(con_dic['con_id']) + "';</script>") self.write(url_cmd) else: self.write( "<script language='javascript'>alert('修改失败');window.location.href='/conmanage';</script>" )
def get(self, *args, **kwargs): node_ip = self.get_argument('node_ip') con_id = self.get_argument('con_id') port_ret = NodeInfo.get_node_port(node_ip) if len(port_ret) < 1: print("There is no port of the node") return else: node_port = port_ret[0][0] myswarm = Myswarm() con_data_handled = myswarm.container_info(node_ip, node_port, con_id) self.render("node/cont_handle.html", name=template_variables, node_ip=node_ip, node_port=node_port, con_id=con_id, con_data=con_data_handled)
# self.key_name.put(i) # # def put_q(self,value=None): # q = self.key_name.put(value) # # def get_q(self,value=None): # q = self.key_name.get(value) # return q # # from myswarm import Myswarm # obj = Myswarm() # port_list = [] # con_list = obj.container_list('192.168.100.200','2375',all) # print (con_list) # for port_key in con_list.values(): # port_dict = port_key['port'] # print (port_dict) # for cport in port_dict.values(): # for i in cport: # port_list.append(i['HostPort']) # print (port_list) from model.node import NodeInfo for i in range(1000): import random con_id = str(random.randint(100000222220, 23323232333333)) NodeInfo.insert_con_usage(con_id, "192.168.1." + str(i), "192.168.1." + str(i))
def delete_con_usage(self, container_id): if not container_id: return else: NodeInfo.delete_con_usage(container_id)
def insert_con_usage(self, node_ip, container_ip, container_id): if not container_id: return else: NodeInfo.insert_con_usage(container_id, container_ip, node_ip)
def _getcontainer(self, id, name): container_ret = NodeInfo.container_list(name) container_data = DataManage.container_list(container_ret, id, name) return container_data
def _getgroup(self): group_data = [] group_ret = NodeInfo.group_list() for i in DataManage.group_list(group_ret): group_data.append(i) return group_data
def get(self, *args, **kwargs): temp_list = NodeInfo.get_group_list() self.render('node/node_create.html', group_list=temp_list)
def post(self, *args, **kwargs): node_name = self.get_argument("node_name", None) flag = True if node_name is None: flag = False node_ip = self.get_argument("node_ip", None) if node_ip is None: flag = False node_port = self.get_argument("node_port", None) if node_port is None: flag = False node_cpus = self.get_argument("node_cpus", None) if node_cpus is None: flag = False node_mem = self.get_argument("node_mem", None) if node_mem is None: flag = False node_imgs = self.get_argument("node_imgs", None) if node_imgs is None: flag = False node_cons = self.get_argument("node_cons", None) if node_cons is None: flag = False node_state = self.get_argument("node_state", None) if node_state is None: flag = False node_os = self.get_argument("node_os", None) if node_os is None: flag = False node_ks = self.get_argument("node_ks", None) if node_ks is None: flag = False node_ds = self.get_argument("node_ds", None) if node_ds is None: flag = False node_ds = self.get_argument("node_ds", None) if node_ds is None: flag = False node_group = self.get_argument("node_group", None) if node_group is None: flag = False user_group = self.get_argument("user_group", None) print(user_group) print(type(user_group)) if user_group is None: flag = False print(user_group) if not flag: self.write("Sorry you submitted the data incorrectly ...") return node_dict = dict() node_dict['node_name'] = node_name node_dict['node_ip'] = node_ip node_dict['node_port'] = node_port node_dict['node_cpus'] = node_cpus node_dict['node_mem'] = node_mem node_dict['node_imgs'] = node_imgs node_dict['node_cons'] = node_cons node_dict['node_state'] = node_state node_dict['node_os'] = node_os node_dict['node_ks'] = node_ks node_dict['node_ds'] = node_ds node_dict['node_group'] = node_group node_dict['user_group'] = user_group # 默认管理员组 print(node_dict) save_status = NodeInfo.save_node(node_dict) self.redirect("/nodemanage?active=2&save_status=True")
def _getnode(self, id, name): node_ret = NodeInfo.node_list(name) node_data = DataManage.node_list(node_ret, id, name) return node_data