server: Add support for new heuristics based VM Deployement for admins (#3454)

Currently an admin can choose which host a VM is to be started on.
They should be able to 'override' the allocation algorthm to a greater
or lesser extent at will, and be able to choose the pod, cluster or host
that they wish a new VM to be deployed in.

DeployVirtualMachine API has been extended with additional, optional
parameters podid and clusterid that will be passed to and used in the
deployment planner, when selecting a viable host. If the user supplies
a pod, a suitable host in the given pod will be selected. If the user
supplies a cluster, a suitable host in the given cluster will be selected.

Based on the parameter supplied and on passing validation, the VM will
then be deployed on the selected host, cluster or pod.
This commit is contained in:
Anurag Awasthi 2019-07-13 12:52:48 +05:30 committed by Rohit Yadav
parent 97df52956c
commit 9e6ee7c63e
12 changed files with 891 additions and 83 deletions

View File

@ -16,6 +16,10 @@
// under the License. // under the License.
package org.apache.cloudstack.api.command.admin.vm; package org.apache.cloudstack.api.command.admin.vm;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.ClusterResponse;
import org.apache.cloudstack.api.response.PodResponse;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.APICommand;
@ -39,6 +43,19 @@ import com.cloud.vm.VirtualMachine;
public class DeployVMCmdByAdmin extends DeployVMCmd { public class DeployVMCmdByAdmin extends DeployVMCmd {
public static final Logger s_logger = Logger.getLogger(DeployVMCmdByAdmin.class.getName()); public static final Logger s_logger = Logger.getLogger(DeployVMCmdByAdmin.class.getName());
@Parameter(name = ApiConstants.POD_ID, type = CommandType.UUID, entityType = PodResponse.class, description = "destination Pod ID to deploy the VM to - parameter available for root admin only", since = "4.13")
private Long podId;
@Parameter(name = ApiConstants.CLUSTER_ID, type = CommandType.UUID, entityType = ClusterResponse.class, description = "destination Cluster ID to deploy the VM to - parameter available for root admin only", since = "4.13")
private Long clusterId;
public Long getPodId() {
return podId;
}
public Long getClusterId() {
return clusterId;
}
@Override @Override
public void execute(){ public void execute(){

View File

@ -24,8 +24,6 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger;
import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.affinity.AffinityGroupResponse; import org.apache.cloudstack.affinity.AffinityGroupResponse;
import org.apache.cloudstack.api.ACL; import org.apache.cloudstack.api.ACL;
@ -49,6 +47,7 @@ import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.context.CallContext;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.apache.log4j.Logger;
import com.cloud.event.EventTypes; import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.ConcurrentOperationException;

View File

@ -16,6 +16,8 @@
// under the License. // under the License.
package org.apache.cloudstack.api.command.user.vm; package org.apache.cloudstack.api.command.user.vm;
import org.apache.cloudstack.api.response.ClusterResponse;
import org.apache.cloudstack.api.response.PodResponse;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.RoleType;
@ -60,6 +62,18 @@ public class StartVMCmd extends BaseAsyncCmd {
required = true, description = "The ID of the virtual machine") required = true, description = "The ID of the virtual machine")
private Long id; private Long id;
@Parameter(name = ApiConstants.POD_ID,
type = CommandType.UUID,
entityType = PodResponse.class,
description = "destination Pod ID to deploy the VM to - parameter available for root admin only")
private Long podId;
@Parameter(name = ApiConstants.CLUSTER_ID,
type = CommandType.UUID,
entityType = ClusterResponse.class,
description = "destination Cluster ID to deploy the VM to - parameter available for root admin only")
private Long clusterId;
@Parameter(name = ApiConstants.HOST_ID, @Parameter(name = ApiConstants.HOST_ID,
type = CommandType.UUID, type = CommandType.UUID,
entityType = HostResponse.class, entityType = HostResponse.class,
@ -82,6 +96,14 @@ public class StartVMCmd extends BaseAsyncCmd {
return hostId; return hostId;
} }
public Long getPodId() {
return podId;
}
public Long getClusterId() {
return clusterId;
}
// /////////////////////////////////////////////////// // ///////////////////////////////////////////////////
// ///////////// API Implementation/////////////////// // ///////////// API Implementation///////////////////
// /////////////////////////////////////////////////// // ///////////////////////////////////////////////////

View File

@ -99,6 +99,9 @@ public interface UserVmManager extends UserVmService {
Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMachine(long vmId, Long hostId, Map<VirtualMachineProfile.Param, Object> additionalParams, String deploymentPlannerToUse) Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMachine(long vmId, Long hostId, Map<VirtualMachineProfile.Param, Object> additionalParams, String deploymentPlannerToUse)
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMachine(long vmId, Long podId, Long clusterId, Long hostId, Map<VirtualMachineProfile.Param, Object> additionalParams, String deploymentPlannerToUse)
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
boolean upgradeVirtualMachine(Long id, Long serviceOfferingId, Map<String, String> customParameters) throws ResourceUnavailableException, boolean upgradeVirtualMachine(Long id, Long serviceOfferingId, Map<String, String> customParameters) throws ResourceUnavailableException,
ConcurrentOperationException, ManagementServerException, ConcurrentOperationException, ManagementServerException,
VirtualMachineMigrationException; VirtualMachineMigrationException;

View File

@ -49,6 +49,7 @@ import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseCmd.HTTPMethod; import org.apache.cloudstack.api.BaseCmd.HTTPMethod;
import org.apache.cloudstack.api.command.admin.vm.AssignVMCmd; import org.apache.cloudstack.api.command.admin.vm.AssignVMCmd;
import org.apache.cloudstack.api.command.admin.vm.DeployVMCmdByAdmin;
import org.apache.cloudstack.api.command.admin.vm.RecoverVMCmd; import org.apache.cloudstack.api.command.admin.vm.RecoverVMCmd;
import org.apache.cloudstack.api.command.user.vm.AddNicToVMCmd; import org.apache.cloudstack.api.command.user.vm.AddNicToVMCmd;
import org.apache.cloudstack.api.command.user.vm.DeployVMCmd; import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
@ -136,6 +137,7 @@ import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.DataCenterVO; import com.cloud.dc.DataCenterVO;
import com.cloud.dc.DedicatedResourceVO; import com.cloud.dc.DedicatedResourceVO;
import com.cloud.dc.HostPodVO; import com.cloud.dc.HostPodVO;
import com.cloud.dc.Pod;
import com.cloud.dc.Vlan; import com.cloud.dc.Vlan;
import com.cloud.dc.Vlan.VlanType; import com.cloud.dc.Vlan.VlanType;
import com.cloud.dc.VlanVO; import com.cloud.dc.VlanVO;
@ -2755,7 +2757,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
@Override @Override
@ActionEvent(eventType = EventTypes.EVENT_VM_START, eventDescription = "starting Vm", async = true) @ActionEvent(eventType = EventTypes.EVENT_VM_START, eventDescription = "starting Vm", async = true)
public UserVm startVirtualMachine(StartVMCmd cmd) throws ExecutionException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { public UserVm startVirtualMachine(StartVMCmd cmd) throws ExecutionException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
return startVirtualMachine(cmd.getId(), cmd.getHostId(), null, cmd.getDeploymentPlanner()).first(); return startVirtualMachine(cmd.getId(), cmd.getPodId(), cmd.getClusterId(), cmd.getHostId(), null, cmd.getDeploymentPlanner()).first();
} }
@Override @Override
@ -4144,20 +4146,27 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
@Override @Override
@ActionEvent(eventType = EventTypes.EVENT_VM_CREATE, eventDescription = "starting Vm", async = true) @ActionEvent(eventType = EventTypes.EVENT_VM_CREATE, eventDescription = "starting Vm", async = true)
public UserVm startVirtualMachine(DeployVMCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException { public UserVm startVirtualMachine(DeployVMCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException {
return startVirtualMachine(cmd, null, cmd.getDeploymentPlanner()); long vmId = cmd.getEntityId();
Long podId = null;
Long clusterId = null;
Long hostId = cmd.getHostId();
Map<Long, DiskOffering> diskOfferingMap = cmd.getDataDiskTemplateToDiskOfferingMap();
if (cmd instanceof DeployVMCmdByAdmin) {
DeployVMCmdByAdmin adminCmd = (DeployVMCmdByAdmin)cmd;
podId = adminCmd.getPodId();
clusterId = adminCmd.getClusterId();
}
return startVirtualMachine(vmId, podId, clusterId, hostId, diskOfferingMap, null, cmd.getDeploymentPlanner());
} }
private UserVm startVirtualMachine(DeployVMCmd cmd, Map<VirtualMachineProfile.Param, Object> additonalParams, String deploymentPlannerToUse) private UserVm startVirtualMachine(long vmId, Long podId, Long clusterId, Long hostId, Map<Long, DiskOffering> diskOfferingMap, Map<VirtualMachineProfile.Param, Object> additonalParams, String deploymentPlannerToUse)
throws ResourceUnavailableException, throws ResourceUnavailableException,
InsufficientCapacityException, ConcurrentOperationException { InsufficientCapacityException, ConcurrentOperationException {
long vmId = cmd.getEntityId();
Long hostId = cmd.getHostId();
UserVmVO vm = _vmDao.findById(vmId); UserVmVO vm = _vmDao.findById(vmId);
Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> vmParamPair = null; Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> vmParamPair = null;
try { try {
vmParamPair = startVirtualMachine(vmId, hostId, additonalParams, deploymentPlannerToUse); vmParamPair = startVirtualMachine(vmId, podId, clusterId, hostId, additonalParams, deploymentPlannerToUse);
vm = vmParamPair.first(); vm = vmParamPair.first();
// At this point VM should be in "Running" state // At this point VM should be in "Running" state
@ -4169,7 +4178,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
} }
try { try {
if (!cmd.getDataDiskTemplateToDiskOfferingMap().isEmpty()) { if (!diskOfferingMap.isEmpty()) {
List<VolumeVO> vols = _volsDao.findByInstance(tmpVm.getId()); List<VolumeVO> vols = _volsDao.findByInstance(tmpVm.getId());
for (VolumeVO vol : vols) { for (VolumeVO vol : vols) {
if (vol.getVolumeType() == Volume.Type.DATADISK) { if (vol.getVolumeType() == Volume.Type.DATADISK) {
@ -4488,8 +4497,14 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
@Override @Override
public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMachine(long vmId, Long hostId, Map<VirtualMachineProfile.Param, Object> additionalParams, String deploymentPlannerToUse) public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMachine(long vmId, Long hostId, Map<VirtualMachineProfile.Param, Object> additionalParams, String deploymentPlannerToUse)
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
return startVirtualMachine(vmId, null, null, hostId, additionalParams, deploymentPlannerToUse);
}
@Override
public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMachine(long vmId, Long podId, Long clusterId, Long hostId, Map<VirtualMachineProfile.Param, Object> additionalParams, String deploymentPlannerToUse)
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
// Input validation // Input validation
Account callerAccount = CallContext.current().getCallingAccount(); final Account callerAccount = CallContext.current().getCallingAccount();
UserVO callerUser = _userDao.findById(CallContext.current().getCallingUserId()); UserVO callerUser = _userDao.findById(CallContext.current().getCallingUserId());
// if account is removed, return error // if account is removed, return error
@ -4514,19 +4529,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
throw new PermissionDeniedException("The owner of " + vm + " is disabled: " + vm.getAccountId()); throw new PermissionDeniedException("The owner of " + vm + " is disabled: " + vm.getAccountId());
} }
Host destinationHost = null;
if (hostId != null) {
Account account = CallContext.current().getCallingAccount();
if (!_accountService.isRootAdmin(account.getId())) {
throw new PermissionDeniedException(
"Parameter hostid can only be specified by a Root Admin, permission denied");
}
destinationHost = _hostDao.findById(hostId);
if (destinationHost == null) {
throw new InvalidParameterValueException("Unable to find the host to deploy the VM, host id=" + hostId);
}
}
// check if vm is security group enabled // check if vm is security group enabled
if (_securityGroupMgr.isVmSecurityGroupEnabled(vmId) && _securityGroupMgr.getSecurityGroupsForVm(vmId).isEmpty() if (_securityGroupMgr.isVmSecurityGroupEnabled(vmId) && _securityGroupMgr.getSecurityGroupsForVm(vmId).isEmpty()
&& !_securityGroupMgr.isVmMappedToDefaultSecurityGroup(vmId) && _networkModel.canAddDefaultSecurityGroup()) { && !_securityGroupMgr.isVmMappedToDefaultSecurityGroup(vmId) && _networkModel.canAddDefaultSecurityGroup()) {
@ -4542,7 +4544,13 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
_securityGroupMgr.addInstanceToGroups(vmId, groupList); _securityGroupMgr.addInstanceToGroups(vmId, groupList);
} }
} }
// Choose deployment planner
// Host takes 1st preference, Cluster takes 2nd preference and Pod takes 3rd
// Default behaviour is invoked when host, cluster or pod are not specified
boolean isRootAdmin = _accountService.isRootAdmin(callerAccount.getId());
Pod destinationPod = getDestinationPod(podId, isRootAdmin);
Cluster destinationCluster = getDestinationCluster(clusterId, isRootAdmin);
Host destinationHost = getDestinationHost(hostId, isRootAdmin);
DataCenterDeployment plan = null; DataCenterDeployment plan = null;
boolean deployOnGivenHost = false; boolean deployOnGivenHost = false;
if (destinationHost != null) { if (destinationHost != null) {
@ -4551,6 +4559,18 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
if (!AllowDeployVmIfGivenHostFails.value()) { if (!AllowDeployVmIfGivenHostFails.value()) {
deployOnGivenHost = true; deployOnGivenHost = true;
} }
} else if (destinationCluster != null) {
s_logger.debug("Destination Cluster to deploy the VM is specified, specifying a deployment plan to deploy the VM");
plan = new DataCenterDeployment(vm.getDataCenterId(), destinationCluster.getPodId(), destinationCluster.getId(), null, null, null);
if (!AllowDeployVmIfGivenHostFails.value()) {
deployOnGivenHost = true;
}
} else if (destinationPod != null) {
s_logger.debug("Destination Pod to deploy the VM is specified, specifying a deployment plan to deploy the VM");
plan = new DataCenterDeployment(vm.getDataCenterId(), destinationPod.getId(), null, null, null, null);
if (!AllowDeployVmIfGivenHostFails.value()) {
deployOnGivenHost = true;
}
} }
// Set parameters // Set parameters
@ -4617,6 +4637,51 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
return vmParamPair; return vmParamPair;
} }
private Pod getDestinationPod(Long podId, boolean isRootAdmin) {
Pod destinationPod = null;
if (podId != null) {
if (!isRootAdmin) {
throw new PermissionDeniedException(
"Parameter " + ApiConstants.POD_ID + " can only be specified by a Root Admin, permission denied");
}
destinationPod = _podDao.findById(podId);
if (destinationPod == null) {
throw new InvalidParameterValueException("Unable to find the pod to deploy the VM, pod id=" + podId);
}
}
return destinationPod;
}
private Cluster getDestinationCluster(Long clusterId, boolean isRootAdmin) {
Cluster destinationCluster = null;
if (clusterId != null) {
if (!isRootAdmin) {
throw new PermissionDeniedException(
"Parameter " + ApiConstants.CLUSTER_ID + " can only be specified by a Root Admin, permission denied");
}
destinationCluster = _clusterDao.findById(clusterId);
if (destinationCluster == null) {
throw new InvalidParameterValueException("Unable to find the cluster to deploy the VM, cluster id=" + clusterId);
}
}
return destinationCluster;
}
private Host getDestinationHost(Long hostId, boolean isRootAdmin) {
Host destinationHost = null;
if (hostId != null) {
if (!isRootAdmin) {
throw new PermissionDeniedException(
"Parameter " + ApiConstants.HOST_ID + " can only be specified by a Root Admin, permission denied");
}
destinationHost = _hostDao.findById(hostId);
if (destinationHost == null) {
throw new InvalidParameterValueException("Unable to find the host to deploy the VM, host id=" + hostId);
}
}
return destinationHost;
}
@Override @Override
public UserVm destroyVm(long vmId, boolean expunge) throws ResourceUnavailableException, ConcurrentOperationException { public UserVm destroyVm(long vmId, boolean expunge) throws ResourceUnavailableException, ConcurrentOperationException {
// Account caller = CallContext.current().getCallingAccount(); // Account caller = CallContext.current().getCallingAccount();

View File

@ -0,0 +1,261 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
""" BVT tests for CM Deployment Planner
"""
# Import Local Modules
from marvin.cloudstackAPI import (deployVirtualMachine, destroyVirtualMachine)
from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.lib.base import (Account,
ServiceOffering,
Host, Pod, Cluster)
from marvin.lib.common import (get_domain,
get_zone,
get_template)
from marvin.lib.utils import cleanup_resources
from nose.plugins.attrib import attr
class TestVMDeploymentPlanner(cloudstackTestCase):
@classmethod
def setUpClass(cls):
testClient = super(TestVMDeploymentPlanner, cls).getClsTestClient()
cls.apiclient = testClient.getApiClient()
cls.services = testClient.getParsedTestDataConfig()
# Get Zone, Domain and templates
cls.domain = get_domain(cls.apiclient)
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
cls.hypervisor = testClient.getHypervisorInfo()
cls.services['mode'] = cls.zone.networktype
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
# Create an account, network, VM and IP addresses
cls.account = Account.create(
cls.apiclient,
cls.services["account"],
domainid=cls.domain.id
)
cls.service_offering = ServiceOffering.create(
cls.apiclient,
cls.services["service_offerings"]["tiny"]
)
cls.cleanup = [
cls.account,
cls.service_offering
]
@classmethod
def tearDownClass(cls):
try:
cls.apiclient = super(
TestVMDeploymentPlanner,
cls
).getClsTestClient().getApiClient()
# Clean up, terminate the created templates
cleanup_resources(cls.apiclient, cls.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
def deploy_vm(self, destination_id):
cmd = deployVirtualMachine.deployVirtualMachineCmd()
template = get_template(
self.apiclient,
self.zone.id,
hypervisor=self.hypervisor
)
cmd.zoneid = self.zone.id
cmd.templateid = template.id
cmd.serviceofferingid = self.service_offering.id
cmd.hostid = destination_id
return self.apiclient.deployVirtualMachine(cmd)
def destroy_vm(self, vm_id):
cmd = destroyVirtualMachine.destroyVirtualMachineCmd()
cmd.expunge = True
cmd.id = vm_id
return self.apiclient.destroyVirtualMachine(cmd)
@attr(tags=["advanced", "advancedns", "ssh", "smoke"], required_hardware="false")
def test_01_deploy_vm_on_specific_host(self):
hosts = Host.list(
self.apiclient,
zoneid=self.zone.id,
type='Routing'
)
target_id = hosts[0].id
vm = self.deploy_vm(target_id)
self.assertEqual(
target_id,
vm.hostid,
"VM instance was not deployed on target host ID")
self.destroy_vm(vm.id)
@attr(tags=["advanced", "advancedns", "ssh", "smoke"], required_hardware="false")
def test_02_deploy_vm_on_specific_cluster(self):
# Select deployment cluster
clusters = Cluster.list(
self.apiclient,
)
target_cluster = clusters[0]
target_id = target_cluster.id
cluster_hypervisor = target_cluster.hypervisortype
template = get_template(
self.apiclient,
hypervisor=cluster_hypervisor
)
# deploy vm on cluster
cmd = deployVirtualMachine.deployVirtualMachineCmd()
cmd.zoneid = target_cluster.zoneid
cmd.serviceofferingid = self.service_offering.id
cmd.templateid = template.id
cmd.clusterid = target_id
vm = self.apiclient.deployVirtualMachine(cmd)
vm_host = Host.list(self.apiclient,
id=vm.hostid
)
self.assertEqual(
target_id,
vm_host[0].clusterid,
"VM was not deployed on the provided cluster"
)
self.destroy_vm(vm.id)
@attr(tags=["advanced", "advancedns", "ssh", "smoke"], required_hardware="false")
def test_03_deploy_vm_on_specific_pod(self):
pods = Pod.list(
self.apiclient,
)
target_pod = pods[0]
# Get host by Pod ID
host = Host.list(
self.apiclient,
podid=target_pod.id)
# deploy vm on pod
cmd = deployVirtualMachine.deployVirtualMachineCmd()
cmd.zoneid = target_pod.zoneid
cmd.serviceofferingid = self.service_offering.id
template = get_template(
self.apiclient,
hypervisor=host[0].hypervisortype
)
cmd.templateid = template.id
cmd.podid = target_pod.id
vm = self.apiclient.deployVirtualMachine(cmd)
vm_host = Host.list(self.apiclient,
id=vm.hostid
)
self.assertEqual(
target_pod.id,
vm_host[0].podid,
"VM was not deployed on the target pod"
)
self.destroy_vm(vm.id)
@attr(tags=["advanced", "advancedns", "ssh", "smoke"], required_hardware="false")
def test_04_deploy_vm_on_host_override_pod_and_cluster(self):
# Optional parameters pod, cluster and host
pod = Pod.list(self.apiclient, zoneid=self.zone.id)[0]
clusters = Cluster.list(self.apiclient, zoneid=self.zone.id, podid=pod.id)
self.assertEqual(
isinstance(clusters, list),
True,
"Check list response returns a valid list"
)
host = Host.list(self.apiclient, zoneid=self.zone.id, clusterid=clusters[0].id, type='Routing')[0]
cmd = deployVirtualMachine.deployVirtualMachineCmd()
# Required parameters
cmd.zoneid = self.zone.id
cmd.serviceofferingid = self.service_offering.id
template = get_template(self.apiclient, zone_id=self.zone.id, hypervisor=host.hypervisor)
cmd.templateid = template.id
# Add optional deployment params
cmd.podid = pod.id
cmd.clusterid = clusters[1].id if len(clusters) > 1 else clusters[0].id
cmd.hostid = host.id
vm = self.apiclient.deployVirtualMachine(cmd)
self.assertEqual(
vm.hostid,
host.id,
"VM was not deployed on the target host ID"
)
self.destroy_vm(vm.id)
@attr(tags=["advanced", "advancedns", "ssh", "smoke"], required_hardware="false")
def test_05_deploy_vm_on_cluster_override_pod(self):
# Optional parameters pod, cluster and host
pod = Pod.list(self.apiclient, zoneid=self.zone.id)[0]
clusters = Cluster.list(self.apiclient, zoneid=self.zone.id, podid=pod.id)
self.assertEqual(
isinstance(clusters, list),
True,
"Check list response returns a valid list"
)
cmd = deployVirtualMachine.deployVirtualMachineCmd()
# Required parameters
cmd.zoneid = self.zone.id
cmd.serviceofferingid = self.service_offering.id
template = get_template(self.apiclient, zone_id=self.zone.id, hypervisor=clusters[0].hypervisortype)
cmd.templateid = template.id
# Add optional deployment params
cmd.podid = pod.id
cmd.clusterid = clusters[0].id
vm = self.apiclient.deployVirtualMachine(cmd)
vm_host = Host.list(self.apiclient,
id=vm.hostid
)
self.assertEqual(
vm_host[0].clusterid,
clusters[0].id,
"VM was not deployed on the target cluster"
)
self.destroy_vm(vm.id)

View File

@ -5545,6 +5545,15 @@ textarea {
background: #d6d6d6; background: #d6d6d6;
} }
.multi-wizard .content .section .larger-area {
height: 134px !important;
}
.multi-wizard .content .section .lower-area {
height: 35px !important ;
margin: 7px auto auto !important ;
}
.multi-wizard .content .section .select-area .desc { .multi-wizard .content .section .select-area .desc {
float: right; float: right;
width: 155px; width: 155px;
@ -5591,6 +5600,14 @@ textarea {
-o-text-shadow: 0 2px 2px #efefef; -o-text-shadow: 0 2px 2px #efefef;
} }
.multi-wizard .content .section.select-deployment .select-area select {
margin: 9px 0 0 14px;
}
.multi-wizard .content .section.select-deployment .select-area label.desc {
padding: 0;
}
.multi-wizard .content .section .select-area label.error { .multi-wizard .content .section .select-area label.error {
margin: 2px 0 0 14px; margin: 2px 0 0 14px;
font-size: 10px; font-size: 10px;
@ -5625,6 +5642,14 @@ textarea {
height: 206px; height: 206px;
} }
.multi-wizard .content .section.select-template {
height: 206px;
}
.multi-wizard .content .section.smaller-height {
height: 126px !important;
}
.multi-wizard .content.tab-view { .multi-wizard .content.tab-view {
margin: 31px 0 0; margin: 31px 0 0;
padding: 0 8px; padding: 0 8px;

View File

@ -94,17 +94,28 @@
<div class="step setup" wizard-step-id="setup"> <div class="step setup" wizard-step-id="setup">
<div class="content"> <div class="content">
<!-- Select a zone --> <!-- Select a zone -->
<div class="section select-zone"> <div class="section select-deployment">
<h3><translate key="label.select.a.zone"/></h3> <h3><translate key="label.select.deployment.infrastructure"/></h3>
<p><translate key="message.select.a.zone"/></p> <p><translate key="message.select.a.zone"/></p>
<div class="select-area"> <div class="select-area lower-area">
<div class="desc"></div> <select name="zoneid" class="zoneid required" required></select>
<select name="zoneid" class="required" required> <label for="zoneid" class="desc"><translate key="label.zone"/></label>
</select> </div>
<div class="select-area lower-area">
<select name="podid" class="podid"></select>
<label for="podid" class="desc"><translate key="label.pod"/></label>
</div>
<div class="select-area lower-area">
<select name="clusterid" class="clusterid"></select>
<label for="clusterid" class="desc"><translate key="label.cluster"/></label>
</div>
<div class="select-area lower-area">
<select name="hostid" class="hostid"></select>
<label for="hostid" class="desc"><translate key="label.host"/></label>
</div> </div>
</div> </div>
<!-- Select template --> <!-- Select template -->
<div class="section select-template"> <div class="section select-template smaller-height">
<h3><translate key="label.select.iso.or.template" /></h3> <h3><translate key="label.select.iso.or.template" /></h3>
<p></p> <p></p>
<div class="select-area"> <div class="select-area">

View File

@ -1543,6 +1543,7 @@ var dictionary = {
"label.select-view":"Select view", "label.select-view":"Select view",
"label.select.a.template":"Select a template", "label.select.a.template":"Select a template",
"label.select.a.zone":"Select a zone", "label.select.a.zone":"Select a zone",
"label.select.deployment.infrastructure":"Select deployment infrastructure",
"label.select.instance":"Select instance", "label.select.instance":"Select instance",
"label.select.host":"Select host", "label.select.host":"Select host",
"label.select.instance.to.attach.volume.to":"Select instance to attach volume to", "label.select.instance.to.attach.volume.to":"Select instance to attach volume to",

View File

@ -22,6 +22,108 @@
var step6ContainerType = 'nothing-to-select'; //'nothing-to-select', 'select-network', 'select-security-group', 'select-advanced-sg'(advanced sg-enabled zone) var step6ContainerType = 'nothing-to-select'; //'nothing-to-select', 'select-network', 'select-security-group', 'select-advanced-sg'(advanced sg-enabled zone)
cloudStack.instanceWizard = { cloudStack.instanceWizard = {
fetchPodList: function (podcallback, parentId) {
var urlString = "listPods";
if (parentId != -1) {
urlString += "&zoneid=" + parentId
}
$.ajax({
url: createURL(urlString),
dataType: "json",
async: false,
success: function (json) {
var pods = [{
id: -1,
description: 'Default',
parentId: -1
}];
var podsObjs = json.listpodsresponse.pod;
if (podsObjs !== undefined) {
$(podsObjs).each(function () {
pods.push({
id: this.id,
description: this.name,
parentId: this.zoneid
});
});
}
podcallback(pods);
}
});
},
fetchClusterList: function (clustercallback, parentId, zoneId) {
var urlString = "listClusters";
// If Pod ID is not specified, filter clusters by Zone
if (parentId != -1) {
urlString += "&podid=" + parentId;
} else if (zoneId != -1) {
urlString += "&zoneid=" + zoneId;
}
$.ajax({
url: createURL(urlString),
dataType: "json",
async: false,
success: function (json) {
var clusters = [{
id: -1,
description: 'Default',
parentId: -1
}];
var clusterObjs = json.listclustersresponse.cluster;
if (clusterObjs != undefined) {
$(clusterObjs).each(function () {
clusters.push({
id: this.id,
description: this.name,
parentId: this.podid
});
});
}
clustercallback(clusters);
}
});
},
fetchHostList: function (hostcallback, parentId, podId, zoneId) {
// If Cluster ID is not specified, filter hosts by Zone or Pod
var urlString = "listHosts&state=Up&type=Routing";
if (parentId != -1) {
urlString += "&clusterid=" + parentId;
} else if (podId != -1) {
urlString += "&podid=" + podId;
} else if (zoneId != -1) {
urlString += "&zoneid=" + zoneId
}
$.ajax({
url: createURL(urlString),
dataType: "json",
async: false,
success: function (json) {
var hosts = [{
id: -1,
description: 'Default',
parentId: -1
}];
var hostObjs = json.listhostsresponse.host;
if (hostObjs != undefined) {
$(hostObjs).each(function () {
hosts.push({
id: this.id,
description: this.name,
parentId: this.clusterid
});
});
}
hostcallback(hosts);
}
});
},
//min disk offering size when custom disk size is used //min disk offering size when custom disk size is used
minDiskOfferingSize: function() { minDiskOfferingSize: function() {
return g_capabilities.customdiskofferingminsize; return g_capabilities.customdiskofferingminsize;
@ -94,25 +196,114 @@
} }
//in all other cases (as well as from instance page) all zones are populated to dropdown //in all other cases (as well as from instance page) all zones are populated to dropdown
else { else {
var postData = {};
var zones = [{
id: -1,
name: 'Default'
}];
$.ajax({ $.ajax({
url: createURL("listZones&available=true"), url: createURL("listZones&available=true"),
dataType: "json", dataType: "json",
async: false, async: false,
success: function(json) { success: function(json) {
zoneObjs = json.listzonesresponse.zone; zoneObjs = json.listzonesresponse.zone;
args.response.success({ $(zoneObjs).each(function() {
data: { zones.push({
zones: zoneObjs id: this.id,
} name: this.name
});
}); });
} }
}); });
$.extend(postData, {
"zones": zones
});
if (isAdmin()) {
pods = [{
id: -1,
description: 'Default',
parentId: -1
}];
$.ajax({
url: createURL("listPods"),
dataType: "json",
async: false,
success: function(json) {
if (json.listpodsresponse.pod != undefined) {
podObjs = json.listpodsresponse.pod;
$(podObjs).each(function() {
pods.push({
id: this.id,
description: this.name,
parentId: this.zoneid
});
});
}
}
});
clusters = [{
id: -1,
description: 'Default',
parentId: -1
}];
$.ajax({
url: createURL("listClusters"),
dataType: "json",
async: false,
success: function(json) {
if (json.listclustersresponse.cluster != undefined) {
clusterObjs = json.listclustersresponse.cluster;
$(clusterObjs).each(function() {
clusters.push({
id: this.id,
description: this.name,
parentId: this.podid
});
});
}
}
});
hosts = [{
id: -1,
description: 'Default',
parentId: -1
}];
$.ajax({
url: createURL("listHosts&state=Up&type=Routing"),
dataType: "json",
async: false,
success: function(json) {
if (json.listhostsresponse.host != undefined) {
hostObjs = json.listhostsresponse.host;
$(hostObjs).each(function() {
hosts.push({
id: this.id,
description: this.name,
parentId: this.clusterid
});
});
}
}
});
$.extend(postData, {
"pods": pods,
"clusters": clusters,
"hosts": hosts
});
}
args.response.success({
data: postData
});
} }
}, },
// Step 2: Select template // Step 2: Select template
function(args) { function(args) {
$(zoneObjs).each(function() { $(zoneObjs).each(function() {
args.currentData.zoneid = (args.currentData.zoneid == -1)? this.id : args.currentData.zoneid ;
if (this.id == args.currentData.zoneid) { if (this.id == args.currentData.zoneid) {
selectedZoneObj = this; selectedZoneObj = this;
return false; //break the $.each() loop return false; //break the $.each() loop
@ -539,7 +730,7 @@
var defaultNetworkArray = [], var defaultNetworkArray = [],
optionalNetworkArray = []; optionalNetworkArray = [];
var networkData = { var networkData = {
zoneId: args.currentData.zoneid, zoneId: selectedZoneObj.id,
canusefordeploy: true canusefordeploy: true
}; };
@ -662,7 +853,7 @@
dataType: "json", dataType: "json",
data: { data: {
forvpc: false, forvpc: false,
zoneid: args.currentData.zoneid, zoneid: selectedZoneObj.id,
guestiptype: 'Isolated', guestiptype: 'Isolated',
supportedServices: 'SourceNat', supportedServices: 'SourceNat',
specifyvlan: false, specifyvlan: false,
@ -769,10 +960,29 @@
var deployVmData = {}; var deployVmData = {};
//step 1 : select zone //step 1 : select zone
zoneId = (args.data.zoneid == -1)? selectedZoneObj.id : args.data.zoneid;
$.extend(deployVmData, { $.extend(deployVmData, {
zoneid : args.data.zoneid zoneid : zoneId
}); });
if (args.data.podid != -1) {
$.extend(deployVmData, {
podid : args.data.podid
});
}
if (args.data.clusterid != -1) {
$.extend(deployVmData, {
clusterid : args.data.clusterid
});
}
if (args.data.hostid != -1) {
$.extend(deployVmData, {
hostid : args.data.hostid
});
}
//step 2: select template //step 2: select template
$.extend(deployVmData, { $.extend(deployVmData, {
templateid : args.data.templateid templateid : args.data.templateid

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
(function($, cloudStack) { (function($, cloudStack) {
var vmMigrationHostObjs, ostypeObjs; var vmMigrationHostObjs, ostypeObjs, zoneWideStorage;
var vmStartAction = function(args) { var vmStartAction = function(args) {
var action = { var action = {
@ -919,49 +919,133 @@
title: 'label.action.start.instance', title: 'label.action.start.instance',
desc: 'message.action.start.instance', desc: 'message.action.start.instance',
fields: { fields: {
hostId: { podId: {
label: 'label.host', label: 'label.pod',
isHidden: function(args) { isHidden: function(args) {
if (isAdmin()) return !isAdmin();
return false; },
else select: function(args) {
return true; if (isAdmin()) {
}, $.ajax({
select: function(args) { url: createURL("listPods&zoneid=" + args.context.instances[0].zoneid),
if (isAdmin()) { dataType: "json",
$.ajax({ async: true,
url: createURL("listHosts&state=Up&type=Routing&zoneid=" + args.context.instances[0].zoneid), success: function(json) {
dataType: "json", if (json.listpodsresponse.pod != undefined) {
async: true, podObjs = json.listpodsresponse.pod;
success: function(json) { var items = [{
if (json.listhostsresponse.host != undefined) { id: -1,
hostObjs = json.listhostsresponse.host; description: 'Default'
var items = [{ }];
id: -1, $(podObjs).each(function() {
description: 'Default' items.push({
}]; id: this.id,
$(hostObjs).each(function() { description: this.name
items.push({
id: this.id,
description: this.name
});
}); });
args.response.success({ });
data: items args.response.success({
}); data: items
} else { });
cloudStack.dialog.notice({ } else {
message: _l('No Hosts are avaialble') cloudStack.dialog.notice({
}); message: _l('No Pods are available')
} });
} }
}); }
} else { });
args.response.success({ } else {
data: null args.response.success({
}); data: null
} });
} }
}
},
clusterId: {
label: 'label.cluster',
dependsOn: 'podId',
select: function(args) {
if (isAdmin()) {
var urlString = "listClusters&zoneid=" + args.context.instances[0].zoneid;
if (args.podId != -1) {
urlString += '&podid=' + args.podId;
}
$.ajax({
url: createURL(urlString),
dataType: "json",
async: true,
success: function(json) {
if (json.listclustersresponse.cluster != undefined) {
clusterObjs = json.listclustersresponse.cluster;
var items = [{
id: -1,
description: 'Default'
}];
$(clusterObjs).each(function() {
items.push({
id: this.id,
description: this.name
});
});
args.response.success({
data: items
});
} else {
cloudStack.dialog.notice({
message: _l('No Clusters are avaialble')
});
}
}
});
} else {
args.response.success({
data: null
});
}
}
},
hostId: {
label: 'label.host',
dependsOn: 'clusterId',
select: function(args) {
var urlString = "listHosts&state=Up&type=Routing&zoneid=" + args.context.instances[0].zoneid;
if (args.clusterId != -1) {
urlString += "&clusterid=" + args.clusterId;
}
if (isAdmin()) {
$.ajax({
url: createURL(urlString),
dataType: "json",
async: true,
success: function(json) {
if (json.listhostsresponse.host != undefined) {
hostObjs = json.listhostsresponse.host;
var items = [{
id: -1,
description: 'Default'
}];
$(hostObjs).each(function() {
items.push({
id: this.id,
description: this.name
});
});
args.response.success({
data: items
});
} else {
cloudStack.dialog.notice({
message: _l('No Hosts are avaialble')
});
}
}
});
} else {
args.response.success({
data: null
});
}
}
} }
} }
}, },
@ -969,6 +1053,16 @@
var data = { var data = {
id: args.context.instances[0].id id: args.context.instances[0].id
} }
if (args.$form.find('.form-item[rel=podId]').css("display") != "none" && args.data.podId != -1) {
$.extend(data, {
podid: args.data.podId
});
}
if (args.$form.find('.form-item[rel=clusterId]').css("display") != "none" && args.data.clusterId != -1) {
$.extend(data, {
clusterid: args.data.clusterId
});
}
if (args.$form.find('.form-item[rel=hostId]').css("display") != "none" && args.data.hostId != -1) { if (args.$form.find('.form-item[rel=hostId]').css("display") != "none" && args.data.hostId != -1) {
$.extend(data, { $.extend(data, {
hostid: args.data.hostId hostid: args.data.hostId

View File

@ -277,6 +277,66 @@
}).click(); }).click();
}; };
if (isAdmin()) {
$step.find('.select-deployment .podid').parent().show();
$step.find('.select-deployment .clusterid').parent().show();
$step.find('.select-deployment .hostid').parent().show();
var updateFieldOptions = function(fieldClass, wizardField) {
return function(data) {
var fieldSelect = $step.find('.select-deployment .' + fieldClass);
fieldSelect.find('option').remove().end();
$(data).each(function() {
fieldSelect.append(
$('<option>')
.attr({
value: this.id,
'wizard-field': wizardField,
'parentId': this.parentId
})
.html(this.description)
.data('json-obj', this)
);
});
}
};
var $zoneSelect = $step.find('.select-deployment .zoneid');
$zoneSelect.unbind('change');
$zoneSelect.change(function() {
zoneId = $zoneSelect.val();
if (zoneId != null && isAdmin()) {
args.fetchPodList(updateFieldOptions('podid', 'pod'), zoneId);
args.fetchClusterList(updateFieldOptions('clusterid', 'cluster'), -1, zoneId);
args.fetchHostList(updateFieldOptions('hostid', 'host'), -1, -1, zoneId);
}
});
var $podSelect = $step.find('.select-deployment .podid');
$podSelect.unbind('change');
$podSelect.change(function() {
podId = $podSelect.val();
if (podId != null) {
args.fetchClusterList(updateFieldOptions('clusterid', 'cluster'), podId, -1);
args.fetchHostList(updateFieldOptions('hostid', 'host'), -1, podId, -1);
}
});
var $clusterSelect = $step.find('.select-deployment .clusterid');
$clusterSelect.unbind('change');
$clusterSelect.change(function() {
clusterId = $clusterSelect.val();
if (clusterId != null) {
args.fetchHostList(updateFieldOptions('hostid', 'host'), clusterId, -1, -1);
}
});
} else {
$step.find('.select-deployment .podid').parent().hide();
$step.find('.select-deployment .clusterid').parent().hide();
$step.find('.select-deployment .hostid').parent().hide();
}
return { return {
response: { response: {
success: function(args) { success: function(args) {
@ -286,13 +346,53 @@
if(index == 0){ if(index == 0){
initialValue = this.id; initialValue = this.id;
} }
$step.find('.select-zone select').append( $step.find('.select-deployment .zoneid').append(
$('<option>') $('<option>')
.attr({ .attr({
value: this.id, value: this.id,
'wizard-field': 'zone' 'wizard-field': 'zone'
}) })
.html(this.name) .html(this.name)
.data('json-obj', this)
)
});
// Pods
$(args.data.pods).each(function() {
$step.find('.select-deployment .podid').append(
$('<option>')
.attr({
value: this.id,
'wizard-field': 'pod',
'parentId': this.parentId
})
.html(this.description)
.data('json-obj', this)
)
});
// Clusters
$(args.data.clusters).each(function() {
$step.find('.select-deployment .clusterid').append(
$('<option>')
.attr({
value: this.id,
'wizard-field': 'cluster',
'parentId': this.parentId
})
.html(this.description)
.data('json-obj', this)
)
});
// Hosts
$(args.data.hosts).each(function() {
$step.find('.select-deployment .hostid').append(
$('<option>')
.attr({
value: this.id,
'wizard-field': 'host',
'parentId': this.parentId
})
.html(this.description)
.data('json-obj', this)
); );
}); });
@ -309,7 +409,7 @@
var $inputs = $step.find('.wizard-step-conditional:visible') var $inputs = $step.find('.wizard-step-conditional:visible')
.find('input[type=radio]'); .find('input[type=radio]');
var $selected = $inputs.filter(function() { var $selected = $inputs.filter(function() {
return $(this).val() == formData.templateid; return $(this).val() === formData.templateid;
}); });
if (!$selected.length) { if (!$selected.length) {