use of com.cloud.offering.ServiceOffering in project cloudstack by apache.
the class VirtualMachineManagerImpl method upgradeVmDb.
@Override
public boolean upgradeVmDb(final long vmId, final long serviceOfferingId) {
final VMInstanceVO vmForUpdate = _vmDao.createForUpdate();
vmForUpdate.setServiceOfferingId(serviceOfferingId);
final ServiceOffering newSvcOff = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
vmForUpdate.setHaEnabled(newSvcOff.getOfferHA());
vmForUpdate.setLimitCpuUse(newSvcOff.getLimitCpuUse());
vmForUpdate.setServiceOfferingId(newSvcOff.getId());
return _vmDao.update(vmId, vmForUpdate);
}
use of com.cloud.offering.ServiceOffering in project cloudstack by apache.
the class UserVmManagerImpl method updateVirtualMachine.
@Override
public UserVm updateVirtualMachine(long id, String displayName, String group, Boolean ha, Boolean isDisplayVmEnabled, Long osTypeId, String userData, Boolean isDynamicallyScalable, HTTPMethod httpMethod, String customId, String hostName, String instanceName, List<Long> securityGroupIdList) throws ResourceUnavailableException, InsufficientCapacityException {
UserVmVO vm = _vmDao.findById(id);
if (vm == null) {
throw new CloudRuntimeException("Unable to find virtual machine with id " + id);
}
if (instanceName != null) {
VMInstanceVO vmInstance = _vmInstanceDao.findVMByInstanceName(instanceName);
if (vmInstance != null && vmInstance.getId() != id) {
throw new CloudRuntimeException("Instance name : " + instanceName + " is not unique");
}
}
if (vm.getState() == State.Error || vm.getState() == State.Expunging) {
s_logger.error("vm is not in the right state: " + id);
throw new InvalidParameterValueException("Vm with id " + id + " is not in the right state");
}
if (displayName == null) {
displayName = vm.getDisplayName();
}
if (ha == null) {
ha = vm.isHaEnabled();
}
ServiceOffering offering = _serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
if (!offering.getOfferHA() && ha) {
throw new InvalidParameterValueException("Can't enable ha for the vm as it's created from the Service offering having HA disabled");
}
if (isDisplayVmEnabled == null) {
isDisplayVmEnabled = vm.isDisplayVm();
}
boolean updateUserdata = false;
if (userData != null) {
// check and replace newlines
userData = userData.replace("\\n", "");
validateUserData(userData, httpMethod);
// update userData on domain router.
updateUserdata = true;
} else {
userData = vm.getUserData();
}
if (isDynamicallyScalable == null) {
isDynamicallyScalable = vm.isDynamicallyScalable();
}
if (osTypeId == null) {
osTypeId = vm.getGuestOSId();
}
if (group != null) {
addInstanceToGroup(id, group);
}
if (isDynamicallyScalable == null) {
isDynamicallyScalable = vm.isDynamicallyScalable();
}
boolean isVMware = (vm.getHypervisorType() == HypervisorType.VMware);
if (securityGroupIdList != null && isVMware) {
throw new InvalidParameterValueException("Security group feature is not supported for vmWare hypervisor");
} else {
// Get default guest network in Basic zone
Network defaultNetwork = null;
try {
DataCenterVO zone = _dcDao.findById(vm.getDataCenterId());
if (zone.getNetworkType() == NetworkType.Basic) {
// Get default guest network in Basic zone
defaultNetwork = _networkModel.getExclusiveGuestNetwork(zone.getId());
} else if (zone.isSecurityGroupEnabled()) {
NicVO defaultNic = _nicDao.findDefaultNicForVM(vm.getId());
if (defaultNic != null) {
defaultNetwork = _networkDao.findById(defaultNic.getNetworkId());
}
}
} catch (InvalidParameterValueException e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(e.getMessage(), e);
}
defaultNetwork = _networkModel.getDefaultNetworkForVm(id);
}
if (securityGroupIdList != null && _networkModel.isSecurityGroupSupportedInNetwork(defaultNetwork) && _networkModel.canAddDefaultSecurityGroup()) {
if (vm.getState() == State.Stopped) {
// Remove instance from security groups
_securityGroupMgr.removeInstanceFromGroups(id);
// Add instance in provided groups
_securityGroupMgr.addInstanceToGroups(id, securityGroupIdList);
} else {
throw new InvalidParameterValueException("Virtual machine must be stopped prior to update security groups ");
}
}
}
if (hostName != null) {
// Check is hostName is RFC compliant
checkNameForRFCCompliance(hostName);
if (vm.getHostName().equalsIgnoreCase(hostName)) {
s_logger.debug("Vm " + vm + " is already set with the hostName specified: " + hostName);
hostName = null;
}
// Verify that vm's hostName is unique
List<NetworkVO> vmNtwks = new ArrayList<NetworkVO>();
List<? extends Nic> nics = _nicDao.listByVmId(vm.getId());
for (Nic nic : nics) {
vmNtwks.add(_networkDao.findById(nic.getNetworkId()));
}
checkIfHostNameUniqueInNtwkDomain(hostName, vmNtwks);
}
_vmDao.updateVM(id, displayName, ha, osTypeId, userData, isDisplayVmEnabled, isDynamicallyScalable, customId, hostName, instanceName);
if (updateUserdata) {
boolean result = updateUserDataInternal(_vmDao.findById(id));
if (result) {
s_logger.debug("User data successfully updated for vm id=" + id);
} else {
throw new CloudRuntimeException("Failed to reset userdata for the virtual machine ");
}
}
return _vmDao.findById(id);
}
use of com.cloud.offering.ServiceOffering in project CloudStack-archive by CloudStack-extras.
the class CreateServiceOfferingCmd method execute.
@Override
public void execute() {
ServiceOffering result = _configService.createServiceOffering(this);
if (result != null) {
ServiceOfferingResponse response = _responseGenerator.createServiceOfferingResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create service offering");
}
}
use of com.cloud.offering.ServiceOffering in project CloudStack-archive by CloudStack-extras.
the class ListServiceOfferingsCmd method execute.
@Override
public void execute() {
List<? extends ServiceOffering> offerings = _mgr.searchForServiceOfferings(this);
ListResponse<ServiceOfferingResponse> response = new ListResponse<ServiceOfferingResponse>();
List<ServiceOfferingResponse> offeringResponses = new ArrayList<ServiceOfferingResponse>();
for (ServiceOffering offering : offerings) {
ServiceOfferingResponse offeringResponse = _responseGenerator.createServiceOfferingResponse(offering);
offeringResponse.setObjectName("serviceoffering");
offeringResponses.add(offeringResponse);
}
response.setResponses(offeringResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
use of com.cloud.offering.ServiceOffering in project CloudStack-archive by CloudStack-extras.
the class UpdateServiceOfferingCmd method execute.
@Override
public void execute() {
//Note
//Once an offering is created, we cannot update the domainId field (keeping consistent with zones logic)
ServiceOffering result = _configService.updateServiceOffering(this);
if (result != null) {
ServiceOfferingResponse response = _responseGenerator.createServiceOfferingResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update service offering");
}
}
Aggregations