Exemplo n.º 1
0
 def get(self, *args, **kargs):
     con_dict = {}
     for key in ['node_ip', 'port', 'con_id']:
         con_dict[key] = self.get_argument(key)
     myswarm = Myswam()
     myswarm.destroy_container(con_dict['node_ip'], con_dict['port'],
                               con_dict['con_id'])
Exemplo n.º 2
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_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 = Myswam()
        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)
Exemplo n.º 3
0
    def get(self, *args, **kargs):
        con_dict = {}
        for key in ['node_ip', 'port', 'con_id']:
            con_dict[key] = self.get_argument(key)

        myswarm = Myswam()
        if not con_dict['con_id']:
            self.write("There is no container id")
        print("      Starting the container......")
        ret = myswarm.start_container(con_dict['node_ip'], con_dict['port'],
                                      con_dict['con_id'])
Exemplo n.º 4
0
 def get(self, *args, **kwargs):
     node_ip = self.get_argument('node_ip', None)
     if node_ip is None:
         self.write('Error')
         return
     else:
         node_port = NodeInfo.get_node_port(node_ip)[0][0]
         myswam = Myswam()
         images_data = myswam.images_list(node_ip, node_port)
         self.render('node/con_create.html',
                     node_ip=node_ip,
                     images=images_data)
Exemplo n.º 5
0
 def _update_node(self):
     node_data = NodeInfo.node_info()
     myswarm = Myswam()
     for line in node_data:
         node_ip = line[2]
         node_port = line[3]
         #用ping测试容器是否运行中,否则在更新数据时会被阻塞一个较长的默认的连接等待时间
         #还能用与报告容器状态
         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)
Exemplo n.º 6
0
 def get(self, *args, **kwargs):
     node_ip = self.get_argument('node_ip', None)
     if node_ip is None:
         self.write('Error')
         return
     else:
         node_port = NodeInfo.get_node_port(node_ip)
         #使用curl去请求docker提供的restful接口,获取节点上的容器列表
         myswam = Myswam()
         con_data = myswam.container_list(node_ip, node_port[0][0])
         self.render('node/rightnode.html',
                     con_data=con_data,
                     node_ip=node_ip)
Exemplo n.º 7
0
    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 = Myswam()
        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)
Exemplo n.º 8
0
    def get(self, *args, **kargs):
        con_dict = {}
        for key in ['node_ip', 'port', 'con_id']:
            con_dict[key] = self.get_argument(key)

        container_ip = {}
        myswarm = Myswam()
        if not con_dict['con_id']:
            self.write("There is no container id")
        myswarm.stop_container(con_dict['node_ip'], con_dict['port'],
                               con_dict['con_id'])
        time.sleep(2)
        myswarm.start_container(con_dict['node_ip'], con_dict['port'],
                                con_dict['con_id'])