Stop scheduling the Install Snapshot check
[controller.git] / opendaylight / networkconfiguration / neutron / src / main / java / org / opendaylight / controller / networkconfig / neutron / NeutronPort.java
1 /*
2  * Copyright IBM Corporation, 2013.  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.controller.networkconfig.neutron;
10
11 import java.io.Serializable;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.Iterator;
15 import java.util.List;
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     /* this attribute stores the floating IP address assigned to
66      * each fixed IP address
67      */
68
69     HashMap<String, NeutronFloatingIP> floatingIPMap;
70
71     public NeutronPort() {
72         floatingIPMap = new HashMap<String, NeutronFloatingIP>();
73     }
74
75     public String getID() { return portUUID; }
76
77     public void setID(String id) { this.portUUID = id; }
78
79     public String getPortUUID() {
80         return portUUID;
81     }
82
83     public void setPortUUID(String portUUID) {
84         this.portUUID = portUUID;
85     }
86
87     public String getNetworkUUID() {
88         return networkUUID;
89     }
90
91     public void setNetworkUUID(String networkUUID) {
92         this.networkUUID = networkUUID;
93     }
94
95     public String getName() {
96         return name;
97     }
98
99     public void setName(String name) {
100         this.name = name;
101     }
102
103     public boolean isAdminStateUp() {
104         if (adminStateUp == null) {
105             return true;
106         }
107         return adminStateUp;
108     }
109
110     public Boolean getAdminStateUp() { return adminStateUp; }
111
112     public void setAdminStateUp(Boolean newValue) {
113             adminStateUp = newValue;
114     }
115
116     public String getStatus() {
117         return status;
118     }
119
120     public void setStatus(String status) {
121         this.status = status;
122     }
123
124     public String getMacAddress() {
125         return macAddress;
126     }
127
128     public void setMacAddress(String macAddress) {
129         this.macAddress = macAddress;
130     }
131
132     public List<Neutron_IPs> getFixedIPs() {
133         return fixedIPs;
134     }
135
136     public void setFixedIPs(List<Neutron_IPs> fixedIPs) {
137         this.fixedIPs = fixedIPs;
138     }
139
140     public String getDeviceID() {
141         return deviceID;
142     }
143
144     public void setDeviceID(String deviceID) {
145         this.deviceID = deviceID;
146     }
147
148     public String getDeviceOwner() {
149         return deviceOwner;
150     }
151
152     public void setDeviceOwner(String deviceOwner) {
153         this.deviceOwner = deviceOwner;
154     }
155
156     public String getTenantID() {
157         return tenantID;
158     }
159
160     public void setTenantID(String tenantID) {
161         this.tenantID = tenantID;
162     }
163
164     public List<NeutronSecurityGroup> getSecurityGroups() {
165         return securityGroups;
166     }
167
168     public void setSecurityGroups(List<NeutronSecurityGroup> securityGroups) {
169         this.securityGroups = securityGroups;
170     }
171
172     public NeutronFloatingIP getFloatingIP(String key) {
173         if (!floatingIPMap.containsKey(key)) {
174             return null;
175         }
176         return floatingIPMap.get(key);
177     }
178
179     public void removeFloatingIP(String key) {
180         floatingIPMap.remove(key);
181     }
182
183     public void addFloatingIP(String key, NeutronFloatingIP floatingIP) {
184         if (!floatingIPMap.containsKey(key)) {
185             floatingIPMap.put(key, floatingIP);
186         }
187     }
188
189     /**
190      * This method copies selected fields from the object and returns them
191      * as a new object, suitable for marshaling.
192      *
193      * @param fields
194      *            List of attributes to be extracted
195      * @return an OpenStackPorts object with only the selected fields
196      * populated
197      */
198
199     public NeutronPort extractFields(List<String> fields) {
200         NeutronPort ans = new NeutronPort();
201         Iterator<String> i = fields.iterator();
202         while (i.hasNext()) {
203             String s = i.next();
204             if (s.equals("id")) {
205                 ans.setPortUUID(this.getPortUUID());
206             }
207             if (s.equals("network_id")) {
208                 ans.setNetworkUUID(this.getNetworkUUID());
209             }
210             if (s.equals("name")) {
211                 ans.setName(this.getName());
212             }
213             if (s.equals("admin_state_up")) {
214                 ans.setAdminStateUp(this.getAdminStateUp());
215             }
216             if (s.equals("status")) {
217                 ans.setStatus(this.getStatus());
218             }
219             if (s.equals("mac_address")) {
220                 ans.setMacAddress(this.getMacAddress());
221             }
222             if (s.equals("fixed_ips")) {
223                 List<Neutron_IPs> fixedIPs = new ArrayList<Neutron_IPs>();
224                 fixedIPs.addAll(this.getFixedIPs());
225                 ans.setFixedIPs(fixedIPs);
226             }
227             if (s.equals("device_id")) {
228                 ans.setDeviceID(this.getDeviceID());
229             }
230             if (s.equals("device_owner")) {
231                 ans.setDeviceOwner(this.getDeviceOwner());
232             }
233             if (s.equals("tenant_id")) {
234                 ans.setTenantID(this.getTenantID());
235             }
236             if (s.equals("security_groups")) {
237                 List<NeutronSecurityGroup> securityGroups = new ArrayList<NeutronSecurityGroup>();
238                 securityGroups.addAll(this.getSecurityGroups());
239                 ans.setSecurityGroups(securityGroups);
240             }
241         }
242         return ans;
243     }
244
245     public void initDefaults() {
246         adminStateUp = true;
247         if (status == null) {
248             status = "ACTIVE";
249         }
250         if (fixedIPs == null) {
251             fixedIPs = new ArrayList<Neutron_IPs>();
252         }
253     }
254
255     /**
256      * This method checks to see if the port has a floating IPv4 address
257      * associated with the supplied fixed IPv4 address
258      *
259      * @param fixedIP
260      *            fixed IPv4 address in dotted decimal format
261      * @return a boolean indicating if there is a floating IPv4 address bound
262      * to the fixed IPv4 address
263      */
264
265     public boolean isBoundToFloatingIP(String fixedIP) {
266         return floatingIPMap.containsKey(fixedIP);
267     }
268
269     @Override
270     public String toString() {
271         return "NeutronPort [portUUID=" + portUUID + ", networkUUID=" + networkUUID + ", name=" + name
272                 + ", adminStateUp=" + adminStateUp + ", status=" + status + ", macAddress=" + macAddress
273                 + ", fixedIPs=" + fixedIPs + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID="
274                 + tenantID + ", floatingIPMap=" + floatingIPMap + ", securityGroups=" + securityGroups + "]";
275     }
276 }