http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SecurityRule.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SecurityRule.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SecurityRule.java deleted file mode 100644 index e23593c..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SecurityRule.java +++ /dev/null @@ -1,138 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.nicira; - -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; - -@SuppressWarnings("serial") -public class SecurityRule extends AccessRule { - - protected String ipPrefix; - - protected int portRangeMin; - - protected int portRangeMax; - - protected String profileUuid; - - - /** - * Default constructor - */ - public SecurityRule() { - } - - /** - * Fully parameterized constructor - */ - public SecurityRule(final String ethertype, final String ipPrefix, final String profileUuid, - final int portRangeMin, final int portRangeMax, final int protocol) { - this.ethertype = ethertype; - this.ipPrefix = ipPrefix; - this.portRangeMin = portRangeMin; - this.portRangeMax = portRangeMax; - this.profileUuid = profileUuid; - this.protocol = protocol; - } - - @Override - public String getEthertype() { - return ethertype; - } - - @Override - public void setEthertype(final String ethertype) { - this.ethertype = ethertype; - } - - public String getIpPrefix() { - return ipPrefix; - } - - public void setIpPrefix(final String ipPrefix) { - this.ipPrefix = ipPrefix; - } - - public int getPortRangeMin() { - return portRangeMin; - } - - public void setPortRangeMin(final int portRangeMin) { - this.portRangeMin = portRangeMin; - } - - public int getPortRangeMax() { - return portRangeMax; - } - - public void setPortRangeMax(final int portRangeMax) { - this.portRangeMax = portRangeMax; - } - - public String getProfileUuid() { - return profileUuid; - } - - public void setProfileUuid(final String profileUuid) { - this.profileUuid = profileUuid; - } - - @Override - public int getProtocol() { - return protocol; - } - - @Override - public void setProtocol(final int protocol) { - this.protocol = protocol; - } - - @Override - public int hashCode() { - return new HashCodeBuilder(17, 31) - .append(ethertype).append(ipPrefix) - .append(portRangeMin).append(portRangeMax) - .append(profileUuid).append(protocol) - .toHashCode(); - } - - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (obj == this) { - return true; - } - if (!(obj instanceof SecurityRule)) { - return false; - } - final SecurityRule another = (SecurityRule) obj; - return new EqualsBuilder() - .append(ethertype, another.ethertype) - .append(ipPrefix, another.ipPrefix) - .append(portRangeMin, another.portRangeMin) - .append(portRangeMax, another.portRangeMax) - .append(profileUuid, another.profileUuid) - .append(protocol, another.protocol) - .isEquals(); - } -}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SingleDefaultRouteImplicitRoutingConfig.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SingleDefaultRouteImplicitRoutingConfig.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SingleDefaultRouteImplicitRoutingConfig.java deleted file mode 100644 index ea5df2c..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SingleDefaultRouteImplicitRoutingConfig.java +++ /dev/null @@ -1,40 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.nicira; - -/** - * - */ -public class SingleDefaultRouteImplicitRoutingConfig extends RoutingConfig { - public RouterNextHop defaultRouteNextHop; - public final String type = "SingleDefaultRouteImplicitRoutingConfig"; - - public SingleDefaultRouteImplicitRoutingConfig(final RouterNextHop routerNextHop) { - defaultRouteNextHop = routerNextHop; - } - - public RouterNextHop getDefaultRouteNextHop() { - return defaultRouteNextHop; - } - - public void setDefaultRouteNextHop(final RouterNextHop defaultRouteNextHop) { - this.defaultRouteNextHop = defaultRouteNextHop; - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SourceNatRule.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SourceNatRule.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SourceNatRule.java deleted file mode 100644 index b95cb9a..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SourceNatRule.java +++ /dev/null @@ -1,119 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.nicira; - -public class SourceNatRule extends NatRule { - private String toSourceIpAddressMax; - private String toSourceIpAddressMin; - private Integer toSourcePort; - - public SourceNatRule() { - setType("SourceNatRule"); - } - - public String getToSourceIpAddressMax() { - return toSourceIpAddressMax; - } - - public void setToSourceIpAddressMax(final String toSourceIpAddressMax) { - this.toSourceIpAddressMax = toSourceIpAddressMax; - } - - public String getToSourceIpAddressMin() { - return toSourceIpAddressMin; - } - - public void setToSourceIpAddressMin(final String toSourceIpAddressMin) { - this.toSourceIpAddressMin = toSourceIpAddressMin; - } - - public Integer getToSourcePort() { - return toSourcePort; - } - - public void setToSourcePort(final Integer toSourcePort) { - this.toSourcePort = toSourcePort; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((toSourceIpAddressMax == null) ? 0 : toSourceIpAddressMax.hashCode()); - result = prime * result + ((toSourceIpAddressMin == null) ? 0 : toSourceIpAddressMin.hashCode()); - result = prime * result + ((toSourcePort == null) ? 0 : toSourcePort.hashCode()); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (!super.equals(obj)) - return false; - if (getClass() != obj.getClass()) - return false; - SourceNatRule other = (SourceNatRule)obj; - if (toSourceIpAddressMax == null) { - if (other.toSourceIpAddressMax != null) - return false; - } else if (!toSourceIpAddressMax.equals(other.toSourceIpAddressMax)) - return false; - if (toSourceIpAddressMin == null) { - if (other.toSourceIpAddressMin != null) - return false; - } else if (!toSourceIpAddressMin.equals(other.toSourceIpAddressMin)) - return false; - if (toSourcePort == null) { - if (other.toSourcePort != null) - return false; - } else if (!toSourcePort.equals(other.toSourcePort)) - return false; - return true; - } - - @Override - public boolean equalsIgnoreUuid(final Object obj) { - if (this == obj) - return true; - if (!super.equalsIgnoreUuid(obj)) - return false; - if (getClass() != obj.getClass()) - return false; - SourceNatRule other = (SourceNatRule)obj; - if (toSourceIpAddressMax == null) { - if (other.toSourceIpAddressMax != null) - return false; - } else if (!toSourceIpAddressMax.equals(other.toSourceIpAddressMax)) - return false; - if (toSourceIpAddressMin == null) { - if (other.toSourceIpAddressMin != null) - return false; - } else if (!toSourceIpAddressMin.equals(other.toSourceIpAddressMin)) - return false; - if (toSourcePort == null) { - if (other.toSourcePort != null) - return false; - } else if (!toSourcePort.equals(other.toSourcePort)) - return false; - return true; - } - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/TransportZoneBinding.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/TransportZoneBinding.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/TransportZoneBinding.java deleted file mode 100644 index c643876..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/TransportZoneBinding.java +++ /dev/null @@ -1,50 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.nicira; - -public class TransportZoneBinding { - private String zoneUuid; - private String transportType; - - public TransportZoneBinding() { - } - - public TransportZoneBinding(String zoneUuid, String transportType) { - this.zoneUuid = zoneUuid; - this.transportType = transportType; - } - - public String getZoneUuid() { - return zoneUuid; - } - - public void setZoneUuid(String zoneUuid) { - this.zoneUuid = zoneUuid; - } - - public String getTransportType() { - return transportType; - } - - public void setTransportType(String transportType) { - this.transportType = transportType; - } - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/VifAttachment.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/VifAttachment.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/VifAttachment.java deleted file mode 100644 index fe7d93a..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/VifAttachment.java +++ /dev/null @@ -1,78 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.nicira; - -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; -import org.apache.commons.lang.builder.ReflectionToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; - -public class VifAttachment extends Attachment { - private final String type = "VifAttachment"; - private String vifUuid; - - public VifAttachment() { - } - - public VifAttachment(final String vifUuid) { - this.vifUuid = vifUuid; - } - - public String getVifUuid() { - return vifUuid; - } - - public void setVifUuid(final String vifUuid) { - this.vifUuid = vifUuid; - } - - public String getType() { - return type; - } - - - @Override - public String toString() { - return ReflectionToStringBuilder.reflectionToString(this, ToStringStyle.DEFAULT_STYLE, false); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(17, 31) - .append(this.getClass()) - .append(vifUuid) - .toHashCode(); - } - - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (obj == this) { - return true; - } - if (!(this.getClass().isInstance(obj))) { - return false; - } - final VifAttachment another = (VifAttachment) obj; - return new EqualsBuilder().append(vifUuid, another.vifUuid).isEquals(); - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpRequestWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpRequestWrapper.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpRequestWrapper.java deleted file mode 100644 index 9d261b2..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpRequestWrapper.java +++ /dev/null @@ -1,77 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.resource; - -import java.util.Hashtable; -import java.util.Set; - -import org.reflections.Reflections; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.Command; -import com.cloud.resource.CommandWrapper; -import com.cloud.resource.RequestWrapper; -import com.cloud.resource.ServerResource; - -public class NiciraNvpRequestWrapper extends RequestWrapper { - - private static NiciraNvpRequestWrapper instance; - - static { - instance = new NiciraNvpRequestWrapper(); - } - - Reflections baseWrappers = new Reflections("com.cloud.network.resource.wrapper"); - @SuppressWarnings("rawtypes") - Set<Class<? extends CommandWrapper>> baseSet = baseWrappers.getSubTypesOf(CommandWrapper.class); - - private NiciraNvpRequestWrapper() { - init(); - } - - @SuppressWarnings("rawtypes") - private void init() { - // NiciraNvpResource commands - final Hashtable<Class<? extends Command>, CommandWrapper> niciraCommands = processAnnotations(baseSet); - - resources.put(NiciraNvpResource.class, niciraCommands); - } - - public static NiciraNvpRequestWrapper getInstance() { - return instance; - } - - @SuppressWarnings({"rawtypes" }) - @Override - public Answer execute(final Command command, final ServerResource serverResource) { - final Class<? extends ServerResource> resourceClass = serverResource.getClass(); - - final Hashtable<Class<? extends Command>, CommandWrapper> resourceCommands = retrieveResource(command, resourceClass); - - CommandWrapper<Command, Answer, ServerResource> commandWrapper = retrieveCommands(command.getClass(), resourceCommands); - - while (commandWrapper == null) { - //Could not find the command in the given resource, will traverse the family tree. - commandWrapper = retryWhenAllFails(command, resourceClass, resourceCommands); - } - - return commandWrapper.execute(command, serverResource); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpResource.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpResource.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpResource.java deleted file mode 100644 index df40db4..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpResource.java +++ /dev/null @@ -1,319 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.resource; - -import java.util.Map; - -import javax.naming.ConfigurationException; - -import org.apache.log4j.Logger; - -import com.cloud.agent.IAgentControl; -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.Command; -import com.cloud.agent.api.PingCommand; -import com.cloud.agent.api.StartupCommand; -import com.cloud.agent.api.StartupNiciraNvpCommand; -import com.cloud.host.Host; -import com.cloud.host.Host.Type; -import com.cloud.network.nicira.ControlClusterStatus; -import com.cloud.network.nicira.DestinationNatRule; -import com.cloud.network.nicira.Match; -import com.cloud.network.nicira.NatRule; -import com.cloud.network.nicira.NiciraNvpApi; -import com.cloud.network.nicira.NiciraNvpApiException; -import com.cloud.network.nicira.SourceNatRule; -import com.cloud.network.utils.CommandRetryUtility; -import com.cloud.resource.ServerResource; - -public class NiciraNvpResource implements ServerResource { - - private static final Logger s_logger = Logger.getLogger(NiciraNvpResource.class); - - public static final int NAME_MAX_LEN = 40; - public static final int NUM_RETRIES = 2; - - private String name; - private String guid; - private String zoneId; - - private NiciraNvpApi niciraNvpApi; - private NiciraNvpUtilities niciraNvpUtilities; - private CommandRetryUtility retryUtility; - - protected NiciraNvpApi createNiciraNvpApi() { - return new NiciraNvpApi(); - } - - @Override - public boolean configure(final String ignoredName, final Map<String, Object> params) throws ConfigurationException { - - name = (String)params.get("name"); - if (name == null) { - throw new ConfigurationException("Unable to find name"); - } - - guid = (String)params.get("guid"); - if (guid == null) { - throw new ConfigurationException("Unable to find the guid"); - } - - zoneId = (String)params.get("zoneId"); - if (zoneId == null) { - throw new ConfigurationException("Unable to find zone"); - } - - final String ip = (String)params.get("ip"); - if (ip == null) { - throw new ConfigurationException("Unable to find IP"); - } - - final String adminuser = (String)params.get("adminuser"); - if (adminuser == null) { - throw new ConfigurationException("Unable to find admin username"); - } - - final String adminpass = (String)params.get("adminpass"); - if (adminpass == null) { - throw new ConfigurationException("Unable to find admin password"); - } - - niciraNvpUtilities = NiciraNvpUtilities.getInstance(); - retryUtility = CommandRetryUtility.getInstance(); - retryUtility.setServerResource(this); - - niciraNvpApi = createNiciraNvpApi(); - niciraNvpApi.setControllerAddress(ip); - niciraNvpApi.setAdminCredentials(adminuser, adminpass); - - return true; - } - - public NiciraNvpApi getNiciraNvpApi() { - return niciraNvpApi; - } - - public NiciraNvpUtilities getNiciraNvpUtilities() { - return niciraNvpUtilities; - } - - public CommandRetryUtility getRetryUtility() { - return retryUtility; - } - - @Override - public boolean start() { - return true; - } - - @Override - public boolean stop() { - return true; - } - - @Override - public String getName() { - return name; - } - - @Override - public Type getType() { - // Think up a better name for this Type? - return Host.Type.L2Networking; - } - - @Override - public StartupCommand[] initialize() { - final StartupNiciraNvpCommand sc = new StartupNiciraNvpCommand(); - sc.setGuid(guid); - sc.setName(name); - sc.setDataCenter(zoneId); - sc.setPod(""); - sc.setPrivateIpAddress(""); - sc.setStorageIpAddress(""); - sc.setVersion(NiciraNvpResource.class.getPackage().getImplementationVersion()); - return new StartupCommand[] {sc}; - } - - @Override - public PingCommand getCurrentStatus(final long id) { - try { - final ControlClusterStatus ccs = niciraNvpApi.getControlClusterStatus(); - if (!"stable".equals(ccs.getClusterStatus())) { - s_logger.error("ControlCluster state is not stable: " + ccs.getClusterStatus()); - return null; - } - } catch (final NiciraNvpApiException e) { - s_logger.error("getControlClusterStatus failed", e); - return null; - } - return new PingCommand(Host.Type.L2Networking, id); - } - - @Override - public Answer executeRequest(final Command cmd) { - final NiciraNvpRequestWrapper wrapper = NiciraNvpRequestWrapper.getInstance(); - try { - return wrapper.execute(cmd, this); - } catch (final Exception e) { - s_logger.debug("Received unsupported command " + cmd.toString()); - return Answer.createUnsupportedCommandAnswer(cmd); - } - } - - @Override - public void disconnected() { - } - - @Override - public IAgentControl getAgentControl() { - return null; - } - - @Override - public void setAgentControl(final IAgentControl agentControl) { - } - - public String natRuleToString(final NatRule rule) { - - final StringBuilder natRuleStr = new StringBuilder(); - natRuleStr.append("Rule "); - natRuleStr.append(rule.getUuid()); - natRuleStr.append(" ("); - natRuleStr.append(rule.getType()); - natRuleStr.append(") :"); - final Match m = rule.getMatch(); - natRuleStr.append("match ("); - natRuleStr.append(m.getProtocol()); - natRuleStr.append(" "); - natRuleStr.append(m.getSourceIpAddresses()); - natRuleStr.append(" ["); - natRuleStr.append(m.getSourcePort()); - natRuleStr.append(" ] -> "); - natRuleStr.append(m.getDestinationIpAddresses()); - natRuleStr.append(" ["); - natRuleStr.append(m.getDestinationPort()); - natRuleStr.append(" ]) -->"); - if ("SourceNatRule".equals(rule.getType())) { - natRuleStr.append(((SourceNatRule)rule).getToSourceIpAddressMin()); - natRuleStr.append("-"); - natRuleStr.append(((SourceNatRule)rule).getToSourceIpAddressMax()); - natRuleStr.append(" ["); - natRuleStr.append(((SourceNatRule)rule).getToSourcePort()); - natRuleStr.append(" ])"); - } else { - natRuleStr.append(((DestinationNatRule)rule).getToDestinationIpAddress()); - natRuleStr.append(" ["); - natRuleStr.append(((DestinationNatRule)rule).getToDestinationPort()); - natRuleStr.append(" ])"); - } - return natRuleStr.toString(); - } - - public String truncate(final String string, final int length) { - if (string.length() <= length) { - return string; - } else { - return string.substring(0, length); - } - } - - public NatRule[] generateStaticNatRulePair(final String insideIp, final String outsideIp) { - final NatRule[] rulepair = new NatRule[2]; - rulepair[0] = new DestinationNatRule(); - rulepair[0].setType("DestinationNatRule"); - rulepair[0].setOrder(100); - rulepair[1] = new SourceNatRule(); - rulepair[1].setType("SourceNatRule"); - rulepair[1].setOrder(100); - - Match m = new Match(); - m.setDestinationIpAddresses(outsideIp); - rulepair[0].setMatch(m); - ((DestinationNatRule)rulepair[0]).setToDestinationIpAddress(insideIp); - - // create matching snat rule - m = new Match(); - m.setSourceIpAddresses(insideIp); - rulepair[1].setMatch(m); - ((SourceNatRule)rulepair[1]).setToSourceIpAddressMin(outsideIp); - ((SourceNatRule)rulepair[1]).setToSourceIpAddressMax(outsideIp); - - return rulepair; - - } - - public NatRule[] generatePortForwardingRulePair(final String insideIp, final int[] insidePorts, final String outsideIp, final int[] outsidePorts, - final String protocol) { - // Start with a basic static nat rule, then add port and protocol details - final NatRule[] rulepair = generateStaticNatRulePair(insideIp, outsideIp); - - ((DestinationNatRule)rulepair[0]).setToDestinationPort(insidePorts[0]); - rulepair[0].getMatch().setDestinationPort(outsidePorts[0]); - rulepair[0].setOrder(50); - rulepair[0].getMatch().setEthertype("IPv4"); - if ("tcp".equals(protocol)) { - rulepair[0].getMatch().setProtocol(6); - } else if ("udp".equals(protocol)) { - rulepair[0].getMatch().setProtocol(17); - } - - ((SourceNatRule)rulepair[1]).setToSourcePort(outsidePorts[0]); - rulepair[1].getMatch().setSourcePort(insidePorts[0]); - rulepair[1].setOrder(50); - rulepair[1].getMatch().setEthertype("IPv4"); - if ("tcp".equals(protocol)) { - rulepair[1].getMatch().setProtocol(6); - } else if ("udp".equals(protocol)) { - rulepair[1].getMatch().setProtocol(17); - } - - return rulepair; - - } - - @Override - public void setName(final String name) { - // TODO Auto-generated method stub - } - - @Override - public void setConfigParams(final Map<String, Object> params) { - // TODO Auto-generated method stub - } - - @Override - public Map<String, Object> getConfigParams() { - // TODO Auto-generated method stub - return null; - } - - @Override - public int getRunLevel() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public void setRunLevel(final int level) { - // TODO Auto-generated method stub - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpUtilities.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpUtilities.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpUtilities.java deleted file mode 100644 index 4edf5c3..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpUtilities.java +++ /dev/null @@ -1,65 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.resource; - -import java.util.ArrayList; -import java.util.List; - -import com.cloud.agent.api.CreateLogicalSwitchPortCommand; -import com.cloud.network.nicira.LogicalSwitch; -import com.cloud.network.nicira.LogicalSwitchPort; -import com.cloud.network.nicira.NiciraNvpTag; -import com.cloud.network.nicira.VifAttachment; - -public class NiciraNvpUtilities { - - private static NiciraNvpUtilities instance; - - static { - instance = new NiciraNvpUtilities(); - } - - private NiciraNvpUtilities() { - } - - public static NiciraNvpUtilities getInstance() { - return instance; - } - - public LogicalSwitch createLogicalSwitch() { - final LogicalSwitch logicalSwitch = new LogicalSwitch(); - return logicalSwitch; - } - - public LogicalSwitchPort createLogicalSwitchPort(final CreateLogicalSwitchPortCommand command) { - final String attachmentUuid = command.getAttachmentUuid(); - - // Tags set to scope cs_account and account name - final List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>(); - tags.add(new NiciraNvpTag("cs_account", command.getOwnerName())); - - final LogicalSwitchPort logicalSwitchPort = new LogicalSwitchPort(attachmentUuid, tags, true); - return logicalSwitchPort; - } - - public VifAttachment createVifAttachment(final String attachmentUuid) { - return new VifAttachment(attachmentUuid); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpConfigurePortForwardingRulesCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpConfigurePortForwardingRulesCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpConfigurePortForwardingRulesCommandWrapper.java deleted file mode 100644 index 89e7a6e..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpConfigurePortForwardingRulesCommandWrapper.java +++ /dev/null @@ -1,120 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.resource.wrapper; - -import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES; - -import org.apache.log4j.Logger; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterAnswer; -import com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterCommand; -import com.cloud.agent.api.to.PortForwardingRuleTO; -import com.cloud.network.nicira.NatRule; -import com.cloud.network.nicira.NiciraNvpApi; -import com.cloud.network.nicira.NiciraNvpApiException; -import com.cloud.network.nicira.NiciraNvpList; -import com.cloud.network.resource.NiciraNvpResource; -import com.cloud.network.utils.CommandRetryUtility; -import com.cloud.resource.CommandWrapper; -import com.cloud.resource.ResourceWrapper; - -@ResourceWrapper(handles = ConfigurePortForwardingRulesOnLogicalRouterCommand.class) -public final class NiciraNvpConfigurePortForwardingRulesCommandWrapper extends CommandWrapper<ConfigurePortForwardingRulesOnLogicalRouterCommand, Answer, NiciraNvpResource> { - - private static final Logger s_logger = Logger.getLogger(NiciraNvpConfigurePortForwardingRulesCommandWrapper.class); - - @Override - public Answer execute(final ConfigurePortForwardingRulesOnLogicalRouterCommand command, final NiciraNvpResource niciraNvpResource) { - final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi(); - try { - final NiciraNvpList<NatRule> existingRules = niciraNvpApi.findNatRulesByLogicalRouterUuid(command.getLogicalRouterUuid()); - // Rules of the game (also known as assumptions-that-will-make-stuff-break-later-on) - // A SourceNat rule with a match other than a /32 cidr is assumed to be the "main" SourceNat rule - // Any other SourceNat rule should have a corresponding DestinationNat rule - - for (final PortForwardingRuleTO rule : command.getRules()) { - if (rule.isAlreadyAdded() && !rule.revoked()) { - // Don't need to do anything - continue; - } - - if (rule.getDstPortRange()[0] != rule.getDstPortRange()[1] || rule.getSrcPortRange()[0] != rule.getSrcPortRange()[1]) { - return new ConfigurePortForwardingRulesOnLogicalRouterAnswer(command, false, "Nicira NVP doesn't support port ranges for port forwarding"); - } - - final NatRule[] rulepair = niciraNvpResource.generatePortForwardingRulePair(rule.getDstIp(), rule.getDstPortRange(), rule.getSrcIp(), rule.getSrcPortRange(), rule.getProtocol()); - - NatRule incoming = null; - NatRule outgoing = null; - - for (final NatRule storedRule : existingRules.getResults()) { - if (storedRule.equalsIgnoreUuid(rulepair[1])) { - // The outgoing rule exists - outgoing = storedRule; - s_logger.debug("Found matching outgoing rule " + outgoing.getUuid()); - if (incoming != null) { - break; - } - } else if (storedRule.equalsIgnoreUuid(rulepair[0])) { - // The incoming rule exists - incoming = storedRule; - s_logger.debug("Found matching incoming rule " + incoming.getUuid()); - if (outgoing != null) { - break; - } - } - } - if (incoming != null && outgoing != null) { - if (rule.revoked()) { - s_logger.debug("Deleting incoming rule " + incoming.getUuid()); - niciraNvpApi.deleteLogicalRouterNatRule(command.getLogicalRouterUuid(), incoming.getUuid()); - - s_logger.debug("Deleting outgoing rule " + outgoing.getUuid()); - niciraNvpApi.deleteLogicalRouterNatRule(command.getLogicalRouterUuid(), outgoing.getUuid()); - } - } else { - if (rule.revoked()) { - s_logger.warn("Tried deleting a rule that does not exist, " + rule.getSrcIp() + " -> " + rule.getDstIp()); - break; - } - - rulepair[0] = niciraNvpApi.createLogicalRouterNatRule(command.getLogicalRouterUuid(), rulepair[0]); - s_logger.debug("Created " + niciraNvpResource.natRuleToString(rulepair[0])); - - try { - rulepair[1] = niciraNvpApi.createLogicalRouterNatRule(command.getLogicalRouterUuid(), rulepair[1]); - s_logger.debug("Created " + niciraNvpResource.natRuleToString(rulepair[1])); - } catch (final NiciraNvpApiException ex) { - s_logger.warn("NiciraNvpApiException during create call, rolling back previous create"); - niciraNvpApi.deleteLogicalRouterNatRule(command.getLogicalRouterUuid(), rulepair[0].getUuid()); - throw ex; // Rethrow the original exception - } - - } - } - return new ConfigurePortForwardingRulesOnLogicalRouterAnswer(command, true, command.getRules().size() + " PortForwarding rules applied"); - } catch (final NiciraNvpApiException e) { - final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility(); - retryUtility.addRetry(command, NUM_RETRIES); - return retryUtility.retry(command, ConfigurePortForwardingRulesOnLogicalRouterAnswer.class, e); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpConfigurePublicIpsCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpConfigurePublicIpsCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpConfigurePublicIpsCommandWrapper.java deleted file mode 100644 index e5d2dcd..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpConfigurePublicIpsCommandWrapper.java +++ /dev/null @@ -1,60 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.resource.wrapper; - -import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterAnswer; -import com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterCommand; -import com.cloud.network.nicira.LogicalRouterPort; -import com.cloud.network.nicira.NiciraNvpApi; -import com.cloud.network.nicira.NiciraNvpApiException; -import com.cloud.network.nicira.NiciraNvpList; -import com.cloud.network.resource.NiciraNvpResource; -import com.cloud.network.utils.CommandRetryUtility; -import com.cloud.resource.CommandWrapper; -import com.cloud.resource.ResourceWrapper; - -@ResourceWrapper(handles = ConfigurePublicIpsOnLogicalRouterCommand.class) -public final class NiciraNvpConfigurePublicIpsCommandWrapper extends CommandWrapper<ConfigurePublicIpsOnLogicalRouterCommand, Answer, NiciraNvpResource> { - - @Override - public Answer execute(final ConfigurePublicIpsOnLogicalRouterCommand command, final NiciraNvpResource niciraNvpResource) { - final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi(); - - try { - final NiciraNvpList<LogicalRouterPort> ports = niciraNvpApi.findLogicalRouterPortByGatewayServiceUuid(command.getLogicalRouterUuid(), command.getL3GatewayServiceUuid()); - if (ports.getResultCount() != 1) { - return new ConfigurePublicIpsOnLogicalRouterAnswer(command, false, "No logical router ports found, unable to set ip addresses"); - } - final LogicalRouterPort lrp = ports.getResults().get(0); - lrp.setIpAddresses(command.getPublicCidrs()); - niciraNvpApi.updateLogicalRouterPort(command.getLogicalRouterUuid(), lrp); - - return new ConfigurePublicIpsOnLogicalRouterAnswer(command, true, "Configured " + command.getPublicCidrs().size() + " ip addresses on logical router uuid " + - command.getLogicalRouterUuid()); - } catch (final NiciraNvpApiException e) { - final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility(); - retryUtility.addRetry(command, NUM_RETRIES); - return retryUtility.retry(command, ConfigurePublicIpsOnLogicalRouterAnswer.class, e); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpConfigureStaticNatRulesCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpConfigureStaticNatRulesCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpConfigureStaticNatRulesCommandWrapper.java deleted file mode 100644 index 1ce3ceb..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpConfigureStaticNatRulesCommandWrapper.java +++ /dev/null @@ -1,113 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.resource.wrapper; - -import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES; - -import org.apache.log4j.Logger; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterAnswer; -import com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterCommand; -import com.cloud.agent.api.to.StaticNatRuleTO; -import com.cloud.network.nicira.NatRule; -import com.cloud.network.nicira.NiciraNvpApi; -import com.cloud.network.nicira.NiciraNvpApiException; -import com.cloud.network.nicira.NiciraNvpList; -import com.cloud.network.resource.NiciraNvpResource; -import com.cloud.network.utils.CommandRetryUtility; -import com.cloud.resource.CommandWrapper; -import com.cloud.resource.ResourceWrapper; - -@ResourceWrapper(handles = ConfigureStaticNatRulesOnLogicalRouterCommand.class) -public final class NiciraNvpConfigureStaticNatRulesCommandWrapper extends CommandWrapper<ConfigureStaticNatRulesOnLogicalRouterCommand, Answer, NiciraNvpResource> { - - private static final Logger s_logger = Logger.getLogger(NiciraNvpConfigureStaticNatRulesCommandWrapper.class); - - @Override - public Answer execute(final ConfigureStaticNatRulesOnLogicalRouterCommand command, final NiciraNvpResource niciraNvpResource) { - final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi(); - - try { - final NiciraNvpList<NatRule> existingRules = niciraNvpApi.findNatRulesByLogicalRouterUuid(command.getLogicalRouterUuid()); - // Rules of the game (also known as assumptions-that-will-make-stuff-break-later-on) - // A SourceNat rule with a match other than a /32 cidr is assumed to be the "main" SourceNat rule - // Any other SourceNat rule should have a corresponding DestinationNat rule - - for (final StaticNatRuleTO rule : command.getRules()) { - - final NatRule[] rulepair = niciraNvpResource.generateStaticNatRulePair(rule.getDstIp(), rule.getSrcIp()); - - NatRule incoming = null; - NatRule outgoing = null; - - for (final NatRule storedRule : existingRules.getResults()) { - if (storedRule.equalsIgnoreUuid(rulepair[1])) { - // The outgoing rule exists - outgoing = storedRule; - s_logger.debug("Found matching outgoing rule " + outgoing.getUuid()); - if (incoming != null) { - break; - } - } else if (storedRule.equalsIgnoreUuid(rulepair[0])) { - // The incoming rule exists - incoming = storedRule; - s_logger.debug("Found matching incoming rule " + incoming.getUuid()); - if (outgoing != null) { - break; - } - } - } - if (incoming != null && outgoing != null) { - if (rule.revoked()) { - s_logger.debug("Deleting incoming rule " + incoming.getUuid()); - niciraNvpApi.deleteLogicalRouterNatRule(command.getLogicalRouterUuid(), incoming.getUuid()); - - s_logger.debug("Deleting outgoing rule " + outgoing.getUuid()); - niciraNvpApi.deleteLogicalRouterNatRule(command.getLogicalRouterUuid(), outgoing.getUuid()); - } - } else { - if (rule.revoked()) { - s_logger.warn("Tried deleting a rule that does not exist, " + rule.getSrcIp() + " -> " + rule.getDstIp()); - break; - } - - rulepair[0] = niciraNvpApi.createLogicalRouterNatRule(command.getLogicalRouterUuid(), rulepair[0]); - s_logger.debug("Created " + niciraNvpResource.natRuleToString(rulepair[0])); - - try { - rulepair[1] = niciraNvpApi.createLogicalRouterNatRule(command.getLogicalRouterUuid(), rulepair[1]); - s_logger.debug("Created " + niciraNvpResource.natRuleToString(rulepair[1])); - } catch (final NiciraNvpApiException ex) { - s_logger.debug("Failed to create SourceNatRule, rolling back DestinationNatRule"); - niciraNvpApi.deleteLogicalRouterNatRule(command.getLogicalRouterUuid(), rulepair[0].getUuid()); - throw ex; // Rethrow original exception - } - - } - } - return new ConfigureStaticNatRulesOnLogicalRouterAnswer(command, true, command.getRules().size() + " StaticNat rules applied"); - } catch (final NiciraNvpApiException e) { - final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility(); - retryUtility.addRetry(command, NUM_RETRIES); - return retryUtility.retry(command, ConfigureStaticNatRulesOnLogicalRouterAnswer.class, e); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalRouterCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalRouterCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalRouterCommandWrapper.java deleted file mode 100644 index 1cddf4f..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalRouterCommandWrapper.java +++ /dev/null @@ -1,152 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.resource.wrapper; - -import static com.cloud.network.resource.NiciraNvpResource.NAME_MAX_LEN; -import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.log4j.Logger; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.CreateLogicalRouterAnswer; -import com.cloud.agent.api.CreateLogicalRouterCommand; -import com.cloud.network.nicira.L3GatewayAttachment; -import com.cloud.network.nicira.LogicalRouter; -import com.cloud.network.nicira.LogicalRouterPort; -import com.cloud.network.nicira.LogicalSwitchPort; -import com.cloud.network.nicira.Match; -import com.cloud.network.nicira.NiciraNvpApi; -import com.cloud.network.nicira.NiciraNvpApiException; -import com.cloud.network.nicira.NiciraNvpTag; -import com.cloud.network.nicira.PatchAttachment; -import com.cloud.network.nicira.RouterNextHop; -import com.cloud.network.nicira.SingleDefaultRouteImplicitRoutingConfig; -import com.cloud.network.nicira.SourceNatRule; -import com.cloud.network.resource.NiciraNvpResource; -import com.cloud.network.utils.CommandRetryUtility; -import com.cloud.resource.CommandWrapper; -import com.cloud.resource.ResourceWrapper; - -@ResourceWrapper(handles = CreateLogicalRouterCommand.class) -public final class NiciraNvpCreateLogicalRouterCommandWrapper extends CommandWrapper<CreateLogicalRouterCommand, Answer, NiciraNvpResource> { - - private static final Logger s_logger = Logger.getLogger(NiciraNvpCreateLogicalRouterCommandWrapper.class); - - @Override - public Answer execute(final CreateLogicalRouterCommand command, final NiciraNvpResource niciraNvpResource) { - final String routerName = command.getName(); - final String gatewayServiceUuid = command.getGatewayServiceUuid(); - final String logicalSwitchUuid = command.getLogicalSwitchUuid(); - - final List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>(); - tags.add(new NiciraNvpTag("cs_account", command.getOwnerName())); - - final String publicNetworkNextHopIp = command.getPublicNextHop(); - final String publicNetworkIpAddress = command.getPublicIpCidr(); - final String internalNetworkAddress = command.getInternalIpCidr(); - - s_logger.debug("Creating a logical router with external ip " + publicNetworkIpAddress + " and internal ip " + internalNetworkAddress + "on gateway service " + - gatewayServiceUuid); - - final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi(); - - try { - // Create the Router - LogicalRouter lrc = new LogicalRouter(); - lrc.setDisplayName(niciraNvpResource.truncate(routerName, NAME_MAX_LEN)); - lrc.setTags(tags); - lrc.setRoutingConfig(new SingleDefaultRouteImplicitRoutingConfig(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(niciraNvpResource.truncate(routerName + "-outside-port", NAME_MAX_LEN)); - lrpo.setTags(tags); - final 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 - final L3GatewayAttachment attachment = new L3GatewayAttachment(gatewayServiceUuid); - if (command.getVlanId() != 0) { - attachment.setVlanId(command.getVlanId()); - } - niciraNvpApi.updateLogicalRouterPortAttachment(lrc.getUuid(), lrpo.getUuid(), attachment); - - // Create the inside port for the router - LogicalRouterPort lrpi = new LogicalRouterPort(); - lrpi.setAdminStatusEnabled(true); - lrpi.setDisplayName(niciraNvpResource.truncate(routerName + "-inside-port", NAME_MAX_LEN)); - lrpi.setTags(tags); - final 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(niciraNvpResource.truncate(routerName + "-inside-port", NAME_MAX_LEN), tags, true); - lsp = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, lsp); - - // Attach the inside router port to the lswitch port with a PatchAttachment - niciraNvpApi.updateLogicalRouterPortAttachment(lrc.getUuid(), lrpi.getUuid(), new PatchAttachment(lsp.getUuid())); - - // Attach the inside lswitch port to the router with a PatchAttachment - niciraNvpApi.updateLogicalSwitchPortAttachment(logicalSwitchUuid, lsp.getUuid(), new PatchAttachment(lrpi.getUuid())); - - // Setup the source nat rule - final SourceNatRule snr = new SourceNatRule(); - snr.setToSourceIpAddressMin(publicNetworkIpAddress.split("/")[0]); - snr.setToSourceIpAddressMax(publicNetworkIpAddress.split("/")[0]); - final Match match = new Match(); - match.setSourceIpAddresses(internalNetworkAddress); - snr.setMatch(match); - snr.setOrder(200); - niciraNvpApi.createLogicalRouterNatRule(lrc.getUuid(), snr); - } catch (final 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 (final NiciraNvpApiException ex) { - } - - throw e; - } - - return new CreateLogicalRouterAnswer(command, true, "Logical Router created (uuid " + lrc.getUuid() + ")", lrc.getUuid()); - } catch (final NiciraNvpApiException e) { - final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility(); - retryUtility.addRetry(command, NUM_RETRIES); - return retryUtility.retry(command, CreateLogicalRouterAnswer.class, e); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalSwitchCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalSwitchCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalSwitchCommandWrapper.java deleted file mode 100644 index 7d66ada..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalSwitchCommandWrapper.java +++ /dev/null @@ -1,73 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.resource.wrapper; - -import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES; - -import java.util.ArrayList; -import java.util.List; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.CreateLogicalSwitchAnswer; -import com.cloud.agent.api.CreateLogicalSwitchCommand; -import com.cloud.network.nicira.LogicalSwitch; -import com.cloud.network.nicira.NiciraNvpApi; -import com.cloud.network.nicira.NiciraNvpApiException; -import com.cloud.network.nicira.NiciraNvpTag; -import com.cloud.network.nicira.TransportZoneBinding; -import com.cloud.network.resource.NiciraNvpResource; -import com.cloud.network.resource.NiciraNvpUtilities; -import com.cloud.network.utils.CommandRetryUtility; -import com.cloud.resource.CommandWrapper; -import com.cloud.resource.ResourceWrapper; - -@ResourceWrapper(handles = CreateLogicalSwitchCommand.class) -public final class NiciraNvpCreateLogicalSwitchCommandWrapper extends CommandWrapper<CreateLogicalSwitchCommand, Answer, NiciraNvpResource> { - - @Override - public Answer execute(final CreateLogicalSwitchCommand command, final NiciraNvpResource niciraNvpResource) { - final NiciraNvpUtilities niciraNvpUtilities = niciraNvpResource.getNiciraNvpUtilities(); - - LogicalSwitch logicalSwitch = niciraNvpUtilities.createLogicalSwitch(); - logicalSwitch.setDisplayName(niciraNvpResource.truncate("lswitch-" + command.getName(), NiciraNvpResource.NAME_MAX_LEN)); - logicalSwitch.setPortIsolationEnabled(false); - - // Set transport binding - final List<TransportZoneBinding> ltzb = new ArrayList<TransportZoneBinding>(); - ltzb.add(new TransportZoneBinding(command.getTransportUuid(), command.getTransportType())); - logicalSwitch.setTransportZones(ltzb); - - // Tags set to scope cs_account and account name - final List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>(); - tags.add(new NiciraNvpTag("cs_account", command.getOwnerName())); - logicalSwitch.setTags(tags); - - try { - final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi(); - logicalSwitch = niciraNvpApi.createLogicalSwitch(logicalSwitch); - final String switchUuid = logicalSwitch.getUuid(); - return new CreateLogicalSwitchAnswer(command, true, "Logicalswitch " + switchUuid + " created", switchUuid); - } catch (final NiciraNvpApiException e) { - final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility(); - retryUtility.addRetry(command, NUM_RETRIES); - return retryUtility.retry(command, CreateLogicalSwitchAnswer.class, e); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalSwitchPortCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalSwitchPortCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalSwitchPortCommandWrapper.java deleted file mode 100644 index 42a4067..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalSwitchPortCommandWrapper.java +++ /dev/null @@ -1,70 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.resource.wrapper; - -import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES; - -import org.apache.log4j.Logger; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.CreateLogicalSwitchPortAnswer; -import com.cloud.agent.api.CreateLogicalSwitchPortCommand; -import com.cloud.network.nicira.LogicalSwitchPort; -import com.cloud.network.nicira.NiciraNvpApi; -import com.cloud.network.nicira.NiciraNvpApiException; -import com.cloud.network.nicira.VifAttachment; -import com.cloud.network.resource.NiciraNvpResource; -import com.cloud.network.resource.NiciraNvpUtilities; -import com.cloud.network.utils.CommandRetryUtility; -import com.cloud.resource.CommandWrapper; -import com.cloud.resource.ResourceWrapper; - -@ResourceWrapper(handles = CreateLogicalSwitchPortCommand.class) -public final class NiciraNvpCreateLogicalSwitchPortCommandWrapper extends CommandWrapper<CreateLogicalSwitchPortCommand, Answer, NiciraNvpResource> { - - private static final Logger s_logger = Logger.getLogger(NiciraNvpCreateLogicalSwitchPortCommandWrapper.class); - - @Override - public Answer execute(final CreateLogicalSwitchPortCommand command, final NiciraNvpResource niciraNvpResource) { - final NiciraNvpUtilities niciraNvpUtilities = niciraNvpResource.getNiciraNvpUtilities(); - - final String logicalSwitchUuid = command.getLogicalSwitchUuid(); - final String attachmentUuid = command.getAttachmentUuid(); - - try { - final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi(); - - final LogicalSwitchPort logicalSwitchPort = niciraNvpUtilities.createLogicalSwitchPort(command); - final LogicalSwitchPort newPort = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, logicalSwitchPort); - try { - niciraNvpApi.updateLogicalSwitchPortAttachment(command.getLogicalSwitchUuid(), newPort.getUuid(), new VifAttachment(attachmentUuid)); - } catch (final NiciraNvpApiException ex) { - s_logger.warn("modifyLogicalSwitchPort failed after switchport was created, removing switchport"); - niciraNvpApi.deleteLogicalSwitchPort(command.getLogicalSwitchUuid(), newPort.getUuid()); - throw ex; // Rethrow the original exception - } - return new CreateLogicalSwitchPortAnswer(command, true, "Logical switch port " + newPort.getUuid() + " created", newPort.getUuid()); - } catch (final NiciraNvpApiException e) { - final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility(); - retryUtility.addRetry(command, NUM_RETRIES); - return retryUtility.retry(command, CreateLogicalSwitchPortAnswer.class, e); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalRouterCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalRouterCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalRouterCommandWrapper.java deleted file mode 100644 index 43665b2..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalRouterCommandWrapper.java +++ /dev/null @@ -1,50 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.resource.wrapper; - -import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.DeleteLogicalRouterAnswer; -import com.cloud.agent.api.DeleteLogicalRouterCommand; -import com.cloud.network.nicira.NiciraNvpApi; -import com.cloud.network.nicira.NiciraNvpApiException; -import com.cloud.network.resource.NiciraNvpResource; -import com.cloud.network.utils.CommandRetryUtility; -import com.cloud.resource.CommandWrapper; -import com.cloud.resource.ResourceWrapper; - -@ResourceWrapper(handles = DeleteLogicalRouterCommand.class) -public final class NiciraNvpDeleteLogicalRouterCommandWrapper extends CommandWrapper<DeleteLogicalRouterCommand, Answer, NiciraNvpResource> { - - @Override - public Answer execute(final DeleteLogicalRouterCommand command, final NiciraNvpResource niciraNvpResource) { - final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi(); - - try { - niciraNvpApi.deleteLogicalRouter(command.getLogicalRouterUuid()); - return new DeleteLogicalRouterAnswer(command, true, "Logical Router deleted (uuid " + command.getLogicalRouterUuid() + ")"); - } catch (final NiciraNvpApiException e) { - final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility(); - retryUtility.addRetry(command, NUM_RETRIES); - return retryUtility.retry(command, DeleteLogicalRouterAnswer.class, e); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalSwitchCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalSwitchCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalSwitchCommandWrapper.java deleted file mode 100644 index f7b8ab9..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalSwitchCommandWrapper.java +++ /dev/null @@ -1,49 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.resource.wrapper; - -import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.DeleteLogicalSwitchAnswer; -import com.cloud.agent.api.DeleteLogicalSwitchCommand; -import com.cloud.network.nicira.NiciraNvpApi; -import com.cloud.network.nicira.NiciraNvpApiException; -import com.cloud.network.resource.NiciraNvpResource; -import com.cloud.network.utils.CommandRetryUtility; -import com.cloud.resource.CommandWrapper; -import com.cloud.resource.ResourceWrapper; - -@ResourceWrapper(handles = DeleteLogicalSwitchCommand.class) -public final class NiciraNvpDeleteLogicalSwitchCommandWrapper extends CommandWrapper<DeleteLogicalSwitchCommand, Answer, NiciraNvpResource> { - - @Override - public Answer execute(final DeleteLogicalSwitchCommand command, final NiciraNvpResource niciraNvpResource) { - try { - final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi(); - niciraNvpApi.deleteLogicalSwitch(command.getLogicalSwitchUuid()); - return new DeleteLogicalSwitchAnswer(command, true, "Logicalswitch " + command.getLogicalSwitchUuid() + " deleted"); - } catch (final NiciraNvpApiException e) { - final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility(); - retryUtility.addRetry(command, NUM_RETRIES); - return retryUtility.retry(command, DeleteLogicalSwitchAnswer.class, e); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalSwitchPortCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalSwitchPortCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalSwitchPortCommandWrapper.java deleted file mode 100644 index b8c69f2..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalSwitchPortCommandWrapper.java +++ /dev/null @@ -1,50 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.resource.wrapper; - -import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.DeleteLogicalSwitchPortAnswer; -import com.cloud.agent.api.DeleteLogicalSwitchPortCommand; -import com.cloud.network.nicira.NiciraNvpApi; -import com.cloud.network.nicira.NiciraNvpApiException; -import com.cloud.network.resource.NiciraNvpResource; -import com.cloud.network.utils.CommandRetryUtility; -import com.cloud.resource.CommandWrapper; -import com.cloud.resource.ResourceWrapper; - -@ResourceWrapper(handles = DeleteLogicalSwitchPortCommand.class) -public final class NiciraNvpDeleteLogicalSwitchPortCommandWrapper extends CommandWrapper<DeleteLogicalSwitchPortCommand, Answer, NiciraNvpResource> { - - @Override - public Answer execute(final DeleteLogicalSwitchPortCommand command, final NiciraNvpResource niciraNvpResource) { - final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi(); - - try { - niciraNvpApi.deleteLogicalSwitchPort(command.getLogicalSwitchUuid(), command.getLogicalSwitchPortUuid()); - return new DeleteLogicalSwitchPortAnswer(command, true, "Logical switch port " + command.getLogicalSwitchPortUuid() + " deleted"); - } catch (final NiciraNvpApiException e) { - final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility(); - retryUtility.addRetry(command, NUM_RETRIES); - return retryUtility.retry(command, DeleteLogicalSwitchPortAnswer.class, e); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpFindLogicalSwitchPortCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpFindLogicalSwitchPortCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpFindLogicalSwitchPortCommandWrapper.java deleted file mode 100644 index 40d58fc..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpFindLogicalSwitchPortCommandWrapper.java +++ /dev/null @@ -1,59 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.resource.wrapper; - -import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.FindLogicalSwitchPortAnswer; -import com.cloud.agent.api.FindLogicalSwitchPortCommand; -import com.cloud.network.nicira.LogicalSwitchPort; -import com.cloud.network.nicira.NiciraNvpApi; -import com.cloud.network.nicira.NiciraNvpApiException; -import com.cloud.network.nicira.NiciraNvpList; -import com.cloud.network.resource.NiciraNvpResource; -import com.cloud.network.utils.CommandRetryUtility; -import com.cloud.resource.CommandWrapper; -import com.cloud.resource.ResourceWrapper; - -@ResourceWrapper(handles = FindLogicalSwitchPortCommand.class) -public final class NiciraNvpFindLogicalSwitchPortCommandWrapper extends CommandWrapper<FindLogicalSwitchPortCommand, Answer, NiciraNvpResource> { - - @Override - public Answer execute(final FindLogicalSwitchPortCommand command, final NiciraNvpResource niciraNvpResource) { - final String logicalSwitchUuid = command.getLogicalSwitchUuid(); - final String logicalSwitchPortUuid = command.getLogicalSwitchPortUuid(); - - final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi(); - - try { - final NiciraNvpList<LogicalSwitchPort> ports = niciraNvpApi.findLogicalSwitchPortsByUuid(logicalSwitchUuid, logicalSwitchPortUuid); - if (ports.getResultCount() == 0) { - return new FindLogicalSwitchPortAnswer(command, false, "Logical switchport " + logicalSwitchPortUuid + " not found", null); - } else { - return new FindLogicalSwitchPortAnswer(command, true, "Logical switchport " + logicalSwitchPortUuid + " found", logicalSwitchPortUuid); - } - } catch (final NiciraNvpApiException e) { - final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility(); - retryUtility.addRetry(command, NUM_RETRIES); - return retryUtility.retry(command, FindLogicalSwitchPortAnswer.class, e); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpMaintainCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpMaintainCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpMaintainCommandWrapper.java deleted file mode 100644 index 3015378..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpMaintainCommandWrapper.java +++ /dev/null @@ -1,36 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.resource.wrapper; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.MaintainAnswer; -import com.cloud.agent.api.MaintainCommand; -import com.cloud.network.resource.NiciraNvpResource; -import com.cloud.resource.CommandWrapper; -import com.cloud.resource.ResourceWrapper; - -@ResourceWrapper(handles = MaintainCommand.class) -public final class NiciraNvpMaintainCommandWrapper extends CommandWrapper<MaintainCommand, Answer, NiciraNvpResource> { - - @Override - public Answer execute(final MaintainCommand command, final NiciraNvpResource niciraNvpResource) { - return new MaintainAnswer(command); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b0989d/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpReadyCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpReadyCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpReadyCommandWrapper.java deleted file mode 100644 index 3d0d3f3..0000000 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpReadyCommandWrapper.java +++ /dev/null @@ -1,36 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.network.resource.wrapper; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.ReadyAnswer; -import com.cloud.agent.api.ReadyCommand; -import com.cloud.network.resource.NiciraNvpResource; -import com.cloud.resource.CommandWrapper; -import com.cloud.resource.ResourceWrapper; - -@ResourceWrapper(handles = ReadyCommand.class) -public final class NiciraNvpReadyCommandWrapper extends CommandWrapper<ReadyCommand, Answer, NiciraNvpResource> { - - @Override - public Answer execute(final ReadyCommand command, final NiciraNvpResource niciraNvpResource) { - return new ReadyAnswer(command); - } -} \ No newline at end of file
