d5a5a55de3cd736a8905945db5c13873b9953516
[netvirt.git] /
1 /*
2  * Copyright (c) 2013, 2015 IBM Corporation and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.netvirt.openstack.netvirt.translator;
10
11
12 import java.io.Serializable;
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.Map;
16
17 import javax.xml.bind.annotation.XmlAccessType;
18 import javax.xml.bind.annotation.XmlAccessorType;
19 import javax.xml.bind.annotation.XmlElement;
20 import javax.xml.bind.annotation.XmlRootElement;
21
22
23 @XmlRootElement
24 @XmlAccessorType(XmlAccessType.NONE)
25
26 public class NeutronPort implements Serializable, INeutronObject {
27     private static final long serialVersionUID = 1L;
28
29     // See OpenStack Network API v2.0 Reference for description of
30     // annotated attributes
31
32     @XmlElement (name = "id")
33     String portUUID;
34
35     @XmlElement (name = "network_id")
36     String networkUUID;
37
38     @XmlElement (name = "name")
39     String name;
40
41     @XmlElement (defaultValue = "true", name = "admin_state_up")
42     Boolean adminStateUp;
43
44     @XmlElement (name = "status")
45     String status;
46
47     @XmlElement (name = "mac_address")
48     String macAddress;
49
50     @XmlElement (name = "fixed_ips")
51     List<Neutron_IPs> fixedIPs;
52
53     @XmlElement (name = "device_id")
54     String deviceID;
55
56     @XmlElement (name = "device_owner")
57     String deviceOwner;
58
59     @XmlElement (name = "tenant_id")
60     String tenantID;
61
62     @XmlElement (name = "security_groups")
63     List<NeutronSecurityGroup> securityGroups;
64
65     @XmlElement (name = "allowed_address_pairs")
66     List<NeutronPort_AllowedAddressPairs> allowedAddressPairs;
67
68     //@XmlElement (name = "binding:host_id")
69     @XmlElement (namespace = "binding", name = "host_id")
70     String bindinghostID;
71
72     //@XmlElement (name = "binding:vnic_type")
73     @XmlElement (namespace = "binding", name = "vnic_type")
74     String bindingvnicType;
75
76     //@XmlElement (name = "binding:vif_type")
77     @XmlElement (namespace = "binding", name = "vif_type")
78     String bindingvifType;
79
80     //@XmlElement (name = "binding:vif_details")
81     @XmlElement (namespace = "binding", name = "vif_details")
82     Map<String, String> vifDetails;
83
84     @XmlElement (name = "extra_dhcp_opts")
85     List<NeutronPort_ExtraDHCPOption> extraDHCPOptions;
86
87     //Port security is enabled by default for backward compatibility.
88     @XmlElement (defaultValue = "true", name = "port_security_enabled")
89     Boolean portSecurityEnabled;
90
91
92     NeutronPort originalPort;
93
94     public NeutronPort() {
95     }
96
97     public String getID() { return portUUID; }
98
99     public void setID(String id) { this.portUUID = id; }
100
101     public String getPortUUID() {
102         return portUUID;
103     }
104
105     public void setPortUUID(String portUUID) {
106         this.portUUID = portUUID;
107     }
108
109     public String getNetworkUUID() {
110         return networkUUID;
111     }
112
113     public void setNetworkUUID(String networkUUID) {
114         this.networkUUID = networkUUID;
115     }
116
117     public String getName() {
118         return name;
119     }
120
121     public void setName(String name) {
122         this.name = name;
123     }
124
125     public boolean isAdminStateUp() {
126         if (adminStateUp == null) {
127             return true;
128         }
129         return adminStateUp;
130     }
131
132     public Boolean getAdminStateUp() { return adminStateUp; }
133
134     public void setAdminStateUp(Boolean newValue) {
135         adminStateUp = newValue;
136     }
137
138     public String getStatus() {
139         return status;
140     }
141
142     public void setStatus(String status) {
143         this.status = status;
144     }
145
146     public String getMacAddress() {
147         return macAddress;
148     }
149
150     public void setMacAddress(String macAddress) {
151         this.macAddress = macAddress;
152     }
153
154     public List<Neutron_IPs> getFixedIPs() {
155         return fixedIPs;
156     }
157
158     public void setFixedIPs(List<Neutron_IPs> fixedIPs) {
159         this.fixedIPs = fixedIPs;
160     }
161
162     public String getDeviceID() {
163         return deviceID;
164     }
165
166     public void setDeviceID(String deviceID) {
167         this.deviceID = deviceID;
168     }
169
170     public String getDeviceOwner() {
171         return deviceOwner;
172     }
173
174     public void setDeviceOwner(String deviceOwner) {
175         this.deviceOwner = deviceOwner;
176     }
177
178     public String getTenantID() {
179         return tenantID;
180     }
181
182     public void setTenantID(String tenantID) {
183         this.tenantID = tenantID;
184     }
185
186     public List<NeutronSecurityGroup> getSecurityGroups() {
187         return securityGroups;
188     }
189
190     public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
191         this.securityGroups = securityGroups;
192     }
193
194     public List<NeutronPort_AllowedAddressPairs> getAllowedAddressPairs() {
195         return allowedAddressPairs;
196     }
197
198     public void setAllowedAddressPairs(List<NeutronPort_AllowedAddressPairs> allowedAddressPairs) {
199         this.allowedAddressPairs = allowedAddressPairs;
200     }
201
202     public List<NeutronPort_ExtraDHCPOption> getExtraDHCPOptions() {
203         return extraDHCPOptions;
204     }
205
206     public void setExtraDHCPOptions(List<NeutronPort_ExtraDHCPOption> extraDHCPOptions) {
207         this.extraDHCPOptions = extraDHCPOptions;
208     }
209
210     public Map<String, String> getVIFDetails() {
211         return vifDetails;
212     }
213
214     public void setVIFDetails(Map<String, String> vifDetails) {
215         this.vifDetails = vifDetails;
216     }
217
218     public String getBindinghostID() {
219         return bindinghostID;
220     }
221
222     public void setBindinghostID(String bindinghostID) {
223         this.bindinghostID = bindinghostID;
224     }
225
226     public String getBindingvnicType() {
227         return bindingvnicType;
228     }
229
230     public void setBindingvnicType(String bindingvnicType) {
231         this.bindingvnicType = bindingvnicType;
232     }
233
234     public String getBindingvifType() {
235         return bindingvifType;
236     }
237
238     public void setBindingvifType(String bindingvifType) {
239         this.bindingvifType = bindingvifType;
240     }
241
242     public Boolean getPortSecurityEnabled() {
243         if (portSecurityEnabled == null) {
244             return true;
245         }
246         return portSecurityEnabled;
247     }
248
249     public void setPortSecurityEnabled(Boolean newValue) {
250         portSecurityEnabled = newValue;
251     }
252
253
254     public NeutronPort getOriginalPort() {
255         return originalPort;
256     }
257
258
259     public void setOriginalPort(NeutronPort originalPort) {
260         this.originalPort = originalPort;
261     }
262
263     /**
264      * This method copies selected fields from the object and returns them
265      * as a new object, suitable for marshaling.
266      *
267      * @param fields
268      *            List of attributes to be extracted
269      * @return an OpenStackPorts object with only the selected fields
270      * populated
271      */
272
273     public NeutronPort extractFields(List<String> fields) {
274         NeutronPort ans = new NeutronPort();
275         for (String field: fields) {
276             if ("id".equals(field)) {
277                 ans.setPortUUID(this.getPortUUID());
278             }
279             if ("network_id".equals(field)) {
280                 ans.setNetworkUUID(this.getNetworkUUID());
281             }
282             if ("name".equals(field)) {
283                 ans.setName(this.getName());
284             }
285             if ("admin_state_up".equals(field)) {
286                 ans.setAdminStateUp(this.getAdminStateUp());
287             }
288             if ("status".equals(field)) {
289                 ans.setStatus(this.getStatus());
290             }
291             if ("mac_address".equals(field)) {
292                 ans.setMacAddress(this.getMacAddress());
293             }
294             if ("fixed_ips".equals(field)) {
295                 ans.setFixedIPs(new ArrayList<>(this.getFixedIPs()));
296             }
297             if ("device_id".equals(field)) {
298                 ans.setDeviceID(this.getDeviceID());
299             }
300             if ("device_owner".equals(field)) {
301                 ans.setDeviceOwner(this.getDeviceOwner());
302             }
303             if ("tenant_id".equals(field)) {
304                 ans.setTenantID(this.getTenantID());
305             }
306             if ("security_groups".equals(field)) {
307                 ans.setSecurityGroups(new ArrayList<>(this.getSecurityGroups()));
308             }
309             if ("port_security_enabled".equals(field)) {
310                 ans.setPortSecurityEnabled(this.getPortSecurityEnabled());
311             }
312         }
313         return ans;
314     }
315
316     public void initDefaults() {
317         adminStateUp = true;
318         portSecurityEnabled = true;
319         if (status == null) {
320             status = "ACTIVE";
321         }
322         if (fixedIPs == null) {
323             fixedIPs = new ArrayList<>();
324         }
325     }
326
327     @Override
328     public String toString() {
329         return "NeutronPort [portUUID=" + portUUID + ", networkUUID=" + networkUUID + ", name=" + name
330                 + ", adminStateUp=" + adminStateUp + ", status=" + status + ", macAddress=" + macAddress
331                 + ", fixedIPs=" + fixedIPs + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID="
332                 + tenantID + ", securityGroups=" + securityGroups
333                 + ", bindinghostID=" + bindinghostID + ", bindingvnicType=" + bindingvnicType
334                 + ", bindingvnicType=" + bindingvnicType + ", portSecurityEnabled=" + portSecurityEnabled +"]";
335     }
336 }