1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.jclouds.savvis.vpdc.domain;
20
21 import static com.google.common.base.Preconditions.checkNotNull;
22
23 import java.util.Map;
24
25 import org.jclouds.ovf.Section;
26
27 import com.google.common.collect.ImmutableMap;
28 import com.google.common.collect.Maps;
29
30
31
32
33
34 public class NetworkConfigSection extends Section<NetworkConfigSection> {
35
36 @SuppressWarnings("unchecked")
37 public static Builder builder() {
38 return new Builder();
39 }
40
41
42
43
44 @Override
45 public Builder toBuilder() {
46 return builder().fromNetworkConfigSection(this);
47 }
48
49 public static class Builder extends Section.Builder<NetworkConfigSection> {
50 private String network;
51 private String fenceMode;
52 private Boolean dhcp;
53 private String gateway;
54 private String netmask;
55 private Map<String, String> internalToExternalNATRules = Maps.newLinkedHashMap();
56
57 public Builder network(String network) {
58 this.network = network;
59 return this;
60 }
61
62 public Builder fenceMode(String fenceMode) {
63 this.fenceMode = fenceMode;
64 return this;
65 }
66
67 public Builder dhcp(Boolean dhcp) {
68 this.dhcp = dhcp;
69 return this;
70 }
71
72 public Builder gateway(String gateway) {
73 this.gateway = gateway;
74 return this;
75 }
76
77 public Builder netmask(String netmask) {
78 this.netmask = netmask;
79 return this;
80 }
81
82 public Builder internalToExternalNATRule(String internalIP, String externalIP) {
83 this.internalToExternalNATRules.put(checkNotNull(internalIP, "internalIP"), checkNotNull(externalIP,
84 "externalIP"));
85 return this;
86 }
87
88 public Builder internalToExternalNATRules(Map<String, String> internalToExternalNATRules) {
89 this.internalToExternalNATRules.putAll(checkNotNull(internalToExternalNATRules, "internalToExternalNATRules"));
90 return this;
91 }
92
93
94
95
96 @Override
97 public NetworkConfigSection build() {
98 return new NetworkConfigSection(info, network, fenceMode, dhcp, gateway, netmask, internalToExternalNATRules);
99 }
100
101 public Builder fromNetworkConfigSection(NetworkConfigSection in) {
102 return fromSection(in).network(in.getNetwork()).fenceMode(in.getFenceMode()).dhcp(in.getDhcp()).gateway(
103 in.getGateway()).netmask(in.getNetmask()).internalToExternalNATRules(
104 in.getInternalToExternalNATRules());
105 }
106
107
108
109
110 @Override
111 public Builder fromSection(Section<NetworkConfigSection> in) {
112 return Builder.class.cast(super.fromSection(in));
113 }
114
115
116
117
118 @Override
119 public Builder info(String info) {
120 return Builder.class.cast(super.info(info));
121 }
122
123 }
124
125 private final String network;
126 private final String fenceMode;
127 private final Boolean dhcp;
128 private final String gateway;
129 private final String netmask;
130 private final Map<String, String> internalToExternalNATRules;
131
132 public NetworkConfigSection(String info, String network, String fenceMode, Boolean dhcp, String gateway,
133 String netmask, Map<String, String> internalToExternalNATRules) {
134 super(info);
135 this.network = network;
136 this.fenceMode = fenceMode;
137 this.dhcp = dhcp;
138 this.gateway = gateway;
139 this.netmask = netmask;
140 this.internalToExternalNATRules = ImmutableMap.copyOf(checkNotNull(internalToExternalNATRules,
141 "internalToExternalNATRules"));
142 }
143
144
145
146
147 public String getGateway() {
148 return gateway;
149 }
150
151
152
153
154 public String getNetmask() {
155 return netmask;
156 }
157
158
159
160
161 public Map<String, String> getInternalToExternalNATRules() {
162 return internalToExternalNATRules;
163 }
164
165 public String getNetwork() {
166 return network;
167 }
168
169 public String getFenceMode() {
170 return fenceMode;
171 }
172
173 public Boolean getDhcp() {
174 return dhcp;
175 }
176
177 @Override
178 public int hashCode() {
179 final int prime = 31;
180 int result = super.hashCode();
181 result = prime * result + ((network == null) ? 0 : network.hashCode());
182 return result;
183 }
184
185 @Override
186 public boolean equals(Object obj) {
187 if (this == obj)
188 return true;
189 if (!super.equals(obj))
190 return false;
191 if (getClass() != obj.getClass())
192 return false;
193 NetworkConfigSection other = (NetworkConfigSection) obj;
194 if (network == null) {
195 if (other.network != null)
196 return false;
197 } else if (!network.equals(other.network))
198 return false;
199 return true;
200 }
201
202 @Override
203 public String toString() {
204 return String.format(
205 "[info=%s, network=%s, dhcp=%s, fenceMode=%s, gateway=%s, internalToExternalNATRules=%s, netmask=%s]",
206 info, network, dhcp, fenceMode, gateway, internalToExternalNATRules, netmask);
207 }
208
209 }