use of com.cloud.host.DetailVO in project cloudstack by apache.
the class NuageVspManagerImpl method addNuageVspDevice.
@Override
public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd) {
final NuageVspResource resource = new NuageVspResource();
final String deviceName = Network.Provider.NuageVsp.getName();
ExternalNetworkDeviceManager.NetworkDevice networkDevice = ExternalNetworkDeviceManager.NetworkDevice.getNetworkDevice(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 (_nuageVspDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
throw new CloudRuntimeException("A NuageVsp device is already configured on this physical network");
}
// While the default VSD port is 8443, clustering via HAProxy will go over port 443 (CLOUD-58)
int port = cmd.getPort() > 0 ? cmd.getPort() : 443;
try {
String apiVersion = null;
String cmsUserPasswordBase64 = NuageVspUtil.encodePassword(cmd.getPassword());
NuageVspResourceConfiguration resourceConfiguration = new NuageVspResourceConfiguration().guid(UUID.randomUUID().toString()).zoneId(String.valueOf(physicalNetwork.getDataCenterId())).hostName(cmd.getHostName()).cmsUser(cmd.getUserName()).cmsUserPassword(cmsUserPasswordBase64).port(String.valueOf(port)).apiVersion(NuageVspApiVersion.CURRENT.toString()).retryCount(NuageVspConstants.DEFAULT_API_RETRY_COUNT.toString()).retryInterval(NuageVspConstants.DEFAULT_API_RETRY_INTERVAL.toString()).apiRelativePath("/nuage");
VspHost vspHost = resourceConfiguration.buildVspHost();
NuageVspPluginClientLoader clientLoader = NuageVspPluginClientLoader.getClientLoader(vspHost);
VspApiDefaults apiDefaults = clientLoader.getNuageVspManagerClient().getApiDefaults();
if (StringUtils.isNotBlank(cmd.getApiVersion())) {
if (!clientLoader.getNuageVspManagerClient().isSupportedApiVersion(cmd.getApiVersion())) {
throw new CloudRuntimeException("Unsupported API version : " + cmd.getApiVersion());
}
apiVersion = cmd.getApiVersion();
} else {
boolean apiVersionFound = false;
Map<NuageVspApiVersion, NuageVspApiVersion.Status> supportedVersions = clientLoader.getNuageVspManagerClient().getSupportedVersions();
for (NuageVspApiVersion selectedVersion : supportedVersions.keySet()) {
if (supportedVersions.get(selectedVersion) == NuageVspApiVersion.Status.CURRENT) {
apiVersion = selectedVersion.toString();
apiVersionFound = true;
break;
}
}
if (!apiVersionFound) {
throw new CloudRuntimeException("No supported API version found!");
}
}
String retryCount = String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryCount(), apiDefaults.getRetryCount()));
String retryInterval = String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryInterval(), apiDefaults.getRetryInterval()));
resourceConfiguration.apiVersion(apiVersion).apiRelativePath("/nuage/api/" + apiVersion).retryCount(retryCount).retryInterval(retryInterval);
Map<String, String> hostDetails = resourceConfiguration.build();
resource.configure("Nuage VSD - " + cmd.getHostName(), Maps.<String, Object>newHashMap(hostDetails));
Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, hostDetails);
if (host == null) {
throw new CloudRuntimeException("Failed to add Nuage Vsp Device due to internal error.");
}
NuageVspDeviceVO nuageVspDevice = new NuageVspDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
_nuageVspDao.persist(nuageVspDevice);
DetailVO detail = new DetailVO(host.getId(), "nuagevspdeviceid", String.valueOf(nuageVspDevice.getId()));
_hostDetailsDao.persist(detail);
NuageVspDeviceVO matchingNuageVspDevice = findMatchingNuageVspDevice(nuageVspDevice);
String cmsId;
if (matchingNuageVspDevice != null) {
cmsId = findNuageVspCmsIdForDeviceOrHost(matchingNuageVspDevice.getId(), matchingNuageVspDevice.getHostId());
} else {
SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(SyncType.REGISTER, null);
SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
if (answer != null && answer.getSuccess()) {
cmsId = answer.getNuageVspCmsId();
} else {
throw new CloudRuntimeException("Failed to register CMS ID");
}
}
host = findNuageVspHost(nuageVspDevice.getHostId());
registerNewNuageVspDevice(host.getId(), cmsId);
resourceConfiguration.nuageVspCmsId(cmsId);
resource.configure(cmd.getHostName(), Maps.<String, Object>newHashMap(resourceConfiguration.build()));
if (matchingNuageVspDevice == null) {
auditDomainsOnVsp((HostVO) host, true);
}
return nuageVspDevice;
} catch (ConfigurationException e) {
s_logger.error("Failed to configure Nuage VSD resource " + cmd.getHostName(), e);
throw new CloudRuntimeException("Failed to configure Nuage VSD resource " + cmd.getHostName(), e);
} catch (ExecutionException ee) {
s_logger.error("Failed to add Nuage VSP device " + cmd.getHostName(), ee);
throw new CloudRuntimeException("Failed to add Nuage VSP device " + cmd.getHostName(), ee);
}
}
use of com.cloud.host.DetailVO in project cloudstack by apache.
the class NuageVspManagerImpl method registerNewNuageVspDevice.
private void registerNewNuageVspDevice(long hostId, String cmsId) {
DetailVO detail = new DetailVO(hostId, "nuagevspcmsid", cmsId);
_hostDetailsDao.persist(detail);
}
use of com.cloud.host.DetailVO in project cloudstack by apache.
the class HostDetailsDaoImpl method findDetail.
@Override
public DetailVO findDetail(long hostId, String name) {
SearchCriteria<DetailVO> sc = DetailSearch.create();
sc.setParameters("hostId", hostId);
sc.setParameters("name", name);
DetailVO detail = findOneIncludingRemovedBy(sc);
if ("password".equals(name) && detail != null) {
detail.setValue(DBEncryptionUtil.decrypt(detail.getValue()));
}
return detail;
}
use of com.cloud.host.DetailVO 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.DetailVO 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());
}
}
Aggregations