package com.bocloud.ims.booter.controller.resource.compute;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bocloud.cmp.model.CloudServerBean;
import com.bocloud.cmp.model.KeypairParam;
import com.bocloud.cmp.model.SecurityGroupOperationParam;
import com.bocloud.cmp.model.common.ApplicationParam;
import com.bocloud.cmp.model.fusionsphere.CdromModel;
import com.bocloud.cmp.vm.model.*;
import com.bocloud.common.annotations.Log;
import com.bocloud.common.enums.BoCloudService;
import com.bocloud.common.model.*;
import com.bocloud.common.utils.Common;
import com.bocloud.common.utils.JSONTools;
import com.bocloud.common.utils.ResultTools;
import com.bocloud.ims.entity.params.QosParam;
import com.bocloud.ims.entity.params.ServerPerformanceParam;
import com.bocloud.ims.entity.resource.*;
import com.bocloud.ims.interfaces.resource.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.Base64;
import java.util.List;
import java.util.Map;


@Slf4j
@Api(value = "云主机管理", tags = "云主机管理")
@RestController
@RequestMapping("/v1/vms")
public class CloudServerController {

    @Autowired
    private CloudServerService cloudServerService;

    @Autowired
    private ResourceAllocateService resourceAllocateService;
    @Autowired
    private RosProcessService rosProcessService;
    @Autowired
    private FileDownloadService fileDownloadService;
    @Autowired
    private VMExtendService vmExtendService;
    @Autowired
    private VMApplyService vMApplyService;

    /**
     * 云主机列表查询
     *
     * @param pager
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询云主机列表", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "查看云主机列表")
    @GetMapping
    public BocloudResult<GridBean<CloudServer>> list(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context) {
        return cloudServerService.list(pager, context);
    }

    /**
     * 云主机列表查询
     *
     * @param pager
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询云主机列表", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "查看云主机列表")
    @GetMapping("/countByUser")
    public BocloudResult<GridBean<CloudServer>> countByUser(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context) {
        return cloudServerService.countByUser(pager, context);
    }

    /**
     * 查询云主机列表(自服务专用)
     *
     * @author sxp
     * @since 2023/8/1
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询云主机列表(自服务专用)", httpMethod = "GET")
    @GetMapping("/tenant")
    public BocloudResult<GridBean<CloudServer>> listForTenant(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context) {
        return cloudServerService.listForTenant(pager, context);
    }

    /**
     * 云主机列表查询
     *
     * @param condition
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "通过condition方式查询云主机列表", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "查看云主机列表")
    @GetMapping("/condition")
    public BocloudResult condition(@RequestParam(value = Common.PAGE, required = false) Integer page,
        @RequestParam(value = Common.ROWS, required = false) Integer rows,
        @RequestParam(Common.CONDITION) String condition, @Value(Common.REQ_CONTEXT) RequestContext context) {
        return cloudServerService.condition(page, rows, condition, context);
    }

    /**
     * 查看云主机统计
     *
     * @param range
     * @param hostId
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询云主机统计", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "查看云主机统计")
    @GetMapping("/file")
    public BocloudResult statistics(@RequestParam(value = "range") String range,
        @RequestParam(value = "hostId") Long hostId, @Value(Common.REQ_CONTEXT) RequestContext context) {
        return vmExtendService.stats(range, hostId, context);
    }

    /**
     * @param context
     * @return com.bocloud.common.model.BocloudResult
     * @Author: lxy
     * @Description: 云平台下云主机信息（个数、cpu、men、disk）统计
     * @Date 2021/5/26 16:42
     * @Param hostId
     * @throws:
     **/
    @ApiOperation(tags = {"CMC", "CSC"}, value = "宿主机下云主机信息统计", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "宿主机下云主机信息统计")
    @GetMapping("/selectAllByVendorId")
    public BocloudResult selectAllByVendorId(@RequestParam(value = "vendorId", required = false) Long vendorId,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        return vmExtendService.selectAllByVendorId(vendorId, context);
    }

    /**
     * 导出云主机列表
     *
     * @param pager
     * @param condition
     * @param action
     * @param context
     * @param request
     * @param response
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "导出云主机列表", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "导出vcenter云主机列表")
    @GetMapping("/download")
    public void download(Pager pager,
        @RequestParam(value = Common.CONDITION, required = false) String condition,
        @RequestParam(value = Common.ACTION, required = false) String action,
        @Value(Common.REQ_CONTEXT) RequestContext context, HttpServletRequest request, HttpServletResponse response) {
        BocloudResult<Map<String, Object>> bocloudResult =
            fileDownloadService.vmDownload(pager, condition, action, context);
        if (bocloudResult.isSuccess()) {
            String content;
            try {
                Map<String, Object> result = bocloudResult.getData();
                String fileName = result.get("fileName").toString();
                if (fileName.contains("pdf")) {
                    response.setContentType("application/pdf");
                } else {
                    response.setContentType("application/vnd.ms-excel");
                }
                final String userAgent = request.getHeader("user-agent").toLowerCase();
                if (userAgent.contains("trident") || userAgent.contains("edge")) {
                    fileName = URLEncoder.encode(fileName, "UTF-8");
                } else {
                    fileName = new String(fileName.getBytes("utf-8"), "iso-8859-1");
                }
                response.setCharacterEncoding("utf-8");
                response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
                OutputStream outputStream = response.getOutputStream();
                content = (String)result.get("data");
                if (content != null) {
                    byte[] bytes = Base64.getDecoder().decode(content);
                    outputStream.write(bytes);
                    outputStream.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 导入云主机列表
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "导入云主机列表", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "导入云主机列表")
    @PostMapping("/import")
    public Result importData(@Value(Common.REQ_CONTEXT) RequestContext requestContext, HttpServletRequest request) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        List<MultipartFile> fileList = multipartRequest.getFiles("file");
        if (fileList.isEmpty()) {
            return new Result(false, "文件错误");
        }
        MultipartFile multipartFile = fileList.get(0);
        String originalFilename = multipartFile.getOriginalFilename();
        // 判断文件名
        if (originalFilename == null || !(originalFilename.endsWith(".xls") || originalFilename.endsWith(".xlsx") || originalFilename.endsWith(".csv"))) {
            return new Result(false, "文件错误");
        }
        new Thread(() -> {
            try {
                cloudServerService.importData(multipartFile, requestContext);
            } catch (Exception e) {
                log.error("导入云主机列表失败", e);
                cloudServerService.sendNotice(false, "导入分配云主机失败：", requestContext);
            }
        }).start();
        return new Result(true, "导入任务已下发");
    }

    /**
     * 添加云主机
     *
     * @param params
     *            云主机属性信息的json字符串，在数据转换时会发生异常，对外抛出400异常【Bad Request】
     * @return 添加结果
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "添加云主机", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "添加云主机")
    @PostMapping
    public BocloudResult create(@RequestBody VmGenericParam params, @Value(Common.REQ_CONTEXT) RequestContext context) {
        String action = params.getAction();
        if ("create".equalsIgnoreCase(action)) {
            return cloudServerService.create(params, context);
        } else if ("ResourcesPool".equalsIgnoreCase(action)) {
            // 指定资源池创建云主机
            return cloudServerService.createInResPool(params, context);
        }
        return new BocloudResult(false, "无效操作！");
    }

    /**
     * 创建快照
     *
     * @param id
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "创建快照", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "创建快照")
    @PostMapping("/{id}/snapshots")
    public BocloudResult snapshot(@PathVariable(value = Common.ID) Long id, @RequestBody VmSnapshotParam params,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        params.setServerId(id);
        return cloudServerService.snapshot(params, context);
    }

    /**
     * 批量创建快照
     *
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "批量创建快照", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "创建快照")
    @PostMapping("/snapshots")
    public BocloudResult batchSnapshot(@RequestBody BatchSnapshotParam params,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        return cloudServerService.batchSnapshot(params, context);
    }

    /**
     * 修改云主机
     *
     * @param bean
     * @param id
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "修改云主机", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "修改云主机")
    @PutMapping("/{id}")
    public BocloudResult modify(@RequestBody CloudServerBean bean, @PathVariable(value = Common.ID) Long id,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        bean.setId(id);
        return cloudServerService.modify(bean, context, null);
    }

    /**
     * 修改数据库中的云主机信息
     *
     * @author sxp
     * @since 2023/8/3
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "修改云主机", httpMethod = "PUT")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "修改数据库中的云主机信息")
    @PutMapping("/db/{id}")
    public BocloudResult modifyServerOfDb(@RequestBody CloudServer bean, @PathVariable(value = Common.ID) Long id,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        bean.setId(id);
        return cloudServerService.modifyServerOfDb(bean, context, null);
    }

    /**
     * 删除云主机
     *
     * @param id
     *            云主机ID
     * @return 操作结果
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "删除云主机", httpMethod = "DELETE")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "删除云主机")
    @DeleteMapping("/{id}")
    public BocloudResult remove(@PathVariable(value = Common.ID) Long id,
        @RequestBody(required = false) VmDeleteParam vmDeleteParam, @Value(Common.REQ_CONTEXT) RequestContext context) {
        if (null != vmDeleteParam) {
            vmDeleteParam.setId(id);
        }
        return cloudServerService.remove(id, vmDeleteParam, context);
    }

    /**
     * 批量删除云主机
     *
     * @param ids
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "批量删除云主机", httpMethod = "DELETE")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "删除云主机")
    @DeleteMapping
    public BocloudResult batchRemove(@RequestBody List<Long> ids, @Value(Common.REQ_CONTEXT) RequestContext context) {
        return cloudServerService.batchRemove(ids, context);
    }

    /**
     * 更新物理机的资源分组
     *
     * @param id
     * @param resourceGroup
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "更新资源分组", httpMethod = "PUT")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "更新资源分组")
    @PutMapping("/groups")
    public BocloudResult updateResourceGroup(@RequestParam(value = Common.ID) String id,
        @RequestParam(value = "resourceGroup") String resourceGroup,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        if (StringUtils.isNotEmpty(id)) {
            String[] ids = id.split(",");
            return vmExtendService.updateResourceGroup(ids, resourceGroup, context.getTarget());
        }
        return new BocloudResult(false, "暂不支持");
    }

    /**
     * 查看云主机详细信息
     *
     * @param id
     * @param context
     * @param action
     * @param params
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查看云主机详情", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "查看云主机详情")
    @GetMapping("/{id}")
    public BocloudResult detail(@PathVariable(value = Common.ID) Long id,
        @Value(Common.REQ_CONTEXT) RequestContext context,
        @RequestParam(value = Common.ACTION, required = false) String action,
        @RequestParam(value = Common.PARAMS, required = false) String params) {
        return cloudServerService.details(id, context, action, params);
    }

    /**
     * 云主机操作类
     *
     * @param id
     * @param context
     * @param params
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "云主机操作", httpMethod = "PATCH")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "克隆云主机")
    @PatchMapping("/{id}")
    public BocloudResult operation(@PathVariable(value = Common.ID) Long id,
        @Value(Common.REQ_CONTEXT) RequestContext context, @RequestBody VmGenericParam params) {
        return cloudServerService.operations(id, params, context);
    }

    /**
     * 云主机磁盘操作
     *
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "云主机磁盘操作", httpMethod = "PATCH")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "云主机磁盘操作")
    @PatchMapping("/disks")
    public BocloudResult diskOperation(@RequestBody DiskOperationParam params,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        return vmExtendService.diskOperation(params, context);
    }

    /**
     * 云主机批量操作
     *
     * @param batchOperationParam
     * @param action
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "云主机批量操作", httpMethod = "PATCH")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "批量重启云主机")
    @PatchMapping
    public BocloudResult batchOperations(@RequestBody VmBatchOperationParam batchOperationParam,
        @RequestParam(value = Common.ACTION, required = false) String action,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        return cloudServerService.batchOperations(batchOperationParam, context);
    }

    /**
     * 获取监控数据接口
     *
     * @param id
     * @param params
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "获取监控数据", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "获取监控数据")
    @GetMapping("/{id}/metrics")
    public BocloudResult performance(@PathVariable(value = Common.ID) Long id,
        @RequestBody(required = false) ServerPerformanceParam params) {
        return vmExtendService.performance(params);
    }

    /**
     * 网络列表
     *
     * @param id
     *            任务ID
     * @return 操作结果
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查看网络列表", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "查看网络列表")
    @GetMapping("/{id}/networks")
    public BocloudResult<List<PortGroup>> networks(@PathVariable(value = Common.ID) Long id) {
        return vmExtendService.networks(id);
    }

    /**
     * 根据VDC 集群 宿主机 查询网络标签
     *
     *            任务ID
     * @return 操作结果
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查看网络列表", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "查看网络列表")
    @GetMapping("/networks")
    public BocloudResult<List<PortGroup>> networkResources(
        @RequestParam(value = "resourceIds", required = false) String resourceIds,
        @RequestParam(value = "type", required = false) String type) {
        return vmExtendService.networkResources(resourceIds, type);
    }

    /**
     * 根据azUuid查询深信服的端口组
     *
     *            任务ID
     * @return 操作结果
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查看网络列表", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "查看网络列表")
    @GetMapping("/sangfor/networks")
    public BocloudResult<List<SangforVlanGroup>> sangforNetwork(
        @RequestParam(value = "azUuid", required = false) String azUuid) {
        return vmExtendService.sangforNetwork(azUuid);
    }

    /**
     * 修改云主机密码(openstack)
     *
     * @param id
     * @param vmModifyParam
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "修改OpenStack云主机密码", httpMethod = "PATCH")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "修改OpenStack云主机密码")
    @PatchMapping("/{id}/password")
    public BocloudResult osChangePwd(@PathVariable(value = Common.ID) Long id, @RequestBody VmModifyParam vmModifyParam,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        return vmExtendService.osChangePwd(vmModifyParam.getVendorId(), id, vmModifyParam.getPassword(), context);
    }

    /**
     * 挂载网卡(openstack)
     *
     * @param id
     * @param attachNetworkParam
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "挂载OpenStack网卡", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "挂载OpenStack网卡")
    @PostMapping("/{id}/networks")
    public BocloudResult attachNetwork(@PathVariable(value = Common.ID) Long id,
        @RequestBody AttachNetworkParam attachNetworkParam, @Value(Common.REQ_CONTEXT) RequestContext context) {
        attachNetworkParam.setId(id);
        return vmExtendService.attachNetwork(attachNetworkParam, context);
    }

    /**
     * 挂载网卡(openstack)
     *
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "批量挂载OpenStack网卡", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "挂载OpenStack网卡")
    @PostMapping("/networks")
    public BocloudResult batchAttachNetwork(@RequestBody List<AttachNetworkParam> params,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        return vmExtendService.batchAttachNetwork(params, context);
    }

    /**
     * 卸载网卡(openstack)
     *
     * @param id
     * @param portId
     * @param context
     * @param action
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "卸载OpenStack网卡", httpMethod = "DELETE")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "卸载OpenStack网卡")
    @DeleteMapping("/{id}/networks")
    public BocloudResult detachNetwork(@PathVariable(value = Common.ID) Long id,
        @RequestParam(value = "portId", required = false) Long portId,
        @Value(Common.REQ_CONTEXT) RequestContext context,
        @RequestParam(value = Common.ACTION, required = false) String action) {
        return vmExtendService.detachNetworks(id, portId, context, action);
    }

    /**
     * 设置网卡qos
     *
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "设置网卡qos", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "设置网卡qos")
    @PostMapping("/{id}/networks/qos")
    public BocloudResult addPortPolicy(@PathVariable(value = Common.ID) Long id, @RequestBody QosParam params,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        params.setId(id);
        return vmExtendService.addPortPolicy(JSONObject.toJSONString(params), context);
    }

    /**
     * 修改配置
     *
     * @param id
     * @param vmModifyParam
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "修改OpenStack云主机配置", httpMethod = "PATCH")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "修改OpenStack云主机配置")
    @PatchMapping("/{id}/flavors")
    public BocloudResult flavors(@PathVariable(value = Common.ID) Long id, @RequestBody VmModifyParam vmModifyParam,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        vmModifyParam.setId(id);
        return vmExtendService.resizes(vmModifyParam, context);
    }

    @ApiOperation(tags = {"CMC", "CSC"}, value = "修改云主机配置", httpMethod = "PATCH")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "修改云主机配置")
    @PatchMapping("/{id}/resize")
    public BocloudResult resize(@PathVariable(value = Common.ID) Long id, @RequestBody String params,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        return vMApplyService.upgradeConfig(params, context);
    }

    /**
     * 查询云主机绑定的端口
     *
     * @param id
     * @param params
     * @param context
     * @param action
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询云主机绑定的端口", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "查询云主机绑定的端口")
    @GetMapping("/{id}/ports")
    public BocloudResult<List<Port>> listPort(@PathVariable(value = Common.ID) Long id,
        @RequestParam(value = Common.PARAMS, required = false) String params,
        @Value(Common.REQ_CONTEXT) RequestContext context,
        @RequestParam(value = Common.ACTION, required = false) String action) {
        return vmExtendService.ports(params, context, action);
    }

    /**
     * 查询高于云主机当前配置的规格
     *
     * @param params
     * @param context
     * @param action
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询高于云主机当前配置的规格", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "查询高于云主机当前配置的规格")
    @GetMapping("/flavors")
    public BocloudResult listFlavor(@RequestParam(value = Common.PARAMS, required = false) String params,
        @Value(Common.REQ_CONTEXT) RequestContext context,
        @RequestParam(value = Common.ACTION, required = false) String action) {
        return vmExtendService.flavors(params, context, action);
    }

    /**
     * 修改账号密码
     *
     * @param account
     * @param password
     * @param id
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询高于云主机当前配置的规格", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "修改账号密码")
    @PutMapping("/{id}/accounts")
    public BocloudResult modifyAccount(@PathVariable(value = Common.ID) Long id,
        @RequestBody VmModifyParam vmModifyParam, @Value(Common.REQ_CONTEXT) RequestContext context) {
        return vmExtendService.modifyAccount(id, vmModifyParam.getAccount(), vmModifyParam.getPassword(), context);
    }

    /**
     * 查看账号密码
     *
     * @param id
     *            云主机ID
     * @return 操作结果
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查看账号密码", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "查看账号密码")
    @GetMapping("/{id}/accounts")
    public BocloudResult<CloudServer> detailAccount(@PathVariable(value = Common.ID) Long id,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        return vmExtendService.queryAccount(id);
    }

    /**
     * 云主机CPU或内存热插拔设置
     *
     * @param id
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "云主机CPU或内存热插拔设置", httpMethod = "PATCH")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "云主机CPU或内存热插拔设置")
    @PatchMapping("/{id}/pluggable")
    public BocloudResult hotConfigEnable(@PathVariable(value = Common.ID) Long id,
        @RequestBody VmModifyParam vmModifyParam, @Value(Common.REQ_CONTEXT) RequestContext context) {
        if (null != vmModifyParam) {
            return vmExtendService.hotConfigEnable(vmModifyParam.getServerId(), context.getTarget(),
                vmModifyParam.getCpuHotEnable(), vmModifyParam.getMemHotEnable());
        }
        return ResultTools.formatErrResult();
    }

    /**
     * 获得vcenter访问remote console的ticket
     *
     * @param id
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "获得vcenter访问remote console的ticket", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "获得vcenter访问remote console的ticket")
    @GetMapping("/{id}/tickets")
    public BocloudResult getTicket(@PathVariable(value = Common.ID) Long id) {
        return vmExtendService.getTicket(id);
    }

    /**
     * 获取VNC远程登录地址
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "获取VNC远程登录地址", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "获取VNC远程登录地址")
    @GetMapping("/{id}/vnc")
    public BocloudResult getVnc(@PathVariable(value = Common.ID) Long id){
        return vmExtendService.getVnc(id);
    }

    /**
     * 获得vcenter访问vmrc控制台
     *
     * @param id
     * @param action
     * @param vncType
     * @param serverId
     * @param region
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "获得vcenter访问vmrc控制台", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "获得vcenter访问vmrc控制台")
    @GetMapping("/{id}/console")
    public BocloudResult console(@PathVariable(value = Common.ID) Long id,
        @RequestParam(value = Common.ACTION, required = false) String action,
        @RequestParam(value = "vncType", required = false) String vncType,
        @RequestParam(value = "serverId", required = false) String serverId,
        @RequestParam(value = "region", required = false) String region,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        return vmExtendService.vncconsoles(id, vncType, serverId, region, context, action);
    }

    /**
     * 挂载/卸载 vmware tools安装镜像
     *
     * @param id
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "挂载vmware tools安装镜像", httpMethod = "PATCH")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "挂载vmware tools安装镜像")
    @PatchMapping("/{id}/vmtools")
    public BocloudResult mountToolsInstaller(@PathVariable(value = Common.ID) Long id,
        @RequestBody VmModifyParam vmModifyParam, @Value(Common.REQ_CONTEXT) RequestContext context) {
        if (null == vmModifyParam) {
            return new BocloudResult<>(false, "参数格式错误");
        }
        return vmExtendService.vmtools(id, vmModifyParam, context);
    }

    /**
     * 根据集群维度或平台维度汇总云主机数量
     *
     * @param params
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "根据集群维度或平台维度汇总云主机数量", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "根据集群维度或平台维度汇总云主机数量")
    @GetMapping("/summary")
    public BocloudResult chart(@RequestParam(value = Common.PARAMS, required = true) String params) {
        return vmExtendService.chart(params);
    }

    /**
     * 分配给用户
     *
     * @param id
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "云主机用户分配", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "云主机用户分配")
    @PostMapping("/users")
    public BocloudResult assign(@RequestBody ResourceAssignParam vmAssignParam,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        return resourceAllocateService.assign(JSONObject.parseObject(JSON.toJSONString(vmAssignParam)),
            vmAssignParam.getResourceCategory(), context);
    }

    /**
     * 批量加入安全组
     *
     * @param id
     * @param securityGroupOperationParam
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "批量加入安全组", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "批量加入安全组")
    @PostMapping("/{id}/sgroups")
    public BocloudResult joinsgrouplist(@PathVariable(value = Common.ID) Long id,
        @RequestBody SecurityGroupOperationParam securityGroupOperationParam,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        return vmExtendService.joinGroups(securityGroupOperationParam, context);
    }

    /**
     * 移除安全组
     *
     * @param id
     * @param groupId
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "移除安全组", httpMethod = "DELETE")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "移除安全组")
    @DeleteMapping("/{id}/sgroups")
    public BocloudResult leaveSGroup(@PathVariable(value = Common.ID) Long id,
        @RequestParam(value = "groupId", required = true) Long groupId,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        return vmExtendService.leaveSGroup(id, groupId, context);
    }

    /**
     * 查询云主机绑定的安全组
     *
     * @param id
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询云主机绑定的安全组", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "查询云主机绑定的安全组")
    @GetMapping("/{id}/sgroups")
    public BocloudResult<List<SecurityGroup>> listSGroup(@PathVariable(value = Common.ID) Long id,
        @Value(Common.REQ_CONTEXT) RequestContext context,
        @RequestParam(value = Common.ACTION, required = false) String action,
        @RequestParam(value = "vpcUuid", required = false) String vpcUuid) {
        return vmExtendService.sgroups(id, context, action, vpcUuid);
    }

    /**
     * 回收租户云主机
     *
     * @param id
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "回收租户云主机", httpMethod = "DELETE")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "回收租户云主机")
    @DeleteMapping("/users")
    public BocloudResult reclaim(@RequestBody ResourceAssignParam vmAssignParam,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        if (null == vmAssignParam) {
            return new BocloudResult<>(false, "参数格式错误");
        }
        return resourceAllocateService.reclaim(vmAssignParam, vmAssignParam.getResourceCategory(), context);
    }

    /**
     * 回收虚拟机
     * <p>
     * com.bocloud.common.http.HttpClient的DELETE方法在服务间调用有bug，无法传递请求体
     * </p>
     *
     * @author sxp
     * @since 2023/8/5
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "回收租户云主机", httpMethod = "DELETE")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "回收租户云主机")
    @PostMapping("/reclaim")
    public BocloudResult reclaimForInterface(@RequestBody ResourceAssignParam vmAssignParam,
                                 @Value(Common.REQ_CONTEXT) RequestContext context) {
        if (null == vmAssignParam) {
            return new BocloudResult<>(false, "参数格式错误");
        }
        return resourceAllocateService.reclaim(vmAssignParam, vmAssignParam.getResourceCategory(), context);
    }

    /**
     * 云主机标记为模板
     *
     * @param id
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "云主机标记为模板", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "云主机标记为模板")
    @PostMapping("/{id}/templates")
    public BocloudResult markAsTemplate(@PathVariable(value = Common.ID) Long id,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        return vmExtendService.markAsTemplate(id, context);
    }

    /**
     * 修改云主机密码
     *
     * @param id
     * @param vmModifyParam
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "修改云主机密码", httpMethod = "PUT")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "修改云主机密码")
    @PutMapping("/{id}/password")
    public BocloudResult vcChangePasswd(@PathVariable(value = Common.ID) Long id,
        @RequestBody VmModifyParam vmModifyParam, @Value(Common.REQ_CONTEXT) RequestContext context) {
        return vmExtendService.vcChangePasswd(vmModifyParam, context);
    }

    /**
     * 批量配置云主机标签
     *
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "批量配置云主机标签", httpMethod = "PUT")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "批量配置云主机标签")
    @PutMapping("/tags")
    public BocloudResult batchModifyLabel(@RequestBody BatchModifyLabelParam params,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        return vmExtendService.batchModifyLabel(params, context);
    }

    /**
     * 扩容vcenter云主机磁盘容量
     *
     * @param id
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "扩容vcenter云主机磁盘容量", httpMethod = "PUT")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "扩容vcenter云主机磁盘容量")
    @PutMapping("/{id}/disks")
    public BocloudResult diskExtend(@PathVariable(value = Common.ID) Long id,
        @RequestParam(value = Common.PARAMS, required = true) String params,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        return vmExtendService.diskExtend(params, context);
    }

    /**
     * 查询模板
     *
     * @param id
     * @param vendorId
     * @param vdcId
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询模板", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "查询模板")
    @GetMapping("/{id}/templates")
    public BocloudResult<List<CloudServer>> listTemplate(@PathVariable(value = Common.ID) Long id,
        @RequestParam(value = Common.VENDORID, required = false) Long vendorId,
        @RequestParam(value = "vdcId", required = false) Long vdcId) {
        return cloudServerService.listTemplate(vendorId, vdcId);
    }

    /**
     * 安装vmware tools
     *
     * @param id
     * @param params
     * @param context
     * @param action
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "安装vmware tools", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "安装vmware tools")
    @PostMapping("/{id}/vmtools")
    public BocloudResult vmToolsInstall(@PathVariable(value = Common.ID) Long id,
        @RequestParam(value = Common.PARAMS, required = true) String params,
        @Value(Common.REQ_CONTEXT) RequestContext context,
        @RequestParam(value = Common.ACTION, required = false) String action) {
        return vmExtendService.vmToolsInstalls(params, context, action);

    }

    /**
     * 创建k8s云主机
     *
     * @param params
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "创建k8s云主机", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "创建k8s云主机")
    @PostMapping("/k8s")
    public BocloudResult createK8sVm(@RequestParam(value = Common.PARAMS) String params) {
        JSONObject object = JSONObject.parseObject(params);
        if (null == object) {
            return ResultTools.formatErrResult();
        }
        return rosProcessService.createK8sVm(object);
    }

    /**
     * 查询云主机绑定的秘钥
     *
     * @param id
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询云主机绑定的秘钥", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "查询云主机绑定的秘钥")
    @GetMapping("/{id}/keypairs")
    public BocloudResult<List<Keypair>> listBindedKeyPair(@PathVariable(value = Common.ID) Long id,
        @Value(Common.REQ_CONTEXT) RequestContext context,
        @RequestParam(value = Common.ACTION, required = false) String action) {
        return vmExtendService.keypairs(id, context, action);
    }

    /**
     * 云主机绑定秘钥
     *
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "云主机绑定秘钥", httpMethod = "PATCH")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "云主机绑定秘钥")
    @PatchMapping("/{id}/keypairs")
    public BocloudResult bindKeypair(@PathVariable(value = Common.ID) Long id, @RequestBody KeypairParam keypairParam,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        return vmExtendService.bindKeypairs(keypairParam, context);
    }

    /**
     * 查看云主机存储卷
     *
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查看云主机存储卷", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "查看云主机存储卷")
    @GetMapping("/volumes")
    public BocloudResult<List<Volume>> listVolume(@RequestParam(value = Common.PARAMS, required = false) String params,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        JSONObject jsonObject = JSONTools.isJSONObj(params);
        if (null != jsonObject) {
            return vmExtendService.listVolume(params);
        }
        return ResultTools.formatErrResult();
    }

    /**
     * 挂载卷
     *
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "云主机挂载卷", httpMethod = "PATCH")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "云主机挂载卷")
    @PatchMapping("/{id}/volumes")
    public BocloudResult attachVolume(@RequestParam(value = Common.PARAMS, required = true) String params,
                                      @RequestParam(value = Common.ACTION, required = false) String action,
                                      @Value(Common.REQ_CONTEXT) RequestContext context) {
        return vmExtendService.volumes(params, action, context);
    }

    /**
     * 根据云主机查询卷
     *
     * @param action attached 查询云主机已经挂载的卷 attachable 查询可供云主机挂载的卷
     * @param pager
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "根据云主机查询卷", httpMethod = "PATCH")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "根据云主机查询卷")
    @GetMapping("/{id}/volumes")
    public BocloudResult<GridBean<Volume>> listVolumes(Pager pager,
                                                       @PathVariable(value = Common.ID) Long id,
                                                       @RequestParam(value = Common.ACTION) String action,
                                                       @Value(Common.REQ_CONTEXT) RequestContext context
    ) {
        if ("attachable".equals(action)) {
            return vmExtendService.listVolumeForAttach(id, pager);
        } else if ("attached".equals(action)) {
            return vmExtendService.listVolumeOfAttached(id, pager);
        } else {
            return new BocloudResult<>(false, "未知的参数action");
        }
    }

    /**
     * 根据云主机查询ISO映像
     *
     * @param action attached 查询云主机已经挂载的ISO映像 attachable 查询可供云主机挂载的ISO映像
     * @param pager
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "根据云主机查询ISO映像", httpMethod = "PATCH")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "根据云主机查询ISO映像")
    @GetMapping("/{id}/images")
    public BocloudResult<GridBean<Image>> listImages(Pager pager,
                                                      @PathVariable(value = Common.ID) Long id,
                                                      @RequestParam(value = Common.ACTION) String action,
                                                      @Value(Common.REQ_CONTEXT) RequestContext context
    ) {
        if ("attachable".equals(action)) {
            return vmExtendService.listImageForAttach(id, pager);
        } else if ("attached".equals(action)) {
            return vmExtendService.listImageOfAttached(id, pager);
        } else if ("cloneable".equals(action)) {
            return vmExtendService.listImageOfCloneable(id, pager);
        } else {
            return new BocloudResult<>(false, "未知的参数action");
        }
    }



    /**
     * 云主机捕获映像对云主机使用卷的操作
     *
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "云主机捕获映像对云主机使用卷的操作", httpMethod = "PUT")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "云主机捕获映像对云主机使用卷的操作")
    @PutMapping("/{id}/images")
    public BocloudResult beforeCaptureImage(@RequestParam(value = Common.PARAMS, required = true) String params,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        JSONObject object = JSONTools.isJSONObj(params);
        if (null != object) {
            return vmExtendService.beforeCaptureImage(params, context);
        }
        return ResultTools.formatErrResult();
    }

    /**
     * 云主机捕获映像
     *
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "云主机捕获映像", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "云主机捕获映像")
    @PostMapping("/{id}/images")
    public BocloudResult captureImage(@PathVariable(value = Common.ID) Long id,
        @RequestParam(value = Common.PARAMS, required = true) String params,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        JSONObject object = JSONTools.isJSONObj(params);
        if (null != object) {
            return vmExtendService.captureImage(params, context);
        }
        return ResultTools.formatErrResult();
    }

    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询可绑定云主机", response = BocloudResult.class, httpMethod = "GET",
        produces = MediaType.APPLICATION_JSON_VALUE)
    @GetMapping("/availableVms")
    public BocloudResult listAllVm(@RequestBody VmGenericParam vmGenericParam,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        if (null != vmGenericParam) {
            return cloudServerService.listAvailableVm(vmGenericParam.getVendorId(), vmGenericParam.getRegionId(),
                context);
        }
        return ResultTools.formatErrResult();
    }

    @ApiOperation(value = "流水号配置", response = BocloudResult.class, httpMethod = "POST",
        produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/configSeq")
    public BocloudResult configSeq(@RequestParam(value = Common.PARAMS, required = false) String params,
        @Value(Common.REQ_CONTEXT) RequestContext context) {
        return cloudServerService.configSeq(params, context);
    }

    @ApiOperation(value = "流水号配置详情", response = BocloudResult.class, httpMethod = "GET",
        produces = MediaType.APPLICATION_JSON_VALUE)
    @GetMapping(value = "/getBusinessById/{id}")
    public BocloudResult getBusinessById(@PathVariable(value = Common.ID) Long id) {
        return cloudServerService.getBusinessById(id);
    }

    @ApiOperation(tags = {"CMC", "CSC"}, value = "云主机查询可调整的规格配置", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "云主机查询可调整的规格配置")
    @GetMapping("/{id}/available/sizes")
    public BocloudResult availableSizes(@PathVariable(value = Common.ID) Long id) {
        return cloudServerService.availableSizes(id);
    }


    @ApiOperation(tags = {"CMC", "CSC"}, value = "开启通用化", httpMethod = "PATCH")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "开启通用化")
    @PatchMapping("/{id}/generalize")
    public BocloudResult generalize(@PathVariable(value = Common.ID) Long id,
                                    @Value(Common.REQ_CONTEXT) RequestContext context) {
        return cloudServerService.generalize(id, context);
    }

    /**
     * 云主机操作类
     *
     * @param id
     * @param context
     * @param params
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "云主机挂载光驱", httpMethod = "PATCH")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "云主机挂载光驱")
    @PatchMapping("/{id}/attach/cdrom")
    public BocloudResult attachCdrom(@PathVariable(value = Common.ID) Long id,
                                     @Value(Common.REQ_CONTEXT) RequestContext context, @RequestBody CdromModel params) {
        return cloudServerService.attachCdrom(params, context);
    }


    /**
     * 云主机操作类
     *
     * @param id
     * @param context
     * @param params
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "云主机卸载光驱", httpMethod = "PATCH")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "云主机卸载光驱")
    @PatchMapping("/{id}/detach/cdrom")
    public BocloudResult detachCdrom(@PathVariable(value = Common.ID) Long id,
                                     @Value(Common.REQ_CONTEXT) RequestContext context, @RequestBody CdromModel params) {
        return cloudServerService.detachCdrom(params, context);
    }

    @ApiOperation(tags = {"CMC", "CSC"}, value = "云主机分组列表", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "云主机分组列表")
    @GetMapping("/vmGroups")
    public BocloudResult listGroup(@Value(Common.REQ_CONTEXT) RequestContext context,
                                   @RequestParam(value = "vendorId", required = false) Long vendorId,
                                   @RequestParam(value = "azId", required = false) String azId) {
        return cloudServerService.listVmGroups(vendorId, azId, context);
    }

    @ApiOperation(tags = {"CMC", "CSC"}, value = "云主机标签列表", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "云主机标签列表")
    @GetMapping("/listLabels")
    public BocloudResult listLabels(@Value(Common.REQ_CONTEXT) RequestContext context, @RequestParam(value = "vendorId") Long vendorId) {
        return cloudServerService.listLabels(vendorId, context);
    }

    @ApiOperation(tags = {"CMC", "CSC"}, value = "网络设备连接列表", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "网络设备连接列表")
    @GetMapping("/listcon")
    public BocloudResult listcon(@Value(Common.REQ_CONTEXT) RequestContext context, @RequestParam(value = "vendorId") Long vendorId
            , @RequestParam(value = "storage") String storage) {
        return cloudServerService.listcon(vendorId, storage, context);
    }

    @ApiOperation(tags = {"CMC", "CSC"}, value = "获取iso列表", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "获取iso列表")
    @GetMapping("/listIso")
    public BocloudResult listIso(@Value(Common.REQ_CONTEXT) RequestContext context, @RequestParam(value = "vendorId") Long vendorId
            , @RequestParam(value = "storage") String storage) {
        return cloudServerService.listIso(vendorId, storage, context);
    }

    @ApiOperation(tags = {"CMC", "CSC"}, value = "获取iso列表", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "获取iso列表")
    @GetMapping("/vnc")
    public BocloudResult vnc(@Value(Common.REQ_CONTEXT) RequestContext context, @RequestParam(value = "vendorId") Long vendorId
            , @RequestParam(value = "instanceId") String instanceId) {
        return cloudServerService.vnc(vendorId, instanceId, context);
    }


    @ApiOperation(tags = {"CMC", "CSC"}, value = "获取虚拟机数据存储信息", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "获取虚拟机数据存储信息")
    @GetMapping("/{id}/dataStore")
    public BocloudResult vmDataStore(@Value(Common.REQ_CONTEXT) RequestContext context, @PathVariable(value = Common.ID) Long id) {
        return cloudServerService.vmDataStore(id);
    }

    @ApiOperation(tags = {"CMC", "CSC"}, value = "云主机询价", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "云主机", operation = "云主机询价")
    @PostMapping("/pricing")
    public BocloudResult pricing(@Value(Common.REQ_CONTEXT) RequestContext context,@RequestBody ApplicationParam applicationParam) {
        return cloudServerService.pricing(applicationParam,context);
    }
}
