use of com.cloud.dc.VlanVO in project cosmic by MissionCriticalCloud.
the class VlanDaoImpl method searchForZoneWideVlans.
@Override
@DB
public List<VlanVO> searchForZoneWideVlans(final long dcId, final String vlanType, final String vlanId) {
final StringBuilder sql = new StringBuilder(FindZoneWideVlans);
final TransactionLegacy txn = TransactionLegacy.currentTxn();
final List<VlanVO> zoneWideVlans = new ArrayList<>();
try (PreparedStatement pstmt = txn.prepareStatement(sql.toString())) {
if (pstmt != null) {
pstmt.setLong(1, dcId);
pstmt.setString(2, vlanType);
pstmt.setString(3, vlanId);
try (ResultSet rs = pstmt.executeQuery()) {
while (rs.next()) {
zoneWideVlans.add(toEntityBean(rs, false));
}
} catch (final SQLException e) {
throw new CloudRuntimeException("searchForZoneWideVlans:Exception:" + e.getMessage(), e);
}
}
return zoneWideVlans;
} catch (final SQLException e) {
throw new CloudRuntimeException("searchForZoneWideVlans:Exception:" + e.getMessage(), e);
}
}
use of com.cloud.dc.VlanVO in project cosmic by MissionCriticalCloud.
the class VpcManagerImpl method configure.
@Override
@DB
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
// configure default vpc offering
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
if (_vpcOffDao.findByUniqueName(VpcOffering.defaultVPCOfferingName) == null) {
s_logger.debug("Creating VPC offering " + VpcOffering.defaultVPCOfferingName);
final Map<Service, Set<Provider>> svcProviderMap = getServiceSetMap(DEFAULT_SERVICES);
createVpcOffering(VpcOffering.defaultVPCOfferingName, VpcOffering.defaultVPCOfferingName, svcProviderMap, true, State.Enabled, null, null, false);
}
if (_vpcOffDao.findByUniqueName(VpcOffering.defaultRemoteGatewayVPCOfferingName) == null) {
s_logger.debug("Creating VPC offering " + VpcOffering.defaultRemoteGatewayVPCOfferingName);
final Map<Service, Set<Provider>> svcProviderMap = getServiceSetMap(REMOTE_GATEWAY_SERVICES);
createVpcOffering(VpcOffering.defaultRemoteGatewayVPCOfferingName, VpcOffering.defaultRemoteGatewayVPCOfferingName, svcProviderMap, true, State.Enabled, null, null, false);
}
if (_vpcOffDao.findByUniqueName(VpcOffering.defaultRemoteGatewayWithVPNVPCOfferingName) == null) {
s_logger.debug("Creating VPC offering " + VpcOffering.defaultRemoteGatewayWithVPNVPCOfferingName);
final Map<Service, Set<Provider>> svcProviderMap = getServiceSetMap(REMOTE_GATEWAY_WITH_VPN_SERVICES);
createVpcOffering(VpcOffering.defaultRemoteGatewayWithVPNVPCOfferingName, VpcOffering.defaultRemoteGatewayWithVPNVPCOfferingName, svcProviderMap, true, State.Enabled, null, null, false);
}
if (_vpcOffDao.findByUniqueName(VpcOffering.defaultInternalVPCOfferingName) == null) {
s_logger.debug("Creating VPC offering " + VpcOffering.defaultInternalVPCOfferingName);
final Map<Service, Set<Provider>> svcProviderMap = getServiceSetMap(INTERNAL_VPC_SERVICES);
createVpcOffering(VpcOffering.defaultInternalVPCOfferingName, VpcOffering.defaultInternalVPCOfferingName, svcProviderMap, true, State.Enabled, null, null, false);
}
if (_vpcOffDao.findByUniqueName(VpcOffering.redundantVPCOfferingName) == null) {
s_logger.debug("Creating VPC offering " + VpcOffering.redundantVPCOfferingName);
// Link the default Redundant VPC offering to the two default router offerings
final ServiceOffering serviceOffering = _serviceOfferingDao.findByName(ServiceOffering.routerDefaultOffUniqueName);
final ServiceOffering secondaryServiceOffering = _serviceOfferingDao.findByName(ServiceOffering.routerDefaultSecondaryOffUniqueName);
Long serviceOfferingId = null;
Long secondaryServiceOfferingId = null;
if (serviceOffering != null) {
serviceOfferingId = serviceOffering.getId();
}
if (secondaryServiceOffering != null) {
secondaryServiceOfferingId = secondaryServiceOffering.getId();
}
final Map<Service, Set<Provider>> svcProviderMap = getServiceSetMap(DEFAULT_SERVICES);
createVpcOffering(VpcOffering.redundantVPCOfferingName, VpcOffering.redundantVPCOfferingName, svcProviderMap, true, State.Enabled, serviceOfferingId, secondaryServiceOfferingId, true);
}
}
});
final Map<String, String> configs = _configDao.getConfiguration(params);
final String value = configs.get(Config.VpcCleanupInterval.key());
// 1 hour
_cleanupInterval = NumbersUtil.parseInt(value, 60 * 60);
final String maxNtwks = configs.get(Config.VpcMaxNetworks.key());
// max=3 is default
_maxNetworks = NumbersUtil.parseInt(maxNtwks, 3);
IpAddressSearch = _ipAddressDao.createSearchBuilder();
IpAddressSearch.and("accountId", IpAddressSearch.entity().getAllocatedToAccountId(), Op.EQ);
IpAddressSearch.and("dataCenterId", IpAddressSearch.entity().getDataCenterId(), Op.EQ);
IpAddressSearch.and("vpcId", IpAddressSearch.entity().getVpcId(), Op.EQ);
IpAddressSearch.and("associatedWithNetworkId", IpAddressSearch.entity().getAssociatedWithNetworkId(), Op.EQ);
final SearchBuilder<VlanVO> virtualNetworkVlanSB = _vlanDao.createSearchBuilder();
virtualNetworkVlanSB.and("vlanType", virtualNetworkVlanSB.entity().getVlanType(), Op.EQ);
IpAddressSearch.join("virtualNetworkVlanSB", virtualNetworkVlanSB, IpAddressSearch.entity().getVlanId(), virtualNetworkVlanSB.entity().getId(), JoinBuilder.JoinType.INNER);
IpAddressSearch.done();
return true;
}
use of com.cloud.dc.VlanVO in project cosmic by MissionCriticalCloud.
the class ResourceLimitManagerImpl method calculatePublicIpForAccount.
private long calculatePublicIpForAccount(final long accountId) {
Long dedicatedCount = 0L;
final Long allocatedCount;
final List<VlanVO> dedicatedVlans = _vlanDao.listDedicatedVlans(accountId);
for (final VlanVO dedicatedVlan : dedicatedVlans) {
final List<IPAddressVO> ips = _ipAddressDao.listByVlanId(dedicatedVlan.getId());
dedicatedCount += new Long(ips.size());
}
allocatedCount = _ipAddressDao.countAllocatedIPsForAccount(accountId);
if (dedicatedCount > allocatedCount) {
return dedicatedCount;
} else {
return allocatedCount;
}
}
use of com.cloud.dc.VlanVO 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();
}
use of com.cloud.dc.VlanVO in project cosmic by MissionCriticalCloud.
the class ManagementServerImpl method searchForVlans.
@Override
public Pair<List<? extends Vlan>, Integer> searchForVlans(final ListVlanIpRangesCmd cmd) {
// If an account name and domain ID are specified, look up the account
final String accountName = cmd.getAccountName();
final Long domainId = cmd.getDomainId();
Long accountId = null;
final Long networkId = cmd.getNetworkId();
final Boolean forVirtual = cmd.getForVirtualNetwork();
String vlanType = null;
final Long projectId = cmd.getProjectId();
final Long physicalNetworkId = cmd.getPhysicalNetworkId();
if (accountName != null && domainId != null) {
if (projectId != null) {
throw new InvalidParameterValueException("Account and projectId can't be specified together");
}
final Account account = _accountDao.findActiveAccount(accountName, domainId);
if (account == null) {
final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find account " + accountName + " in specified domain");
// Since we don't have a DomainVO object here, we directly set
// tablename to "domain".
final DomainVO domain = ApiDBUtils.findDomainById(domainId);
String domainUuid = domainId.toString();
if (domain != null) {
domainUuid = domain.getUuid();
}
ex.addProxyObject(domainUuid, "domainId");
throw ex;
} else {
accountId = account.getId();
}
}
if (forVirtual != null) {
if (forVirtual) {
vlanType = VlanType.VirtualNetwork.toString();
} else {
vlanType = VlanType.DirectAttached.toString();
}
}
// set project information
if (projectId != null) {
final Project project = _projectMgr.getProject(projectId);
if (project == null) {
final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project by id " + projectId);
ex.addProxyObject(projectId.toString(), "projectId");
throw ex;
}
accountId = project.getProjectAccountId();
}
final Filter searchFilter = new Filter(VlanVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
final Object id = cmd.getId();
final Object vlan = cmd.getVlan();
final Object dataCenterId = cmd.getZoneId();
final Object podId = cmd.getPodId();
final Object keyword = cmd.getKeyword();
final SearchBuilder<VlanVO> sb = _vlanDao.createSearchBuilder();
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("vlan", sb.entity().getVlanTag(), SearchCriteria.Op.EQ);
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
sb.and("vlan", sb.entity().getVlanTag(), SearchCriteria.Op.EQ);
sb.and("networkId", sb.entity().getNetworkId(), SearchCriteria.Op.EQ);
sb.and("vlanType", sb.entity().getVlanType(), SearchCriteria.Op.EQ);
sb.and("physicalNetworkId", sb.entity().getPhysicalNetworkId(), SearchCriteria.Op.EQ);
if (accountId != null) {
final SearchBuilder<AccountVlanMapVO> accountVlanMapSearch = _accountVlanMapDao.createSearchBuilder();
accountVlanMapSearch.and("accountId", accountVlanMapSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
sb.join("accountVlanMapSearch", accountVlanMapSearch, sb.entity().getId(), accountVlanMapSearch.entity().getVlanDbId(), JoinBuilder.JoinType.INNER);
}
if (podId != null) {
final SearchBuilder<PodVlanMapVO> podVlanMapSearch = _podVlanMapDao.createSearchBuilder();
podVlanMapSearch.and("podId", podVlanMapSearch.entity().getPodId(), SearchCriteria.Op.EQ);
sb.join("podVlanMapSearch", podVlanMapSearch, sb.entity().getId(), podVlanMapSearch.entity().getVlanDbId(), JoinBuilder.JoinType.INNER);
}
final SearchCriteria<VlanVO> sc = sb.create();
if (keyword != null) {
final SearchCriteria<VlanVO> ssc = _vlanDao.createSearchCriteria();
ssc.addOr("vlanTag", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("ipRange", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("vlanTag", SearchCriteria.Op.SC, ssc);
} else {
if (id != null) {
sc.setParameters("id", id);
}
if (vlan != null) {
sc.setParameters("vlan", vlan);
}
if (dataCenterId != null) {
sc.setParameters("dataCenterId", dataCenterId);
}
if (networkId != null) {
sc.setParameters("networkId", networkId);
}
if (accountId != null) {
sc.setJoinParameters("accountVlanMapSearch", "accountId", accountId);
}
if (podId != null) {
sc.setJoinParameters("podVlanMapSearch", "podId", podId);
}
if (vlanType != null) {
sc.setParameters("vlanType", vlanType);
}
if (physicalNetworkId != null) {
sc.setParameters("physicalNetworkId", physicalNetworkId);
}
}
final Pair<List<VlanVO>, Integer> result = _vlanDao.searchAndCount(sc, searchFilter);
return new Pair<>(result.first(), result.second());
}
Aggregations