Search in sources :

Example 6 with ConfigurationVO

use of com.cloud.framework.config.impl.ConfigurationVO in project cosmic by MissionCriticalCloud.

the class ConfigurationServerImpl method updateSecondaryStorageVMSharedKey.

/**
 * preshared key to be used by management server to communicate with SSVM during volume/template upload
 */
private void updateSecondaryStorageVMSharedKey() {
    try {
        final ConfigurationVO configInDB = _configDao.findByName(Config.SSVMPSK.key());
        if (configInDB == null) {
            final ConfigurationVO configVO = new ConfigurationVO(Config.SSVMPSK.getCategory(), "DEFAULT", Config.SSVMPSK.getComponent(), Config.SSVMPSK.key(), getPrivateKey(), Config.SSVMPSK.getDescription());
            s_logger.info("generating a new SSVM PSK. This goes to SSVM on Start");
            _configDao.persist(configVO);
        } else if (StringUtils.isEmpty(configInDB.getValue())) {
            s_logger.info("updating the SSVM PSK with new value. This goes to SSVM on Start");
            _configDao.update(Config.SSVMPSK.key(), Config.SSVMPSK.getCategory(), getPrivateKey());
        }
    } catch (final NoSuchAlgorithmException ex) {
        s_logger.error("error generating ssvm psk", ex);
    }
}
Also used : ConfigurationVO(com.cloud.framework.config.impl.ConfigurationVO) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 7 with ConfigurationVO

use of com.cloud.framework.config.impl.ConfigurationVO in project cosmic by MissionCriticalCloud.

the class ConfigurationServerImpl method getConfigListByScope.

@Override
public List<ConfigurationVO> getConfigListByScope(final String scope, final Long resourceId) {
    // Getting the list of parameters defined at the scope
    final Set<ConfigKey<?>> configList = _configDepot.getConfigListByScope(scope);
    final List<ConfigurationVO> configVOList = new ArrayList<>();
    for (final ConfigKey<?> param : configList) {
        final ConfigurationVO configVo = _configDao.findByName(param.toString());
        configVo.setValue(_configDepot.get(param.toString()).valueIn(resourceId).toString());
        configVOList.add(configVo);
    }
    return configVOList;
}
Also used : ConfigKey(com.cloud.framework.config.ConfigKey) ConfigurationVO(com.cloud.framework.config.impl.ConfigurationVO) ArrayList(java.util.ArrayList)

Example 8 with ConfigurationVO

use of com.cloud.framework.config.impl.ConfigurationVO in project cosmic by MissionCriticalCloud.

the class ConfigurationServerImpl method updateSSLKeystore.

protected void updateSSLKeystore() {
    if (s_logger.isInfoEnabled()) {
        s_logger.info("Processing updateSSLKeyStore");
    }
    final String dbString = _configDao.getValue("ssl.keystore");
    final File confFile = PropertiesUtil.findConfigFile("db.properties");
    String confPath = null;
    String keystorePath = null;
    File keystoreFile = null;
    if (null != confFile) {
        confPath = confFile.getParent();
        keystorePath = confPath + Link.keystoreFile;
        keystoreFile = new File(keystorePath);
    }
    final boolean dbExisted = (dbString != null && !dbString.isEmpty());
    s_logger.info("SSL keystore located at " + keystorePath);
    try {
        if (!dbExisted && null != confFile) {
            if (!keystoreFile.exists()) {
                generateDefaultKeystore(keystorePath);
                s_logger.info("Generated SSL keystore.");
            }
            final String base64Keystore = getBase64Keystore(keystorePath);
            final ConfigurationVO configVO = new ConfigurationVO("Hidden", "DEFAULT", "management-server", "ssl.keystore", base64Keystore, "SSL Keystore for the management servers");
            _configDao.persist(configVO);
            s_logger.info("Stored SSL keystore to database.");
        } else {
            // !keystoreFile.exists() and dbExisted
            // Export keystore to local file
            final byte[] storeBytes = Base64.decodeBase64(dbString);
            final String tmpKeystorePath = "/tmp/tmpkey";
            try (FileOutputStream fo = new FileOutputStream(tmpKeystorePath)) {
                fo.write(storeBytes);
                final Script script = new Script(true, "cp", 5000, null);
                script.add("-f");
                script.add(tmpKeystorePath);
                // There is a chance, although small, that the keystorePath is null. In that case, do not add it to the script.
                if (null != keystorePath) {
                    script.add(keystorePath);
                }
                final String result = script.execute();
                if (result != null) {
                    throw new IOException();
                }
            } catch (final Exception e) {
                throw new IOException("Fail to create keystore file!", e);
            }
            s_logger.info("Stored database keystore to local.");
        }
    } catch (final Exception ex) {
        s_logger.warn("Would use fail-safe keystore to continue.", ex);
    }
}
Also used : Script(com.cloud.utils.script.Script) ConfigurationVO(com.cloud.framework.config.impl.ConfigurationVO) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 9 with ConfigurationVO

use of com.cloud.framework.config.impl.ConfigurationVO in project cosmic by MissionCriticalCloud.

the class ConfigurationServerImpl method persistDefaultValues.

@Override
public void persistDefaultValues() throws InternalErrorException {
    // Create system user and admin user
    saveUser();
    // Get init
    final String init = _configDao.getValue("init");
    if (init == null || init.equals("false")) {
        s_logger.debug("ConfigurationServer is saving default values to the database.");
        // Save default Configuration Table values
        final List<String> categories = Config.getCategories();
        for (final String category : categories) {
            // If this is not a premium environment, don't insert premium configuration values
            if (!_configDao.isPremium() && category.equals("Premium")) {
                continue;
            }
            final List<Config> configs = Config.getConfigs(category);
            for (final Config c : configs) {
                final String name = c.key();
                // if the config value already present in the db, don't insert it again
                if (_configDao.findByName(name) != null) {
                    continue;
                }
                final String instance = "DEFAULT";
                final String component = c.getComponent();
                final String value = c.getDefaultValue();
                final String description = c.getDescription();
                final ConfigurationVO configVO = new ConfigurationVO(category, instance, component, name, value, description);
                configVO.setDefaultValue(value);
                _configDao.persist(configVO);
            }
        }
        _configDao.update(Config.UseSecondaryStorageVm.key(), Config.UseSecondaryStorageVm.getCategory(), "true");
        s_logger.debug("ConfigurationServer made secondary storage vm required.");
        _configDao.update(Config.SecStorageEncryptCopy.key(), Config.SecStorageEncryptCopy.getCategory(), "false");
        s_logger.debug("ConfigurationServer made secondary storage copy encrypt set to false.");
        _configDao.update("secstorage.secure.copy.cert", "realhostip");
        s_logger.debug("ConfigurationServer made secondary storage copy use realhostip.");
        _configDao.update("user.password.encoders.exclude", "MD5,LDAP,PLAINTEXT");
        s_logger.debug("Configuration server excluded insecure encoders");
        _configDao.update("user.authenticators.exclude", "PLAINTEXT");
        s_logger.debug("Configuration server excluded plaintext authenticator");
        // Save default service offerings
        createServiceOffering(User.UID_SYSTEM, "Small Instance", 1, 512, "Small Instance", ProvisioningType.THIN, false, false, null);
        createServiceOffering(User.UID_SYSTEM, "Medium Instance", 1, 1024, "Medium Instance", ProvisioningType.THIN, false, false, null);
        // Save default disk offerings
        createdefaultDiskOffering(null, "Small", "Small Disk, 5 GB", ProvisioningType.THIN, 5, null, false, false);
        createdefaultDiskOffering(null, "Medium", "Medium Disk, 20 GB", ProvisioningType.THIN, 20, null, false, false);
        createdefaultDiskOffering(null, "Large", "Large Disk, 100 GB", ProvisioningType.THIN, 100, null, false, false);
        createdefaultDiskOffering(null, "Large", "Large Disk, 100 GB", ProvisioningType.THIN, 100, null, false, false);
        createdefaultDiskOffering(null, "Custom", "Custom Disk", ProvisioningType.THIN, 0, null, true, false);
        // Save the mount parent to the configuration table
        final String mountParent = getMountParent();
        if (mountParent != null) {
            _configDao.update(Config.MountParent.key(), Config.MountParent.getCategory(), mountParent);
            s_logger.debug("ConfigurationServer saved \"" + mountParent + "\" as mount.parent.");
        } else {
            s_logger.debug("ConfigurationServer could not detect mount.parent.");
        }
        final String hostIpAdr = NetUtils.getDefaultHostIp();
        boolean needUpdateHostIp = true;
        if (hostIpAdr != null) {
            final Boolean devel = Boolean.valueOf(_configDao.getValue("developer"));
            if (devel) {
                final String value = _configDao.getValue(ApiServiceConfiguration.ManagementHostIPAdr.key());
                if (value != null && !value.equals("localhost")) {
                    needUpdateHostIp = false;
                }
            }
            if (needUpdateHostIp) {
                _configDepot.createOrUpdateConfigObject(ApiServiceConfiguration.class.getSimpleName(), ApiServiceConfiguration.ManagementHostIPAdr, hostIpAdr);
                s_logger.debug("ConfigurationServer saved \"" + hostIpAdr + "\" as host.");
            }
        }
        // generate a single sign-on key
        updateSSOKey();
        // Create default networks
        createDefaultNetworks();
        // Create userIpAddress ranges
        // Update existing vlans with networkId
        final List<VlanVO> vlans = _vlanDao.listAll();
        if (vlans != null && !vlans.isEmpty()) {
            for (final VlanVO vlan : vlans) {
                if (vlan.getNetworkId().longValue() == 0) {
                    updateVlanWithNetworkId(vlan);
                }
                // Create vlan user_ip_address range
                final String ipPange = vlan.getIpRange();
                final String[] range = ipPange.split("-");
                final String startIp = range[0];
                final String endIp = range[1];
                Transaction.execute(new TransactionCallbackNoReturn() {

                    @Override
                    public void doInTransactionWithoutResult(final TransactionStatus status) {
                        final IPRangeConfig config = new IPRangeConfig();
                        final long startIPLong = NetUtils.ip2Long(startIp);
                        final long endIPLong = NetUtils.ip2Long(endIp);
                        config.savePublicIPRange(TransactionLegacy.currentTxn(), startIPLong, endIPLong, vlan.getDataCenterId(), vlan.getId(), vlan.getNetworkId(), vlan.getPhysicalNetworkId());
                    }
                });
            }
        }
    }
    // Update resource count if needed
    updateResourceCount();
    // keystore for SSL/TLS connection
    updateSSLKeystore();
    // store the public and private keys in the database
    updateKeyPairs();
    // generate a PSK to communicate with SSVM
    updateSecondaryStorageVMSharedKey();
    // generate a random password for system vm
    updateSystemvmPassword();
    // generate a random password used to authenticate zone-to-zone copy
    generateSecStorageVmCopyPassword();
    // Update the cloud identifier
    updateCloudIdentifier();
    _configDepotAdmin.populateConfigurations();
    // setup XenServer default PV driver version
    initiateXenServerPVDriverVersion();
    // We should not update seed data UUID column here since this will be invoked in upgrade case as well.
    // updateUuids();
    // Set init to true
    _configDao.update("init", "Hidden", "true");
    // invalidate cache in DAO as we have changed DB status
    _configDao.invalidateCache();
}
Also used : Config(com.cloud.configuration.Config) IPRangeConfig(com.cloud.test.IPRangeConfig) IPRangeConfig(com.cloud.test.IPRangeConfig) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ApiServiceConfiguration(com.cloud.config.ApiServiceConfiguration) ConfigurationVO(com.cloud.framework.config.impl.ConfigurationVO) VlanVO(com.cloud.dc.VlanVO)

Example 10 with ConfigurationVO

use of com.cloud.framework.config.impl.ConfigurationVO in project cosmic by MissionCriticalCloud.

the class LDAPConfigCmd method updateLDAP.

private boolean updateLDAP() {
    _ldapManager.addConfiguration(hostname, port);
    /**
     * There is no query filter now. It is derived from ldap.user.object and ldap.search.group.principle
     */
    // ConfigurationVO cvo = _configDao.findByName(LDAPParams.queryfilter.toString());
    // _configDao.update(cvo.getName(),cvo.getCategory(),getQueryFilter());
    ConfigurationVO cvo = _configDao.findByName("ldap.basedn");
    _configDao.update(cvo.getName(), cvo.getCategory(), getSearchBase());
    /**
     * There is no ssl now. it is derived from the presence of trust store and password
     */
    // cvo = _configDao.findByName(LDAPParams.usessl.toString());
    // _configDao.update(cvo.getName(),cvo.getCategory(),getUseSSL().toString());
    cvo = _configDao.findByName("ldap.bind.principal");
    _configDao.update(cvo.getName(), cvo.getCategory(), getBindDN());
    cvo = _configDao.findByName("ldap.bind.password");
    _configDao.update(cvo.getName(), cvo.getCategory(), getBindPassword());
    cvo = _configDao.findByName("ldap.truststore");
    _configDao.update(cvo.getName(), cvo.getCategory(), getTrustStore());
    cvo = _configDao.findByName("ldap.truststore.password");
    _configDao.update(cvo.getName(), cvo.getCategory(), getTrustStorePassword());
    return true;
}
Also used : LdapConfigurationVO(com.cloud.ldap.LdapConfigurationVO) ConfigurationVO(com.cloud.framework.config.impl.ConfigurationVO)

Aggregations

ConfigurationVO (com.cloud.framework.config.impl.ConfigurationVO)13 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)4 ConfigurationException (javax.naming.ConfigurationException)3 IPRangeConfig (com.cloud.test.IPRangeConfig)2 Account (com.cloud.user.Account)2 User (com.cloud.user.User)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 ApiServiceConfiguration (com.cloud.config.ApiServiceConfiguration)1 Config (com.cloud.configuration.Config)1 VlanVO (com.cloud.dc.VlanVO)1 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)1 ActionEvent (com.cloud.event.ActionEvent)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 InternalErrorException (com.cloud.exception.InternalErrorException)1 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)1 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)1