Beispiel #1
0
 def get(self, *args, **kwargs):
     group_name = self.get_argument('group_name', None)
     #print(group_name)
     data_list = {}
     self.num = 1
     node_ip_list = NodeInfo.get_node_ip(group_name)
     #print(node_ip_list,len(node_ip_list))
     for index in range(len(node_ip_list)):
         node_ip = node_ip_list[index][0]
         #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)
             for con in con_data:
                 #print(con_data[con])
                 data_list[self.num] = con_data[con]
                 self.num += 1
     #print(data_list)
     self.render('node/groupconlist.html',
                 con_data=data_list,
                 node_ip=node_ip,
                 group_name=group_name)
Beispiel #2
0
 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)
         #print("con_data",con_data)
         for con in con_data:
             #print(con_data[con]["id_num"],con_data[con]["con_ip"],node_ip)
             ret = NodeInfo.get_con_usage_info(con_data[con]["id_num"],
                                               node_ip)
             if len(ret) == 0:
                 NodeInfo.insert_con_usage(con_data[con]["id_num"],
                                           con_data[con]["con_ip"],
                                           con_data[con]["con_name"],
                                           node_ip)
             else:
                 continue
         self.render('node/rightnode.html',
                     con_data=con_data,
                     node_ip=node_ip)
Beispiel #3
0
 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/con_create.html',
                     node_ip=node_ip,
                     images=images_data)
Beispiel #4
0
    def get(self, *args, **kwargs):
        #node_ip = self.get_argument('node_ip')
        con_id = self.get_argument('con_id')
        con_node_ip = NodeInfo.get_con_usage_node_ip(con_id)
        #print(node_ip,con_node_ip[0][0])
        #if node_ip != con_node_ip[0][0]:
        #   node_ip = con_node_ip[0][0]
        node_ip = con_node_ip[0][0]
        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/con_action.html",
                    name=template_variables,
                    node_ip=node_ip,
                    node_port=node_port,
                    con_id=con_id,
                    con_data=con_data_handled)
Beispiel #5
0
    def post(self, *args, **kwargs):
        json_ret = json.loads(basejson[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_name = self.get_argument('con_name', None)
        con_num = self.get_argument('con_num', None)
        if len(con_num) == 0:
            con_num = 1
        con_num = int(con_num)
        print(u'待创建容器个数:%s' % (con_num))

        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])

        name_list = []
        if con_num > 1:
            for num in range(con_num):
                #print(num + 1)
                if len(con_name) == 0:
                    con_name = str(uuid.uuid4())[0:13]
                    #print(u'待创建容器名:%s' % con_name)
                    name_list.append(con_name)
                    con_name = ''
                else:
                    con_name = '%s%s' % (con_name, str(num + 1))
                    #print(u'待创建容器名:%s' % con_name)
                    name_list.append(con_name)
                    con_name = con_name[:-len(str(num + 1))]
        else:
            if len(con_name) == 0:
                con_name = str(uuid.uuid4())[0:13]
            name_list.append(con_name)

        threads = []
        create_con = threading.Thread(target=self._create_con,
                                      args=(name_list, node_ip, node_port,
                                            json_ret))
        threads.append(create_con)
        create_pass = threading.Thread(
            target=self._create_pass)  #此函数在于构成for循环,用于异构
        threads.append(create_pass)
        #print(threads)
        for t in threads:
            t.setDaemon(True)
            t.start()
        t.join()
        #time.sleep(con_num*2)
        time.sleep(1)
        self.write(u"%s节点上容器创建并启动成功" % (node_ip))