From b3ff2ed7e146a89a55440420a9f7f55cdb4587f9 Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Thu, 5 Sep 2024 09:29:23 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=A9=E7=90=86=E6=9C=BA=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PhysicalServerController.java | 6 ++-- .../compute/TianyiPhysicalProvider.java | 29 ++++++++++++++++++- .../plugin/service/PhysicalServerService.java | 2 +- .../impl/PhysicalServerServiceImpl.java | 4 +-- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java index 4533ad8b..2f3cdc4a 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java @@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** @@ -42,8 +43,9 @@ public class PhysicalServerController { @Operation(tags = {"CMC", "CSC"}, summary = "获取物理机列表") @GetMapping(value = "/listAll") - public GeneralResult listAll() { - return physicalServerService.listAll(); + public GeneralResult listAll(@RequestParam(value = "regionId") String regionId, + @RequestParam(value = "regionId") String zoneId) { + return physicalServerService.listAll(regionId, zoneId); } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java index 2f486192..5b0e1391 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java @@ -41,7 +41,6 @@ public class TianyiPhysicalProvider extends TianyiProvider { if (!CollectionUtils.isEmpty(zoneList)) { List results = new ArrayList<>(); for (JSONObject zone : zoneList) { - log.info("zoneName:" + zone.getString("name")); String apiUrl = "/v4/ebm/list"; JSONObject body = new JSONObject(); body.put("regionID", this.getRegionId()); @@ -216,4 +215,32 @@ public class TianyiPhysicalProvider extends TianyiProvider { } } + public GeneralResult> listAll(String regionId, String zoneId) { + try { + List physicalModels = new ArrayList<>(); + String apiUrl = "/v4/ebm/list"; + JSONObject body = new JSONObject(); + body.put("regionID", regionId); + body.put("azName", zoneId); + body.put("pageNo", 1); + body.put("pageSize", this.PAGE_SIZE); + Result result = doGet(apiUrl, null, body); + log.info("物理机数据:" + JSON.toJSONString(result)); + JSONObject returnObj = checkResult(result, "查询物理机列表"); + List results = new ArrayList<>(); + results.addAll(JSONArray.parseArray(returnObj.getString("results"), JSONObject.class)); + if (ListTool.isEmpty(results)) { + return new GeneralResult(true, results, "物理机列表为空"); + } + for (JSONObject model : results) { + physicalModels.add(physcicalConvertor.convertModel(model)); + } + log.info("results:" + JSON.toJSONString(physicalModels)); + return new GeneralResult(true, physicalModels, "查询物理机列表成功"); + } catch (Exception e) { + log.error("查询物理机列表失败 :", e); + return new GeneralResult(false, "查询物理机列表失败" + e.getMessage()); + } + } + } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/PhysicalServerService.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/PhysicalServerService.java index 75949a62..4a509312 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/PhysicalServerService.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/PhysicalServerService.java @@ -10,7 +10,7 @@ public interface PhysicalServerService { GeneralResult> list(Pager pager, RequestContext context); - GeneralResult listAll(); + GeneralResult listAll( String regionId, String zoneId); GeneralResult detail(Long id); diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java index d910f93e..60063f95 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java @@ -80,10 +80,10 @@ public class PhysicalServerServiceImpl implements PhysicalServerService { } @Override - public GeneralResult listAll() { + public GeneralResult listAll( String regionId, String zoneId) { CloudVendor vendor = cloudVendorRepository.query(1L); TianyiPhysicalProvider physicalProvider = new TianyiPhysicalProvider(butlerConfig.regionButler(vendor.getUuid(), "2022guizhou_syj")); - GeneralResult result = physicalProvider.list(); + GeneralResult result = physicalProvider.listAll(regionId, zoneId); return null; }