NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
if (networkDevice == null) {
throw new CloudRuntimeException("No network device found for name " + 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");
}
final Map<String, String> hostParams = new HashMap<String, String>();
hostParams.put("guid", UUID.randomUUID().toString());
hostParams.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId()));
hostParams.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
hostParams.put("name", "ODL Controller - " + hostParams.get("guid"));
hostParams.put("url", cmd.getUrl());
hostParams.put("username", cmd.getUsername());
hostParams.put("password", cmd.getPassword());