Search in sources :

Example 11 with TrafficType

use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.

the class DomainRouterJoinDaoImpl method setDomainRouterResponse.

@Override
public DomainRouterResponse setDomainRouterResponse(DomainRouterResponse vrData, DomainRouterJoinVO vr) {
    long nic_id = vr.getNicId();
    if (nic_id > 0) {
        TrafficType ty = vr.getTrafficType();
        if (ty != null) {
            // nics response object
            if (ty == TrafficType.Public) {
                vrData.setPublicIp(vr.getIpAddress());
                vrData.setPublicMacAddress(vr.getMacAddress());
                vrData.setPublicNetmask(vr.getNetmask());
                vrData.setGateway(vr.getGateway());
                vrData.setPublicNetworkId(vr.getNetworkUuid());
            } else if (ty == TrafficType.Control) {
                vrData.setLinkLocalIp(vr.getIpAddress());
                vrData.setLinkLocalMacAddress(vr.getMacAddress());
                vrData.setLinkLocalNetmask(vr.getNetmask());
                vrData.setLinkLocalNetworkId(vr.getNetworkUuid());
            } else if (ty == TrafficType.Guest) {
                vrData.setGuestIpAddress(vr.getIpAddress());
                vrData.setGuestMacAddress(vr.getMacAddress());
                vrData.setGuestNetmask(vr.getNetmask());
                vrData.setGuestNetworkId(vr.getNetworkUuid());
                vrData.setGuestNetworkName(vr.getNetworkName());
                vrData.setNetworkDomain(vr.getNetworkDomain());
            }
        }
        NicResponse nicResponse = new NicResponse();
        nicResponse.setId(vr.getNicUuid());
        nicResponse.setIpaddress(vr.getIpAddress());
        nicResponse.setGateway(vr.getGateway());
        nicResponse.setNetmask(vr.getNetmask());
        nicResponse.setNetworkid(vr.getNetworkUuid());
        nicResponse.setNetworkName(vr.getNetworkName());
        nicResponse.setMacAddress(vr.getMacAddress());
        nicResponse.setIp6Address(vr.getIp6Address());
        nicResponse.setIp6Gateway(vr.getIp6Gateway());
        nicResponse.setIp6Cidr(vr.getIp6Cidr());
        if (vr.getBroadcastUri() != null) {
            nicResponse.setBroadcastUri(vr.getBroadcastUri().toString());
        }
        if (vr.getIsolationUri() != null) {
            nicResponse.setIsolationUri(vr.getIsolationUri().toString());
        }
        if (vr.getTrafficType() != null) {
            nicResponse.setTrafficType(vr.getTrafficType().toString());
        }
        if (vr.getGuestType() != null) {
            nicResponse.setType(vr.getGuestType().toString());
        }
        nicResponse.setIsDefault(vr.isDefaultNic());
        nicResponse.setObjectName("nic");
        vrData.addNic(nicResponse);
    }
    return vrData;
}
Also used : TrafficType(com.cloud.network.Networks.TrafficType) NicResponse(org.apache.cloudstack.api.response.NicResponse)

Example 12 with TrafficType

use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.

the class DomainRouterJoinDaoImpl method newDomainRouterResponse.

@Override
public DomainRouterResponse newDomainRouterResponse(DomainRouterJoinVO router, Account caller) {
    DomainRouterResponse routerResponse = new DomainRouterResponse();
    routerResponse.setId(router.getUuid());
    routerResponse.setZoneId(router.getDataCenterUuid());
    routerResponse.setName(router.getName());
    routerResponse.setTemplateId(router.getTemplateUuid());
    routerResponse.setCreated(router.getCreated());
    routerResponse.setState(router.getState());
    routerResponse.setIsRedundantRouter(router.isRedundantRouter());
    routerResponse.setRedundantState(router.getRedundantState().toString());
    if (router.getTemplateVersion() != null) {
        String routerVersion = Version.trimRouterVersion(router.getTemplateVersion());
        routerResponse.setVersion(routerVersion);
        routerResponse.setRequiresUpgrade((Version.compare(routerVersion, NetworkOrchestrationService.MinVRVersion.valueIn(router.getDataCenterId())) < 0));
    } else {
        routerResponse.setVersion("UNKNOWN");
        routerResponse.setRequiresUpgrade(true);
    }
    if (caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN || _accountMgr.isRootAdmin(caller.getId())) {
        if (router.getHostId() != null) {
            routerResponse.setHostId(router.getHostUuid());
            routerResponse.setHostName(router.getHostName());
            routerResponse.setHypervisor(router.getHypervisorType().toString());
        }
        routerResponse.setPodId(router.getPodUuid());
        long nic_id = router.getNicId();
        if (nic_id > 0) {
            TrafficType ty = router.getTrafficType();
            if (ty != null) {
                // nics response object
                if (ty == TrafficType.Public) {
                    routerResponse.setPublicIp(router.getIpAddress());
                    routerResponse.setPublicMacAddress(router.getMacAddress());
                    routerResponse.setPublicNetmask(router.getNetmask());
                    routerResponse.setGateway(router.getGateway());
                    routerResponse.setPublicNetworkId(router.getNetworkUuid());
                } else if (ty == TrafficType.Control) {
                    routerResponse.setLinkLocalIp(router.getIpAddress());
                    routerResponse.setLinkLocalMacAddress(router.getMacAddress());
                    routerResponse.setLinkLocalNetmask(router.getNetmask());
                    routerResponse.setLinkLocalNetworkId(router.getNetworkUuid());
                } else if (ty == TrafficType.Guest) {
                    routerResponse.setGuestIpAddress(router.getIpAddress());
                    routerResponse.setGuestMacAddress(router.getMacAddress());
                    routerResponse.setGuestNetmask(router.getNetmask());
                    routerResponse.setGuestNetworkId(router.getNetworkUuid());
                    routerResponse.setGuestNetworkName(router.getNetworkName());
                    routerResponse.setNetworkDomain(router.getNetworkDomain());
                }
            }
            NicResponse nicResponse = new NicResponse();
            nicResponse.setId(router.getNicUuid());
            nicResponse.setIpaddress(router.getIpAddress());
            nicResponse.setGateway(router.getGateway());
            nicResponse.setNetmask(router.getNetmask());
            nicResponse.setNetworkid(router.getNetworkUuid());
            nicResponse.setNetworkName(router.getNetworkName());
            nicResponse.setMacAddress(router.getMacAddress());
            nicResponse.setIp6Address(router.getIp6Address());
            nicResponse.setIp6Gateway(router.getIp6Gateway());
            nicResponse.setIp6Cidr(router.getIp6Cidr());
            if (router.getBroadcastUri() != null) {
                nicResponse.setBroadcastUri(router.getBroadcastUri().toString());
            }
            if (router.getIsolationUri() != null) {
                nicResponse.setIsolationUri(router.getIsolationUri().toString());
            }
            if (router.getTrafficType() != null) {
                nicResponse.setTrafficType(router.getTrafficType().toString());
            }
            if (router.getGuestType() != null) {
                nicResponse.setType(router.getGuestType().toString());
            }
            nicResponse.setIsDefault(router.isDefaultNic());
            nicResponse.setObjectName("nic");
            routerResponse.addNic(nicResponse);
        }
    }
    routerResponse.setServiceOfferingId(router.getServiceOfferingUuid());
    routerResponse.setServiceOfferingName(router.getServiceOfferingName());
    // populate owner.
    ApiResponseHelper.populateOwner(routerResponse, router);
    routerResponse.setDomainId(router.getDomainUuid());
    routerResponse.setDomainName(router.getDomainName());
    routerResponse.setZoneName(router.getDataCenterName());
    routerResponse.setDns1(router.getDns1());
    routerResponse.setDns2(router.getDns2());
    routerResponse.setIp6Dns1(router.getIp6Dns1());
    routerResponse.setIp6Dns2(router.getIp6Dns2());
    routerResponse.setVpcId(router.getVpcUuid());
    routerResponse.setVpcName(router.getVpcName());
    routerResponse.setRole(router.getRole().toString());
    // set async job
    if (router.getJobId() != null) {
        routerResponse.setJobId(router.getJobUuid());
        routerResponse.setJobStatus(router.getJobStatus());
    }
    if (router.getRole() == Role.INTERNAL_LB_VM) {
        routerResponse.setObjectName("internalloadbalancervm");
    } else {
        routerResponse.setObjectName("router");
    }
    return routerResponse;
}
Also used : DomainRouterResponse(org.apache.cloudstack.api.response.DomainRouterResponse) TrafficType(com.cloud.network.Networks.TrafficType) NicResponse(org.apache.cloudstack.api.response.NicResponse)

Example 13 with TrafficType

use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.

the class PodBasedNetworkGuru method design.

@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
    TrafficType type = offering.getTrafficType();
    if (!isMyTrafficType(type)) {
        return null;
    }
    NetworkVO config = new NetworkVO(type, Mode.Static, BroadcastDomainType.Native, offering.getId(), Network.State.Setup, plan.getDataCenterId(), plan.getPhysicalNetworkId(), offering.getRedundantRouter());
    return config;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) TrafficType(com.cloud.network.Networks.TrafficType)

Example 14 with TrafficType

use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.

the class PodZoneConfig method savePhysicalNetwork.

@DB
public void savePhysicalNetwork(boolean printOutput, long id, long dcId, int vnetStart, int vnetEnd) {
    if (printOutput)
        System.out.println("Saving physical network, please wait...");
    String columns = null;
    String values = null;
    columns = "(id ";
    values = "('" + id + "'";
    columns += ", name ";
    values += ",'physical network'";
    columns += ", data_center_id ";
    values += ",'" + dcId + "'";
    //save vnet information
    columns += ", vnet";
    values += ",'" + vnetStart + "-" + vnetEnd + "'";
    columns += ", state";
    values += ", 'Enabled'";
    columns += ", uuid";
    values += ", UUID()";
    columns += ")";
    values += ")";
    String sql = "INSERT INTO `cloud`.`physical_network` " + columns + " VALUES " + values;
    DatabaseConfig.saveSQL(sql, "Failed to save physical network due to exception. Please contact Cloud Support.");
    // Hardcode the vnet range to be the full range
    int begin = 0x64;
    int end = 64000;
    // If vnet arguments were passed in, use them
    if (vnetStart != -1 && vnetEnd != -1) {
        begin = vnetStart;
        end = vnetEnd;
    }
    String insertVnet = "INSERT INTO `cloud`.`op_dc_vnet_alloc` (vnet, data_center_id, physical_network_id) VALUES ( ?, ?, ?)";
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    try {
        PreparedStatement stmt = txn.prepareAutoCloseStatement(insertVnet);
        for (int i = begin; i <= end; i++) {
            stmt.setString(1, Integer.toString(i));
            stmt.setLong(2, dcId);
            stmt.setLong(3, id);
            stmt.addBatch();
        }
        stmt.executeBatch();
    } catch (SQLException ex) {
        printError("Error creating vnet for the physical network. Please contact Cloud Support.");
    }
    //add default traffic types
    //get default Xen network labels
    String defaultXenPrivateNetworkLabel = getDefaultXenNetworkLabel(TrafficType.Management);
    String defaultXenPublicNetworkLabel = getDefaultXenNetworkLabel(TrafficType.Public);
    String defaultXenStorageNetworkLabel = getDefaultXenNetworkLabel(TrafficType.Storage);
    String defaultXenGuestNetworkLabel = getDefaultXenNetworkLabel(TrafficType.Guest);
    String insertTraficType = "INSERT INTO `cloud`.`physical_network_traffic_types` " + "(physical_network_id, traffic_type, xenserver_network_label) VALUES ( ?, ?, ?)";
    try {
        PreparedStatement stmt = txn.prepareAutoCloseStatement(insertTraficType);
        for (TrafficType traffic : TrafficType.values()) {
            if (traffic.equals(TrafficType.Control) || traffic.equals(TrafficType.Vpn) || traffic.equals(TrafficType.None)) {
                continue;
            }
            stmt.setLong(1, id);
            stmt.setString(2, traffic.toString());
            if (traffic.equals(TrafficType.Public)) {
                stmt.setString(3, defaultXenPublicNetworkLabel);
            } else if (traffic.equals(TrafficType.Management)) {
                stmt.setString(3, defaultXenPrivateNetworkLabel);
            } else if (traffic.equals(TrafficType.Storage)) {
                stmt.setString(3, defaultXenStorageNetworkLabel);
            } else if (traffic.equals(TrafficType.Guest)) {
                stmt.setString(3, defaultXenGuestNetworkLabel);
            }
            stmt.addBatch();
        }
        stmt.executeBatch();
    } catch (SQLException ex) {
        printError("Error adding default traffic types for the physical network. Please contact Cloud Support.");
    }
    if (printOutput)
        System.out.println("Successfully saved physical network.");
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) TrafficType(com.cloud.network.Networks.TrafficType) DB(com.cloud.utils.db.DB)

Example 15 with TrafficType

use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.

the class SecondaryStorageManagerImpl method getDefaultNetworkForAdvancedZone.

/**
     * Get default network for a secondary storage VM starting up in an advanced zone. If the zone
     * is security group-enabled, the first network found that supports SG services is returned.
     * If the zone is not SG-enabled, the Public network is returned.
     * @param dc - The zone.
     * @return The selected default network.
     * @throws CloudRuntimeException - If the zone is not a valid choice or a network couldn't be found.
     */
protected NetworkVO getDefaultNetworkForAdvancedZone(DataCenter dc) {
    if (dc.getNetworkType() != NetworkType.Advanced) {
        throw new CloudRuntimeException("Zone " + dc + " is not advanced.");
    }
    if (dc.isSecurityGroupEnabled()) {
        List<NetworkVO> networks = _networkDao.listByZoneSecurityGroup(dc.getId());
        if (CollectionUtils.isEmpty(networks)) {
            throw new CloudRuntimeException("Can not found security enabled network in SG Zone " + dc);
        }
        return networks.get(0);
    } else {
        TrafficType defaultTrafficType = TrafficType.Public;
        List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dc.getId(), defaultTrafficType);
        // api should never allow this situation to happen
        if (defaultNetworks.size() != 1) {
            throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
        }
        return defaultNetworks.get(0);
    }
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TrafficType(com.cloud.network.Networks.TrafficType)

Aggregations

TrafficType (com.cloud.network.Networks.TrafficType)26 NetworkVO (com.cloud.network.dao.NetworkVO)13 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)6 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 Pair (com.cloud.utils.Pair)3 ConfigurationException (javax.naming.ConfigurationException)3 Test (org.junit.Test)3 ActionEvent (com.cloud.event.ActionEvent)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 NetworkOffering (com.cloud.offering.NetworkOffering)2 DB (com.cloud.utils.db.DB)2 IOException (java.io.IOException)2 Map (java.util.Map)2 NicResponse (org.apache.cloudstack.api.response.NicResponse)2 ListResponse (com.cloud.api.response.ListResponse)1 TrafficTypeImplementorResponse (com.cloud.api.response.TrafficTypeImplementorResponse)1 DataCenterVO (com.cloud.dc.DataCenterVO)1 CloudException (com.cloud.exception.CloudException)1