Example #1
0
    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)
Example #2
0
 def get(self, *args, **kargs):
     con_dict = {}
     for key in ['node_ip', 'port', 'con_id']:
         con_dict[key] = self.get_argument(key)
     myswarm = Myswarm()
     myswarm.destroy_container(con_dict['node_ip'], con_dict['port'],
                               con_dict['con_id'])
Example #3
0
 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()
Example #4
0
 def get(self, *args, **kargs):
     con_dict = {}
     for key in ['node_ip', 'port', 'con_id']:
         con_dict[key] = self.get_argument(key)
     myswarm = Myswarm()
     myswarm.destroy_container(con_dict['node_ip'], con_dict['port'],
                               con_dict['con_id'])
     self.redirect("/contlist?active=3&get_all_node=True")
Example #5
0
    def get(self, *args, **kargs):
        con_dict = {}
        for key in ['node_ip', 'port', 'con_id']:
            con_dict[key] = self.get_argument(key)

        myswarm = Myswarm()
        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'])
Example #6
0
 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)
Example #7
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/cont_create.html',
                     node_ip=node_ip,
                     images=images_data)
Example #8
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)
         self.render('node/rightnode.html',
                     con_data=con_data,
                     node_ip=node_ip)
Example #9
0
 def get(self, *args, **kwargs):
     action = self.get_argument('action', None)
     node_ip = self.get_argument('node_ip', None)
     node_port = self.get_argument('node_port', None)
     image_id = self.get_argument('image_id', None)
     if node_ip is None or node_port is None or image_id is None or action is None:
         self.write("Sorry you submitted the data incorrectly ...")
     myswarm = Myswarm()
     if action == "delete":
         res = myswarm.remove_images(node_ip, node_port, image_id)
         self.redirect("/imglist?active=4&delete_status=True")
     elif action == "detail":
         res = myswarm.detail_image(node_ip, node_port, image_id)
         self.render("node/image_detail.html", detail_data=res)
Example #10
0
 def post(self, *args, **kwargs):
     node_ip = self.get_argument("node_ip", None)
     node_port = self.get_argument("node_port", None)
     action = self.get_argument("action", None)
     myswarm = Myswarm()
     if action == "search":
         search_content = self.get_argument("search_content", None)
         res = myswarm.search_image(node_ip, node_port, search_content)
         search_data = DataManage.search_images_list(res)
         self.render("node/image_pull.html",
                     node_ip=node_ip,
                     node_port=node_port,
                     search_data=search_data)
     elif action == "pull":
         pull_name = self.get_argument("pull_name", None)
         res = myswarm.pull_image(node_ip, node_port, pull_name)
Example #11
0
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
Example #12
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 = 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)
Example #13
0
 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)
Example #14
0
 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)
Example #15
0
 def post(self, *args, **kwargs):
     registry_name = self.get_argument("registry_name", None)
     registry_port = self.get_argument("registry_port", None)
     push_list = self.get_argument("push_list", None)
     push_list = json.loads(push_list)
     myswarm = Myswarm()
     print(push_list)
     for row in push_list:
         # ip, port, push_name, registry_ip, registry_port, registry_img_name, tag
         thr = threading.Thread(target=myswarm.push_image,
                                args=(row[1], row[2], row[3], registry_name,
                                      registry_port, row[4], row[5]))
         thr.start()
     self.redirect('/imglist?active=4')
Example #16
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 = Myswarm()
        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'])
Example #17
0
#
# test(test_dict=test_dict)


# import docker
# def create_container(self, node_ip, node_port, conf):
#     client_ins = docker.APIClient(base_url='tcp://' + node_ip + ":" + node_port, version='1.24', timeout=5)
#     print("      Create the container......")
#     container_ret = client_ins.create_container(image=conf['Image'],
#                                                 stdin_open=conf['OpenStdin'],
#                                                 tty=conf['Tty'],
#                                                 command=conf['Cmd'],
#                                                 name=conf['Name'],
#                                                 hostname=conf['Hostname'],
#                                                 host_config=conf['HostConfig'])
#     if container_ret:
#         time.sleep(0.3)
#         return (container_ret['Id'])

# from model.mysql_server1 import MysqlServer
# from settings import DATABASES
#
# obj = MysqlServer(DATABASES)
# l = obj.run_sql('select * from user')
#
# print (l)

from myswarm import Myswarm
myswarm = Myswarm()
ret = myswarm.show_port('192.168.100.200','2375','1a537')
print (ret)