Search in sources :

Example 1 with NetworkDevice

use of com.cloud.network.ExternalNetworkDeviceManager.NetworkDevice 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());
    }
}
Also used : HashMap(java.util.HashMap) NetworkDevice(com.cloud.network.ExternalNetworkDeviceManager.NetworkDevice) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ServerResource(com.cloud.resource.ServerResource) NiciraNvpResource(com.cloud.network.resource.NiciraNvpResource) TransactionStatus(com.cloud.utils.db.TransactionStatus) Host(com.cloud.host.Host) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) DetailVO(com.cloud.host.DetailVO) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DB(com.cloud.utils.db.DB)

Aggregations

DetailVO (com.cloud.host.DetailVO)1 Host (com.cloud.host.Host)1 NetworkDevice (com.cloud.network.ExternalNetworkDeviceManager.NetworkDevice)1 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)1 PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)1 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)1 NiciraNvpResource (com.cloud.network.resource.NiciraNvpResource)1 ServerResource (com.cloud.resource.ServerResource)1 DB (com.cloud.utils.db.DB)1 TransactionStatus (com.cloud.utils.db.TransactionStatus)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)1 HashMap (java.util.HashMap)1 ConfigurationException (javax.naming.ConfigurationException)1