Skip to content

Commit 86c61ca

Browse files
committed
Disallow importing to disbled clusters
1 parent 0bed37b commit 86c61ca

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,10 @@ private UserVmResponse baseImportInstance(ImportUnmanagedInstanceCmd cmd) {
13061306
Long clusterId = cmd.getClusterId();
13071307
Cluster cluster = basicAccessChecks(clusterId);
13081308

1309+
if (!cluster.getAllocationState().equals(Cluster.AllocationState.Enabled)) {
1310+
throw new InvalidParameterValueException(String.format("Cluster [%s] is not enabled.", cluster));
1311+
}
1312+
13091313
final Account caller = CallContext.current().getCallingAccount();
13101314
final DataCenter zone = dataCenterDao.findById(cluster.getDataCenterId());
13111315
final Account owner = accountService.getActiveAccountById(cmd.getEntityOwnerId());

server/src/test/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImplTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import com.cloud.network.dao.NetworkVO;
6666
import com.cloud.offering.NetworkOffering;
6767
import com.cloud.offering.ServiceOffering;
68+
import com.cloud.org.Grouping;
6869
import com.cloud.resource.ResourceManager;
6970
import com.cloud.resource.ResourceState;
7071
import com.cloud.service.ServiceOfferingVO;
@@ -598,6 +599,7 @@ private void baseTestImportVmFromVmwareToKvm(VcenterParameter vcenterParameter,
598599

599600
ClusterVO cluster = mock(ClusterVO.class);
600601
when(cluster.getId()).thenReturn(clusterId);
602+
when(cluster.getAllocationState()).thenReturn(Grouping.AllocationState.Enabled);
601603
when(cluster.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM);
602604
when(cluster.getDataCenterId()).thenReturn(zoneId);
603605
when(clusterDao.findById(clusterId)).thenReturn(cluster);

ui/src/views/tools/ManageInstances.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,8 @@ export default {
826826
options: {
827827
zoneid: _.get(this.zone, 'id'),
828828
podid: this.podId,
829-
hypervisor: this.destinationHypervisor
829+
hypervisor: this.destinationHypervisor,
830+
allocationstate: 'Enabled'
830831
},
831832
field: 'clusterid'
832833
},

0 commit comments

Comments
 (0)