Search in sources :

Example 21 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 22 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)

Example 23 with NetworkVO

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

the class ServerDBSyncImpl method syncVirtualNetwork.

/*
     *  Virtual Network Synchronization methods
     */
@SuppressWarnings({ "unchecked" })
public boolean syncVirtualNetwork() throws Exception {
    final ApiConnector api = _manager.getApiConnector();
    try {
        List<TrafficType> types = new ArrayList<TrafficType>();
        types.add(TrafficType.Public);
        types.add(TrafficType.Guest);
        List<NetworkVO> dbNets = _manager.findManagedNetworks(types);
        List<VirtualNetwork> vList = (List<VirtualNetwork>) api.list(VirtualNetwork.class, null);
        List<VirtualNetwork> vncList = new ArrayList<VirtualNetwork>();
        for (VirtualNetwork vn : vList) {
            if (!_manager.isSystemDefaultNetwork(vn)) {
                vncList.add(vn);
            }
        }
        s_logger.debug("sync VN - DB size: " + dbNets.size() + " VNC Size: " + vncList.size());
        return _dbSync.syncGeneric(VirtualNetwork.class, dbNets, vncList);
    } catch (Exception ex) {
        s_logger.warn("sync virtual-networks", ex);
        throw ex;
    }
}
Also used : VirtualNetwork(net.juniper.contrail.api.types.VirtualNetwork) NetworkVO(com.cloud.network.dao.NetworkVO) ApiConnector(net.juniper.contrail.api.ApiConnector) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException) TrafficType(com.cloud.network.Networks.TrafficType)

Example 24 with NetworkVO

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

the class OpendaylightGuestNetworkGuru method release.

@Override
public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) {
    boolean success = super.release(nic, vm, reservationId);
    if (success) {
        //get physical network id
        NetworkVO network = _networkDao.findById(nic.getNetworkId());
        Long physicalNetworkId = network.getPhysicalNetworkId();
        List<OpenDaylightControllerVO> devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physicalNetworkId);
        if (devices.isEmpty()) {
            s_logger.error("No Controller on physical network " + physicalNetworkId);
            throw new CloudRuntimeException("No OpenDaylight controller on this physical network");
        }
        OpenDaylightControllerVO controller = devices.get(0);
        DestroyPortCommand cmd = new DestroyPortCommand(UUID.fromString(nic.getUuid()));
        DestroyPortAnswer answer = (DestroyPortAnswer) agentManager.easySend(controller.getHostId(), cmd);
        if (answer == null || !answer.getResult()) {
            s_logger.error("DestroyPortCommand failed");
            success = false;
        }
    }
    return success;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DestroyPortCommand(org.apache.cloudstack.network.opendaylight.agent.commands.DestroyPortCommand) DestroyPortAnswer(org.apache.cloudstack.network.opendaylight.agent.responses.DestroyPortAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) OpenDaylightControllerVO(org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO)

Example 25 with NetworkVO

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

the class OpendaylightGuestNetworkGuru method implement.

@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
    assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
    long dcId = dest.getDataCenter().getId();
    //get physical network id
    Long physicalNetworkId = network.getPhysicalNetworkId();
    // physical network id can be null in Guest Network in Basic zone, so locate the physical network
    if (physicalNetworkId == null) {
        physicalNetworkId = networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
    }
    NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated, network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
    if (network.getGateway() != null) {
        implemented.setGateway(network.getGateway());
    }
    if (network.getCidr() != null) {
        implemented.setCidr(network.getCidr());
    }
    // Name is either the given name or the uuid
    String name = network.getName();
    if (name == null || name.isEmpty()) {
        name = ((NetworkVO) network).getUuid();
    }
    List<OpenDaylightControllerVO> devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physicalNetworkId);
    if (devices.isEmpty()) {
        s_logger.error("No Controller on physical network " + physicalNetworkId);
        return null;
    }
    OpenDaylightControllerVO controller = devices.get(0);
    ConfigureNetworkCommand cmd = new ConfigureNetworkCommand(name, context.getAccount().getAccountName());
    ConfigureNetworkAnswer answer = (ConfigureNetworkAnswer) agentManager.easySend(controller.getHostId(), cmd);
    if (answer == null || !answer.getResult()) {
        s_logger.error("ConfigureNetworkCommand failed");
        return null;
    }
    implemented.setBroadcastUri(BroadcastDomainType.OpenDaylight.toUri(answer.getNetworkUuid()));
    implemented.setBroadcastDomainType(BroadcastDomainType.OpenDaylight);
    s_logger.info("Implemented OK, network linked to  = " + implemented.getBroadcastUri().toString());
    return implemented;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ConfigureNetworkAnswer(org.apache.cloudstack.network.opendaylight.agent.responses.ConfigureNetworkAnswer) ConfigureNetworkCommand(org.apache.cloudstack.network.opendaylight.agent.commands.ConfigureNetworkCommand) OpenDaylightControllerVO(org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO)

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