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.util.ArrayList;
12 import java.util.Iterator;
13 import java.util.List;
15 import javax.xml.bind.annotation.XmlAccessType;
16 import javax.xml.bind.annotation.XmlAccessorType;
17 import javax.xml.bind.annotation.XmlElement;
18 import javax.xml.bind.annotation.XmlRootElement;
20 @XmlRootElement(name = "network")
21 @XmlAccessorType(XmlAccessType.NONE)
23 public class NeutronNetwork {
24 // See OpenStack Network API v2.0 Reference for description of
25 // annotated attributes
27 @XmlElement (name="id")
28 String networkUUID; // network UUID
30 @XmlElement (name="name")
31 String networkName; // name
33 @XmlElement (defaultValue="true", name="admin_state_up")
34 Boolean adminStateUp; // admin state up (true/false)
36 @XmlElement (defaultValue="false", name="shared")
37 Boolean shared; // shared network or not
39 @XmlElement (name="tenant_id")
40 String tenantID; // tenant for this network
42 @XmlElement (defaultValue="false", namespace="router", name="external")
43 Boolean routerExternal; // network external or not
45 @XmlElement (defaultValue="flat", namespace="provider", name="network_type")
46 String providerNetworkType; // provider network type (flat or vlan)
48 @XmlElement (namespace="provider", name="physical_network")
49 String providerPhysicalNetwork; // provider physical network (name)
51 @XmlElement (namespace="provider", name="segmentation_id")
52 String providerSegmentationID; // provide segmentation ID (vlan ID)
54 @XmlElement (name="status")
55 String status; // status (read-only)
57 @XmlElement (name="subnets")
58 List<String> subnets; // subnets (read-only)
60 /* This attribute lists the ports associated with an instance
61 * which is needed for determining if that instance can be deleted
64 List<NeutronPort> myPorts;
66 public NeutronNetwork() {
67 myPorts = new ArrayList<NeutronPort>();
70 public void initDefaults() {
71 subnets = new ArrayList<String>();
75 if (adminStateUp == null) {
81 if (routerExternal == null) {
82 routerExternal = false;
84 if (providerNetworkType == null) {
85 providerNetworkType = "flat";
89 public String getID() { return networkUUID; }
91 public String getNetworkUUID() {
95 public void setNetworkUUID(String networkUUID) {
96 this.networkUUID = networkUUID;
99 public String getNetworkName() {
103 public void setNetworkName(String networkName) {
104 this.networkName = networkName;
107 public boolean isAdminStateUp() {
111 public Boolean getAdminStateUp() { return adminStateUp; }
113 public void setAdminStateUp(boolean newValue) {
114 adminStateUp = newValue;
117 public boolean isShared() { return shared; }
119 public Boolean getShared() { return shared; }
121 public void setShared(boolean newValue) {
125 public String getTenantID() {
129 public void setTenantID(String tenantID) {
130 this.tenantID = tenantID;
133 public boolean isRouterExternal() { return routerExternal; }
135 public Boolean getRouterExternal() { return routerExternal; }
137 public void setRouterExternal(boolean newValue) {
138 routerExternal = newValue;
141 public String getProviderNetworkType() {
142 return providerNetworkType;
145 public void setProviderNetworkType(String providerNetworkType) {
146 this.providerNetworkType = providerNetworkType;
149 public String getProviderPhysicalNetwork() {
150 return providerPhysicalNetwork;
153 public void setProviderPhysicalNetwork(String providerPhysicalNetwork) {
154 this.providerPhysicalNetwork = providerPhysicalNetwork;
157 public String getProviderSegmentationID() {
158 return providerSegmentationID;
161 public void setProviderSegmentationID(String providerSegmentationID) {
162 this.providerSegmentationID = providerSegmentationID;
165 public String getStatus() {
169 public void setStatus(String status) {
170 this.status = status;
173 public List<String> getSubnets() {
177 public void setSubnets(List<String> subnets) {
178 this.subnets = subnets;
181 public void addSubnet(String uuid) {
185 public void removeSubnet(String uuid) {
186 subnets.remove(uuid);
189 public List<NeutronPort> getPortsOnNetwork() {
193 public void addPort(NeutronPort port) {
197 public void removePort(NeutronPort port) {
198 myPorts.remove(port);
202 * This method copies selected fields from the object and returns them
203 * as a new object, suitable for marshaling.
206 * List of attributes to be extracted
207 * @return an OpenStackNetworks object with only the selected fields
211 public NeutronNetwork extractFields(List<String> fields) {
212 NeutronNetwork ans = new NeutronNetwork();
213 Iterator<String> i = fields.iterator();
214 while (i.hasNext()) {
216 if (s.equals("id")) {
217 ans.setNetworkUUID(this.getNetworkUUID());
219 if (s.equals("name")) {
220 ans.setNetworkName(this.getNetworkName());
222 if (s.equals("admin_state_up")) {
223 ans.setAdminStateUp(adminStateUp);
225 if (s.equals("status")) {
226 ans.setStatus(this.getStatus());
228 if (s.equals("subnets")) {
229 List<String> subnetList = new ArrayList<String>();
230 subnetList.addAll(this.getSubnets());
231 ans.setSubnets(subnetList);
233 if (s.equals("shared")) {
234 ans.setShared(shared);
236 if (s.equals("tenant_id")) {
237 ans.setTenantID(this.getTenantID());