use of com.cloud.storage.GuestOSVO in project cosmic by MissionCriticalCloud.
the class FirstFitAllocator method getTemplateGuestOSCategory.
protected String getTemplateGuestOSCategory(final VMTemplateVO template) {
final long guestOSId = template.getGuestOSId();
final GuestOSVO guestOS = _guestOSDao.findById(guestOSId);
final long guestOSCategoryId = guestOS.getCategoryId();
final GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId);
return guestOSCategory.getName();
}
use of com.cloud.storage.GuestOSVO in project cosmic by MissionCriticalCloud.
the class KVMGuru method implement.
@Override
public VirtualMachineTO implement(final VirtualMachineProfile vm) {
final VirtualMachineTO to = toVirtualMachineTO(vm);
// Determine the VM's OS description
final GuestOSVO guestOS = _guestOsDao.findByIdIncludingRemoved(vm.getVirtualMachine().getGuestOSId());
to.setOs(guestOS.getDisplayName());
to.setCpuflags(guestOS.getCpuflags());
to.setManufacturer(guestOS.getManufacturer());
final HostVO host = _hostDao.findById(vm.getVirtualMachine().getHostId());
GuestOSHypervisorVO guestOsMapping = null;
if (host != null) {
guestOsMapping = _guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), getHypervisorType().toString(), host.getHypervisorVersion());
}
if (guestOsMapping == null) {
to.setPlatformEmulator("Default - VirtIO capable OS (64-bit)");
} else {
to.setPlatformEmulator(guestOsMapping.getGuestOsName());
}
return to;
}
use of com.cloud.storage.GuestOSVO in project cosmic by MissionCriticalCloud.
the class ManagementServerImpl method addGuestOs.
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_ADD, eventDescription = "Adding new guest OS type", create = true)
public GuestOS addGuestOs(final AddGuestOsCmd cmd) {
final Long categoryId = cmd.getOsCategoryId();
final String displayName = cmd.getOsDisplayName();
final String name = cmd.getOsName();
final GuestOSCategoryVO guestOsCategory = ApiDBUtils.findGuestOsCategoryById(categoryId);
if (guestOsCategory == null) {
throw new InvalidParameterValueException("Guest OS category not found. Please specify a valid Guest OS category");
}
final GuestOS guestOs = ApiDBUtils.findGuestOSByDisplayName(displayName);
if (guestOs != null) {
throw new InvalidParameterValueException("The specified Guest OS name : " + displayName + " already exists. Please specify a unique name");
}
final GuestOSVO guestOsVo = new GuestOSVO();
guestOsVo.setCategoryId(categoryId.longValue());
guestOsVo.setDisplayName(displayName);
guestOsVo.setName(name);
guestOsVo.setIsUserDefined(true);
return _guestOSDao.persist(guestOsVo);
}
use of com.cloud.storage.GuestOSVO in project cosmic by MissionCriticalCloud.
the class ManagementServerImpl method updateGuestOs.
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_UPDATE, eventDescription = "updating guest OS type", async = true)
public GuestOS updateGuestOs(final UpdateGuestOsCmd cmd) {
final Long id = cmd.getId();
final String displayName = cmd.getOsDisplayName();
// check if guest OS exists
final GuestOS guestOsHandle = ApiDBUtils.findGuestOSById(id);
if (guestOsHandle == null) {
throw new InvalidParameterValueException("Guest OS not found. Please specify a valid ID for the Guest OS");
}
if (!guestOsHandle.getIsUserDefined()) {
throw new InvalidParameterValueException("Unable to modify system defined guest OS");
}
// Check if update is needed
if (displayName.equals(guestOsHandle.getDisplayName())) {
return guestOsHandle;
}
// Check if another Guest OS by same name exists
final GuestOS duplicate = ApiDBUtils.findGuestOSByDisplayName(displayName);
if (duplicate != null) {
throw new InvalidParameterValueException("The specified Guest OS name : " + displayName + " already exists. Please specify a unique guest OS name");
}
final GuestOSVO guestOs = _guestOSDao.createForUpdate(id);
guestOs.setDisplayName(displayName);
if (_guestOSDao.update(id, guestOs)) {
return _guestOSDao.findById(id);
} else {
return null;
}
}
use of com.cloud.storage.GuestOSVO in project cloudstack by apache.
the class VMwareGuru method implement.
@Override
public VirtualMachineTO implement(VirtualMachineProfile vm) {
VirtualMachineTO to = toVirtualMachineTO(vm);
to.setBootloader(BootloaderType.HVM);
Map<String, String> details = to.getDetails();
if (details == null)
details = new HashMap<String, String>();
Type vmType = vm.getType();
boolean userVm = !(vmType.equals(VirtualMachine.Type.DomainRouter) || vmType.equals(VirtualMachine.Type.ConsoleProxy) || vmType.equals(VirtualMachine.Type.SecondaryStorageVm));
String nicDeviceType = details.get(VmDetailConstants.NIC_ADAPTER);
if (!userVm) {
if (nicDeviceType == null) {
details.put(VmDetailConstants.NIC_ADAPTER, _vmwareMgr.getSystemVMDefaultNicAdapterType());
} else {
try {
VirtualEthernetCardType.valueOf(nicDeviceType);
} catch (Exception e) {
s_logger.warn("Invalid NIC device type " + nicDeviceType + " is specified in VM details, switch to default E1000");
details.put(VmDetailConstants.NIC_ADAPTER, VirtualEthernetCardType.E1000.toString());
}
}
} else {
// for user-VM, use E1000 as default
if (nicDeviceType == null) {
details.put(VmDetailConstants.NIC_ADAPTER, VirtualEthernetCardType.E1000.toString());
} else {
try {
VirtualEthernetCardType.valueOf(nicDeviceType);
} catch (Exception e) {
s_logger.warn("Invalid NIC device type " + nicDeviceType + " is specified in VM details, switch to default E1000");
details.put(VmDetailConstants.NIC_ADAPTER, VirtualEthernetCardType.E1000.toString());
}
}
}
String diskDeviceType = details.get(VmDetailConstants.ROOT_DISK_CONTROLLER);
if (userVm) {
if (diskDeviceType == null) {
details.put(VmDetailConstants.ROOT_DISK_CONTROLLER, _vmwareMgr.getRootDiskController());
}
}
String diskController = details.get(VmDetailConstants.DATA_DISK_CONTROLLER);
if (userVm) {
if (diskController == null) {
details.put(VmDetailConstants.DATA_DISK_CONTROLLER, DiskControllerType.lsilogic.toString());
}
}
List<NicProfile> nicProfiles = vm.getNics();
for (NicProfile nicProfile : nicProfiles) {
if (nicProfile.getTrafficType() == TrafficType.Guest) {
if (_networkMgr.isProviderSupportServiceInNetwork(nicProfile.getNetworkId(), Service.Firewall, Provider.CiscoVnmc)) {
details.put("ConfigureVServiceInNexus", Boolean.TRUE.toString());
}
break;
}
}
long clusterId = getClusterId(vm.getId());
details.put(VmwareReserveCpu.key(), VmwareReserveCpu.valueIn(clusterId).toString());
details.put(VmwareReserveMemory.key(), VmwareReserveMemory.valueIn(clusterId).toString());
to.setDetails(details);
if (vmType.equals(VirtualMachine.Type.DomainRouter)) {
NicProfile publicNicProfile = null;
for (NicProfile nicProfile : nicProfiles) {
if (nicProfile.getTrafficType() == TrafficType.Public) {
publicNicProfile = nicProfile;
break;
}
}
if (publicNicProfile != null) {
NicTO[] nics = to.getNics();
// reserve extra NICs
NicTO[] expandedNics = new NicTO[nics.length + _vmwareMgr.getRouterExtraPublicNics()];
int i = 0;
int deviceId = -1;
for (i = 0; i < nics.length; i++) {
expandedNics[i] = nics[i];
if (nics[i].getDeviceId() > deviceId)
deviceId = nics[i].getDeviceId();
}
deviceId++;
long networkId = publicNicProfile.getNetworkId();
NetworkVO network = _networkDao.findById(networkId);
for (; i < nics.length + _vmwareMgr.getRouterExtraPublicNics(); i++) {
NicTO nicTo = new NicTO();
nicTo.setDeviceId(deviceId++);
nicTo.setBroadcastType(publicNicProfile.getBroadcastType());
nicTo.setType(publicNicProfile.getTrafficType());
nicTo.setIp("0.0.0.0");
nicTo.setNetmask("255.255.255.255");
try {
String mac = _networkMgr.getNextAvailableMacAddressInNetwork(networkId);
nicTo.setMac(mac);
} catch (InsufficientAddressCapacityException e) {
throw new CloudRuntimeException("unable to allocate mac address on network: " + networkId);
}
nicTo.setDns1(publicNicProfile.getIPv4Dns1());
nicTo.setDns2(publicNicProfile.getIPv4Dns2());
if (publicNicProfile.getIPv4Gateway() != null) {
nicTo.setGateway(publicNicProfile.getIPv4Gateway());
} else {
nicTo.setGateway(network.getGateway());
}
nicTo.setDefaultNic(false);
nicTo.setBroadcastUri(publicNicProfile.getBroadCastUri());
nicTo.setIsolationuri(publicNicProfile.getIsolationUri());
Integer networkRate = _networkMgr.getNetworkRate(network.getId(), null);
nicTo.setNetworkRateMbps(networkRate);
expandedNics[i] = nicTo;
}
to.setNics(expandedNics);
}
StringBuffer sbMacSequence = new StringBuffer();
for (NicTO nicTo : sortNicsByDeviceId(to.getNics())) {
sbMacSequence.append(nicTo.getMac()).append("|");
}
if (!sbMacSequence.toString().isEmpty()) {
sbMacSequence.deleteCharAt(sbMacSequence.length() - 1);
String bootArgs = to.getBootArgs();
to.setBootArgs(bootArgs + " nic_macs=" + sbMacSequence.toString());
}
}
// Should only be done on user machines
if (userVm) {
configureNestedVirtualization(details, to);
}
// Determine the VM's OS description
GuestOSVO guestOS = _guestOsDao.findByIdIncludingRemoved(vm.getVirtualMachine().getGuestOSId());
to.setOs(guestOS.getDisplayName());
to.setHostName(vm.getHostName());
HostVO host = _hostDao.findById(vm.getVirtualMachine().getHostId());
GuestOSHypervisorVO guestOsMapping = null;
if (host != null) {
guestOsMapping = _guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), getHypervisorType().toString(), host.getHypervisorVersion());
}
if (guestOsMapping == null || host == null) {
to.setPlatformEmulator(null);
} else {
to.setPlatformEmulator(guestOsMapping.getGuestOsName());
}
return to;
}
Aggregations