| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.vcloud.domain.network; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.net.URI; |
| 24 | |
| 25 | import org.jclouds.javax.annotation.Nullable; |
| 26 | |
| 27 | /** |
| 28 | * |
| 29 | * @author Adrian Cole |
| 30 | */ |
| 31 | public class NetworkConfig { |
| 32 | @Nullable |
| 33 | private final String networkName; |
| 34 | private final URI parentNetwork; |
| 35 | @Nullable |
| 36 | private final FenceMode fenceMode; |
| 37 | |
| 38 | /** |
| 39 | * |
| 40 | * Create a new NetworkConfig. |
| 41 | * |
| 42 | * @param networkName |
| 43 | * a valid {@networkConfig |
| 44 | * org.jclouds.vcloud.domain.VAppTemplate#getNetworkSection network in the vapp |
| 45 | * template}, or null to have us choose default |
| 46 | * @param parentNetwork |
| 47 | * a valid {@networkConfig org.jclouds.vcloud.domain.Org#getNetworks in |
| 48 | * the Org} |
| 49 | * @param fenceMode |
| 50 | * how to manage the relationship between the two networks |
| 51 | */ |
| 52 | public NetworkConfig(String networkName, URI parentNetwork, FenceMode fenceMode) { |
| 53 | this.networkName = networkName; |
| 54 | this.parentNetwork = checkNotNull(parentNetwork, "parentNetwork"); |
| 55 | this.fenceMode = fenceMode; |
| 56 | } |
| 57 | |
| 58 | public NetworkConfig(URI parentNetwork) { |
| 59 | this(null, parentNetwork, null); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * A name for the network. If the |
| 64 | * {@link org.jclouds.vcloud.domain.VAppTemplate#getNetworkSection} includes a |
| 65 | * {@link NetworkSection.Network} network element, the name you specify for the vApp network must |
| 66 | * match the name specified in that element?s name attribute. |
| 67 | * |
| 68 | * @return |
| 69 | */ |
| 70 | public String getNetworkName() { |
| 71 | return networkName; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * |
| 76 | * @return A reference to the organization network to which this network connects. |
| 77 | */ |
| 78 | public URI getParentNetwork() { |
| 79 | return parentNetwork; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * A value of bridged indicates that this vApp network is connected directly to the organization |
| 84 | * network. |
| 85 | */ |
| 86 | public FenceMode getFenceMode() { |
| 87 | return fenceMode; |
| 88 | } |
| 89 | |
| 90 | |
| 91 | @Override |
| 92 | public int hashCode() { |
| 93 | final int prime = 31; |
| 94 | int result = 1; |
| 95 | result = prime * result + ((fenceMode == null) ? 0 : fenceMode.hashCode()); |
| 96 | result = prime * result + ((parentNetwork == null) ? 0 : parentNetwork.hashCode()); |
| 97 | result = prime * result + ((networkName == null) ? 0 : networkName.hashCode()); |
| 98 | return result; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public boolean equals(Object obj) { |
| 103 | if (this == obj) |
| 104 | return true; |
| 105 | if (obj == null) |
| 106 | return false; |
| 107 | if (getClass() != obj.getClass()) |
| 108 | return false; |
| 109 | NetworkConfig other = (NetworkConfig) obj; |
| 110 | if (fenceMode == null) { |
| 111 | if (other.fenceMode != null) |
| 112 | return false; |
| 113 | } else if (!fenceMode.equals(other.fenceMode)) |
| 114 | return false; |
| 115 | if (parentNetwork == null) { |
| 116 | if (other.parentNetwork != null) |
| 117 | return false; |
| 118 | } else if (!parentNetwork.equals(other.parentNetwork)) |
| 119 | return false; |
| 120 | if (networkName == null) { |
| 121 | if (other.networkName != null) |
| 122 | return false; |
| 123 | } else if (!networkName.equals(other.networkName)) |
| 124 | return false; |
| 125 | return true; |
| 126 | } |
| 127 | |
| 128 | @Override |
| 129 | public String toString() { |
| 130 | return "[networkName=" + networkName + ", parentNetwork=" + parentNetwork + ", fenceMode=" + fenceMode + "]"; |
| 131 | } |
| 132 | } |