Beispiel #1
0
                                content_type='application/octet-stream')
            response.headers[
                "Content-disposition"] = 'attachment; filename=%s' % file_name
            return response

    @time_logger
    def post(self, action):
        if action == "upload":
            iso_file = request.files["file"]
            file_name = request.args.get("name")
            system_type = request.args.get("system_type")
            filename = iso_file.filename
            print(filename)
            iso_file.save(filename)
            return build_result("Success")

        elif action == "down":
            data = request.get_json()
            image_id = data.get("image_id", "")
            image_type = data.get("image_type", "")
            # return down_iso_file(iso_file)
            return down_image_file(image_id, image_type)


api_v1.add_url_rule('/iso/<string:action>',
                    view_func=IsoAPI.as_view('iso'),
                    methods=["GET", "POST"])
api_v1.add_url_rule('/image/<string:action>',
                    view_func=ImageAPI.as_view('image'),
                    methods=["GET", "POST"])
Beispiel #2
0
                template_uuid = data.get("uuid", "")
                result = TemplateController().edit_template(template_uuid)
            elif action == "resync":
                """
                模板镜像重传
                {
                    "ipaddr": "172.16.1.11",
                    "image_id": "",
                    "path": "",
                    "role": 1,
                    "version": 1
                }
                """
                result = TemplateController().retransmit(data)
            elif action == "check_ip":
                result = TemplateController().check_ip(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("template action %s failed:%s", action, e)
            return build_result("OtherError")


api_v1.add_url_rule('/template/<string:action>',
                    view_func=TemplateAPI.as_view('template'),
                    methods=["GET", "POST"])
Beispiel #3
0
class TerminalInstanceAPI(MethodView):
    @time_logger
    def post(self, action):
        try:
            data = request.get_json()
            if action == "list":
                return TerminalController().terminal_instance_match(data)
            elif action == "close":
                return TerminalController().terminal_instance_close(data)
            elif action == "group":
                return TerminalController().terminal_group_list(data)
            else:
                return abort_error(404)
        except Exception as e:
            logger.error("personal desktop action %s failed:%s",
                         action,
                         e,
                         exc_info=True)
            return build_result("OtherError")


api_v1.add_url_rule('/terminal/personal/<string:action>',
                    view_func=TerminalPersonalAPI.as_view('terminal_personal'),
                    methods=["POST"])
api_v1.add_url_rule('/terminal/education/<string:action>',
                    view_func=TerminalEduAPI.as_view('terminal_education'),
                    methods=["POST"])
api_v1.add_url_rule('/terminal/instance/<string:action>',
                    view_func=TerminalInstanceAPI.as_view('terminal_instance'),
                    methods=["POST"])
Beispiel #4
0
                        "end_ip": "",
                        "dhcp": {
                            "start_ip": "172.16.1.40",
                            "end_ip": "172.16.1.54",
                            "netmask": "255.255.255.0",
                            "gateway": "172.16.1.254",
                            "exclude": [
                                {"start": "172.16.1.24", "end": "172.16.1.24"},
                                {"start": "172.16.1.24", "end": "172.16.1.24"}
                            ]
                        }
                    }
                }
                """
                result = VoiGroupController().update_group(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("voi group action %s failed:%s", action, e)
            return build_result("OtherError")


api_v1.add_url_rule('/voi/group/<string:action>',
                    view_func=VoiEducationGroupAPI.as_view('voi_group'),
                    methods=["POST"])
Beispiel #5
0
                        "title": "支付宝工具",
                        "icon": "alipay",
                        "noCache": True
                    }
                }, {
                    "name": "Preview",
                    "path": "generator/preview/:tableName",
                    "hidden": True,
                    "component": "generator/preview",
                    "meta": {
                        "title": "生成预览",
                        "icon": "java",
                        "noCache": False
                    }
                }]
            }
        ]
        # return jsonify(menus)
        return build_result("Success", {"menus": menus})


api_v1.add_url_rule('/login',
                    view_func=LoginAPI.as_view('login'),
                    methods=['GET', "POST"])
api_v1.add_url_rule('/build',
                    view_func=BuildAPI.as_view('build'),
                    methods=['GET', "POST"])
api_v1.add_url_rule('/dictDetail',
                    view_func=DictDetailAPI.as_view('dictDetail'),
                    methods=['GET', "POST"])
Beispiel #6
0
            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")


api_v1.add_url_rule('/network/<string:action>',
                    view_func=NetworkAPI.as_view('network'),
                    methods=["GET", "POST"])
api_v1.add_url_rule('/subnet/<string:action>',
                    view_func=SubnetAPI.as_view('subnet'),
                    methods=["POST"])
api_v1.add_url_rule('/vswitch/<string:action>',
                    view_func=VirtualSwitchAPI.as_view('vswitch'),
                    methods=["GET", "POST"])
Beispiel #7
0
                    "desktop_name": "",
                    "group_uuid": "",
                    "group_name": ""
                }
                """
                result = InstanceController().change_group(data)
            elif action == "console":
                """
                {
                    "uuid": "",
                    "name": ""
                }
                """
                result = InstanceController().get_console(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("instance action %s failed:%s", action, e)
            return build_result("OtherError")


api_v1.add_url_rule('/desktop/education/<string:action>', view_func=EducationDesktopAPI.as_view('education_desktop'),
                    methods=["POST"])
api_v1.add_url_rule('/desktop/personal/<string:action>', view_func=PersonalDesktopAPI.as_view('personal_desktop'),
                    methods=["POST"])
api_v1.add_url_rule('/instance/<string:action>', view_func=InstanceAPI.as_view('instance'), methods=["POST"])
Beispiel #8
0
                return abort_error(404)
            return build_result("Success", ret)
        except Exception as e:
            logger.error("monitor node action %s failed:%s", action, e, exc_info=True)
            return build_result("OtherError")


class MonitorTerminalAPI(MethodView):

    controller = TerminalMonitorController()

    @time_logger
    def post(self, action):
        try:
            data = request.get_json()
            logger.debug(data)
            if action == "export_resources":
                return self.controller.export_resources(data)
            elif action == "terminal_hardware":
                return self.controller.terminal_hardware(data)
            else:
                return abort_error(404)
        except Exception as e:
            logger.error("monitor terminal action %s failed:%s", action, e, exc_info=True)
            return build_result("OtherError")


api_v1.add_url_rule('/monitor/node/<string:action>', view_func=MonitorNodeAPI.as_view('monitor_node'), methods=["POST"])
api_v1.add_url_rule('/monitor/terminal/<string:action>', view_func=MonitorTerminalAPI.as_view('monitor_terminal'),
                    methods=["POST"])
Beispiel #9
0
            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")


api_v1.add_url_rule('/system/database/<string:action>',
                    view_func=DatabaseManagerAPI.as_view('database_manager'),
                    methods=["POST"])

api_v1.add_url_rule('/system/crontab_task/<string:action>',
                    view_func=CrontabManagerAPI.as_view('add_crontab_manager'),
                    methods=["POST"])

api_v1.add_url_rule('/system/admin/auth',
                    view_func=AdminAuthAPI.as_view('admin-auth'),
                    methods=["POST"])

api_v1.add_url_rule('/system/warn/setup/<string:action>',
                    view_func=WarnSetupManagerAPI.as_view('log_setup_manager'),
                    methods=["POST"])

api_v1.add_url_rule(
Beispiel #10
0
                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")


api_v1.add_url_rule('/course_schedule/<string:action>',
                    view_func=CourseScheduleAPI.as_view('course'),
                    methods=["POST"])
api_v1.add_url_rule('/term/<string:action>',
                    view_func=TermAPI.as_view('term'),
                    methods=["POST"])
Beispiel #11
0
                    "value": {
                        "group_uuid": "570ddad8-27b5-11ea-a53d-562668d3ccea"
                        "user_name": "user1",
                        "passwd": "password",
                        "name": "john",
                        "phone": "13144556677",
                        "email": [email protected]",
                        "enabled": 1
                    }
                }
                """
                result = GroupUserController().update_user(data)

            else:
                result = abort_error(404)
            if result and isinstance(result, dict):
                return jsonify(result)
            else:
                return build_result("ReturnError")
        except Exception as e:
            logger.exception("group user action %s failed:%s", action, e)
            return build_result("OtherError")


api_v1.add_url_rule('/group/<string:action>',
                    view_func=EducationGroupAPI.as_view('group'),
                    methods=["POST"])
api_v1.add_url_rule('/group/user/<string:action>',
                    view_func=GroupUserAPI.as_view('user'),
                    methods=["GET", "POST"])
Beispiel #12
0

class VoiTerminalShareDiskAPI(MethodView):
    @time_logger
    def post(self, action):
        try:
            data = request.get_json()
            logger.info("post data: {}".format(data))
            if action == "create":
                return VoiTerminalController().create_share_disk(data)
            elif action == "update":
                return VoiTerminalController().update_share_disk(data)
            else:
                return abort_error(404)
        except Exception as e:
            logger.error("personal desktop action %s failed:%s",
                         action,
                         e,
                         exc_info=True)
            return build_result("OtherError")


api_v1.add_url_rule(
    '/voi/terminal/education/<string:action>',
    view_func=VoiTerminalEduAPI.as_view('voi_terminal_education'),
    methods=["POST"])
api_v1.add_url_rule(
    '/voi/terminal/share_disk/<string:action>',
    view_func=VoiTerminalShareDiskAPI.as_view('voi_terminal_share_disk'),
    methods=["POST"])
Beispiel #13
0
                return self.node.unbond(data)
            elif action == "master":
                """
                    {
                        "master_ip": "172.16.1.25"
                    }
                """
                return self.node.change_master(data)
            elif action == "disk_part":
                result = self.node.get_disk_parts(data)
            elif action == "vg_detail":
                result = self.node.vg_detail(data)
            elif action == "extend_vg":
                result = self.node.extend_vg(data)
            elif action == "extend_lv":
                result = self.node.extend_lv(data)
            elif action == "create_lv":
                result = self.node.create_lv(data)

            if result and isinstance(result, dict):
                return jsonify(result)
            else:
                return build_result("Success", ret)
        except Exception as e:
            logger.error("node action %s failed:%s", action, e, exc_info=True)
            return build_result("OtherError")


api_v1.add_url_rule('/controller/<string:action>', view_func=ControllerAPI.as_view('controller'), methods=["POST"])
api_v1.add_url_rule('/node/<string:action>', view_func=NodeAPI.as_view('node'), methods=["POST", "GET"])
Beispiel #14
0
                result = VoiTemplateController().get_info_by_system_disk(data)
            elif action == "upload":
                result = VoiTemplateController().upload_template_diff_disk(
                    data)
            elif action == "save_torrent":
                result = VoiTemplateController().save_torrent_file(data)
            elif action == "download":
                result = VoiTemplateController().download_template_diff_disk(
                    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.error("voi template action %s failed:%s",
                         action,
                         e,
                         exc_info=True)
            return build_result("OtherError")


api_v1.add_url_rule('/voi/template/<string:action>',
                    view_func=VoiTemplateAPI.as_view('voi_template'),
                    methods=["GET", "POST"])
api_v1.add_url_rule('/voi/template_disk/<string:action>',
                    view_func=VoiTemplateDiskAPI.as_view('voi_template_disk'),
                    methods=["GET", "POST"])
Beispiel #15
0
class IndexAPI(MethodView):
    @time_logger
    def post(self, action):
        try:
            data = request.get_json()
            logger.debug("action: {}, data: {}".format(action, data))
            if action == "get_top_data":
                statis_period = data.get("statis_period", None)
                if statis_period:
                    result = IndexController().get_top_data(statis_period)
                else:
                    result = dict()
            elif action == "get_voi_data":
                result = IndexController().get_voi_data(data)
            else:
                result = abort_error(404)
            if result and isinstance(result, dict):
                return jsonify(result)
            else:
                return build_result("ReturnError")
        except Exception as e:
            logger.error("index action %s failed:%s", action, e)
            logger.error(''.join(traceback.format_exc()))
            return build_result("OtherError")


api_v1.add_url_rule('/index/<string:action>',
                    view_func=IndexAPI.as_view('index'),
                    methods=["POST"])
Beispiel #16
0
                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")


api_v1.add_url_rule('/remote_storage/<string:action>',
                    view_func=RemoteStorageAPI.as_view('remote_storage'),
                    methods=["GET", "POST"])
Beispiel #17
0
            elif action == "resync":
                """
                {
                    "ipaddr": "172.16.1.11",
                    "image_id": "",
                    "image_path": "",
                    "md5_sum": ""
                }
                """
                return ResourcePoolController().retransmit_image(data)
            elif action == "publish":
                return ResourcePoolController().publish_images(data)

            elif action == "delete":
                # 删除基础镜像
                return ResourcePoolController().delete_images(data)

            return abort_error(404)
        except Exception as e:
            logger.exception("resource pool image action %s failed:%s", action,
                             e)
            return build_result("OtherError")


api_v1.add_url_rule('/resource_pool/<string:action>',
                    view_func=ResourcePoolAPI.as_view('resource_pool'),
                    methods=["GET", "POST"])
api_v1.add_url_rule('/resource_pool/images/<string:action>',
                    view_func=ResourcePoolImagesAPI.as_view('images'),
                    methods=["GET", "POST"])
Beispiel #18
0
                desktop_uuid = data.get("uuid", "")
                result = VoiDesktopController().delete_voi_desktop(
                    desktop_uuid)
                if result.get("code", -1) == 0:
                    self.notify_terminal(desktop_uuid)

            elif action == "update":
                desktop_uuid = data.get("uuid", "")
                result = VoiDesktopController().update_voi_desktop(data)
                if result.get("code", -1) == 0:
                    self.notify_terminal(desktop_uuid)

            else:
                return abort_error(404)
            if result and isinstance(result, dict):
                return jsonify(result)
            else:
                return build_result("ReturnError")
        except Exception as e:
            logger.error("voi education desktop action %s failed:%d",
                         action,
                         e,
                         exc_info=True)
            return build_result("OtherError")


api_v1.add_url_rule(
    '/voi/desktop/education/<string:action>',
    view_func=VoiEducationDesktopAPI.as_view('voi_education_desktop'),
    methods=["POST"])