Package com.cloud.network.nicira

Examples of com.cloud.network.nicira.LogicalSwitchPort


        try {
            // Tags set to scope cs_account and account name
            List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>();
            tags.add(new NiciraNvpTag("cs_account",cmd.getOwnerName()));

            LogicalSwitchPort logicalSwitchPort = new LogicalSwitchPort(attachmentUuid, tags, true);
            LogicalSwitchPort newPort = _niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, logicalSwitchPort);
            try {
                _niciraNvpApi.modifyLogicalSwitchPortAttachment(cmd.getLogicalSwitchUuid(), newPort.getUuid(), new VifAttachment(attachmentUuid));
            } catch (NiciraNvpApiException ex) {
                s_logger.warn("modifyLogicalSwitchPort failed after switchport was created, removing switchport");
                _niciraNvpApi.deleteLogicalSwitchPort(cmd.getLogicalSwitchUuid(), newPort.getUuid());
                throw (ex); // Rethrow the original exception
            }
            return new CreateLogicalSwitchPortAnswer(cmd, true, "Logical switch port " + newPort.getUuid() + " created", newPort.getUuid());
        } catch (NiciraNvpApiException e) {
            if (numRetries > 0) {
                return retry(cmd, --numRetries);
            }
            else {
View Full Code Here


            lrc.setRoutingConfig(new SingleDefaultRouteImplictRoutingConfig(
                    new RouterNextHop(publicNetworkNextHopIp)));
            lrc = _niciraNvpApi.createLogicalRouter(lrc);

            // store the switchport for rollback
            LogicalSwitchPort lsp = null;

            try {
                // Create the outside port for the router
                LogicalRouterPort lrpo = new LogicalRouterPort();
                lrpo.setAdminStatusEnabled(true);
                lrpo.setDisplayName(truncate(routerName + "-outside-port", 40));
                lrpo.setTags(tags);
                List<String> outsideIpAddresses = new ArrayList<String>();
                outsideIpAddresses.add(publicNetworkIpAddress);
                lrpo.setIpAddresses(outsideIpAddresses);
                lrpo = _niciraNvpApi.createLogicalRouterPort(lrc.getUuid(),lrpo);

                // Attach the outside port to the gateway service on the correct VLAN
                L3GatewayAttachment attachment = new L3GatewayAttachment(gatewayServiceUuid);
                if (cmd.getVlanId() != 0) {
                    attachment.setVlanId(cmd.getVlanId());
                }
                _niciraNvpApi.modifyLogicalRouterPortAttachment(lrc.getUuid(), lrpo.getUuid(), attachment);

                // Create the inside port for the router
                LogicalRouterPort lrpi = new LogicalRouterPort();
                lrpi.setAdminStatusEnabled(true);
                lrpi.setDisplayName(truncate(routerName + "-inside-port", 40));
                lrpi.setTags(tags);
                List<String> insideIpAddresses = new ArrayList<String>();
                insideIpAddresses.add(internalNetworkAddress);
                lrpi.setIpAddresses(insideIpAddresses);
                lrpi = _niciraNvpApi.createLogicalRouterPort(lrc.getUuid(),lrpi);

                // Create the inside port on the lswitch
                lsp = new LogicalSwitchPort(truncate(routerName + "-inside-port", 40), tags, true);
                lsp = _niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, lsp);

                // Attach the inside router port to the lswitch port with a PatchAttachment
                _niciraNvpApi.modifyLogicalRouterPortAttachment(lrc.getUuid(), lrpi.getUuid(),
                        new PatchAttachment(lsp.getUuid()));

                // Attach the inside lswitch port to the router with a PatchAttachment
                _niciraNvpApi.modifyLogicalSwitchPortAttachment(logicalSwitchUuid, lsp.getUuid(),
                        new PatchAttachment(lrpi.getUuid()));

                // Setup the source nat rule
                SourceNatRule snr = new SourceNatRule();
                snr.setToSourceIpAddressMin(publicNetworkIpAddress.split("/")[0]);
                snr.setToSourceIpAddressMax(publicNetworkIpAddress.split("/")[0]);
                Match match = new Match();
                match.setSourceIpAddresses(internalNetworkAddress);
                snr.setMatch(match);
                snr.setOrder(200);
                _niciraNvpApi.createLogicalRouterNatRule(lrc.getUuid(), snr);
            } catch (NiciraNvpApiException e) {
                // We need to destroy the router if we already created it
                // this will also take care of any router ports and rules
                try {
                    _niciraNvpApi.deleteLogicalRouter(lrc.getUuid());
                    if (lsp != null) {
                        _niciraNvpApi.deleteLogicalSwitchPort(logicalSwitchUuid, lsp.getUuid());
                    }
                } catch (NiciraNvpApiException ex) {}

                throw e;
            }
View Full Code Here

TOP

Related Classes of com.cloud.network.nicira.LogicalSwitchPort

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.