Search in sources :

Example 6 with VlanVO

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;
        }
    });
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AccountVlanMapVO(com.cloud.dc.AccountVlanMapVO) PodVlanMapVO(com.cloud.dc.PodVlanMapVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) ArrayList(java.util.ArrayList) List(java.util.List) IPAddressVO(com.cloud.network.dao.IPAddressVO) VlanVO(com.cloud.dc.VlanVO) DomainVlanMapVO(com.cloud.dc.DomainVlanMapVO)

Example 7 with VlanVO

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();
}
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 8 with VlanVO

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);
    }
}
Also used : VirtualNetworkPolicyType(net.juniper.contrail.api.types.VirtualNetworkPolicyType) VlanDao(com.cloud.dc.dao.VlanDao) ApiConnector(net.juniper.contrail.api.ApiConnector) IOException(java.io.IOException) SubnetType(net.juniper.contrail.api.types.SubnetType) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VirtualNetwork(net.juniper.contrail.api.types.VirtualNetwork) Project(net.juniper.contrail.api.types.Project) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetworkIpam(net.juniper.contrail.api.types.NetworkIpam) ArrayList(java.util.ArrayList) List(java.util.List) VlanVO(com.cloud.dc.VlanVO) VnSubnetsType(net.juniper.contrail.api.types.VnSubnetsType)

Example 9 with VlanVO

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;
}
Also used : VirtualNetworkPolicyType(net.juniper.contrail.api.types.VirtualNetworkPolicyType) VlanDao(com.cloud.dc.dao.VlanDao) ApiConnector(net.juniper.contrail.api.ApiConnector) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ObjectReference(net.juniper.contrail.api.ObjectReference) VlanVO(com.cloud.dc.VlanVO) VnSubnetsType(net.juniper.contrail.api.types.VnSubnetsType) HashSet(java.util.HashSet)

Example 10 with VlanVO

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;
}
Also used : VlanDao(com.cloud.dc.dao.VlanDao) ApiConnector(net.juniper.contrail.api.ApiConnector) NetworkIpam(net.juniper.contrail.api.types.NetworkIpam) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) SubnetType(net.juniper.contrail.api.types.SubnetType) VlanVO(com.cloud.dc.VlanVO) VnSubnetsType(net.juniper.contrail.api.types.VnSubnetsType)

Aggregations

VlanVO (com.cloud.dc.VlanVO)58 ArrayList (java.util.ArrayList)22 IPAddressVO (com.cloud.network.dao.IPAddressVO)15 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)14 DB (com.cloud.utils.db.DB)14 HostVO (com.cloud.host.HostVO)11 Network (com.cloud.network.Network)11 Account (com.cloud.user.Account)11 TransactionStatus (com.cloud.utils.db.TransactionStatus)11 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 List (java.util.List)8 Answer (com.cloud.agent.api.Answer)7 AccountVlanMapVO (com.cloud.dc.AccountVlanMapVO)7 DataCenter (com.cloud.dc.DataCenter)7 PublicIp (com.cloud.network.addr.PublicIp)7 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)6 NetworkVO (com.cloud.network.dao.NetworkVO)6 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)6 NetworkOffering (com.cloud.offering.NetworkOffering)6 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)6