Skip to content

Commit 8a8947a

Browse files
authored
Including instance details in KubernetesClusterResponse (#4420)
1 parent 86f2b79 commit 8a8947a

4 files changed

Lines changed: 29 additions & 18 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ public class ApiConstants {
386386
public static final String VIRTUAL_MACHINE_NAME = "virtualmachinename";
387387
public static final String VIRTUAL_MACHINE_ID_IP = "vmidipmap";
388388
public static final String VIRTUAL_MACHINE_COUNT = "virtualmachinecount";
389+
public static final String VIRTUAL_MACHINES = "virtualmachines";
389390
public static final String USAGE_ID = "usageid";
390391
public static final String USAGE_TYPE = "usagetype";
391392
public static final String INCLUDE_TAGS = "includetags";

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.security.SecureRandom;
2323
import java.util.ArrayList;
2424
import java.util.Date;
25+
import java.util.EnumSet;
2526
import java.util.HashMap;
2627
import java.util.List;
2728
import java.util.Map;
@@ -38,6 +39,8 @@
3839
import org.apache.cloudstack.acl.ControlledEntity;
3940
import org.apache.cloudstack.acl.SecurityChecker;
4041
import org.apache.cloudstack.api.ApiConstants;
42+
import org.apache.cloudstack.api.ApiConstants.VMDetails;
43+
import org.apache.cloudstack.api.ResponseObject.ResponseView;
4144
import org.apache.cloudstack.api.command.user.kubernetes.cluster.CreateKubernetesClusterCmd;
4245
import org.apache.cloudstack.api.command.user.kubernetes.cluster.DeleteKubernetesClusterCmd;
4346
import org.apache.cloudstack.api.command.user.kubernetes.cluster.GetKubernetesClusterConfigCmd;
@@ -49,6 +52,7 @@
4952
import org.apache.cloudstack.api.response.KubernetesClusterConfigResponse;
5053
import org.apache.cloudstack.api.response.KubernetesClusterResponse;
5154
import org.apache.cloudstack.api.response.ListResponse;
55+
import org.apache.cloudstack.api.response.UserVmResponse;
5256
import org.apache.cloudstack.context.CallContext;
5357
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
5458
import org.apache.cloudstack.framework.config.ConfigKey;
@@ -61,7 +65,9 @@
6165
import com.cloud.api.ApiDBUtils;
6266
import com.cloud.api.query.dao.NetworkOfferingJoinDao;
6367
import com.cloud.api.query.dao.TemplateJoinDao;
68+
import com.cloud.api.query.dao.UserVmJoinDao;
6469
import com.cloud.api.query.vo.NetworkOfferingJoinVO;
70+
import com.cloud.api.query.vo.UserVmJoinVO;
6571
import com.cloud.capacity.CapacityManager;
6672
import com.cloud.dc.ClusterDetailsDao;
6773
import com.cloud.dc.ClusterDetailsVO;
@@ -144,10 +150,8 @@
144150
import com.cloud.utils.fsm.NoTransitionException;
145151
import com.cloud.utils.fsm.StateMachine2;
146152
import com.cloud.utils.net.NetUtils;
147-
import com.cloud.vm.UserVmVO;
148153
import com.cloud.vm.VMInstanceVO;
149154
import com.cloud.vm.VirtualMachine;
150-
import com.cloud.vm.dao.UserVmDao;
151155
import com.cloud.vm.dao.VMInstanceDao;
152156
import com.google.common.base.Strings;
153157

@@ -194,7 +198,7 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
194198
@Inject
195199
protected VMInstanceDao vmInstanceDao;
196200
@Inject
197-
protected UserVmDao userVmDao;
201+
protected UserVmJoinDao userVmJoinDao;
198202
@Inject
199203
protected NetworkOfferingDao networkOfferingDao;
200204
@Inject
@@ -606,17 +610,25 @@ public KubernetesClusterResponse createKubernetesClusterResponse(long kubernetes
606610
response.setEndpoint(kubernetesCluster.getEndpoint());
607611
response.setNetworkId(ntwk.getUuid());
608612
response.setAssociatedNetworkName(ntwk.getName());
609-
List<String> vmIds = new ArrayList<String>();
613+
List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
610614
List<KubernetesClusterVmMapVO> vmList = kubernetesClusterVmMapDao.listByClusterId(kubernetesCluster.getId());
615+
ResponseView respView = ResponseView.Restricted;
616+
Account caller = CallContext.current().getCallingAccount();
617+
if (accountService.isRootAdmin(caller.getId())) {
618+
respView = ResponseView.Full;
619+
}
620+
final String responseName = "virtualmachine";
611621
if (vmList != null && !vmList.isEmpty()) {
612622
for (KubernetesClusterVmMapVO vmMapVO : vmList) {
613-
UserVmVO userVM = userVmDao.findById(vmMapVO.getVmId());
623+
UserVmJoinVO userVM = userVmJoinDao.findById(vmMapVO.getVmId());
614624
if (userVM != null) {
615-
vmIds.add(userVM.getUuid());
625+
UserVmResponse vmResponse = ApiDBUtils.newUserVmResponse(respView, responseName, userVM,
626+
EnumSet.noneOf(VMDetails.class), caller);
627+
vmResponses.add(vmResponse);
616628
}
617629
}
618630
}
619-
response.setVirtualMachineIds(vmIds);
631+
response.setVirtualMachines(vmResponses);
620632
return response;
621633
}
622634

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/response/KubernetesClusterResponse.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ public class KubernetesClusterResponse extends BaseResponse implements Controlle
129129
@Param(description = "URL end point for the Kubernetes cluster dashboard UI")
130130
private String consoleEndpoint;
131131

132-
@SerializedName(ApiConstants.VIRTUAL_MACHINE_IDS)
133-
@Param(description = "the list of virtualmachine IDs associated with this Kubernetes cluster")
134-
private List<String> virtualMachineIds;
132+
@SerializedName(ApiConstants.VIRTUAL_MACHINES)
133+
@Param(description = "the list of virtualmachine associated with this Kubernetes cluster")
134+
private List<UserVmResponse> virtualMachines;
135135

136136
public KubernetesClusterResponse() {
137137
}
@@ -317,13 +317,11 @@ public void setServiceOfferingName(String serviceOfferingName) {
317317
this.serviceOfferingName = serviceOfferingName;
318318
}
319319

320-
public void setVirtualMachineIds(List<String> virtualMachineIds) {
321-
this.virtualMachineIds = virtualMachineIds;
320+
public void setVirtualMachines(List<UserVmResponse> virtualMachines) {
321+
this.virtualMachines = virtualMachines;
322322
}
323323

324-
;
325-
326-
public List<String> getVirtualMachineIds() {
327-
return virtualMachineIds;
324+
public List<UserVmResponse> getVirtualMachines() {
325+
return virtualMachines;
328326
}
329327
}

test/integration/smoke/test_kubernetes_clusters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,9 @@ def deleteKubernetesClusterAndVerify(self, cluster_id, verify = True, forced = F
749749
self.deleteKubernetesCluster(cluster_id)
750750
else:
751751
forceDeleted = True
752-
for cluster_vm_id in cluster.virtualmachineids:
752+
for cluster_vm in cluster.virtualmachines:
753753
cmd = destroyVirtualMachine.destroyVirtualMachineCmd()
754-
cmd.id = cluster_vm_id
754+
cmd.id = cluster_vm.id
755755
cmd.expunge = True
756756
self.apiclient.destroyVirtualMachine(cmd)
757757
cmd = deleteNetwork.deleteNetworkCmd()

0 commit comments

Comments
 (0)