use of com.cloud.dc.VlanVO in project cloudstack by apache.
the class ConfigurationManagerImpl method commitVlanAndIpRange.
private VlanVO commitVlanAndIpRange(final long zoneId, final long networkId, final long physicalNetworkId, final Long podId, final String startIP, final String endIP, final String vlanGateway, final String vlanNetmask, final String vlanId, final Domain domain, final Account vlanOwner, final String vlanIp6Gateway, final String vlanIp6Cidr, final boolean ipv4, final DataCenterVO zone, final VlanType vlanType, final String ipv6Range, final String ipRange) {
return Transaction.execute(new TransactionCallback<VlanVO>() {
@Override
public VlanVO doInTransaction(final TransactionStatus status) {
VlanVO vlan = new VlanVO(vlanType, vlanId, vlanGateway, vlanNetmask, zone.getId(), ipRange, networkId, physicalNetworkId, vlanIp6Gateway, vlanIp6Cidr, ipv6Range);
s_logger.debug("Saving vlan range " + vlan);
vlan = _vlanDao.persist(vlan);
// public ip range
if (ipv4) {
if (!savePublicIPRange(startIP, endIP, zoneId, vlan.getId(), networkId, physicalNetworkId)) {
throw new CloudRuntimeException("Failed to save IPv4 range. Please contact Cloud Support.");
}
}
if (vlanOwner != null) {
// This VLAN is account-specific, so create an AccountVlanMapVO
// entry
final AccountVlanMapVO accountVlanMapVO = new AccountVlanMapVO(vlanOwner.getId(), vlan.getId());
_accountVlanMapDao.persist(accountVlanMapVO);
// generate usage event for dedication of every ip address in the
// range
final List<IPAddressVO> ips = _publicIpAddressDao.listByVlanId(vlan.getId());
for (final IPAddressVO ip : ips) {
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_ASSIGN, vlanOwner.getId(), ip.getDataCenterId(), ip.getId(), ip.getAddress().toString(), ip.isSourceNat(), vlan.getVlanType().toString(), ip.getSystem(), ip.getClass().getName(), ip.getUuid());
}
// increment resource count for dedicated public ip's
_resourceLimitMgr.incrementResourceCount(vlanOwner.getId(), ResourceType.public_ip, new Long(ips.size()));
} else if (domain != null) {
// This VLAN is domain-wide, so create a DomainVlanMapVO entry
final DomainVlanMapVO domainVlanMapVO = new DomainVlanMapVO(domain.getId(), vlan.getId());
_domainVlanMapDao.persist(domainVlanMapVO);
} else if (podId != null) {
// This VLAN is pod-wide, so create a PodVlanMapVO entry
final PodVlanMapVO podVlanMapVO = new PodVlanMapVO(podId, vlan.getId());
_podVlanMapDao.persist(podVlanMapVO);
}
return vlan;
}
});
}
use of com.cloud.dc.VlanVO 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(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
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.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 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());
}
});
}
}
}
// 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 cloudstack by apache.
the class VirtualNetworkModel method update.
@Override
public void update(ModelController controller) throws InternalErrorException, IOException {
assert _initialized;
ApiConnector api = controller.getApiAccessor();
VlanDao vlanDao = controller.getVlanDao();
VirtualNetwork vn = _vn;
if (!isDynamicNetwork()) {
_vn = (VirtualNetwork) controller.getApiAccessor().findById(VirtualNetwork.class, _uuid);
return;
}
assert _uuid != null : "uuid is not set";
if (_vn == null) {
vn = _vn = (VirtualNetwork) controller.getApiAccessor().findById(VirtualNetwork.class, _uuid);
if (vn == null) {
vn = new VirtualNetwork();
if (_projectId != null) {
Project project;
try {
project = (Project) api.findById(Project.class, _projectId);
} catch (IOException ex) {
s_logger.debug("project read", ex);
throw new CloudRuntimeException("Failed to read project", ex);
}
vn.setParent(project);
}
vn.setName(_name);
vn.setUuid(_uuid);
}
}
if (_policyModel == null) {
vn.clearNetworkPolicy();
} else if (!_policyModel.hasPolicyRules()) {
vn.clearNetworkPolicy();
_policyModel.removeSuccessor(this);
} else {
vn.setNetworkPolicy(_policyModel.getPolicy(), new VirtualNetworkPolicyType(new VirtualNetworkPolicyType.SequenceType(1, 0), null));
}
if (_ipam == null) {
NetworkIpam ipam = null;
try {
String ipam_id = api.findByName(NetworkIpam.class, null, "default-network-ipam");
if (ipam_id == null) {
s_logger.debug("could not find default-network-ipam");
return;
}
ipam = (NetworkIpam) api.findById(NetworkIpam.class, ipam_id);
if (ipam == null) {
s_logger.debug("could not find NetworkIpam with ipam_id: " + ipam_id);
return;
}
} catch (IOException ex) {
s_logger.error(ex);
return;
}
_ipam = ipam;
}
if (_prefix != null) {
VnSubnetsType subnet = new VnSubnetsType();
String[] addr_pair = _prefix.split("\\/");
subnet.addIpamSubnets(new SubnetType(addr_pair[0], Integer.parseInt(addr_pair[1])), _gateway);
vn.setNetworkIpam(_ipam, subnet);
} else if (_trafficType == TrafficType.Public) {
vn.clearNetworkIpam();
/* Subnet information for Public is stored in the vlan table */
List<VlanVO> vlan_list = vlanDao.listVlansByNetworkId(_id);
for (VlanVO vlan : vlan_list) {
String cidr = NetUtils.ipAndNetMaskToCidr(vlan.getVlanGateway(), vlan.getVlanNetmask());
int slash = cidr.indexOf('/');
String ip_addr = cidr.substring(0, slash);
int plen = Integer.parseInt(cidr.substring(slash + 1));
VnSubnetsType subnet = new VnSubnetsType();
subnet.addIpamSubnets(new SubnetType(ip_addr, plen), vlan.getVlanGateway());
vn.addNetworkIpam(_ipam, subnet);
}
}
if (_vn == null) {
try {
api.create(vn);
} catch (Exception ex) {
s_logger.debug("virtual-network create", ex);
throw new CloudRuntimeException("Failed to create virtual-network", ex);
}
_vn = vn;
} else {
try {
api.update(vn);
} catch (IOException ex) {
s_logger.warn("virtual-network update", ex);
throw new CloudRuntimeException("Unable to update virtual-network object", ex);
}
}
for (ModelObject successor : successors()) {
successor.update(controller);
}
}
use of com.cloud.dc.VlanVO in project cloudstack by apache.
the class VirtualNetworkModel method verify.
@Override
public boolean verify(ModelController controller) {
assert _initialized : "initialized is false";
assert _uuid != null : "uuid is not set";
ApiConnector api = controller.getApiAccessor();
VlanDao vlanDao = controller.getVlanDao();
try {
_vn = (VirtualNetwork) api.findById(VirtualNetwork.class, _uuid);
} catch (IOException e) {
e.printStackTrace();
}
if (_vn == null) {
return false;
}
if (!isDynamicNetwork()) {
return true;
}
List<String> dbSubnets = new ArrayList<String>();
if (_trafficType == TrafficType.Public) {
List<VlanVO> vlan_list = vlanDao.listVlansByNetworkId(_id);
for (VlanVO vlan : vlan_list) {
String cidr = NetUtils.ipAndNetMaskToCidr(vlan.getVlanGateway(), vlan.getVlanNetmask());
dbSubnets.add(vlan.getVlanGateway() + cidr);
}
} else {
dbSubnets.add(_gateway + _prefix);
}
List<ObjectReference<VnSubnetsType>> ipamRefs = _vn.getNetworkIpam();
List<String> vncSubnets = new ArrayList<String>();
if (ipamRefs == null && !dbSubnets.isEmpty()) {
return false;
}
if (ipamRefs != null) {
for (ObjectReference<VnSubnetsType> ref : ipamRefs) {
VnSubnetsType vnSubnetType = ref.getAttr();
if (vnSubnetType != null) {
List<VnSubnetsType.IpamSubnetType> subnets = vnSubnetType.getIpamSubnets();
if (subnets != null && !subnets.isEmpty()) {
VnSubnetsType.IpamSubnetType ipamSubnet = subnets.get(0);
vncSubnets.add(ipamSubnet.getDefaultGateway() + ipamSubnet.getSubnet().getIpPrefix() + "/" + ipamSubnet.getSubnet().getIpPrefixLen());
}
}
}
}
// unordered, no duplicates hence perform negation operation as set
Set<String> diff = new HashSet<String>(dbSubnets);
diff.removeAll(vncSubnets);
if (!diff.isEmpty()) {
s_logger.debug("Subnets changed, network: " + _name + "; db: " + dbSubnets + ", vnc: " + vncSubnets + ", diff: " + diff);
return false;
}
List<ObjectReference<VirtualNetworkPolicyType>> policyRefs = _vn.getNetworkPolicy();
if ((policyRefs == null || policyRefs.isEmpty()) && _policyModel != null) {
return false;
}
if ((policyRefs != null && !policyRefs.isEmpty()) && _policyModel == null) {
return false;
}
if (policyRefs != null && !policyRefs.isEmpty() && _policyModel != null) {
ObjectReference<VirtualNetworkPolicyType> ref = policyRefs.get(0);
if (!ref.getUuid().equals(_policyModel.getUuid())) {
return false;
}
}
for (ModelObject successor : successors()) {
if (!successor.verify(controller)) {
return false;
}
}
return true;
}
use of com.cloud.dc.VlanVO in project cloudstack by apache.
the class VirtualNetworkModel method read.
public void read(ModelController controller) {
ApiConnector api = controller.getApiAccessor();
VlanDao vlanDao = controller.getVlanDao();
try {
_vn = (VirtualNetwork) api.findById(VirtualNetwork.class, _uuid);
} catch (IOException e) {
e.printStackTrace();
}
if (_vn == null) {
return;
}
if (_ipam == null) {
NetworkIpam ipam = null;
try {
String ipam_id = api.findByName(NetworkIpam.class, null, "default-network-ipam");
if (ipam_id == null) {
s_logger.debug("could not find default-network-ipam");
return;
}
ipam = (NetworkIpam) api.findById(NetworkIpam.class, ipam_id);
if (ipam == null) {
s_logger.debug("could not find NetworkIpam with ipam_id: " + ipam_id);
return;
}
} catch (IOException ex) {
s_logger.error(ex);
return;
}
_ipam = ipam;
}
if (_prefix != null) {
VnSubnetsType subnet = new VnSubnetsType();
String[] addr_pair = _prefix.split("\\/");
subnet.addIpamSubnets(new SubnetType(addr_pair[0], Integer.parseInt(addr_pair[1])), _gateway);
_vn.setNetworkIpam(_ipam, subnet);
} else if (_trafficType == TrafficType.Public) {
_vn.clearNetworkIpam();
/* Subnet information for Public is stored in the vlan table */
List<VlanVO> vlan_list = vlanDao.listVlansByNetworkId(_id);
for (VlanVO vlan : vlan_list) {
String cidr = NetUtils.ipAndNetMaskToCidr(vlan.getVlanGateway(), vlan.getVlanNetmask());
int slash = cidr.indexOf('/');
String ip_addr = cidr.substring(0, slash);
int plen = Integer.parseInt(cidr.substring(slash + 1));
VnSubnetsType subnet = new VnSubnetsType();
subnet.addIpamSubnets(new SubnetType(ip_addr, plen), vlan.getVlanGateway());
_vn.addNetworkIpam(_ipam, subnet);
}
}
return;
}
Aggregations