Search in sources :

Example 1 with Config

use of com.cloud.configuration.Config in project cloudstack by apache.

the class ConfigurationServerImpl method persistDefaultValues.

@Override
public void persistDefaultValues() throws InternalErrorException {
    // Create system user and admin user
    saveUser();
    // Get init
    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
        List<String> categories = Config.getCategories();
        for (String category : categories) {
            // If this is not a premium environment, don't insert premium configuration values
            if (!_configDao.isPremium() && category.equals("Premium")) {
                continue;
            }
            List<Config> configs = Config.getConfigs(category);
            for (Config c : configs) {
                String name = c.key();
                // if the config value already present in the db, don't insert it again
                if (_configDao.findByName(name) != null) {
                    continue;
                }
                String instance = "DEFAULT";
                String component = c.getComponent();
                String value = c.getDefaultValue();
                String description = c.getDescription();
                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, 500, "Small Instance", ProvisioningType.THIN, false, false, null);
        createServiceOffering(User.UID_SYSTEM, "Medium Instance", 1, 1024, 1000, "Medium Instance", ProvisioningType.THIN, false, false, null);
        // Save default disk offerings
        createDefaultDiskOffering("Small", "Small Disk, 5 GB", ProvisioningType.THIN, 5, null, false, false);
        createDefaultDiskOffering("Medium", "Medium Disk, 20 GB", ProvisioningType.THIN, 20, null, false, false);
        createDefaultDiskOffering("Large", "Large Disk, 100 GB", ProvisioningType.THIN, 100, null, false, false);
        createDefaultDiskOffering("Large", "Large Disk, 100 GB", ProvisioningType.THIN, 100, null, false, false);
        createDefaultDiskOffering("Custom", "Custom Disk", ProvisioningType.THIN, 0, null, true, false);
        // Save the mount parent to the configuration table
        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.");
        }
        String hostIpAdr = NetUtils.getDefaultHostIp();
        boolean needUpdateHostIp = true;
        if (hostIpAdr != null) {
            Boolean devel = Boolean.valueOf(_configDao.getValue("developer"));
            if (devel) {
                String value = _configDao.getValue(ApiServiceConfiguration.ManagementServerAddresses.key());
                if (value != null && !value.equals("localhost")) {
                    needUpdateHostIp = false;
                }
            }
            if (needUpdateHostIp) {
                _configDepot.createOrUpdateConfigObject(ApiServiceConfiguration.class.getSimpleName(), ApiServiceConfiguration.ManagementServerAddresses, hostIpAdr);
                s_logger.debug("ConfigurationServer saved \"" + hostIpAdr + "\" as host.");
            }
        }
        // generate a single sign-on key
        updateSSOKey();
        // Create default network offerings
        createDefaultNetworkOfferings();
        // Create default networks
        createDefaultNetworks();
        // Create userIpAddress ranges
        // Update existing vlans with networkId
        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
                String ipPange = vlan.getIpRange();
                String[] range = ipPange.split("-");
                final String startIp = range[0];
                final String endIp = range[1];
                Transaction.execute(new TransactionCallbackNoReturn() {

                    @Override
                    public void doInTransactionWithoutResult(TransactionStatus status) {
                        IPRangeConfig config = new IPRangeConfig();
                        long startIPLong = NetUtils.ip2Long(startIp);
                        long endIPLong = NetUtils.ip2Long(endIp);
                        config.savePublicIPRange(TransactionLegacy.currentTxn(), startIPLong, endIPLong, vlan.getDataCenterId(), vlan.getId(), vlan.getNetworkId(), vlan.getPhysicalNetworkId(), false);
                    }
                });
            }
        }
    }
    // Update resource count if needed
    updateResourceCount();
    // 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(org.apache.cloudstack.config.ApiServiceConfiguration) ConfigurationVO(org.apache.cloudstack.framework.config.impl.ConfigurationVO) VlanVO(com.cloud.dc.VlanVO)

Example 2 with Config

use of com.cloud.configuration.Config 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)

Aggregations

Config (com.cloud.configuration.Config)2 VlanVO (com.cloud.dc.VlanVO)2 IPRangeConfig (com.cloud.test.IPRangeConfig)2 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)2 TransactionStatus (com.cloud.utils.db.TransactionStatus)2 ApiServiceConfiguration (com.cloud.config.ApiServiceConfiguration)1 ConfigurationVO (com.cloud.framework.config.impl.ConfigurationVO)1 ApiServiceConfiguration (org.apache.cloudstack.config.ApiServiceConfiguration)1 ConfigurationVO (org.apache.cloudstack.framework.config.impl.ConfigurationVO)1