Search in sources :

Example 46 with NetworkVO

use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.

the class NetworkOrchestrator method reallocate.

@DB
@Override
public boolean reallocate(final VirtualMachineProfile vm, final DataCenterDeployment dest) throws InsufficientCapacityException, ConcurrentOperationException {
    final VMInstanceVO vmInstance = _vmDao.findById(vm.getId());
    final DataCenterVO dc = _dcDao.findById(vmInstance.getDataCenterId());
    if (dc.getNetworkType() == NetworkType.Basic) {
        final List<NicVO> nics = _nicDao.listByVmId(vmInstance.getId());
        final NetworkVO network = _networksDao.findById(nics.get(0).getNetworkId());
        final LinkedHashMap<Network, List<? extends NicProfile>> profiles = new LinkedHashMap<Network, List<? extends NicProfile>>();
        profiles.put(network, new ArrayList<NicProfile>());
        Transaction.execute(new TransactionCallbackWithExceptionNoReturn<InsufficientCapacityException>() {

            @Override
            public void doInTransactionWithoutResult(final TransactionStatus status) throws InsufficientCapacityException {
                cleanupNics(vm);
                allocate(vm, profiles);
            }
        });
    }
    return true;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) NicProfile(com.cloud.vm.NicProfile) LinkedHashMap(java.util.LinkedHashMap) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ArrayList(java.util.ArrayList) List(java.util.List) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) NicVO(com.cloud.vm.NicVO) DB(com.cloud.utils.db.DB)

Example 47 with NetworkVO

use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.

the class NetworkOrchestrator method convertNetworkToNetworkProfile.

@Override
public NetworkProfile convertNetworkToNetworkProfile(final long networkId) {
    final NetworkVO network = _networksDao.findById(networkId);
    final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
    final NetworkProfile profile = new NetworkProfile(network);
    guru.updateNetworkProfile(profile);
    return profile;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkProfile(com.cloud.network.NetworkProfile) NetworkGuru(com.cloud.network.guru.NetworkGuru)

Example 48 with NetworkVO

use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.

the class NetworkOrchestrator method allocateNic.

@DB
@Override
public Pair<NicProfile, Integer> allocateNic(final NicProfile requested, final Network network, final Boolean isDefaultNic, int deviceId, final VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
    final NetworkVO ntwkVO = _networksDao.findById(network.getId());
    s_logger.debug("Allocating nic for vm " + vm.getVirtualMachine() + " in network " + network + " with requested profile " + requested);
    final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, ntwkVO.getGuruName());
    if (requested != null && requested.getMode() == null) {
        requested.setMode(network.getMode());
    }
    final NicProfile profile = guru.allocate(network, requested, vm);
    if (profile == null) {
        return null;
    }
    if (isDefaultNic != null) {
        profile.setDefaultNic(isDefaultNic);
    }
    if (requested != null && requested.getMode() == null) {
        profile.setMode(requested.getMode());
    } else {
        profile.setMode(network.getMode());
    }
    NicVO vo = new NicVO(guru.getName(), vm.getId(), network.getId(), vm.getType());
    deviceId = applyProfileToNic(vo, profile, deviceId);
    vo = _nicDao.persist(vo);
    final Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
    final NicProfile vmNic = new NicProfile(vo, network, vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network));
    return new Pair<NicProfile, Integer>(vmNic, Integer.valueOf(deviceId));
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkGuru(com.cloud.network.guru.NetworkGuru) NicProfile(com.cloud.vm.NicProfile) NicVO(com.cloud.vm.NicVO) Pair(com.cloud.utils.Pair) DB(com.cloud.utils.db.DB)

Example 49 with NetworkVO

use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.

the class VMwareGuru method finalizeExpungeNics.

@Override
public List<Command> finalizeExpungeNics(VirtualMachine vm, List<NicProfile> nics) {
    List<Command> commands = new ArrayList<Command>();
    List<NicVO> nicVOs = _nicDao.listByVmId(vm.getId());
    for (NicVO nic : nicVOs) {
        NetworkVO network = _networkDao.findById(nic.getNetworkId());
        if (network.getBroadcastDomainType() == BroadcastDomainType.Lswitch) {
            s_logger.debug("Nic " + nic.toString() + " is connected to an lswitch, cleanup required");
            NetworkVO networkVO = _networkDao.findById(nic.getNetworkId());
            // We need the traffic label to figure out which vSwitch has the
            // portgroup
            PhysicalNetworkTrafficTypeVO trafficTypeVO = _physicalNetworkTrafficTypeDao.findBy(networkVO.getPhysicalNetworkId(), networkVO.getTrafficType());
            UnregisterNicCommand unregisterNicCommand = new UnregisterNicCommand(vm.getInstanceName(), trafficTypeVO.getVmwareNetworkLabel(), UUID.fromString(nic.getUuid()));
            commands.add(unregisterNicCommand);
        }
    }
    return commands;
}
Also used : UnregisterNicCommand(com.cloud.agent.api.UnregisterNicCommand) NetworkVO(com.cloud.network.dao.NetworkVO) DeleteCommand(org.apache.cloudstack.storage.command.DeleteCommand) BackupSnapshotCommand(com.cloud.agent.api.BackupSnapshotCommand) CreateVolumeOVACommand(com.cloud.agent.api.storage.CreateVolumeOVACommand) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) PrepareOVAPackingCommand(com.cloud.agent.api.storage.PrepareOVAPackingCommand) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) UnregisterNicCommand(com.cloud.agent.api.UnregisterNicCommand) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) StorageSubSystemCommand(org.apache.cloudstack.storage.command.StorageSubSystemCommand) CreateVolumeFromSnapshotCommand(com.cloud.agent.api.CreateVolumeFromSnapshotCommand) CreateEntityDownloadURLCommand(com.cloud.agent.api.storage.CreateEntityDownloadURLCommand) Command(com.cloud.agent.api.Command) CreatePrivateTemplateFromVolumeCommand(com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand) ArrayList(java.util.ArrayList) PhysicalNetworkTrafficTypeVO(com.cloud.network.dao.PhysicalNetworkTrafficTypeVO) NicVO(com.cloud.vm.NicVO)

Example 50 with NetworkVO

use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.

the class NetworkPolicyModel method build.

public void build(ModelController controller, List<? extends NetworkACLItem> rules) throws Exception {
    String projectName = null;
    if (_project != null) {
        _fqName = StringUtils.join(_project.getQualifiedName(), ':') + ":" + _name;
        projectName = StringUtils.join(_project.getQualifiedName(), ':');
    } else {
        _fqName = ContrailManager.VNC_ROOT_DOMAIN + ":" + ContrailManager.VNC_DEFAULT_PROJECT + ":" + _name;
        projectName = ContrailManager.VNC_ROOT_DOMAIN + ":" + ContrailManager.VNC_DEFAULT_PROJECT;
    }
    PolicyEntriesType policyMap = new PolicyEntriesType();
    for (NetworkACLItem rule : rules) {
        if (rule.getState() != NetworkACLItem.State.Active && rule.getState() != NetworkACLItem.State.Add) {
            continue;
        }
        String action = null;
        if (rule.getAction() == Action.Allow) {
            action = "pass";
        } else if (rule.getAction() == Action.Deny) {
            action = "deny";
        }
        List<String> cidrList = rule.getSourceCidrList();
        String protocol = rule.getProtocol();
        if (protocol == null || protocol.equalsIgnoreCase("ALL") || protocol.isEmpty()) {
            protocol = "any";
        } else {
            protocol = protocol.toLowerCase();
        }
        Integer portStart = rule.getSourcePortStart();
        Integer portEnd = rule.getSourcePortEnd();
        if (portStart == null) {
            portStart = 0;
        }
        if (portEnd == null) {
            portEnd = 65535;
        }
        List<PolicyRuleType.AddressType> srcList = new ArrayList<PolicyRuleType.AddressType>();
        List<PolicyRuleType.AddressType> dstList = new ArrayList<PolicyRuleType.AddressType>();
        List<PolicyRuleType.PortType> srcPorts = new ArrayList<PolicyRuleType.PortType>();
        List<PolicyRuleType.PortType> dstPorts = new ArrayList<PolicyRuleType.PortType>();
        if (rule.getTrafficType() == NetworkACLItem.TrafficType.Egress) {
            for (String cidr : cidrList) {
                NetworkVO net = cidrToNetwork(controller, cidr);
                /*String[] maskInfo = StringUtils.splitByWholeSeparator(cidr, "/");
                    SubnetType subnet = new SubnetType();
                    subnet.setIpPrefix(maskInfo[0]);
                    subnet.setIpPrefixLen(Integer.parseInt(maskInfo[1]));
                    */
                String netName = projectName + ":" + controller.getManager().getCanonicalName(net);
                dstList.add(new PolicyRuleType.AddressType(null, netName, null));
            }
            dstPorts.add(new PolicyRuleType.PortType(portStart, portEnd));
            srcList.add(new PolicyRuleType.AddressType(null, "local", null));
            srcPorts.add(new PolicyRuleType.PortType(0, 65535));
        } else {
            for (String cidr : cidrList) {
                NetworkVO net = cidrToNetwork(controller, cidr);
                String netName = projectName + ":" + controller.getManager().getCanonicalName(net);
                srcList.add(new PolicyRuleType.AddressType(null, netName, null));
            }
            dstPorts.add(new PolicyRuleType.PortType(portStart, portEnd));
            dstList.add(new PolicyRuleType.AddressType(null, "local", null));
            srcPorts.add(new PolicyRuleType.PortType(0, 65535));
        }
        PolicyRuleType vnRule = new PolicyRuleType(new PolicyRuleType.SequenceType(1, 0), rule.getUuid(), "<>", protocol, srcList, srcPorts, null, dstList, dstPorts, new PolicyRuleType.ActionListType(action, null, null, null));
        policyMap.addPolicyRule(vnRule);
    }
    _policyMap = policyMap;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PolicyEntriesType(net.juniper.contrail.api.types.PolicyEntriesType) ArrayList(java.util.ArrayList) PolicyRuleType(net.juniper.contrail.api.types.PolicyEntriesType.PolicyRuleType) NetworkACLItem(com.cloud.network.vpc.NetworkACLItem)

Aggregations

NetworkVO (com.cloud.network.dao.NetworkVO)230 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)108 ArrayList (java.util.ArrayList)79 Test (org.junit.Test)56 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)55 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)49 Account (com.cloud.user.Account)44 Network (com.cloud.network.Network)39 DataCenterVO (com.cloud.dc.DataCenterVO)35 DataCenter (com.cloud.dc.DataCenter)34 NicVO (com.cloud.vm.NicVO)33 NicProfile (com.cloud.vm.NicProfile)27 HostVO (com.cloud.host.HostVO)24 NetworkOffering (com.cloud.offering.NetworkOffering)24 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)22 ReservationContext (com.cloud.vm.ReservationContext)22 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)20 DeployDestination (com.cloud.deploy.DeployDestination)19 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)19 NetworkGuru (com.cloud.network.guru.NetworkGuru)19