use of com.cloud.host.DetailVO in project cosmic by MissionCriticalCloud.
the class NiciraNvpElement method addNiciraNvpDevice.
@Override
@DB
public NiciraNvpDeviceVO addNiciraNvpDevice(final AddNiciraNvpDeviceCmd cmd) {
final ServerResource resource = new NiciraNvpResource();
final String deviceName = Network.Provider.NiciraNvp.getName();
final NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
if (networkDevice == null) {
throw new CloudRuntimeException("No network device found for " + deviceName);
}
final Long physicalNetworkId = cmd.getPhysicalNetworkId();
final PhysicalNetworkVO physicalNetwork = physicalNetworkDao.findById(physicalNetworkId);
if (physicalNetwork == null) {
throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
}
final 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");
}
final Map<String, String> params = new HashMap<>();
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());
}
final Map<String, Object> hostdetails = new HashMap<>();
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(final TransactionStatus status) {
final NiciraNvpDeviceVO niciraNvpDevice = new NiciraNvpDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
niciraNvpDao.persist(niciraNvpDevice);
final 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 (final ConfigurationException e) {
throw new CloudRuntimeException(e.getMessage());
}
}
use of com.cloud.host.DetailVO in project cosmic by MissionCriticalCloud.
the class FirstFitAllocator method getHostGuestOSCategory.
protected String getHostGuestOSCategory(final Host host) {
final DetailVO hostDetail = _hostDetailsDao.findDetail(host.getId(), "guest.os.category.id");
if (hostDetail != null) {
final String guestOSCategoryIdString = hostDetail.getValue();
final long guestOSCategoryId;
try {
guestOSCategoryId = Long.parseLong(guestOSCategoryIdString);
} catch (final Exception e) {
return null;
}
final GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId);
if (guestOSCategory != null) {
return guestOSCategory.getName();
} else {
return null;
}
} else {
return null;
}
}
use of com.cloud.host.DetailVO in project cosmic by MissionCriticalCloud.
the class ResourceManagerImpl method getGuestOSCategoryId.
@Override
public Long getGuestOSCategoryId(final long hostId) {
final HostVO host = _hostDao.findById(hostId);
if (host == null) {
return null;
} else {
_hostDao.loadDetails(host);
final DetailVO detail = _hostDetailsDao.findDetail(hostId, "guest.os.category.id");
if (detail == null) {
return null;
} else {
return Long.parseLong(detail.getValue());
}
}
}
use of com.cloud.host.DetailVO in project cosmic by MissionCriticalCloud.
the class ResourceManagerImpl method updateHost.
@Override
public Host updateHost(final UpdateHostCmd cmd) throws NoTransitionException {
final Long hostId = cmd.getId();
final Long guestOSCategoryId = cmd.getOsCategoryId();
// Verify that the host exists
final HostVO host = _hostDao.findById(hostId);
if (host == null) {
throw new InvalidParameterValueException("Host with id " + hostId + " doesn't exist");
}
if (cmd.getAllocationState() != null) {
final ResourceState.Event resourceEvent = ResourceState.Event.toEvent(cmd.getAllocationState());
if (resourceEvent != ResourceState.Event.Enable && resourceEvent != ResourceState.Event.Disable) {
throw new CloudRuntimeException("Invalid allocation state:" + cmd.getAllocationState() + ", only Enable/Disable are allowed");
}
resourceStateTransitTo(host, resourceEvent, _nodeId);
}
if (guestOSCategoryId != null) {
// Verify that the guest OS Category exists
if (!(guestOSCategoryId > 0) || _guestOSCategoryDao.findById(guestOSCategoryId) == null) {
throw new InvalidParameterValueException("Please specify a valid guest OS category.");
}
final GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId);
final DetailVO guestOSDetail = _hostDetailsDao.findDetail(hostId, "guest.os.category.id");
if (guestOSCategory != null && !GuestOSCategoryVO.CATEGORY_NONE.equalsIgnoreCase(guestOSCategory.getName())) {
// Create/Update an entry for guest.os.category.id
if (guestOSDetail != null) {
guestOSDetail.setValue(String.valueOf(guestOSCategory.getId()));
_hostDetailsDao.update(guestOSDetail.getId(), guestOSDetail);
} else {
final Map<String, String> detail = new HashMap<>();
detail.put("guest.os.category.id", String.valueOf(guestOSCategory.getId()));
_hostDetailsDao.persist(hostId, detail);
}
} else {
// Delete any existing entry for guest.os.category.id
if (guestOSDetail != null) {
_hostDetailsDao.remove(guestOSDetail.getId());
}
}
}
final List<String> hostTags = cmd.getHostTags();
if (hostTags != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Updating Host Tags to :" + hostTags);
}
_hostTagsDao.persist(hostId, hostTags);
}
final String url = cmd.getUrl();
if (url != null) {
_storageMgr.updateSecondaryStorage(cmd.getId(), cmd.getUrl());
}
final HostVO updatedHost = _hostDao.findById(hostId);
return updatedHost;
}
use of com.cloud.host.DetailVO in project cloudstack by apache.
the class CloudZonesStartupProcessor method updateHostDetails.
private void updateHostDetails(HostVO host, StartupRoutingCommand startupRoutingCmd) {
final String name = "supportsResign";
final String value = String.valueOf(startupRoutingCmd.getSupportsClonedVolumes());
DetailVO hostDetail = hostDetailsDao.findDetail(host.getId(), name);
if (hostDetail != null) {
hostDetail.setValue(value);
hostDetailsDao.update(hostDetail.getId(), hostDetail);
} else {
hostDetail = new DetailVO(host.getId(), name, value);
hostDetailsDao.persist(hostDetail);
}
}
Aggregations