Search in sources :

Example 26 with PhysicalNetworkServiceProviderVO

use of com.cloud.network.dao.PhysicalNetworkServiceProviderVO in project cloudstack by apache.

the class NetworkServiceImpl method deleteNetworkServiceProvider.

@Override
@ActionEvent(eventType = EventTypes.EVENT_SERVICE_PROVIDER_DELETE, eventDescription = "Deleting physical network ServiceProvider", async = true)
public boolean deleteNetworkServiceProvider(Long id) throws ConcurrentOperationException, ResourceUnavailableException {
    PhysicalNetworkServiceProviderVO provider = _pNSPDao.findById(id);
    if (provider == null) {
        throw new InvalidParameterValueException("Network Service Provider id=" + id + "doesn't exist in the system");
    }
    // check if there are networks using this provider
    List<NetworkVO> networks = _networksDao.listByPhysicalNetworkAndProvider(provider.getPhysicalNetworkId(), provider.getProviderName());
    if (networks != null && !networks.isEmpty()) {
        throw new CloudRuntimeException("Provider is not deletable because there are active networks using this provider, please upgrade these networks to new network offerings");
    }
    User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
    Account callerAccount = _accountMgr.getActiveAccountById(callerUser.getAccountId());
    // shutdown the provider instances
    ReservationContext context = new ReservationContextImpl(null, null, callerUser, callerAccount);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Shutting down the service provider id=" + id + " on physical network: " + provider.getPhysicalNetworkId());
    }
    NetworkElement element = _networkModel.getElementImplementingProvider(provider.getProviderName());
    if (element == null) {
        throw new InvalidParameterValueException("Unable to find the Network Element implementing the Service Provider '" + provider.getProviderName() + "'");
    }
    if (element != null && element.shutdownProviderInstances(provider, context)) {
        provider.setState(PhysicalNetworkServiceProvider.State.Shutdown);
    }
    return _pNSPDao.remove(id);
}
Also used : Account(com.cloud.user.Account) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) User(com.cloud.user.User) NetworkElement(com.cloud.network.element.NetworkElement) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ReservationContext(com.cloud.vm.ReservationContext) ActionEvent(com.cloud.event.ActionEvent)

Example 27 with PhysicalNetworkServiceProviderVO

use of com.cloud.network.dao.PhysicalNetworkServiceProviderVO in project cloudstack by apache.

the class NetworkServiceImpl method enableBaremetalProvider.

private void enableBaremetalProvider(String providerName) {
    QueryBuilder<PhysicalNetworkServiceProviderVO> q = QueryBuilder.create(PhysicalNetworkServiceProviderVO.class);
    q.and(q.entity().getProviderName(), SearchCriteria.Op.EQ, providerName);
    PhysicalNetworkServiceProviderVO provider = q.find();
    provider.setState(PhysicalNetworkServiceProvider.State.Enabled);
    _pNSPDao.update(provider.getId(), provider);
}
Also used : PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO)

Example 28 with PhysicalNetworkServiceProviderVO

use of com.cloud.network.dao.PhysicalNetworkServiceProviderVO in project cloudstack by apache.

the class NetworkServiceImpl method listNetworkServiceProviders.

@Override
public Pair<List<? extends PhysicalNetworkServiceProvider>, Integer> listNetworkServiceProviders(Long physicalNetworkId, String name, String state, Long startIndex, Long pageSize) {
    Filter searchFilter = new Filter(PhysicalNetworkServiceProviderVO.class, "id", false, startIndex, pageSize);
    SearchBuilder<PhysicalNetworkServiceProviderVO> sb = _pNSPDao.createSearchBuilder();
    SearchCriteria<PhysicalNetworkServiceProviderVO> sc = sb.create();
    if (physicalNetworkId != null) {
        sc.addAnd("physicalNetworkId", Op.EQ, physicalNetworkId);
    }
    if (name != null) {
        sc.addAnd("providerName", Op.EQ, name);
    }
    if (state != null) {
        sc.addAnd("state", Op.EQ, state);
    }
    Pair<List<PhysicalNetworkServiceProviderVO>, Integer> result = _pNSPDao.searchAndCount(sc, searchFilter);
    return new Pair<List<? extends PhysicalNetworkServiceProvider>, Integer>(result.first(), result.second());
}
Also used : Filter(com.cloud.utils.db.Filter) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair)

Example 29 with PhysicalNetworkServiceProviderVO

use of com.cloud.network.dao.PhysicalNetworkServiceProviderVO in project cloudstack by apache.

the class BareMetalPingServiceImpl method addPxeServer.

@Override
@DB
public BaremetalPxeVO addPxeServer(AddBaremetalPxeCmd cmd) {
    AddBaremetalPxePingServerCmd pcmd = (AddBaremetalPxePingServerCmd) cmd;
    PhysicalNetworkVO pNetwork = null;
    long zoneId;
    if (cmd.getPhysicalNetworkId() == null || cmd.getUrl() == null || cmd.getUsername() == null || cmd.getPassword() == null) {
        throw new IllegalArgumentException("At least one of the required parameters(physical network id, url, username, password) is null");
    }
    pNetwork = _physicalNetworkDao.findById(cmd.getPhysicalNetworkId());
    if (pNetwork == null) {
        throw new IllegalArgumentException("Could not find phyical network with ID: " + cmd.getPhysicalNetworkId());
    }
    zoneId = pNetwork.getDataCenterId();
    PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(pNetwork.getId(), BaremetalPxeManager.BAREMETAL_PXE_SERVICE_PROVIDER.getName());
    if (ntwkSvcProvider == null) {
        throw new CloudRuntimeException("Network Service Provider: " + BaremetalPxeManager.BAREMETAL_PXE_SERVICE_PROVIDER.getName() + " is not enabled in the physical network: " + cmd.getPhysicalNetworkId() + "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: " + cmd.getPhysicalNetworkId() + "to add this device");
    }
    HostPodVO pod = _podDao.findById(cmd.getPodId());
    if (pod == null) {
        throw new IllegalArgumentException("Could not find pod with ID: " + cmd.getPodId());
    }
    List<HostVO> pxes = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.BaremetalPxe, null, cmd.getPodId(), zoneId);
    if (pxes.size() != 0) {
        throw new IllegalArgumentException("Already had a PXE server in Pod: " + cmd.getPodId() + " zone: " + zoneId);
    }
    String storageServerIp = pcmd.getPingStorageServerIp();
    if (storageServerIp == null) {
        throw new IllegalArgumentException("No IP for storage server specified");
    }
    String pingDir = pcmd.getPingDir();
    if (pingDir == null) {
        throw new IllegalArgumentException("No direcotry for storage server specified");
    }
    String tftpDir = pcmd.getTftpDir();
    if (tftpDir == null) {
        throw new IllegalArgumentException("No TFTP directory specified");
    }
    String cifsUsername = pcmd.getPingStorageServerUserName();
    if (cifsUsername == null || cifsUsername.equalsIgnoreCase("")) {
        cifsUsername = "xxx";
    }
    String cifsPassword = pcmd.getPingStorageServerPassword();
    if (cifsPassword == null || cifsPassword.equalsIgnoreCase("")) {
        cifsPassword = "xxx";
    }
    URI uri;
    try {
        uri = new URI(cmd.getUrl());
    } catch (Exception e) {
        s_logger.debug(e);
        throw new IllegalArgumentException(e.getMessage());
    }
    String ipAddress = uri.getHost();
    String guid = getPxeServerGuid(Long.toString(zoneId) + "-" + pod.getId(), BaremetalPxeType.PING.toString(), ipAddress);
    ServerResource resource = null;
    Map params = new HashMap<String, String>();
    params.put(BaremetalPxeService.PXE_PARAM_ZONE, Long.toString(zoneId));
    params.put(BaremetalPxeService.PXE_PARAM_POD, String.valueOf(pod.getId()));
    params.put(BaremetalPxeService.PXE_PARAM_IP, ipAddress);
    params.put(BaremetalPxeService.PXE_PARAM_USERNAME, cmd.getUsername());
    params.put(BaremetalPxeService.PXE_PARAM_PASSWORD, cmd.getPassword());
    params.put(BaremetalPxeService.PXE_PARAM_PING_STORAGE_SERVER_IP, storageServerIp);
    params.put(BaremetalPxeService.PXE_PARAM_PING_ROOT_DIR, pingDir);
    params.put(BaremetalPxeService.PXE_PARAM_TFTP_DIR, tftpDir);
    params.put(BaremetalPxeService.PXE_PARAM_PING_STORAGE_SERVER_USERNAME, cifsUsername);
    params.put(BaremetalPxeService.PXE_PARAM_PING_STORAGE_SERVER_PASSWORD, cifsPassword);
    params.put(BaremetalPxeService.PXE_PARAM_GUID, guid);
    resource = new BaremetalPingPxeResource();
    try {
        resource.configure("PING PXE resource", params);
    } catch (Exception e) {
        s_logger.debug(e);
        throw new CloudRuntimeException(e.getMessage());
    }
    Host pxeServer = _resourceMgr.addHost(zoneId, resource, Host.Type.BaremetalPxe, params);
    if (pxeServer == null) {
        throw new CloudRuntimeException("Cannot add PXE server as a host");
    }
    BaremetalPxeVO vo = new BaremetalPxeVO();
    vo.setHostId(pxeServer.getId());
    vo.setNetworkServiceProviderId(ntwkSvcProvider.getId());
    vo.setPodId(pod.getId());
    vo.setPhysicalNetworkId(pcmd.getPhysicalNetworkId());
    vo.setDeviceType(BaremetalPxeType.PING.toString());
    _pxeDao.persist(vo);
    return vo;
}
Also used : HashMap(java.util.HashMap) ServerResource(com.cloud.resource.ServerResource) Host(com.cloud.host.Host) HostPodVO(com.cloud.dc.HostPodVO) URI(java.net.URI) HostVO(com.cloud.host.HostVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) AddBaremetalPxePingServerCmd(org.apache.cloudstack.api.AddBaremetalPxePingServerCmd) HashMap(java.util.HashMap) Map(java.util.Map) BaremetalPxeVO(com.cloud.baremetal.database.BaremetalPxeVO) DB(com.cloud.utils.db.DB)

Example 30 with PhysicalNetworkServiceProviderVO

use of com.cloud.network.dao.PhysicalNetworkServiceProviderVO in project cloudstack by apache.

the class OpenDaylightControllerResourceManagerImpl method addController.

@Override
public OpenDaylightControllerVO addController(AddOpenDaylightControllerCmd cmd) {
    ServerResource odlController = new OpenDaylightControllerResource();
    final String deviceName = NetworkDevice.OpenDaylightController.getName();
    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());
    Map<String, Object> hostdetails = new HashMap<String, Object>();
    hostdetails.putAll(hostParams);
    try {
        odlController.configure(hostParams.get("name"), hostdetails);
        final Host host = resourceManager.addHost(zoneId, odlController, Host.Type.L2Networking, hostParams);
        if (host != null) {
            return Transaction.execute(new TransactionCallback<OpenDaylightControllerVO>() {

                @Override
                public OpenDaylightControllerVO doInTransaction(TransactionStatus status) {
                    OpenDaylightControllerVO controller = new OpenDaylightControllerVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), hostParams.get("name"));
                    openDaylightControllerMappingDao.persist(controller);
                    return controller;
                }
            });
        } else {
            throw new CloudRuntimeException("Failed to create host object for ODL Controller");
        }
    } catch (ConfigurationException e) {
        throw new CloudRuntimeException("Failed to add ODL Controller as a resource", e);
    }
}
Also used : HashMap(java.util.HashMap) NetworkDevice(org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice) ServerResource(com.cloud.resource.ServerResource) TransactionStatus(com.cloud.utils.db.TransactionStatus) Host(com.cloud.host.Host) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) OpenDaylightControllerVO(org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO)

Aggregations

PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)33 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)19 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)15 Host (com.cloud.host.Host)13 ConfigurationException (javax.naming.ConfigurationException)11 DB (com.cloud.utils.db.DB)10 HashMap (java.util.HashMap)10 TransactionStatus (com.cloud.utils.db.TransactionStatus)9 NetworkDevice (org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice)9 HostVO (com.cloud.host.HostVO)8 ServerResource (com.cloud.resource.ServerResource)8 ArrayList (java.util.ArrayList)8 DetailVO (com.cloud.host.DetailVO)7 Test (org.junit.Test)6 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)5 URI (java.net.URI)5 Map (java.util.Map)5 ActionEvent (com.cloud.event.ActionEvent)4 DataCenterVO (com.cloud.dc.DataCenterVO)3