mirror of https://github.com/apache/cloudstack.git
Successful creation of domr and uservm with all programming done correctly.....yahooo
This commit is contained in:
parent
0c044a10d1
commit
6311644e08
|
|
@ -23,7 +23,7 @@ import com.cloud.utils.SerialVersionUID;
|
|||
/**
|
||||
* Exception thrown when the end there's not enough ip addresses in the system.
|
||||
*/
|
||||
public class InsufficientAddressCapacityException extends InsufficientCapacityException {
|
||||
public class InsufficientAddressCapacityException extends InsufficientNetworkCapacityException {
|
||||
|
||||
private static final long serialVersionUID = SerialVersionUID.InsufficientAddressCapacityException;
|
||||
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ package com.cloud.exception;
|
|||
|
||||
import com.cloud.utils.SerialVersionUID;
|
||||
|
||||
public class InsufficientVirtualNetworkCapcityException extends InsufficientCapacityException {
|
||||
private static final long serialVersionUID = SerialVersionUID.InsufficientCapacityException;
|
||||
public class InsufficientVirtualNetworkCapcityException extends InsufficientNetworkCapacityException {
|
||||
private static final long serialVersionUID = SerialVersionUID.InsufficientVirtualNetworkCapacityException;
|
||||
|
||||
public InsufficientVirtualNetworkCapcityException(String msg) {
|
||||
super(msg);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package com.cloud.network.element;
|
|||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientNetworkCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.NetworkConfiguration;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
|
|
@ -26,7 +27,7 @@ public interface NetworkElement extends Adapter {
|
|||
*/
|
||||
boolean implement(NetworkConfiguration config, NetworkOffering offering, DeployDestination dest, Account user) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException;
|
||||
|
||||
boolean prepare(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, DeployDestination dest, Account user) throws ConcurrentOperationException, ResourceUnavailableException;
|
||||
boolean prepare(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, DeployDestination dest, Account user) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientNetworkCapacityException;
|
||||
|
||||
boolean release(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, Account user) throws ConcurrentOperationException, ResourceUnavailableException;
|
||||
|
||||
|
|
|
|||
|
|
@ -117,5 +117,7 @@ public interface VirtualMachine extends RunningOn, ControlledEntity {
|
|||
*/
|
||||
public Date getCreated();
|
||||
|
||||
public long getServiceOfferingId();
|
||||
|
||||
Type getType();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,15 +36,24 @@ public class VirtualMachineProfile {
|
|||
List<NicProfile> _nics;
|
||||
String _os;
|
||||
String _password;
|
||||
String _userData;
|
||||
|
||||
public VirtualMachineProfile(VirtualMachine.Type type) {
|
||||
this._type = type;
|
||||
}
|
||||
|
||||
public long getServiceOfferingId() {
|
||||
return _vm.getServiceOfferingId();
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return _password;
|
||||
}
|
||||
|
||||
public String getUserData() {
|
||||
return _userData;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return _vm.getInstanceName();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class Commands {
|
|||
|
||||
public Answer getAnswer(String id) {
|
||||
int i = _ids.indexOf(id);
|
||||
return _answers[i];
|
||||
return i == -1 ? null : _answers[i];
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
|||
|
|
@ -315,4 +315,11 @@ public class NetworkConfigurationVO implements NetworkConfiguration {
|
|||
public boolean isImplemented() {
|
||||
return broadcastUri != null && cidr != null && gateway != null && mode != null && broadcastDomainType != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder buf = new StringBuilder("NtwkCfg:");
|
||||
buf.append(id).append("-").append(trafficType.toString()).append("-").append(networkOfferingId);
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ import com.cloud.deploy.DeploymentPlan;
|
|||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
|
||||
import com.cloud.exception.InsufficientNetworkCapacityException;
|
||||
import com.cloud.exception.InternalErrorException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.NetworkRuleConflictException;
|
||||
|
|
@ -306,7 +306,7 @@ public interface NetworkManager extends Manager {
|
|||
|
||||
List<NicProfile> allocate(VirtualMachineProfile vm, List<Pair<NetworkConfigurationVO, NicProfile>> networks) throws InsufficientCapacityException;
|
||||
|
||||
NicTO[] prepare(VirtualMachineProfile profile, DeployDestination dest, Account user) throws InsufficientAddressCapacityException, InsufficientVirtualNetworkCapcityException, ConcurrentOperationException, ResourceUnavailableException;
|
||||
NicTO[] prepare(VirtualMachineProfile profile, DeployDestination dest, Account user) throws InsufficientNetworkCapacityException, ConcurrentOperationException, ResourceUnavailableException;
|
||||
void release(VirtualMachineProfile vmProfile);
|
||||
|
||||
<K extends VMInstanceVO> List<NicVO> getNics(K vm);
|
||||
|
|
|
|||
|
|
@ -68,8 +68,8 @@ import com.cloud.configuration.dao.ResourceLimitDao;
|
|||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.dc.VlanVO;
|
||||
import com.cloud.dc.Vlan.VlanType;
|
||||
import com.cloud.dc.VlanVO;
|
||||
import com.cloud.dc.dao.AccountVlanMapDao;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.dc.dao.HostPodDao;
|
||||
|
|
@ -86,7 +86,7 @@ import com.cloud.exception.AgentUnavailableException;
|
|||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
|
||||
import com.cloud.exception.InsufficientNetworkCapacityException;
|
||||
import com.cloud.exception.InternalErrorException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.NetworkRuleConflictException;
|
||||
|
|
@ -141,10 +141,10 @@ import com.cloud.utils.component.Adapters;
|
|||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.JoinBuilder;
|
||||
import com.cloud.utils.db.JoinBuilder.JoinType;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.JoinBuilder.JoinType;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.DomainRouter;
|
||||
|
|
@ -1953,7 +1953,7 @@ public class NetworkManagerImpl implements NetworkManager, DomainRouterService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NicTO[] prepare(VirtualMachineProfile vmProfile, DeployDestination dest, Account user) throws InsufficientAddressCapacityException, InsufficientVirtualNetworkCapcityException, ConcurrentOperationException, ResourceUnavailableException {
|
||||
public NicTO[] prepare(VirtualMachineProfile vmProfile, DeployDestination dest, Account user) throws InsufficientNetworkCapacityException, ConcurrentOperationException, ResourceUnavailableException {
|
||||
List<NicVO> nics = _nicDao.listBy(vmProfile.getId());
|
||||
NicTO[] nicTos = new NicTO[nics.size()];
|
||||
int i = 0;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import org.apache.log4j.Logger;
|
|||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientNetworkCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.Network.TrafficType;
|
||||
import com.cloud.network.NetworkConfiguration;
|
||||
|
|
@ -38,7 +39,6 @@ import com.cloud.utils.component.Inject;
|
|||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.UserVmManager;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VirtualMachine.Type;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
|
|
@ -72,15 +72,13 @@ public class DomainRouterElement extends AdapterBase implements NetworkElement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean prepare(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, DeployDestination dest, Account user) throws ConcurrentOperationException {
|
||||
public boolean prepare(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, DeployDestination dest, Account user) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ResourceUnavailableException {
|
||||
if (config.getTrafficType() != TrafficType.Guest || vm.getType() != Type.User) {
|
||||
s_logger.trace("Domain Router only cares about guest network and User VMs");
|
||||
return false;
|
||||
}
|
||||
|
||||
UserVmVO userVm = _userVmDao.findById(vm.getId());
|
||||
|
||||
return _routerMgr.addVirtualMachineToGuestNetwork(userVm, vm.getPassword(), 1) != null;
|
||||
return _routerMgr.addVirtualMachineIntoNetwork(config, nic, vm, user) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import com.cloud.dc.VlanVO;
|
|||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientNetworkCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
|
|
@ -41,7 +42,9 @@ import com.cloud.user.Account;
|
|||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.vm.DomainRouter;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
/**
|
||||
* NetworkManager manages the network for the different end users.
|
||||
|
|
@ -174,4 +177,6 @@ public interface DomainRouterManager extends Manager {
|
|||
RemoteAccessVpnVO startRemoteAccessVpn(RemoteAccessVpnVO vpnVO);
|
||||
|
||||
boolean deleteRemoteAccessVpn(RemoteAccessVpnVO vpnVO);
|
||||
|
||||
DomainRouterVO addVirtualMachineIntoNetwork(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, Account caller) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ResourceUnavailableException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,6 +93,7 @@ import com.cloud.event.dao.EventDao;
|
|||
import com.cloud.exception.AgentUnavailableException;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientNetworkCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
|
|
@ -158,6 +159,7 @@ import com.cloud.vm.DomainRouter;
|
|||
import com.cloud.vm.DomainRouter.Role;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.State;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
|
|
@ -220,7 +222,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
|
|||
@Inject NicDao _nicDao;
|
||||
@Inject GuestOSDao _guestOSDao = null;
|
||||
@Inject NetworkManager _networkMgr;
|
||||
@Inject VmManager _vmMgr;
|
||||
@Inject VmManager _itMgr;
|
||||
|
||||
long _routerTemplateId = -1;
|
||||
int _routerRamSize;
|
||||
|
|
@ -1454,7 +1456,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
|
|||
|
||||
_agentMgr.registerForHostEvents(new SshKeysDistriMonitor(this, _hostDao, _configDao), true, false, false);
|
||||
_haMgr.registerHandler(VirtualMachine.Type.DomainRouter, this);
|
||||
_vmMgr.registerGuru(VirtualMachine.Type.DomainRouter, this);
|
||||
_itMgr.registerGuru(VirtualMachine.Type.DomainRouter, this);
|
||||
|
||||
boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key()));
|
||||
String networkRateStr = _configDao.getValue("network.throttling.rate");
|
||||
|
|
@ -2011,9 +2013,6 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
|
|||
|
||||
DataCenterDeployment plan = new DataCenterDeployment(dcId, 1);
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
guestConfig = _networkConfigurationDao.lock(guestConfig.getId(), true);
|
||||
if (guestConfig == null) {
|
||||
throw new ConcurrentOperationException("Unable to get the lock on " + guestConfig);
|
||||
|
|
@ -2050,14 +2049,17 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
|
|||
networks.add(new Pair<NetworkConfigurationVO, NicProfile>((NetworkConfigurationVO)guestConfig, gatewayNic));
|
||||
networks.add(new Pair<NetworkConfigurationVO, NicProfile>(controlConfig, null));
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
router = new DomainRouterVO(id, _offering.getId(), VirtualMachineName.getRouterName(id, _instance), _template.getId(), _template.getGuestOSId(), owner.getDomainId(), owner.getId(), guestConfig.getId(), _offering.getOfferHA());
|
||||
router = _routerDao.persist(router);
|
||||
|
||||
_vmMgr.allocate(router, _template, _offering, networks, plan, owner);
|
||||
_itMgr.allocate(router, _template, _offering, networks, plan, owner);
|
||||
txn.commit();
|
||||
}
|
||||
txn.commit();
|
||||
|
||||
return _vmMgr.start(router, plan, owner);
|
||||
return _itMgr.start(router, plan, owner);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -2163,7 +2165,88 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public DomainRouterVO start(long routerId, Account caller) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
|
||||
return start(_routerDao.findById(routerId), caller);
|
||||
}
|
||||
|
||||
public DomainRouterVO start(DomainRouterVO router, Account caller) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
|
||||
DataCenterDeployment plan = new DataCenterDeployment(router.getDataCenterId(), 1);
|
||||
return _itMgr.start(router, plan, caller);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DomainRouterVO addVirtualMachineIntoNetwork(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, Account caller) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ResourceUnavailableException {
|
||||
DomainRouterVO router = _routerDao.findByNetworkConfiguration(config.getId());
|
||||
try {
|
||||
router = start(router, caller);
|
||||
} catch (InsufficientNetworkCapacityException e) {
|
||||
throw e;
|
||||
} catch (InsufficientCapacityException e) {
|
||||
throw new ResourceUnavailableException("Unable to start router for " + config, e);
|
||||
}
|
||||
|
||||
if (router == null) {
|
||||
s_logger.error("Can't find a domain router to start VM: " + vm.getName());
|
||||
throw new ResourceUnavailableException("Can't find a domain router to start " + vm + " in " + config);
|
||||
}
|
||||
|
||||
String password = null;
|
||||
String userData = vm.getUserData();
|
||||
int cmdsLength = (password == null ? 0:1) + 1;
|
||||
Commands cmds = new Commands(OnError.Stop);
|
||||
String routerPublicIpAddress = nic.getIp4Address();
|
||||
String routerControlIpAddress = null;
|
||||
List<NicVO> nics = _nicDao.listBy(router.getId());
|
||||
for (NicVO n : nics) {
|
||||
NetworkConfigurationVO nc = _networkConfigurationDao.findById(n.getNetworkConfigurationId());
|
||||
if (n.getIp4Address() != null && nc.getTrafficType() == TrafficType.Public) {
|
||||
routerPublicIpAddress = nic.getIp4Address();
|
||||
} else if (nc.getTrafficType() == TrafficType.Control) {
|
||||
routerControlIpAddress = n.getIp4Address();
|
||||
}
|
||||
}
|
||||
|
||||
cmds.addCommand("dhcp", new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), routerControlIpAddress, vm.getName()));
|
||||
if (password != null) {
|
||||
final String encodedPassword = rot13(password);
|
||||
cmds.addCommand("password", new SavePasswordCommand(encodedPassword, nic.getIp4Address(), routerControlIpAddress, vm.getName()));
|
||||
}
|
||||
|
||||
String serviceOffering = _serviceOfferingDao.findById(vm.getServiceOfferingId()).getDisplayText();
|
||||
String zoneName = _dcDao.findById(config.getDataCenterId()).getName();
|
||||
|
||||
|
||||
cmds.addCommand("vmdata", generateVmDataCommand(routerControlIpAddress, routerPublicIpAddress, nic.getIp4Address(), userData, serviceOffering, zoneName, nic.getIp4Address(), vm.getName(), vm.getName(), vm.getId()));
|
||||
|
||||
try {
|
||||
_agentMgr.send(router.getHostId(), cmds);
|
||||
} catch (AgentUnavailableException e) {
|
||||
throw new ResourceUnavailableException("Unable to reach the agent ", e);
|
||||
} catch (OperationTimedoutException e) {
|
||||
throw new ResourceUnavailableException("Unable to reach the agent ", e);
|
||||
}
|
||||
|
||||
Answer answer = cmds.getAnswer("dhcp");
|
||||
if (!answer.getResult()) {
|
||||
s_logger.error("Unable to set dhcp entry for " + vm.getId() + " - " + vm.getName() +" on domR: " + router.getName() + " due to " + answer.getDetails());
|
||||
throw new ResourceUnavailableException("Unable to set dhcp entry for " + vm + " due to " + answer.getDetails());
|
||||
}
|
||||
|
||||
answer = cmds.getAnswer("password");
|
||||
if (answer != null && !answer.getResult()) {
|
||||
s_logger.error("Unable to set password for " + vm.getId() + " - " + vm.getName() + " due to " + answer.getDetails());
|
||||
throw new ResourceUnavailableException("Unable to set password due to " + answer.getDetails());
|
||||
}
|
||||
|
||||
answer = cmds.getAnswer("vmdata");
|
||||
if (answer != null && !answer.getResult()) {
|
||||
s_logger.error("Unable to set VM data for " + vm.getId() + " - " + vm.getName() + " due to " + answer.getDetails());
|
||||
throw new ResourceUnavailableException("Unable to set VM data due to " + answer.getDetails());
|
||||
}
|
||||
return router;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DomainRouterVO persist(DomainRouterVO router) {
|
||||
return _routerDao.persist(router);
|
||||
|
|
|
|||
|
|
@ -27,13 +27,11 @@ import com.cloud.async.executor.StopVMExecutor;
|
|||
import com.cloud.async.executor.VMOperationParam;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientStorageCapacityException;
|
||||
import com.cloud.exception.InternalErrorException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
import com.cloud.network.security.NetworkGroupVO;
|
||||
import com.cloud.offerings.NetworkOfferingVO;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
import com.cloud.storage.StoragePoolVO;
|
||||
|
|
@ -51,8 +49,6 @@ import com.cloud.vm.VirtualMachine.Event;
|
|||
*/
|
||||
public interface UserVmManager extends Manager, VirtualMachineManager<UserVmVO> {
|
||||
|
||||
UserVmVO allocate(String displayName, VMTemplateVO template, ServiceOfferingVO serviceOffering, NetworkOfferingVO[] networkOfferings, DiskOfferingVO[] diskOfferings, AccountVO owner, long userId) throws InsufficientCapacityException;
|
||||
|
||||
static final int MAX_USER_DATA_LENGTH_BYTES = 2048;
|
||||
/**
|
||||
* @param hostId get all of the virtual machines that belong to one host.
|
||||
|
|
|
|||
|
|
@ -144,7 +144,6 @@ import com.cloud.network.security.NetworkGroupManager;
|
|||
import com.cloud.network.security.NetworkGroupVO;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.offerings.NetworkOfferingVO;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
|
|
@ -1559,175 +1558,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
|
|||
_vmDao.update(userVm.getId(), userVm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVmVO allocate(String displayName, VMTemplateVO template, ServiceOfferingVO serviceOffering, NetworkOfferingVO[] networkOfferings, DiskOfferingVO[] diskOfferings, AccountVO owner, long userId) throws InsufficientCapacityException {
|
||||
/*
|
||||
long accountId = account.getId();
|
||||
long dataCenterId = dc.getId();
|
||||
long serviceOfferingId = offering.getId();
|
||||
UserVmVO vm = new UserVmVO();
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Creating vm for account id=" + account.getId() +
|
||||
", name="+ account.getAccountName() + "; dc=" + dc.getName() +
|
||||
"; offering=" + offering.getId() + "; diskOffering=" + ((diskOffering != null) ? diskOffering.getName() : "none") +
|
||||
"; template=" + template.getId());
|
||||
}
|
||||
|
||||
DomainRouterVO router = _routerDao.findBy(accountId, dataCenterId, Role.DHCP_FIREWALL_LB_PASSWD_USERDATA);
|
||||
if (router == null) {
|
||||
throw new InternalErrorException("Cannot find a router for account (" + accountId + "/" +
|
||||
account.getAccountName() + ") in " + dataCenterId);
|
||||
}
|
||||
|
||||
// Determine the Guest OS Id
|
||||
long guestOSId;
|
||||
if (template != null) {
|
||||
guestOSId = template.getGuestOSId();
|
||||
} else {
|
||||
throw new InternalErrorException("No template or ISO was specified for the VM.");
|
||||
}
|
||||
long numVolumes = -1;
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
long routerId = router.getId();
|
||||
|
||||
String name;
|
||||
txn.start();
|
||||
|
||||
account = _accountDao.lock(accountId, true);
|
||||
if (account == null) {
|
||||
throw new InternalErrorException("Unable to lock up the account: " + accountId);
|
||||
}
|
||||
|
||||
// First check that the maximum number of UserVMs for the given accountId will not be exceeded
|
||||
if (_accountMgr.resourceLimitExceeded(account, ResourceType.user_vm)) {
|
||||
ResourceAllocationException rae = new ResourceAllocationException("Maximum number of virtual machines for account: " + account.getAccountName() + " has been exceeded.");
|
||||
rae.setResourceType("vm");
|
||||
throw rae;
|
||||
}
|
||||
|
||||
boolean isIso = Storage.ImageFormat.ISO.equals(template.getFormat());
|
||||
numVolumes = (isIso || (diskOffering == null)) ? 1 : 2;
|
||||
_accountMgr.incrementResourceCount(account.getId(), ResourceType.user_vm);
|
||||
_accountMgr.incrementResourceCount(account.getId(), ResourceType.volume, numVolumes);
|
||||
txn.commit();
|
||||
|
||||
name = VirtualMachineName.getVmName(vmId, accountId, _instance);
|
||||
|
||||
String diskOfferingIdentifier = (diskOffering != null) ? String.valueOf(diskOffering.getId()) : "-1";
|
||||
String eventParams = "id=" + vmId + "\nvmName=" + name + "\nsoId=" + serviceOfferingId + "\ndoId=" + diskOfferingIdentifier + "\ntId=" + template.getId() + "\ndcId=" + dataCenterId;
|
||||
EventVO event = new EventVO();
|
||||
event.setUserId(userId);
|
||||
event.setAccountId(accountId);
|
||||
event.setStartId(startEventId);
|
||||
event.setState(EventState.Completed);
|
||||
event.setType(EventTypes.EVENT_VM_CREATE);
|
||||
event.setParameters(eventParams);
|
||||
|
||||
try {
|
||||
Pair<HostPodVO, Long> pod = null;
|
||||
long poolid = 0;
|
||||
Set<Long> podsToAvoid = new HashSet<Long>();
|
||||
|
||||
while ((pod = _agentMgr.findPod(template, offering, dc, account.getId(), podsToAvoid)) != null) {
|
||||
if (vm == null) {
|
||||
vm = new UserVmVO(vmId, name, template.getId(), guestOSId, accountId, account.getDomainId().longValue(),
|
||||
serviceOfferingId, null, null, router.getGuestNetmask(),
|
||||
null,null,null,
|
||||
routerId, pod.first().getId(), dataCenterId,
|
||||
offering.getOfferHA(), displayName, group, userData);
|
||||
|
||||
if (diskOffering != null) {
|
||||
vm.setMirroredVols(diskOffering.isMirrored());
|
||||
}
|
||||
|
||||
vm.setLastHostId(pod.second());
|
||||
|
||||
vm = _vmDao.persist(vm);
|
||||
} else {
|
||||
vm.setPodId(pod.first().getId());
|
||||
_vmDao.updateIf(vm, Event.OperationRetry, null);
|
||||
}
|
||||
|
||||
String ipAddressStr = acquireGuestIpAddress(dataCenterId, accountId, vm);
|
||||
if (ipAddressStr == null) {
|
||||
s_logger.warn("Failed user vm creation : no guest ip address available");
|
||||
releaseGuestIpAddress(vm);
|
||||
ResourceAllocationException rae = new ResourceAllocationException("No guest ip addresses available for " + account.getAccountName() + " (try destroying some instances)");
|
||||
rae.setResourceType("vm");
|
||||
throw rae;
|
||||
}
|
||||
|
||||
poolid = _storageMgr.createUserVM(account, vm, template, dc, pod.first(), offering, diskOffering, avoids);
|
||||
if ( poolid != 0) {
|
||||
break;
|
||||
}
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Unable to find storage host in pod " + pod.first().getName() + " (id:" + pod.first().getId() + ") while creating " + vm.toString() + ", checking other pods");
|
||||
}
|
||||
|
||||
// if it fails at storage allocation round, reset lastHostId to "release"
|
||||
// the CPU/memory allocation on the candidate host
|
||||
vm.setLastHostId(null);
|
||||
_vmDao.update(vm.getId(), vm);
|
||||
|
||||
podsToAvoid.add(pod.first().getId());
|
||||
}
|
||||
|
||||
if ((vm == null) || (poolid == 0)) {
|
||||
throw new ResourceAllocationException("Create VM " + ((vm == null) ? vmId : vm.toString()) + " failed due to no Storage Pool is available");
|
||||
}
|
||||
|
||||
txn.start();
|
||||
if(vm != null && vm.getName() != null && vm.getDisplayName() != null)
|
||||
{
|
||||
if(!vm.getName().equals(vm.getDisplayName()))
|
||||
event.setDescription("successfully created VM instance : " + vm.getName()+"("+vm.getDisplayName()+")");
|
||||
else
|
||||
event.setDescription("successfully created VM instance : " + vm.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
event.setDescription("successfully created VM instance :"+name);
|
||||
}
|
||||
|
||||
_eventDao.persist(event);
|
||||
|
||||
_vmDao.updateIf(vm, Event.OperationSucceeded, null);
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("vm created " + vmId);
|
||||
}
|
||||
txn.commit();
|
||||
|
||||
return _vmDao.findById(vmId);
|
||||
} catch (Throwable th) {
|
||||
s_logger.error("Unable to create vm", th);
|
||||
if (vm != null) {
|
||||
_vmDao.delete(vmId);
|
||||
}
|
||||
_accountMgr.decrementResourceCount(account.getId(), ResourceType.user_vm);
|
||||
_accountMgr.decrementResourceCount(account.getId(), ResourceType.volume, numVolumes);
|
||||
|
||||
String eventDescription = "Failed to create VM: ";
|
||||
if (vm == null) {
|
||||
eventDescription += "new instance";
|
||||
} else {
|
||||
eventDescription += vm.getName();
|
||||
if (!vm.getName().equals(vm.getDisplayName())) {
|
||||
eventDescription += " (" + vm.getDisplayName() + ")";
|
||||
}
|
||||
}
|
||||
|
||||
if (th instanceof ResourceAllocationException) {
|
||||
throw (ResourceAllocationException)th;
|
||||
}
|
||||
throw new CloudRuntimeException("Unable to create vm", th);
|
||||
}
|
||||
*/
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
public UserVmVO createVirtualMachine(Long vmId, long userId, AccountVO account, DataCenterVO dc, ServiceOfferingVO offering, VMTemplateVO template, DiskOfferingVO diskOffering, String displayName, String userData, List<StoragePoolVO> avoids, long startEventId, long size) throws InternalErrorException, ResourceAllocationException {
|
||||
long accountId = account.getId();
|
||||
|
|
|
|||
|
|
@ -12,5 +12,4 @@ public interface NicDao extends GenericDao<NicVO, Long> {
|
|||
List<NicVO> listBy(long instanceId);
|
||||
|
||||
List<String> listIpAddressInNetworkConfiguration(long networkConfigId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,9 @@ public interface SerialVersionUID {
|
|||
public static final long CloudRuntimeException = Base | 0x2;
|
||||
public static final long CloudStartupServlet = Base | 0x3;
|
||||
public static final long CloudServiceImpl = Base | 0x4;
|
||||
public static final long AccountLimitException = Base | 0x5;
|
||||
public static final long AccountLimitException = Base | 0x5;
|
||||
public static final long InsufficientNetworkCapacity = Base | 0x6;
|
||||
public static final long InsufficientVirtualNetworkCapacityException = Base | 0x7;
|
||||
public static final long UnsupportedVersionException = Base | 0xb;
|
||||
public static final long DataCenterIpAddressPK = Base | 0xc;
|
||||
public static final long UnableToExecuteException = Base | 0xd;
|
||||
|
|
|
|||
Loading…
Reference in New Issue