use of com.cloud.host.Host in project cloudstack by apache.
the class BrocadeVcsElement method addBrocadeVcsDevice.
@Override
@DB
public BrocadeVcsDeviceVO addBrocadeVcsDevice(AddBrocadeVcsDeviceCmd cmd) {
ServerResource resource = new BrocadeVcsResource();
final String deviceName = Network.Provider.BrocadeVcs.getName();
NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
if (networkDevice == null) {
throw new CloudRuntimeException("No network device found for " + deviceName);
}
final Long physicalNetworkId = cmd.getPhysicalNetworkId();
PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
if (physicalNetwork == null) {
throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
}
long zoneId = physicalNetwork.getDataCenterId();
final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(), networkDevice.getNetworkServiceProvder());
if (ntwkSvcProvider == null) {
throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + " is not enabled in the physical network: " + physicalNetworkId + "to add this device");
} else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() + " is in shutdown state in the physical network: " + physicalNetworkId + "to add this device");
}
Map<String, String> params = new HashMap<String, String>();
params.put("guid", UUID.randomUUID().toString());
params.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId()));
params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
params.put("name", "Brocade VCS - " + cmd.getHost());
params.put("ip", cmd.getHost());
params.put("adminuser", cmd.getUsername());
params.put("adminpass", cmd.getPassword());
Map<String, Object> hostdetails = new HashMap<String, Object>();
hostdetails.putAll(params);
try {
resource.configure(cmd.getHost(), hostdetails);
final Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, params);
if (host != null) {
return Transaction.execute(new TransactionCallback<BrocadeVcsDeviceVO>() {
@Override
public BrocadeVcsDeviceVO doInTransaction(TransactionStatus status) {
BrocadeVcsDeviceVO brocadeVcsDevice = new BrocadeVcsDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
_brocadeVcsDao.persist(brocadeVcsDevice);
DetailVO detail = new DetailVO(host.getId(), "brocadevcsdeviceid", String.valueOf(brocadeVcsDevice.getId()));
_hostDetailsDao.persist(detail);
return brocadeVcsDevice;
}
});
} else {
throw new CloudRuntimeException("Failed to add Brocade VCS Switch due to internal error.");
}
} catch (ConfigurationException e) {
throw new CloudRuntimeException(e.getMessage());
}
}
use of com.cloud.host.Host in project cloudstack by apache.
the class NetscalerElement method allocateNCCResourceForNetwork.
public HostVO allocateNCCResourceForNetwork(Network guestConfig) throws ConfigurationException {
Map<String, String> _configs;
List<NetScalerControlCenterVO> ncc = _netscalerControlCenterDao.listAll();
HostVO hostVO = null;
if (ncc.size() > 0) {
NetScalerControlCenterVO nccVO = ncc.get(0);
String ipAddress = nccVO.getNccip();
Map hostDetails = new HashMap<String, String>();
String hostName = "NetscalerControlCenter";
hostDetails.put("name", hostName);
hostDetails.put("guid", UUID.randomUUID().toString());
hostDetails.put("zoneId", Long.toString(guestConfig.getDataCenterId()));
hostDetails.put("ip", ipAddress);
hostDetails.put("username", nccVO.getUsername());
hostDetails.put("password", DBEncryptionUtil.decrypt(nccVO.getPassword()));
hostDetails.put("deviceName", "netscaler control center");
hostDetails.put("cmdTimeOut", Long.toString(NumbersUtil.parseInt(_configDao.getValue(Config.NCCCmdTimeOut.key()), 600000)));
ServerResource resource = new NetScalerControlCenterResource();
resource.configure(hostName, hostDetails);
final Host host = _resourceMgr.addHost(guestConfig.getDataCenterId(), resource, Host.Type.NetScalerControlCenter, hostDetails);
hostVO = _hostDao.findById(host.getId());
}
return hostVO;
}
use of com.cloud.host.Host in project cloudstack by apache.
the class NiciraNvpElement method addNiciraNvpDevice.
@Override
@DB
public NiciraNvpDeviceVO addNiciraNvpDevice(AddNiciraNvpDeviceCmd cmd) {
ServerResource resource = new NiciraNvpResource();
final String deviceName = Network.Provider.NiciraNvp.getName();
NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
if (networkDevice == null) {
throw new CloudRuntimeException("No network device found for " + deviceName);
}
final Long physicalNetworkId = cmd.getPhysicalNetworkId();
PhysicalNetworkVO physicalNetwork = physicalNetworkDao.findById(physicalNetworkId);
if (physicalNetwork == null) {
throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
}
long zoneId = physicalNetwork.getDataCenterId();
final PhysicalNetworkServiceProviderVO ntwkSvcProvider = physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(), networkDevice.getNetworkServiceProvder());
if (ntwkSvcProvider == null) {
throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + " is not enabled in the physical network: " + physicalNetworkId + "to add this device");
} else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() + " is in shutdown state in the physical network: " + physicalNetworkId + "to add this device");
}
if (niciraNvpDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
throw new CloudRuntimeException("A NiciraNvp device is already configured on this physical network");
}
Map<String, String> params = new HashMap<String, String>();
params.put("guid", UUID.randomUUID().toString());
params.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId()));
params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
params.put("name", "Nicira Controller - " + cmd.getHost());
params.put("ip", cmd.getHost());
params.put("adminuser", cmd.getUsername());
params.put("adminpass", cmd.getPassword());
params.put("transportzoneuuid", cmd.getTransportzoneUuid());
// FIXME What to do with multiple isolation types
params.put("transportzoneisotype", physicalNetwork.getIsolationMethods().get(0).toLowerCase());
if (cmd.getL3GatewayServiceUuid() != null) {
params.put("l3gatewayserviceuuid", cmd.getL3GatewayServiceUuid());
}
if (cmd.getL2GatewayServiceUuid() != null) {
params.put("l2gatewayserviceuuid", cmd.getL2GatewayServiceUuid());
}
Map<String, Object> hostdetails = new HashMap<String, Object>();
hostdetails.putAll(params);
try {
resource.configure(cmd.getHost(), hostdetails);
final Host host = resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, params);
if (host != null) {
return Transaction.execute(new TransactionCallback<NiciraNvpDeviceVO>() {
@Override
public NiciraNvpDeviceVO doInTransaction(TransactionStatus status) {
NiciraNvpDeviceVO niciraNvpDevice = new NiciraNvpDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
niciraNvpDao.persist(niciraNvpDevice);
DetailVO detail = new DetailVO(host.getId(), "niciranvpdeviceid", String.valueOf(niciraNvpDevice.getId()));
hostDetailsDao.persist(detail);
return niciraNvpDevice;
}
});
} else {
throw new CloudRuntimeException("Failed to add Nicira Nvp Device due to internal error.");
}
} catch (ConfigurationException e) {
throw new CloudRuntimeException(e.getMessage());
}
}
use of com.cloud.host.Host in project cloudstack by apache.
the class CapacityManagerImpl method checkIfHostHasCpuCapability.
@Override
public boolean checkIfHostHasCpuCapability(long hostId, Integer cpuNum, Integer cpuSpeed) {
// Check host can support the Cpu Number and Speed.
Host host = _hostDao.findById(hostId);
boolean isCpuNumGood = host.getCpus().intValue() >= cpuNum;
boolean isCpuSpeedGood = host.getSpeed().intValue() >= cpuSpeed;
if (isCpuNumGood && isCpuSpeedGood) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Host: " + hostId + " has cpu capability (cpu:" + host.getCpus() + ", speed:" + host.getSpeed() + ") to support requested CPU: " + cpuNum + " and requested speed: " + cpuSpeed);
}
return true;
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Host: " + hostId + " doesn't have cpu capability (cpu:" + host.getCpus() + ", speed:" + host.getSpeed() + ") to support requested CPU: " + cpuNum + " and requested speed: " + cpuSpeed);
}
return false;
}
}
use of com.cloud.host.Host in project cloudstack by apache.
the class CapacityManagerImpl method postStateTransitionEvent.
@Override
public boolean postStateTransitionEvent(StateMachine2.Transition<State, Event> transition, VirtualMachine vm, boolean status, Object opaque) {
if (!status) {
return false;
}
@SuppressWarnings("unchecked") Pair<Long, Long> hosts = (Pair<Long, Long>) opaque;
Long oldHostId = hosts.first();
State oldState = transition.getCurrentState();
State newState = transition.getToState();
Event event = transition.getEvent();
Host lastHost = _hostDao.findById(vm.getLastHostId());
Host oldHost = _hostDao.findById(oldHostId);
Host newHost = _hostDao.findById(vm.getHostId());
s_logger.debug(String.format("%s state transited from [%s] to [%s] with event [%s]. VM's original host: %s, new host: %s, host before state transition: %s", vm, oldState, newState, event, lastHost, newHost, oldHost));
if (oldState == State.Starting) {
if (newState != State.Running) {
releaseVmCapacity(vm, false, false, oldHostId);
}
} else if (oldState == State.Running) {
if (event == Event.AgentReportStopped) {
releaseVmCapacity(vm, false, true, oldHostId);
} else if (event == Event.AgentReportMigrated) {
releaseVmCapacity(vm, false, false, oldHostId);
}
} else if (oldState == State.Migrating) {
if (event == Event.AgentReportStopped) {
/* Release capacity from original host */
releaseVmCapacity(vm, false, false, vm.getLastHostId());
releaseVmCapacity(vm, false, false, oldHostId);
} else if (event == Event.OperationFailed) {
/* Release from dest host */
releaseVmCapacity(vm, false, false, oldHostId);
} else if (event == Event.OperationSucceeded) {
releaseVmCapacity(vm, false, false, vm.getLastHostId());
}
} else if (oldState == State.Stopping) {
if (event == Event.OperationSucceeded) {
releaseVmCapacity(vm, false, true, oldHostId);
} else if (event == Event.AgentReportStopped) {
releaseVmCapacity(vm, false, false, oldHostId);
} else if (event == Event.AgentReportMigrated) {
releaseVmCapacity(vm, false, false, oldHostId);
}
} else if (oldState == State.Stopped) {
if (event == Event.DestroyRequested || event == Event.ExpungeOperation) {
releaseVmCapacity(vm, true, false, vm.getLastHostId());
} else if (event == Event.AgentReportMigrated) {
releaseVmCapacity(vm, false, false, oldHostId);
}
}
if ((newState == State.Starting || newState == State.Migrating || event == Event.AgentReportMigrated) && vm.getHostId() != null) {
boolean fromLastHost = false;
if (vm.getHostId().equals(vm.getLastHostId())) {
s_logger.debug("VM starting again on the last host it was stopped on");
fromLastHost = true;
}
allocateVmCapacity(vm, fromLastHost);
}
if (newState == State.Stopped) {
if (vm.getType() == VirtualMachine.Type.User) {
UserVmVO userVM = _userVMDao.findById(vm.getId());
_userVMDao.loadDetails(userVM);
// free the message sent flag if it exists
userVM.setDetail(VmDetailConstants.MESSAGE_RESERVED_CAPACITY_FREED_FLAG, "false");
_userVMDao.saveDetails(userVM);
}
}
return true;
}
Aggregations