Search in sources :

Example 21 with DetailVO

use of com.cloud.host.DetailVO in project cosmic by MissionCriticalCloud.

the class ManagementServerImpl method updateHostPassword.

@Override
@DB
public boolean updateHostPassword(final UpdateHostPasswordCmd cmd) {
    if (cmd.getHostId() == null) {
        throw new InvalidParameterValueException("You should provide an host id.");
    }
    final HostVO host = _hostDao.findById(cmd.getHostId());
    if (host.getHypervisorType() == HypervisorType.XenServer) {
        throw new InvalidParameterValueException("Single host update is not supported by XenServer hypervisors. Please try again informing the Cluster ID.");
    }
    if (!supportedHypervisors.contains(host.getHypervisorType())) {
        throw new InvalidParameterValueException("This operation is not supported for this hypervisor type");
    }
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Changing password for host name = " + host.getName());
            }
            // update password for this host
            final DetailVO nv = _detailsDao.findDetail(host.getId(), ApiConstants.USERNAME);
            if (nv.getValue().equals(cmd.getUsername())) {
                final DetailVO nvp = _detailsDao.findDetail(host.getId(), ApiConstants.PASSWORD);
                nvp.setValue(DBEncryptionUtil.encrypt(cmd.getPassword()));
                _detailsDao.persist(nvp);
            } else {
                // rollback to maintain consistency
                throw new InvalidParameterValueException("The username is not same for the hosts..");
            }
        }
    });
    return true;
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) DetailVO(com.cloud.host.DetailVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) HostVO(com.cloud.host.HostVO) DB(com.cloud.utils.db.DB)

Example 22 with DetailVO

use of com.cloud.host.DetailVO in project cloudstack by apache.

the class HostDetailsDaoImpl method findDetails.

@Override
public Map<String, String> findDetails(long hostId) {
    SearchCriteria<DetailVO> sc = HostSearch.create();
    sc.setParameters("hostId", hostId);
    List<DetailVO> results = search(sc, null);
    Map<String, String> details = new HashMap<String, String>(results.size());
    for (DetailVO result : results) {
        if ("password".equals(result.getName())) {
            details.put(result.getName(), DBEncryptionUtil.decrypt(result.getValue()));
        } else {
            details.put(result.getName(), result.getValue());
        }
    }
    return details;
}
Also used : DetailVO(com.cloud.host.DetailVO) HashMap(java.util.HashMap)

Example 23 with DetailVO

use of com.cloud.host.DetailVO in project cloudstack by apache.

the class HostDetailsDaoImpl method deleteDetails.

@Override
public void deleteDetails(long hostId) {
    SearchCriteria sc = HostSearch.create();
    sc.setParameters("hostId", hostId);
    List<DetailVO> results = search(sc, null);
    for (DetailVO result : results) {
        remove(result.getId());
    }
}
Also used : DetailVO(com.cloud.host.DetailVO) SearchCriteria(com.cloud.utils.db.SearchCriteria)

Example 24 with DetailVO

use of com.cloud.host.DetailVO in project cloudstack by apache.

the class CiscoVnmcElement method addCiscoVnmcResource.

@Override
public CiscoVnmcController addCiscoVnmcResource(AddCiscoVnmcResourceCmd cmd) {
    final String deviceName = Provider.CiscoVnmc.getName();
    NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
    final Long physicalNetworkId = cmd.getPhysicalNetworkId();
    CiscoVnmcController ciscoVnmcResource = null;
    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 (_ciscoVnmcDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
        throw new CloudRuntimeException("A Cisco Vnmc 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", "Cisco VNMC Controller - " + cmd.getHost());
    params.put("ip", cmd.getHost());
    params.put("username", cmd.getUsername());
    params.put("password", cmd.getPassword());
    Map<String, Object> hostdetails = new HashMap<String, Object>();
    hostdetails.putAll(params);
    ServerResource resource = new CiscoVnmcResource();
    try {
        resource.configure(cmd.getHost(), hostdetails);
        final Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.ExternalFirewall, params);
        if (host != null) {
            return Transaction.execute(new TransactionCallback<CiscoVnmcController>() {

                @Override
                public CiscoVnmcController doInTransaction(TransactionStatus status) {
                    CiscoVnmcController ciscoVnmcResource = new CiscoVnmcControllerVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
                    _ciscoVnmcDao.persist((CiscoVnmcControllerVO) ciscoVnmcResource);
                    DetailVO detail = new DetailVO(host.getId(), "deviceid", String.valueOf(ciscoVnmcResource.getId()));
                    _hostDetailsDao.persist(detail);
                    return ciscoVnmcResource;
                }
            });
        } else {
            throw new CloudRuntimeException("Failed to add Cisco Vnmc 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) ServerResource(com.cloud.resource.ServerResource) 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) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CiscoVnmcResource(com.cloud.network.resource.CiscoVnmcResource) CiscoVnmcController(com.cloud.network.cisco.CiscoVnmcController) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO)

Example 25 with DetailVO

use of com.cloud.host.DetailVO in project cloudstack by apache.

the class ResourceManagerImpl method doUpdateHostPassword.

private boolean doUpdateHostPassword(final long hostId) {
    if (!_agentMgr.isAgentAttached(hostId)) {
        return false;
    }
    DetailVO nv = _hostDetailsDao.findDetail(hostId, ApiConstants.USERNAME);
    final String username = nv.getValue();
    nv = _hostDetailsDao.findDetail(hostId, ApiConstants.PASSWORD);
    final String password = nv.getValue();
    final HostVO host = _hostDao.findById(hostId);
    final String hostIpAddress = host.getPrivateIpAddress();
    final UpdateHostPasswordCommand cmd = new UpdateHostPasswordCommand(username, password, hostIpAddress);
    final Answer answer = _agentMgr.easySend(hostId, cmd);
    s_logger.info("Result returned from update host password ==> " + answer.getDetails());
    return answer.getResult();
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) GetGPUStatsAnswer(com.cloud.agent.api.GetGPUStatsAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) Answer(com.cloud.agent.api.Answer) DetailVO(com.cloud.host.DetailVO) UpdateHostPasswordCommand(com.cloud.agent.api.UpdateHostPasswordCommand) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO)

Aggregations

DetailVO (com.cloud.host.DetailVO)38 HostVO (com.cloud.host.HostVO)15 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)13 TransactionStatus (com.cloud.utils.db.TransactionStatus)13 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)13 ConfigurationException (javax.naming.ConfigurationException)13 HashMap (java.util.HashMap)12 Host (com.cloud.host.Host)9 DB (com.cloud.utils.db.DB)9 PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)8 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)8 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)7 NetworkDevice (org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice)6 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)5 InsufficientNetworkCapacityException (com.cloud.exception.InsufficientNetworkCapacityException)5 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)5 ServerResource (com.cloud.resource.ServerResource)5 UnableDeleteHostException (com.cloud.resource.UnableDeleteHostException)5 GuestOSCategoryVO (com.cloud.storage.GuestOSCategoryVO)4 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)4