use of com.cloud.resource.ServerResource 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.resource.ServerResource 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.resource.ServerResource 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.resource.ServerResource in project cloudstack by apache.
the class NetscalerElement method registerNetscalerControlCenter.
@Override
@DB
public NetScalerControlCenterVO registerNetscalerControlCenter(RegisterNetscalerControlCenterCmd cmd) {
if (_netscalerControlCenterDao.listAll() != null && _netscalerControlCenterDao.listAll().size() != 0) {
throw new CloudRuntimeException("One Netscaler Control Center already exist in the DataBase. At a time only one Netscaler Control Center is allowed");
}
final RegisterNetscalerControlCenterCmd cmdinfo = cmd;
String ipAddress = cmd.getIpaddress();
Map hostDetails = new HashMap<String, String>();
String hostName = "NetscalerControlCenter";
hostDetails.put("name", hostName);
hostDetails.put("guid", UUID.randomUUID().toString());
List<DataCenterVO> dcVO = _dcDao.listEnabledZones();
if (dcVO.size() == 0) {
throw new CloudRuntimeException("There is no single enabled zone. Please add a zone, enable it and then add Netscaler ControlCenter");
}
hostDetails.put("zoneId", "1");
hostDetails.put("ip", ipAddress);
hostDetails.put("username", cmd.getUsername());
hostDetails.put("password", cmd.getPassword());
hostDetails.put("deviceName", "Netscaler ControlCenter");
ServerResource resource = new NetScalerControlCenterResource();
try {
resource.configure(hostName, hostDetails);
return Transaction.execute(new TransactionCallback<NetScalerControlCenterVO>() {
@Override
public NetScalerControlCenterVO doInTransaction(TransactionStatus status) {
NetScalerControlCenterVO nccVO = new NetScalerControlCenterVO(cmdinfo.getUsername(), DBEncryptionUtil.encrypt(cmdinfo.getPassword()), cmdinfo.getIpaddress(), cmdinfo.getNumretries());
_netscalerControlCenterDao.persist(nccVO);
return nccVO;
}
});
} catch (ConfigurationException e) {
resource = null;
throw new CloudRuntimeException(e.getMessage());
}
}
use of com.cloud.resource.ServerResource in project cloudstack by apache.
the class VmwareServerDiscoverer method reloadResource.
@Override
public ServerResource reloadResource(HostVO host) {
String resourceName = host.getResource();
ServerResource resource = getResource(resourceName);
if (resource != null) {
_hostDao.loadDetails(host);
HashMap<String, Object> params = buildConfigParams(host);
try {
resource.configure(host.getName(), params);
} catch (ConfigurationException e) {
s_logger.warn("Unable to configure resource due to " + e.getMessage());
return null;
}
if (!resource.start()) {
s_logger.warn("Unable to start the resource");
return null;
}
}
return resource;
}
Aggregations