Search in sources :

Example 1 with ServerResource

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());
    }
}
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) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO) BrocadeVcsResource(com.cloud.network.resource.BrocadeVcsResource) InvalidParameterValueException(com.cloud.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)

Example 2 with ServerResource

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;
}
Also used : HashMap(java.util.HashMap) NetScalerControlCenterVO(com.cloud.network.NetScalerControlCenterVO) ServerResource(com.cloud.resource.ServerResource) Host(com.cloud.host.Host) Map(java.util.Map) HashMap(java.util.HashMap) NetScalerControlCenterResource(com.cloud.network.resource.NetScalerControlCenterResource) HostVO(com.cloud.host.HostVO)

Example 3 with ServerResource

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());
    }
}
Also used : HashMap(java.util.HashMap) NetworkDevice(org.apache.cloudstack.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.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)

Example 4 with ServerResource

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());
    }
}
Also used : RegisterNetscalerControlCenterCmd(com.cloud.api.commands.RegisterNetscalerControlCenterCmd) DataCenterVO(com.cloud.dc.DataCenterVO) HashMap(java.util.HashMap) NetScalerControlCenterVO(com.cloud.network.NetScalerControlCenterVO) ServerResource(com.cloud.resource.ServerResource) TransactionStatus(com.cloud.utils.db.TransactionStatus) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Map(java.util.Map) HashMap(java.util.HashMap) NetScalerControlCenterResource(com.cloud.network.resource.NetScalerControlCenterResource) DB(com.cloud.utils.db.DB)

Example 5 with ServerResource

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;
}
Also used : ConfigurationException(javax.naming.ConfigurationException) ServerResource(com.cloud.resource.ServerResource)

Aggregations

ServerResource (com.cloud.resource.ServerResource)23 ConfigurationException (javax.naming.ConfigurationException)17 HashMap (java.util.HashMap)15 Host (com.cloud.host.Host)12 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)9 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)9 DB (com.cloud.utils.db.DB)8 TransactionStatus (com.cloud.utils.db.TransactionStatus)7 Map (java.util.Map)7 HostVO (com.cloud.host.HostVO)6 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)5 DetailVO (com.cloud.host.DetailVO)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 NetworkDevice (org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice)5 URI (java.net.URI)4 ClusterVO (com.cloud.dc.ClusterVO)3 DataCenterVO (com.cloud.dc.DataCenterVO)3 BaremetalPxeVO (com.cloud.baremetal.database.BaremetalPxeVO)2 NetScalerControlCenterVO (com.cloud.network.NetScalerControlCenterVO)2