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