Search in sources :

Example 16 with Vpc

use of com.cloud.network.vpc.Vpc in project cloudstack by apache.

the class BigSwitchBcfElement method applyStaticNats.

@Override
public boolean applyStaticNats(Network network, List<? extends StaticNat> rules) throws ResourceUnavailableException {
    bcfUtilsInit();
    _bcfUtils.listACLbyNetwork(network);
    Vpc vpc = null;
    if (network.getVpcId() != null) {
        vpc = _vpcDao.acquireInLockTable(network.getVpcId());
    }
    String tenantId;
    if (vpc != null) {
        tenantId = vpc.getUuid();
        _vpcDao.releaseFromLockTable(vpc.getId());
    } else {
        // use account in CS as tenant in BSN
        // use network uuid as tenantId for non-VPC networks
        tenantId = network.getUuid();
    }
    for (StaticNat rule : rules) {
        String srcIp = _ipAddressDao.findById(rule.getSourceIpAddressId()).getAddress().addr();
        String dstIp = rule.getDestIpAddress();
        String mac = rule.getSourceMacAddress();
        if (!rule.isForRevoke()) {
            s_logger.debug("BCF enables static NAT for public IP: " + srcIp + " private IP " + dstIp + " mac " + mac);
            CreateBcfStaticNatCommand cmd = new CreateBcfStaticNatCommand(tenantId, network.getUuid(), dstIp, srcIp, mac);
            _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd, network);
        } else {
            s_logger.debug("BCF removes static NAT for public IP: " + srcIp + " private IP " + dstIp + " mac " + mac);
            DeleteBcfStaticNatCommand cmd = new DeleteBcfStaticNatCommand(tenantId, srcIp);
            _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd, network);
        }
    }
    return true;
}
Also used : DeleteBcfStaticNatCommand(com.cloud.agent.api.DeleteBcfStaticNatCommand) CreateBcfStaticNatCommand(com.cloud.agent.api.CreateBcfStaticNatCommand) Vpc(com.cloud.network.vpc.Vpc) StaticNat(com.cloud.network.rules.StaticNat)

Example 17 with Vpc

use of com.cloud.network.vpc.Vpc in project cloudstack by apache.

the class BigSwitchBcfGuestNetworkGuru 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;
    bcfUtilsInit();
    long dcId = dest.getDataCenter().getId();
    long 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, false);
    if (network.getGateway() != null) {
        implemented.setGateway(network.getGateway());
    }
    if (network.getCidr() != null) {
        implemented.setCidr(network.getCidr());
    }
    String vnetId = "";
    if (network.getBroadcastUri() == null) {
        vnetId = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), context.getReservationId(), UseSystemGuestVlans.valueIn(network.getAccountId()));
        if (vnetId == null) {
            throw new InsufficientVirtualNetworkCapacityException("Unable to allocate vnet as a " + "part of network " + network + " implement ", DataCenter.class, dcId);
        }
        implemented.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vnetId));
        ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), network.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_ASSIGN, "Assigned Zone Vlan: " + vnetId + " Network Id: " + network.getId(), 0);
    } else {
        implemented.setBroadcastUri(network.getBroadcastUri());
    }
    // Name is either the given name or the uuid
    String name = network.getName();
    if (name == null || name.isEmpty()) {
        name = ((NetworkVO) network).getUuid();
    }
    if (name.length() > 64) {
        // max length 64
        name = name.substring(0, 63);
    }
    // update fields in network object
    NetworkVO networkObject = (NetworkVO) network;
    // determine whether this is VPC network or stand-alone network
    Vpc vpc = null;
    if (network.getVpcId() != null) {
        vpc = _vpcDao.acquireInLockTable(network.getVpcId());
    }
    // use uuid of networkVO as network id in BSN
    String networkId = networkObject.getUuid();
    String tenantId;
    String tenantName;
    if (vpc != null) {
        tenantId = vpc.getUuid();
        tenantName = vpc.getName();
        _vpcDao.releaseFromLockTable(vpc.getId());
    } else {
        // use network in CS as tenant in BSN
        // for non-VPC networks, use network name and id as tenant name and id
        tenantId = networkId;
        tenantName = name;
    }
    // store tenantId in networkObject for NetworkOrchestrator implementNetwork use
    networkObject.setNetworkDomain(tenantId);
    // store tenant Id in implemented object for future actions (e.g., shutdown)
    implemented.setNetworkDomain(tenantId);
    String vlanStr = BroadcastDomainType.getValue(implemented.getBroadcastUri());
    // get public net info - needed to set up source nat gateway
    NetworkVO pubNet = _bcfUtils.getPublicNetwork(physicalNetworkId);
    // locate subnet info
    SearchCriteria<VlanVO> sc = _vlanDao.createSearchCriteria();
    sc.setParameters("network_id", pubNet.getId());
    VlanVO pubVlanVO = _vlanDao.findOneBy(sc);
    String pubVlanStr = pubVlanVO.getVlanTag();
    Integer vlan;
    if (StringUtils.isNumeric(vlanStr)) {
        vlan = Integer.valueOf(vlanStr);
    } else {
        vlan = 0;
    }
    CreateBcfSegmentCommand cmd1 = new CreateBcfSegmentCommand(tenantId, tenantName, networkId, name, vlan);
    _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd1, networkObject);
    if (_bcfUtils.isNatEnabled()) {
        Integer pvlan;
        if (StringUtils.isNumeric(pubVlanStr)) {
            pvlan = Integer.valueOf(pubVlanStr);
        } else {
            pvlan = 0;
        }
        CreateBcfSegmentCommand cmd2 = new CreateBcfSegmentCommand("external", "external", "external", "external", pvlan);
        _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd2, networkObject);
        CreateBcfRouterCommand cmd3 = new CreateBcfRouterCommand(tenantId);
        _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd3, network);
        CreateBcfRouterInterfaceCommand cmd5 = new CreateBcfRouterInterfaceCommand(tenantId, network.getUuid(), network.getCidr(), network.getGateway(), network.getName());
        _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd5, network);
    }
    return implemented;
}
Also used : CreateBcfSegmentCommand(com.cloud.agent.api.CreateBcfSegmentCommand) CreateBcfRouterCommand(com.cloud.agent.api.CreateBcfRouterCommand) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) CreateBcfRouterInterfaceCommand(com.cloud.agent.api.CreateBcfRouterInterfaceCommand) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) Vpc(com.cloud.network.vpc.Vpc) VlanVO(com.cloud.dc.VlanVO)

Example 18 with Vpc

use of com.cloud.network.vpc.Vpc in project cloudstack by apache.

the class BigSwitchBcfElement method updateBcfRouter.

private void updateBcfRouter(Network network) throws IllegalArgumentException {
    bcfUtilsInit();
    Vpc vpc = null;
    if (network.getVpcId() != null) {
        vpc = _vpcDao.acquireInLockTable(network.getVpcId());
    }
    String tenantId;
    if (vpc != null) {
        tenantId = vpc.getUuid();
        _vpcDao.releaseFromLockTable(vpc.getId());
    } else {
        tenantId = network.getUuid();
    }
    UpdateBcfRouterCommand cmd = new UpdateBcfRouterCommand(tenantId);
    List<AclData> aclList = _bcfUtils.listACLbyNetwork(network);
    for (AclData acl : aclList) {
        cmd.addAcl(acl);
    }
    if (vpc != null) {
        cmd.setPublicIp(_bcfUtils.getPublicIpByVpc(vpc));
    } else {
        cmd.setPublicIp(_bcfUtils.getPublicIpByNetwork(network));
    }
    BcfAnswer answer = _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd, network);
    if (answer != null && !answer.getResult()) {
        throw new IllegalArgumentException("Illegal router update arguments");
    }
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) AclData(com.cloud.network.bigswitch.AclData) Vpc(com.cloud.network.vpc.Vpc) UpdateBcfRouterCommand(com.cloud.agent.api.UpdateBcfRouterCommand)

Example 19 with Vpc

use of com.cloud.network.vpc.Vpc in project cloudstack by apache.

the class BigSwitchBcfElement method prepare.

@Override
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    if (!canHandle(network, Service.Connectivity)) {
        return false;
    }
    bcfUtilsInit();
    // get arguments for CreateBcfAttachmentCommand
    // determine whether this is VPC network or stand-alone network
    Vpc vpc = null;
    if (network.getVpcId() != null) {
        vpc = _vpcDao.acquireInLockTable(network.getVpcId());
    }
    String tenantId;
    String tenantName;
    if (vpc != null) {
        tenantId = vpc.getUuid();
        tenantName = vpc.getName();
        _vpcDao.releaseFromLockTable(vpc.getId());
    } else {
        // use account in CS as tenant in BSN
        // use network id/name as tenant id/name for non-VPC networks
        tenantId = network.getUuid();
        tenantName = network.getName();
    }
    String networkId = network.getUuid();
    String hostname = dest.getHost().getName();
    String nicId = nic.getUuid();
    Integer vlan = Integer.valueOf(BroadcastDomainType.getValue(nic.getIsolationUri()));
    String ipv4 = nic.getIPv4Address();
    String mac = nic.getMacAddress();
    long zoneId = network.getDataCenterId();
    String vmwareVswitchLabel = _networkModel.getDefaultGuestTrafficLabel(zoneId, HypervisorType.VMware);
    String[] labelArray = null;
    String vswitchName = null;
    if (vmwareVswitchLabel != null) {
        labelArray = vmwareVswitchLabel.split(",");
        vswitchName = labelArray[0];
    }
    // hypervisor type:
    //   kvm: ivs port name
    //   vmware: specific portgroup naming convention
    String pgName = "";
    if (dest.getHost().getHypervisorType() == HypervisorType.KVM) {
        pgName = hostname;
    } else if (dest.getHost().getHypervisorType() == HypervisorType.VMware) {
        pgName = hostname + "-" + vswitchName;
    }
    CreateBcfAttachmentCommand cmd = new CreateBcfAttachmentCommand(tenantId, tenantName, networkId, pgName, nicId, vlan, ipv4, mac);
    _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd, network);
    return true;
}
Also used : CreateBcfAttachmentCommand(com.cloud.agent.api.CreateBcfAttachmentCommand) Vpc(com.cloud.network.vpc.Vpc)

Example 20 with Vpc

use of com.cloud.network.vpc.Vpc in project cloudstack by apache.

the class UpdateVPCCmdByAdmin method execute.

@Override
public void execute() {
    Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText(), getCustomId(), getDisplayVpc());
    if (result != null) {
        VpcResponse response = _responseGenerator.createVpcResponse(ResponseView.Full, result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update VPC");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) VpcResponse(org.apache.cloudstack.api.response.VpcResponse) Vpc(com.cloud.network.vpc.Vpc)

Aggregations

Vpc (com.cloud.network.vpc.Vpc)45 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)12 DomainRouterVO (com.cloud.vm.DomainRouterVO)10 ArrayList (java.util.ArrayList)10 DataCenter (com.cloud.dc.DataCenter)9 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 Account (com.cloud.user.Account)7 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)6 Network (com.cloud.network.Network)6 NetworkVO (com.cloud.network.dao.NetworkVO)6 VpcResponse (org.apache.cloudstack.api.response.VpcResponse)6 IpAddress (com.cloud.network.IpAddress)5 PublicIpAddress (com.cloud.network.PublicIpAddress)5 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)5 ServerApiException (org.apache.cloudstack.api.ServerApiException)5 DataCenterVO (com.cloud.dc.DataCenterVO)4 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4 Capability (com.cloud.network.Network.Capability)4 HashMap (java.util.HashMap)4 VlanVO (com.cloud.dc.VlanVO)3