Example #1
0
 def _create_con(self, name_list, node_ip, node_port, json_ret):
     #print(name_list)
     for i in range(len(name_list)):
         #time.sleep(0.1)
         if len(name_list[i]) == 0:
             json_ret['Name'] = str(uuid.uuid4())[0:13]
             json_ret['Hostname'] = json_ret['Name']
         elif len(name_list[i]) == 13:
             json_ret['Name'] = name_list[i]
             json_ret['Hostname'] = name_list[i]
         else:
             json_ret['Name'] = name_list[i]
             json_ret['Hostname'] = str(uuid.uuid4())[0:13]
         print(u'节点:[%s],端口:[%s],容器ID:[%s],容器名:[%s]' %
               (node_ip, node_port, json_ret['Hostname'], json_ret['Name']))
         myswarm = Myswarm()
         if NodeInfo.get_con_usage_info(json_ret['Hostname'], node_ip):
             continue
         elif NodeInfo.get_con_usage_con_name(node_ip, json_ret['Name']):
             continue
         else:
             container_id = myswarm.create_container(
                 node_ip, node_port, json_ret)
             if not container_id:
                 print("Can not create the Container")
                 return
             #print(node_ip, node_port,container_id)
             ret = myswarm.start_container(node_ip, node_port, container_id)
             print(u"%s节点上容器%s创建并启动成功" % (node_ip, container_id[0:12]))
Example #2
0
 def start_container(self, node_ip, node_port, container_id):
     if len(container_id) > 0:
         container_ip = ""
         client_ins = docker.Client(base_url='tcp://' + node_ip + ":" +
                                    node_port,
                                    version='1.20',
                                    timeout=5)
         client_ins.start(container_id)
         time.sleep(0.5)
         con_info = self._container_detail(node_ip, node_port, container_id)
         ret = NodeInfo.get_con_usage_info(container_id, node_ip)
         print(ret)
         if len(ret) == 0:
             NodeInfo.insert_con_usage(
                 container_id[0:12],
                 con_info['NetworkSettings']['IPAddress'],
                 con_info['Name'].replace('/', ''), node_ip)
         else:
             #print('update_con_usage')
             #print(con_info['NetworkSettings']['IPAddress'], con_info['Name'].replace('/', ''), node_ip, container_id[0:12])
             NodeInfo.update_con_usage(
                 container_id[0:12],
                 con_info['NetworkSettings']['IPAddress'],
                 con_info['Name'].replace('/', ''), node_ip)
         return 0
     else:
         print("Please enter the Container ID")
         return
Example #3
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)