2 * Copyright IBM Corporation, 2013. All rights reserved.
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
9 package org.opendaylight.controller.networkconfig.neutron;
11 import java.io.Serializable;
12 import java.util.ArrayList;
13 import java.util.Iterator;
14 import java.util.List;
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;
21 @XmlRootElement(name = "network")
22 @XmlAccessorType(XmlAccessType.NONE)
24 public class NeutronNetwork implements Serializable {
25 // See OpenStack Network API v2.0 Reference for description of
26 // annotated attributes
28 private static final long serialVersionUID = 1L;
30 @XmlElement (name="id")
31 String networkUUID; // network UUID
33 @XmlElement (name="name")
34 String networkName; // name
36 @XmlElement (defaultValue="true", name="admin_state_up")
37 Boolean adminStateUp; // admin state up (true/false)
39 @XmlElement (defaultValue="false", name="shared")
40 Boolean shared; // shared network or not
42 @XmlElement (name="tenant_id")
43 String tenantID; // tenant for this network
45 @XmlElement (defaultValue="false", namespace="router", name="external")
46 Boolean routerExternal; // network external or not
48 @XmlElement (defaultValue="flat", namespace="provider", name="network_type")
49 String providerNetworkType; // provider network type (flat or vlan)
51 @XmlElement (namespace="provider", name="physical_network")
52 String providerPhysicalNetwork; // provider physical network (name)
54 @XmlElement (namespace="provider", name="segmentation_id")
55 String providerSegmentationID; // provide segmentation ID (vlan ID)
57 @XmlElement (name="status")
58 String status; // status (read-only)
60 @XmlElement (name="subnets")
61 List<String> subnets; // subnets (read-only)
63 /* This attribute lists the ports associated with an instance
64 * which is needed for determining if that instance can be deleted
67 List<NeutronPort> myPorts;
69 public NeutronNetwork() {
70 myPorts = new ArrayList<NeutronPort>();
73 public void initDefaults() {
74 subnets = new ArrayList<String>();
78 if (adminStateUp == null) {
84 if (routerExternal == null) {
85 routerExternal = false;
87 if (providerNetworkType == null) {
88 providerNetworkType = "flat";
92 public String getID() { return networkUUID; }
94 public String getNetworkUUID() {
98 public void setNetworkUUID(String networkUUID) {
99 this.networkUUID = networkUUID;
102 public String getNetworkName() {
106 public void setNetworkName(String networkName) {
107 this.networkName = networkName;
110 public boolean isAdminStateUp() {
114 public Boolean getAdminStateUp() { return adminStateUp; }
116 public void setAdminStateUp(boolean newValue) {
117 adminStateUp = newValue;
120 public boolean isShared() { return shared; }
122 public Boolean getShared() { return shared; }
124 public void setShared(boolean newValue) {
128 public String getTenantID() {
132 public void setTenantID(String tenantID) {
133 this.tenantID = tenantID;
136 public boolean isRouterExternal() { return routerExternal; }
138 public Boolean getRouterExternal() { return routerExternal; }
140 public void setRouterExternal(boolean newValue) {
141 routerExternal = newValue;
144 public String getProviderNetworkType() {
145 return providerNetworkType;
148 public void setProviderNetworkType(String providerNetworkType) {
149 this.providerNetworkType = providerNetworkType;
152 public String getProviderPhysicalNetwork() {
153 return providerPhysicalNetwork;
156 public void setProviderPhysicalNetwork(String providerPhysicalNetwork) {
157 this.providerPhysicalNetwork = providerPhysicalNetwork;
160 public String getProviderSegmentationID() {
161 return providerSegmentationID;
164 public void setProviderSegmentationID(String providerSegmentationID) {
165 this.providerSegmentationID = providerSegmentationID;
168 public String getStatus() {
172 public void setStatus(String status) {
173 this.status = status;
176 public List<String> getSubnets() {
180 public void setSubnets(List<String> subnets) {
181 this.subnets = subnets;
184 public void addSubnet(String uuid) {
188 public void removeSubnet(String uuid) {
189 subnets.remove(uuid);
192 public List<NeutronPort> getPortsOnNetwork() {
196 public void addPort(NeutronPort port) {
200 public void removePort(NeutronPort port) {
201 myPorts.remove(port);
205 * This method copies selected fields from the object and returns them
206 * as a new object, suitable for marshaling.
209 * List of attributes to be extracted
210 * @return an OpenStackNetworks object with only the selected fields
214 public NeutronNetwork extractFields(List<String> fields) {
215 NeutronNetwork ans = new NeutronNetwork();
216 Iterator<String> i = fields.iterator();
217 while (i.hasNext()) {
219 if (s.equals("id")) {
220 ans.setNetworkUUID(this.getNetworkUUID());
222 if (s.equals("name")) {
223 ans.setNetworkName(this.getNetworkName());
225 if (s.equals("admin_state_up")) {
226 ans.setAdminStateUp(adminStateUp);
228 if (s.equals("status")) {
229 ans.setStatus(this.getStatus());
231 if (s.equals("subnets")) {
232 List<String> subnetList = new ArrayList<String>();
233 subnetList.addAll(this.getSubnets());
234 ans.setSubnets(subnetList);
236 if (s.equals("shared")) {
237 ans.setShared(shared);
239 if (s.equals("tenant_id")) {
240 ans.setTenantID(this.getTenantID());
247 public String toString() {
248 return "NeutronNetwork [networkUUID=" + networkUUID + ", networkName=" + networkName + ", adminStateUp="
249 + adminStateUp + ", shared=" + shared + ", tenantID=" + tenantID + ", routerExternal=" + routerExternal
250 + ", providerNetworkType=" + providerNetworkType + ", providerPhysicalNetwork="
251 + providerPhysicalNetwork + ", providerSegmentationID=" + providerSegmentationID + ", status=" + status
252 + ", subnets=" + subnets + ", myPorts=" + myPorts + "]";