Beispiel #1
0
    def post(self, action):
        try:
            data = request.get_json()
            if action == "create":
                return VirtualSwitchController().create_virtual_switch(data)

            elif action == "delete":
                vswitch_uuid = data.get("uuid", "")
                return VirtualSwitchController().delete_virtual_switch(
                    vswitch_uuid)

            elif action == "update":
                return VirtualSwitchController().update_virtual_switchs(data)

            elif action == "update_map":
                return VirtualSwitchController().update_virtual_switch(data)

            elif action == "info":
                if not data:
                    return build_result("ParamError")
                vswitch_uuid = data.get("uuid", "")
                return VirtualSwitchController().virtual_switch_info(
                    vswitch_uuid)

            else:
                return abort_error(404)
        except Exception as e:
            print(e)
            logger.exception("vswitch action %s failed:%s", action, e)
            return build_result("OtherError")
Beispiel #2
0
    def post(self, action):
        try:
            data = request.get_json()
            ret = {}
            if action == "create":
                if not data:
                    return build_result("ParamError")
                return NetworkController().create_subnet(data)

            elif action == "delete":
                subnet_uuids = data.get("uuids", "")
                return NetworkController().delete_subnet(subnet_uuids)

            elif action == "update":
                return NetworkController().update_subnet(data)

            elif action == "list":
                if not data:
                    return build_result("ParamError")
                network_uuid = data.get("network_uuid", "")
                return NetworkController().get_subnets_of_network(network_uuid)
            return build_result("Success", ret)
        except Exception as e:
            logger.exception("subnet action %s failed:%s", action, e)
            return build_result("OtherError")
Beispiel #3
0
    def user_password_change(self, data):
        """ 终端用户密码修改 """
        user_name = data.get("user_name", "")
        passwd = data.get("password", "")
        user = db_api.get_group_user_with_first({"user_name": user_name})
        if not user:
            logger.error("terminal user login error: %s not exist" % user_name)
            return build_result("TerminalUserNotExistError")
        if not user.validate_password(passwd):
            logger.error("terminal user login error: %s password error" %
                         user_name)
            return build_result("TerminalAccountError")
        if not user.enabled:
            logger.error("terminal user login error: %s is unenabled" %
                         user_name)
            return build_result("TerminalUserUnenabledError")

        new_password = data.get("new_password", "")
        if not new_password:
            return build_result("ParamError")

        user.change_password(new_password)
        user.online = 0
        user.mac = ""
        user.soft_update()
        # session.soft_delete()
        logger.info("terminal user %s change password success!" %
                    user.user_name)
        return build_result("Success")
Beispiel #4
0
    def post(self, action):
        try:
            data = request.get_json()
            ret = {}
            # if action == "init":
            #     return NetworkController().init_network(data)

            if action == "create":
                return NetworkController().create_network(data)

            elif action == "delete":
                network_uuid = data.get("uuid", "")
                return NetworkController().delete_network(network_uuid)

            elif action == "list":
                return NetworkController().get_network_list()

            elif action == "update":
                if not data:
                    return build_result("ParamError")
                return NetworkController().update_network(data)

            return build_result("Success", ret)
        except Exception as e:
            logger.exception("network action %s failed:%s", action, e)
            return build_result("OtherError")
Beispiel #5
0
 def update_storages(self, resource_pool_uuid, data):
     if resource_pool_uuid:
         nodes = db_api.get_node_with_all(
             {'resource_pool_uuid': resource_pool_uuid})
     else:
         nodes = db_api.get_node_with_all({})
     # 需要所有节点都有此存储路径才能进行配置
     node_uuid_list = []
     for node in nodes:
         node_uuid_list.append(node.uuid)
         storages = db_api.get_node_storage_all({'node_uuid': node.uuid})
         for path, role in data.items():
             for store in storages:
                 if path == store.path:
                     break
             else:
                 return build_result("NodeStorageNotExist",
                                     node=node.name,
                                     path=path)
     # 配置存储路径,同时清掉之前存储路径的角色
     storages = db_api.get_node_storage_all({})
     for store in storages:
         if store.node_uuid in node_uuid_list:
             for path, role in data.items():
                 if path == store.path:
                     store.role = role
                     break
             else:
                 store.role = ''
             store.soft_update()
     return build_result("Success")
Beispiel #6
0
    def virtual_switch_info(self, vswitch_uuid):
        """
        虚拟交换机的信息
        :param vswitch_uuid:
        :return:
        """
        virtual_switch = db_api.get_virtual_switch(vswitch_uuid)
        if not virtual_switch:
            logger.error("virtual switch: %s not exist", vswitch_uuid)
            return build_result("VSwitchNotExist")

        info = {
            "name": virtual_switch.name,
            "type": virtual_switch.type,
            "default": virtual_switch.default,
            "desc": virtual_switch.desc or '',
            "uplinks": list()
        }
        for uplink in virtual_switch.uplinks:
            if not uplink.deleted:
                node = db_api.get_node_by_uuid(uplink.node_uuid)
                if node:
                    uplink_info = {
                        "hostname": node.hostname,
                        "interface": uplink.interface
                    }
                    info['uplinks'].append(uplink_info)
        return build_result("Success", info)
 def update_desktop_sent_flag(self, data):
     logger.info("input data: {}".format(data))
     try:
         terminal_mac = data.get("mac")
         sys_uuids = data.get("sys_disk_uuids").split(',')
         group_uuid = data.get("group_uuid", "")
         for uuid in sys_uuids:
             disk = db_api.get_item_with_first(models.YzyVoiDeviceInfo, {
                 "uuid": uuid,
                 "type": "system"
             })
             if disk and disk.instance_uuid:
                 desktop_group = db_api.get_item_with_first(
                     models.YzyVoiDesktop, {
                         "template_uuid": disk.instance_uuid,
                         "group_uuid": group_uuid
                     })
                 if desktop_group and desktop_group.uuid:
                     db_api.update_voi_terminal_desktop_bind(
                         desktop_group.uuid, terminal_mac,
                         {"desktop_is_sent": 1})
                     logger.info(
                         "update yzy_voi_terminal_to_desktops, mac: {}, dsk_grp_uuid: {}"
                         .format(terminal_mac, desktop_group.uuid))
         return build_result("Success")
     except Exception as e:
         logger.error("", exc_info=True)
         return build_result("OtherError")
Beispiel #8
0
 def update_resource_pool(self, data):
     """
     :param data:
         {
             "uuid": "e4a53850-26e9-11ea-a72d-562668d3ccea",
             "value": {
                 "name": "pool1",
                 "desc": "this is pool1"
             }
         }
     :return:
     """
     pool_uuid = data.get('uuid', '')
     pool = db_api.get_resource_pool_by_key('uuid', pool_uuid)
     if not pool:
         logger.error("resource pool: %s not exist", pool_uuid)
         return build_result("ResourcePoolNotExist")
     try:
         pool.update(data['value'])
         pool.soft_update()
     except Exception as e:
         logger.error("update resource pool:%s failed:%s", pool_uuid, e)
         return build_result("ResourcePoolUpdateError", name=pool.name)
     logger.info("update resource pool:%s success", pool_uuid)
     return build_result("Success")
Beispiel #9
0
 def update_network(self, data):
     """
     修改网络的名称
     :param data:
         {
             "uuid": "e4a53850-26e9-11ea-a72d-562668d3ccea",
             "value": {
                 "name": "network1"
             }
         }
     :return:
     """
     network_uuid = data.get('uuid', '')
     network = db_api.get_network_by_uuid(network_uuid)
     if not network:
         logger.error("network: %s not exist" % network_uuid)
         return build_result("NetworkInfoNotExist")
     try:
         network.update(data)
         network.soft_update()
     except Exception as e:
         logger.error("update network:%s failed:%s",
                      network_uuid,
                      e,
                      exc_info=True)
         return build_result("NetworkUpdateError", name=network.name)
     logger.info("update network:%s success", network_uuid)
     return build_result("Success")
Beispiel #10
0
 def create_subnet(self, data):
     """
     创建子网
     :param data:
         {
             "network_uuid": "570a316e-27b5-11ea-9eac-562668d3ccea",
             "name": "subnet1",
             "start_ip": "172.16.1.10",
             "end_ip": "172.16.1.20",
             "netmask": "255.255.0.0",
             "gateway": "172.16.1.254",
             "dns1": "8.8.8.8",
             "dns2": ""
         }
     :return:
     """
     subnet = db_api.get_subnet_by_name(data['name'], data['network_uuid'])
     if subnet:
         return build_result("SubnetNameRepeatError", name=data['name'])
     try:
         self.check_subnet_params(data)
     except Exception as e:
         return build_result("SubnetInfoError",
                             e.__str__(),
                             name=data['name'])
     try:
         subnet_info = self._generate_subnet_info(data)
         db_api.add_subnet(subnet_info)
     except Exception as e:
         logger.info("create subnet failed:%s", e)
         return build_result("SubnetCreateError", name=data['name'])
     return build_result("Success", subnet_info)
Beispiel #11
0
    def edu_desktop_groups(self, data):
        """ 教学桌面组列表 """
        logger.debug(
            "get education desktop info, terminal_id:%s, terminal_ip:%s",
            data.get("terminal_id", 0), data.get("terminal_ip", ""))
        terminal_id = data.get("terminal_id", 0)
        if not terminal_id:
            logger.error("terminal id param error: %s" % terminal_id)
            return build_result("ParamError")

        terminal_ip = data.get("terminal_ip", "")
        if not is_ip_addr(terminal_ip):
            logger.error("terminal edu desktop group info error, %s not ip" %
                         terminal_ip)
            return build_result("IPAddrError", ipaddr=terminal_ip)

        groups = db_api.get_group_with_all(
            {"group_type": constants.EDUCATION_DESKTOP})
        terminal_group = None
        for group in groups:
            if group.start_ip and group.end_ip:
                if terminal_ip in find_ips(group.start_ip, group.end_ip):
                    terminal_group = group
                    break

        _groups = list()
        if not terminal_group:
            logger.error("terminal group not exist: %s" % terminal_ip)
            return build_result("Success", _groups)

        logger.debug(
            "get education desktop terminal ip: %s, terminal_group: %s",
            terminal_ip, terminal_group.uuid)
        terminal_id = int(terminal_id)
        # 查找分组
        desktops = db_api.get_desktop_with_all({
            "group_uuid": terminal_group.uuid,
            "active": True
        })
        logger.debug("get education desktop terminal ip: %s, desktops_len: %s",
                     terminal_ip, len(desktops))
        for desktop in desktops:
            # 判断是否总数大于序号
            if desktop.instance_num < terminal_id:
                continue

            _d = {
                "uuid": desktop.uuid,
                "name": desktop.name,
                "desc": desktop.template.desc,
                "active": desktop.active,
                "order_num": desktop.order_num,
                "os_type": desktop.os_type
            }
            _groups.append(_d)

        _groups = sorted(_groups, key=lambda _groups: _groups['order_num'])
        logger.debug("edu terminal_ip %s desktop group list: %s" %
                     (terminal_ip, _groups))
        return build_result("Success", _groups)
Beispiel #12
0
    def post(self, action):
        try:
            data = request.get_json()

            if action == "update":
                result = CourseScheduleController().update(data)

            elif action == "delete":
                result = CourseScheduleController().delete(data)

            elif action == "apply":
                result = CourseScheduleController().apply(data)

            elif action == "enable":
                result = CourseScheduleController().enable(data)

            elif action == "disable":
                result = CourseScheduleController().disable(data)

            else:
                return abort_error(404)
            if result and isinstance(result, dict):
                return jsonify(result)
            else:
                return build_result("ReturnError")
        except Exception as e:
            logger.exception("course_schedule action %s failed:%s", action, e)
            return build_result("OtherError")
Beispiel #13
0
    def create_resource_pool(self, data):
        """
        :param data:
            {
                "name": "default",
                "desc": "this is default pool",
                "default": 1
            }
        :return:
        """
        if not data:
            return build_result("ParamError")
        if not data.get('name', ''):
            return build_result("ParamError")
        res_pool = db_api.get_resource_pool_by_key("name", data['name'])
        if res_pool:
            return build_result("ResourcePoolNameExistErr", name=data['name'])

        _uuid = create_uuid()
        data['uuid'] = _uuid
        try:
            db_api.add_resource_pool(data)
        except Exception as e:
            current_app.logger.error(traceback.format_exc())
            return build_result("ResourcePoolAddError", name=data['name'])
        return build_result("Success")
Beispiel #14
0
 def create_remote_storage(self, data):
     """
     创建远端存储, 目前只支持nfs
     :param data:
         {
             "name": "remote_storage_name",
             "type": "nfs"
             "server": "172.16.1.23:/mnt/nfs/",
         }
     :return:
     """
     if not (data.get('name') and data.get('type') and data.get('server_ip')
             and data.get('mount_point')):
         return build_result("ParamError")
     server = ':'.join([data['server_ip'], data['mount_point']])
     if db_api.get_remote_storage_by_key('name', data['name']):
         logger.error("remote storage is already exist")
         return build_result("RemoteStorageNameExistError")
     if db_api.get_remote_storage_by_key('server', server):
         logger.error("server is already added")
         return build_result("ServerExistError")
     remote_storage_uuid = create_uuid()
     remote_storage_value = {
         "uuid": remote_storage_uuid,
         "name": data['name'],
         "type": data['type'],
         "server": server
     }
     try:
         db_api.add_remote_storage(remote_storage_value)
         logger.info("add remote storage:%s success", data['name'])
     except Exception as e:
         logger.error("add remote storage failed:%s", e, exc_info=True)
         return build_result("Others")
     return build_result("Success", remote_storage_value)
Beispiel #15
0
    def terminal_instance_close(self, data):
        """
        终端发起单个桌面关闭请求
        {
            "uuid": "xxxxxxxx"
        }
        :param data:
        :return:
        """
        instance_uuid = data.get("desktop_uuid", "")
        instance = db_api.get_instance_with_first({"uuid": instance_uuid})
        if not instance:
            logger.error("terminal close instance error: %s not exist" %
                         instance_uuid)
            return build_result("TerminalInstanceNotExist")

        desktop_uuid = instance.desktop_uuid
        desktop_type = instance.classify
        if desktop_type == constants.EDUCATION_DESKTOP:
            desktop = db_api.get_desktop_by_uuid(desktop_uuid)
        else:
            desktop = db_api.get_personal_desktop_with_first(
                {"uuid": desktop_uuid})
        contraller = BaseController()
        sys_restore = desktop.sys_restore
        if not contraller.stop_instance(instance, desktop):
            logger.error("terminal close instance error: %s close fail" %
                         instance_uuid)
            return build_result("TerminalInstanceCloseFail")
        logger.info("terminal close instance success ! %s" % instance_uuid)
        return build_result("Success")
Beispiel #16
0
    def person_desktop_groups(self, data):
        """ 个人桌面组列表 """
        session_id = data.get("session_id", "")
        session = db_api.get_group_user_session_first(
            {"session_id": session_id})
        if not session:
            logger.error(
                "terminal user query desktop group error: %s not exist" %
                session_id)
            return build_result("TerminalUserLogout")

        user = db_api.get_group_user_with_first({"uuid": session.user_uuid})
        if not user:
            logger.error(
                "terminal user query desktop group error: %s not exist" %
                session.user_uuid)
            return build_result("TerminalUserNotExistError")

        if not user.enabled:
            logger.error(
                "terminal user query desktop group error: %s is unenabled" %
                user.user_name)
            return build_result("TerminalUserUnenabledError")

        # 个人桌面组分为随机桌面组和静态桌面组
        desktop_uuids = list()
        # 随机桌面
        random_desktop_groups = db_api.get_random_desktop_with_all(
            {"group_uuid": user.group_uuid})
        for group in random_desktop_groups:
            desktop_uuids.append(group.desktop_uuid)

        # instance_uuids = list()
        static_instances = db_api.get_instance_with_all(
            {"user_uuid": user.uuid})
        for instance in static_instances:
            desktop_uuids.append(instance.desktop_uuid)

        # instances = db_api.get_instance_all_by_uuids(instance_uuids)
        # for instance in instances:
        #     desktop_uuids.append(instance.desktop_uuid)

        desktop_groups = db_api.get_personal_desktop_all_by_uuids(
            desktop_uuids)
        _groups = list()
        for desktop in desktop_groups:
            _d = {
                "uuid": desktop.uuid,
                "name": desktop.name,
                "desc": desktop.template.desc,
                "maintenance": desktop.maintenance,
                "order_num": desktop.order_num,
                "os_type": desktop.os_type
            }
            _groups.append(_d)

        _groups = sorted(_groups, key=lambda _groups: _groups['order_num'])
        logger.info("person terminal desktop group list: %s" % _groups)
        return build_result("Success", _groups)
Beispiel #17
0
    def person_instance_close(self, data):
        """ 关闭个人终端的所有桌面 """
        session_id = data.get("session_id", "")
        session = db_api.get_group_user_session_first(
            {"session_id": session_id})
        if not session:
            logger.error(
                "terminal user query desktop group error: %s not exist" %
                session_id)
            return build_result("TerminalUserLogout")

        user = db_api.get_group_user_with_first({"uuid": session.user_uuid})
        if not user:
            logger.error(
                "terminal user query desktop group error: %s not exist" %
                session.user_uuid)
            return build_result("TerminalUserNotExistError")

        if not user.enabled:
            logger.error(
                "terminal user query desktop group error: %s is unenabled" %
                user.user_name)
            return build_result("TerminalUserUnenabledError")

        contraller = BaseController()
        random_instances = db_api.get_user_random_instance_with_all(
            {"user_uuid": user.uuid})

        static_instances = db_api.get_instance_with_all({
            "classify": constants.PERSONAL_DEKSTOP,
            "user_uuid": user.uuid
        })
        for i in random_instances:
            desktop = i.desktop
            instance = i.instance
            # sys_restore = desktop.sys_restore
            if not contraller.stop_instance(instance, desktop):
                logger.error("terminal close personal instance fail: %s" %
                             instance.uuid)
            instance.allocated = 0

        desktop_uuids = list()
        for instance in static_instances:
            desktop_uuid = instance.desktop_uuid
            if desktop_uuid not in desktop_uuids:
                desktop_uuids.append(desktop_uuid)
        desktop_dict = dict()
        desktops = db_api.get_personal_desktop_all_by_uuids(desktop_uuids)
        for desktop in desktops:
            desktop_dict[desktop.uuid] = desktop

        for instance in static_instances:
            desktop = desktop_dict[instance.desktop_uuid]
            if not contraller.stop_instance(instance, desktop):
                logger.error("terminal close personal instance fail: %s" %
                             instance.uuid)

        logger.info("terminal close personal instance success !!!")
        return build_result("Success")
Beispiel #18
0
 def set_system_time(self, _datetime, time_zone):
     try:
         os.system('timedatectl set-timezone "{}"'.format(time_zone))
         os.system('date -s "{}"'.format(_datetime))
         os.system("hwclock -w")
     except Exception as e:
         logging.error("set system time failed:%s", e)
         return utils.build_result("OtherError")
     return utils.build_result("Success")
Beispiel #19
0
 def get_pool_nodes(self, pool_uuid):
     pool = db_api.get_resource_pool_by_key("uuid", pool_uuid)
     if not pool:
         return build_result("ResourcePoolNotExist")
     node_list = list()
     for node in pool.nodes:
         if not node.deleted:
             node_list.append(node.to_json())
     return build_result("Success", {"node_list": node_list})
Beispiel #20
0
 def delete_resource_pool(self, pool_uuid):
     pool = db_api.get_resource_pool_by_key('uuid', pool_uuid)
     if not pool:
         logger.error("resource pool: %s not exist", pool_uuid)
         return build_result("ResourcePoolNotExist")
     if pool.default:
         logger.error("the resource pool is default one, can not delete")
         return build_result("ResourceDefaultError", name=pool.name)
     pool.soft_delete()
     return build_result("Success")
Beispiel #21
0
    def update_virtual_switch(self, data):
        """
        更新虚拟交换机信息
        限制条件比较多
        1、有模板或者桌面使用基于该虚拟机交换机的网络时,不能修改节点的接口对应关系
        2、修改节点的接口对应关系时,需要删除原先创建的设备,然后重新创建新的网络设备
        :param data:
            {
                "uuid": "caa5d57e-3731-11ea-801e-000c295dd728",
                "node_uuid": "",
                "nic_uuid": ""
            }
        :return:
        """
        vswitch_uuid = data.get('uuid', '')
        logger.info("update vswitch %s", vswitch_uuid)
        vswitch = db_api.get_virtual_switch(vswitch_uuid)
        if not vswitch:
            return build_result("VSwitchNotExist")
        # 虚拟交换机有被使用,无法修改
        networks = db_api.get_network_all({"switch_uuid": vswitch.uuid})
        for network in networks:
            templates = db_api.get_template_with_all(
                {"network_uuid": network.uuid})
            if templates:
                return build_result("VSwitchUsedError", name=vswitch.name)
            desktops = db_api.get_desktop_with_all(
                {"network_uuid": network.uuid})
            if desktops:
                return build_result("VSwitchUsedError", name=vswitch.name)

        # 如果没有数据网络使用该虚拟交换机,则只需要修改对应关系
        try:
            for uplink in vswitch.uplinks:
                if not uplink.deleted:
                    if data['node_uuid'] == uplink.node_uuid:
                        if data['nic_uuid'] != uplink.nic_uuid:
                            logger.info("update nic from %s to %s",
                                        uplink.nic_uuid, data['nic_uuid'])
                            node = db_api.get_node_by_uuid(data['node_uuid'])
                            nic = db_api.get_nics_first(
                                {'uuid': data['nic_uuid']})
                            for network in networks:
                                self._delete_network(node.ip, network.uuid,
                                                     network.vlan_id)
                                self._create_network(node.ip, network.uuid,
                                                     network.switch_type,
                                                     nic.nic, network.vlan_id)
                            uplink.nic_uuid = data['nic_uuid']
                            uplink.soft_update()
                            break
        except Exception as e:
            return build_result("OtherError")
        return build_result("Success")
Beispiel #22
0
 def post(self, action):
     try:
         data = request.get_json()
         username = data.get("username", "")
         password = data.get("password")
         result = AdminAuthController().authorization(username, password)
         if result and isinstance(result, dict):
             return jsonify(result)
         else:
             return build_result("ReturnError")
     except Exception as e:
         logger.exception("database back action %s failed:%d", action, e)
         return build_result("OtherError")
Beispiel #23
0
 def get_history_perf(self, data):
     logger.info("get data: {}".format(data))
     node_uuid = data.get("node_uuid")
     statis_hours = data.get("statis_hours")
     step_minutes = data.get("step_minutes")
     if not (node_uuid and statis_hours and step_minutes):
         return build_result("ParamError")
     node = db_api.get_item_with_all(models.YzyNodes, {"uuid": node_uuid})
     if not node:
         return build_result("ParamError")
     _data = self.get_perf_info(node_uuid, statis_hours, step_minutes)
     _data.update({"node_uuid": node_uuid})
     return build_result("Success", data=_data)
Beispiel #24
0
 def post(self, action):
     try:
         data = request.get_json()
         if action == "set_system_time":
             result = StrategyManager().set_system_time(data)
         else:
             return abort_error(404)
         if result and isinstance(result, dict):
             return jsonify(result)
         else:
             return build_result("ReturnError")
     except Exception as e:
         logger.exception("set system time failed:%s", e)
         return build_result("OtherError")
 def delete_terminal_desktop_bind(self, data):
     """
         'new_group_uuid','terminal_mac'
     """
     logger.info("delete terminal desktop bind data: {}".format(data))
     try:
         terminal_mac = data.get("terminal_mac", "")
         new_group_uuid = data.get("new_group_uuid", "")
         # group_uuid != input group_uuid, then delete all old data
         db_api.delete_voi_terminal_desktops(new_group_uuid, terminal_mac)
         return build_result("Success")
     except Exception as e:
         logger.error("", exc_info=True)
         return build_result("OtherError")
Beispiel #26
0
 def upload_images(self, data):
     """
     web端上传镜像后,服务端这边主要是做镜像同步
     :param data:
         {
             "pool_uuid": "d1c76db6-380a-11ea-a26e-000c2902e179",
             "image_id": "d2699e42-380a-11ea-a26e-000c2902e179",
             "image_path": "",
             "md5_sum": ""
         }
     :return:
     """
     pool_uuid = data.get('pool_uuid')
     pool = db_api.get_resource_pool_by_key("uuid", pool_uuid)
     if not pool:
         logger.error("resource pool: %s not exist", pool_uuid)
         return build_result("ResourcePoolNotExist")
     logger.info("sync the diff disk file to compute nodes")
     controller_image = db_api.get_controller_image()
     # controller = db_api.get_controller_node()
     nodes = db_api.get_node_by_pool_uuid(pool_uuid)
     ips = list()
     tasks = list()
     # failed_nodes = list()
     for item in nodes:
         # if item.ip != controller.ip:
         info = {"ipaddr": item.ip, "host_uuid": item.uuid}
         ips.append(info)
     logger.info("start sync base image, nodes:%s", ips)
     for item in ips:
         th = ResultThread(
             self.sync_base,
             (item['ipaddr'], controller_image.ip, data['image_id'],
              data['image_path'], item['host_uuid'], data['md5_sum']))
         tasks.append(th)
     for task in tasks:
         task.start()
     # with ThreadPoolExecutor(max_workers=constants.MAX_THREADS) as executor:
     #     for ipaddr in ips:
     #         task = executor.submit(self.sync_base, ipaddr, node.ip, data['image_id'])
     #         tasks.append(task)
     #     for future in as_completed(tasks):
     #         res = future.result()
     #         if res.get('code') != 0:
     #             logger.error("node :%s sync base image failed:%s", res['ipaddr'], res.get('msg', ''))
     #             failed_nodes.append(res['ipaddr'])
     # if failed_nodes:
     #     return build_result("ResourceImageSyncError", {"failed_nodes": failed_nodes})
     return build_result("Success")
Beispiel #27
0
 def terminal_hardware(self, data):
     terminal_uuid = data.get("terminal_uuid")
     if not terminal_uuid:
         logger.error("terminal hardware collection error:param error")
         return build_result("ParamError")
     try:
         sql = "select * from yzy_voi_terminal_hard_ware where deleted=False and terminal_uuid=\'{}\'".format(
             terminal_uuid)
         df = pd.read_sql(sql, engine)
         file_target = pd.DataFrame(df, index=range(len(df)), columns=['target'])
         file_all = df.join(file_target, how="outer")
         file_all.to_csv(constants.TERMINAL_HARDWARE_PATH)
         return build_result("Success")
     except Exception as e:
         logger.error("terminal hardware collection error:%s", e, exc_info=True)
         return build_result("OtherError")
Beispiel #28
0
 def post(self, action):
     try:
         data = request.get_json()
         if action == "login":
             return TerminalController().user_login(data)
         elif action == 'logout':
             return TerminalController().user_logout(data)
         elif action == 'change_pwd':
             return TerminalController().user_password_change(data)
         elif action == 'person_desktops':
             return TerminalController().person_desktop_groups(data)
         elif action == 'instance':
             return TerminalController().person_instance(data)
         elif action == "close_instance":
             return TerminalController().person_instance_close(data)
         elif action == "group":
             return TerminalController().person_group()
         else:
             return abort_error(404)
     except Exception as e:
         logger.error("education desktop action %s failed:%d",
                      action,
                      e,
                      exc_info=True)
         return build_result("OtherError")
Beispiel #29
0
 def update_subnet(self, data):
     subnet_uuid = data.get("uuid", "")
     subnet = db_api.get_subnet_by_uuid(subnet_uuid)
     if not subnet:
         logger.error("subnet: %s not exist", subnet_uuid)
         return build_result("SubnetNotExist")
     subnet.name = data['name']
     subnet.start_ip = data['start_ip']
     subnet.end_ip = data['end_ip']
     subnet.netmask = data['netmask']
     subnet.gateway = data['gateway']
     subnet.dns1 = data['dns1']
     subnet.dns2 = data['dns2']
     subnet.soft_update()
     logger.info("update subnet:%s success", subnet_uuid)
     return build_result("Success", data=subnet)
Beispiel #30
0
    def post(self, action):
        try:
            data = request.get_json()
            if action == "create":
                return RemoteStorageController().create_remote_storage(data)

            elif action == "delete":
                remote_storage_uuid = data.get("uuid", "")
                return RemoteStorageController().delete_remote_storage(
                    remote_storage_uuid)

            elif action == 'allocate':
                remote_storage_uuid = data.get("remote_storage_uuid", "")
                resource_pool_uuid = data.get("resource_pool_uuid", "")
                return RemoteStorageController().allocate_remote_storage(
                    remote_storage_uuid, resource_pool_uuid)

            elif action == 'reclaim':
                remote_storage_uuid = data.get("remote_storage_uuid", "")
                return RemoteStorageController().reclaim_remote_storage(
                    remote_storage_uuid)

            elif action == 'show_mount':
                ip_addr = data.get("ip_addr", "")
                return RemoteStorageController().show_mount(ip_addr)
            else:
                return abort_error(404)
        except Exception as e:
            logger.exception("remote storage action %s failed:%s", action, e)
            return build_result("OtherError")