summaryrefslogtreecommitdiffstats
path: root/quantum-client
diff options
context:
space:
mode:
Diffstat (limited to 'quantum-client')
-rw-r--r--quantum-client/pom.xml25
-rw-r--r--quantum-client/src/main/java/com/woorea/openstack/quantum/Quantum.java51
-rw-r--r--quantum-client/src/main/java/com/woorea/openstack/quantum/api/NetworksResource.java84
-rw-r--r--quantum-client/src/main/java/com/woorea/openstack/quantum/api/PortsResource.java85
-rw-r--r--quantum-client/src/main/java/com/woorea/openstack/quantum/api/RoutersResource.java102
-rw-r--r--quantum-client/src/main/java/com/woorea/openstack/quantum/api/SubnetsResource.java84
-rw-r--r--quantum-client/src/main/java/com/woorea/openstack/quantum/api/query/AbsOpenStackCmd.java80
7 files changed, 511 insertions, 0 deletions
diff --git a/quantum-client/pom.xml b/quantum-client/pom.xml
new file mode 100644
index 0000000..1487637
--- /dev/null
+++ b/quantum-client/pom.xml
@@ -0,0 +1,25 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.openecomp.mso.libs</groupId>
+ <artifactId>openstack-java-sdk</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+ <groupId>org.openecomp.mso.libs.openstack-java-sdk</groupId>
+ <artifactId>quantum-client</artifactId>
+ <name>OpenStack Quantum Client</name>
+ <description>OpenStack Quantum Client</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.openecomp.mso.libs.openstack-java-sdk</groupId>
+ <artifactId>openstack-client</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.mso.libs.openstack-java-sdk</groupId>
+ <artifactId>quantum-model</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/quantum-client/src/main/java/com/woorea/openstack/quantum/Quantum.java b/quantum-client/src/main/java/com/woorea/openstack/quantum/Quantum.java
new file mode 100644
index 0000000..ec9c40f
--- /dev/null
+++ b/quantum-client/src/main/java/com/woorea/openstack/quantum/Quantum.java
@@ -0,0 +1,51 @@
+package com.woorea.openstack.quantum;
+
+
+import com.woorea.openstack.base.client.OpenStackClient;
+import com.woorea.openstack.base.client.OpenStackClientConnector;
+import com.woorea.openstack.quantum.api.NetworksResource;
+import com.woorea.openstack.quantum.api.PortsResource;
+import com.woorea.openstack.quantum.api.RoutersResource;
+import com.woorea.openstack.quantum.api.SubnetsResource;
+
+
+public class Quantum extends OpenStackClient {
+
+ private final NetworksResource NETWORKS;
+
+ private final PortsResource PORTS;
+
+ private final SubnetsResource SUBNETS;
+ private final RoutersResource ROUTERS;
+
+ public Quantum(String endpoint, OpenStackClientConnector connector) {
+ super(endpoint, connector);
+ NETWORKS = new NetworksResource(this);
+ PORTS = new PortsResource(this);
+ SUBNETS = new SubnetsResource(this);
+ ROUTERS=new RoutersResource(this);
+
+ }
+
+ public Quantum(String endpoint) {
+ this(endpoint, null);
+ }
+
+ public NetworksResource networks() {
+ return NETWORKS;
+ }
+
+ public PortsResource ports() {
+ return PORTS;
+ }
+
+ public SubnetsResource subnets() {
+ return SUBNETS;
+ }
+ public RoutersResource routers()
+ {
+ return ROUTERS;
+ }
+
+
+}
diff --git a/quantum-client/src/main/java/com/woorea/openstack/quantum/api/NetworksResource.java b/quantum-client/src/main/java/com/woorea/openstack/quantum/api/NetworksResource.java
new file mode 100644
index 0000000..97a919a
--- /dev/null
+++ b/quantum-client/src/main/java/com/woorea/openstack/quantum/api/NetworksResource.java
@@ -0,0 +1,84 @@
+package com.woorea.openstack.quantum.api;
+
+
+import com.woorea.openstack.base.client.Entity;
+import com.woorea.openstack.base.client.HttpMethod;
+import com.woorea.openstack.base.client.OpenStackClient;
+import com.woorea.openstack.base.client.OpenStackRequest;
+import com.woorea.openstack.quantum.model.Network;
+import com.woorea.openstack.quantum.model.Networks;
+
+public class NetworksResource {
+
+ private final OpenStackClient CLIENT;
+
+ public NetworksResource(OpenStackClient client) {
+ CLIENT = client;
+ }
+
+ public List list() {
+ return new List();
+ }
+
+ public Create create(Network net) {
+ return new Create(net);
+ }
+
+ public Update update(Network net) {
+ return new Update(net);
+ }
+
+ public Delete delete(String netId){
+ return new Delete(netId);
+ }
+
+ public Show show(String netId){
+ return new Show(netId);
+ }
+
+ public class List extends OpenStackRequest<Networks> {
+
+ public List() {
+ super(CLIENT, HttpMethod.GET, "networks", null, Networks.class);
+ }
+ }
+
+ public class Query extends OpenStackRequest<Networks> {
+
+ public Query(Network network) {
+ //super(network);
+// target = target.path("v2.0").path("networks");
+// target = queryParam(target);
+// return target.request(MediaType.APPLICATION_JSON).get(Networks.class);
+ }
+ }
+
+
+ public class Create extends OpenStackRequest<Network> {
+
+ public Create(Network net) {
+ super(CLIENT, HttpMethod.POST, "networks", Entity.json(net), Network.class);
+ }
+ }
+
+ public class Update extends OpenStackRequest<Network> {
+
+ public Update(Network net) {
+ super(CLIENT, HttpMethod.PUT, buildPath("networks/", net.getId()), Entity.json(net), Network.class);
+ }
+ }
+
+ public class Show extends OpenStackRequest<Network> {
+
+ public Show(String id) {
+ super(CLIENT, HttpMethod.GET, buildPath("networks/", id), null, Network.class);
+ }
+ }
+
+ public class Delete extends OpenStackRequest<Void> {
+
+ public Delete(String id){
+ super(CLIENT, HttpMethod.DELETE, buildPath("networks/", id), null, Void.class);
+ }
+ }
+}
diff --git a/quantum-client/src/main/java/com/woorea/openstack/quantum/api/PortsResource.java b/quantum-client/src/main/java/com/woorea/openstack/quantum/api/PortsResource.java
new file mode 100644
index 0000000..d14e860
--- /dev/null
+++ b/quantum-client/src/main/java/com/woorea/openstack/quantum/api/PortsResource.java
@@ -0,0 +1,85 @@
+package com.woorea.openstack.quantum.api;
+
+
+import com.woorea.openstack.base.client.Entity;
+import com.woorea.openstack.base.client.HttpMethod;
+import com.woorea.openstack.base.client.OpenStackClient;
+import com.woorea.openstack.base.client.OpenStackRequest;
+import com.woorea.openstack.quantum.model.Port;
+import com.woorea.openstack.quantum.model.Ports;
+
+public class PortsResource {
+
+ private final OpenStackClient CLIENT;
+
+ public PortsResource(OpenStackClient client) {
+ CLIENT = client;
+ }
+
+ public List list() {
+ return new List();
+ }
+
+ public Create create(Port port){
+ return new Create(port);
+ }
+
+ public Update update(Port port){
+ return new Update(port);
+ }
+
+ public Delete delete(String portId){
+ return new Delete(portId);
+ }
+
+ public Show show(String portId){
+ return new Show(portId);
+ }
+
+ public class List extends OpenStackRequest<Ports> {
+
+ public List() {
+ super(CLIENT, HttpMethod.GET, "ports", null, Ports.class);
+ }
+ }
+
+ public class Query extends OpenStackRequest<Ports> {
+
+ public Query(Port port) {
+ //super(port);
+// target = target.path("v2.0").path("ports");
+// target = queryParam(target);
+// return target.request(MediaType.APPLICATION_JSON).get(Ports.class);
+ }
+
+ }
+
+
+ public class Create extends OpenStackRequest<Port> {
+
+ public Create(Port port){
+ super(CLIENT, HttpMethod.POST, "ports", Entity.json(port), Port.class);
+ }
+ }
+
+ public class Update extends OpenStackRequest<Port> {
+
+ public Update(Port port){
+ super(CLIENT, HttpMethod.PUT, buildPath("ports/", port.getId()), Entity.json(port), Port.class);
+ }
+ }
+
+ public class Show extends OpenStackRequest<Port> {
+
+ public Show(String id) {
+ super(CLIENT, HttpMethod.GET, buildPath("ports/", id), null, Port.class);
+ }
+ }
+
+ public class Delete extends OpenStackRequest<Void> {
+
+ public Delete(String id){
+ super(CLIENT, HttpMethod.DELETE, buildPath("ports/", id), null, Void.class);
+ }
+ }
+}
diff --git a/quantum-client/src/main/java/com/woorea/openstack/quantum/api/RoutersResource.java b/quantum-client/src/main/java/com/woorea/openstack/quantum/api/RoutersResource.java
new file mode 100644
index 0000000..bcd646d
--- /dev/null
+++ b/quantum-client/src/main/java/com/woorea/openstack/quantum/api/RoutersResource.java
@@ -0,0 +1,102 @@
+package com.woorea.openstack.quantum.api;
+
+import com.woorea.openstack.base.client.Entity;
+import com.woorea.openstack.base.client.HttpMethod;
+import com.woorea.openstack.base.client.OpenStackClient;
+import com.woorea.openstack.base.client.OpenStackRequest;
+import com.woorea.openstack.quantum.model.Router;
+import com.woorea.openstack.quantum.model.RouterForAddInterface;
+import com.woorea.openstack.quantum.model.RouterForCreate;
+import com.woorea.openstack.quantum.model.RouterInterface;
+import com.woorea.openstack.quantum.model.Routers;
+
+public class RoutersResource {
+
+ private final OpenStackClient CLIENT;
+
+ public RoutersResource(OpenStackClient client) {
+ CLIENT = client;
+ }
+
+ public List list() {
+ return new List();
+ }
+
+ public Create create(RouterForCreate router){
+ return new Create(router);
+ }
+
+ public Delete delete(String netId){
+ return new Delete(netId);
+ }
+
+ public Show show(String netId){
+ return new Show(netId);
+ }
+
+ public class List extends OpenStackRequest<Routers> {
+
+ public List() {
+ super(CLIENT, HttpMethod.GET, "routers", null, Routers.class);
+ }
+ }
+
+ public class Query extends OpenStackRequest<Routers> {
+
+ public Query(Router router) {
+ //super(network);
+// target = target.path("v2.0").path("networks");
+// target = queryParam(target);
+// return target.request(MediaType.APPLICATION_JSON).get(Networks.class);
+ }
+ }
+ public class Create extends OpenStackRequest<Router> {
+
+ public Create(RouterForCreate router){
+ super(CLIENT, HttpMethod.POST, "routers", Entity.json(router), Router.class);
+ }
+ }
+
+
+
+ public class Show extends OpenStackRequest<Router> {
+
+ public Show(String id) {
+ super(CLIENT, HttpMethod.GET, buildPath("routers/", id), null, Router.class);
+ }
+ }
+
+ public class Delete extends OpenStackRequest<Void> {
+
+ public Delete(String id){
+ super(CLIENT, HttpMethod.DELETE, buildPath("routers/", id), null, Void.class);
+ }
+ }
+ public Attach addInterface(RouterForAddInterface interfaceToAdd){
+ return new Attach(interfaceToAdd);
+ }
+ public class Attach extends OpenStackRequest<RouterInterface> {
+
+ public Attach(RouterForAddInterface interfaceToAdd){
+ super(CLIENT, HttpMethod.PUT, buildPath("routers/",interfaceToAdd.getRouterId(),"/add_router_interface"), Entity.json(interfaceToAdd),RouterInterface.class);
+ }
+
+ }
+ public Detach deleteInterface(RouterForAddInterface interfaceRouter) {
+ return new Detach(interfaceRouter);
+ }
+
+ public class Detach extends OpenStackRequest<RouterInterface> {
+
+ public Detach(RouterForAddInterface interfaceToAdd) {
+ super(CLIENT, HttpMethod.PUT, buildPath("routers/",
+ interfaceToAdd.getRouterId(), "/remove_router_interface"),
+ Entity.json(interfaceToAdd), RouterInterface.class);
+ }
+
+ }
+
+
+
+
+}
diff --git a/quantum-client/src/main/java/com/woorea/openstack/quantum/api/SubnetsResource.java b/quantum-client/src/main/java/com/woorea/openstack/quantum/api/SubnetsResource.java
new file mode 100644
index 0000000..1864604
--- /dev/null
+++ b/quantum-client/src/main/java/com/woorea/openstack/quantum/api/SubnetsResource.java
@@ -0,0 +1,84 @@
+package com.woorea.openstack.quantum.api;
+
+
+import com.woorea.openstack.base.client.Entity;
+import com.woorea.openstack.base.client.HttpMethod;
+import com.woorea.openstack.base.client.OpenStackClient;
+import com.woorea.openstack.base.client.OpenStackRequest;
+import com.woorea.openstack.quantum.model.Subnet;
+import com.woorea.openstack.quantum.model.Subnets;
+
+public class SubnetsResource {
+
+ private final OpenStackClient CLIENT;
+
+ public SubnetsResource(OpenStackClient client) {
+ CLIENT = client;
+ }
+
+ public List list() {
+ return new List();
+ }
+
+ public Create create(Subnet net) {
+ return new Create(net);
+ }
+
+ public Update update(Subnet net) {
+ return new Update(net);
+ }
+
+ public Delete delete(String netId){
+ return new Delete(netId);
+ }
+
+ public Show show(String netId){
+ return new Show(netId);
+ }
+
+ public class List extends OpenStackRequest<Subnets> {
+
+ public List() {
+ super(CLIENT, HttpMethod.GET, "subnets", null, Subnets.class);
+ }
+ }
+
+ public class Query extends OpenStackRequest<Subnets> {
+
+ public Query(Subnet subnet) {
+ //super(subnet);
+// target = target.path("v2.0").path("subnets");
+// target = queryParam(target);
+// return target.request(MediaType.APPLICATION_JSON).get(Subnets.class);
+ }
+ }
+
+
+ public class Create extends OpenStackRequest<Subnet> {
+
+ public Create(Subnet subnet) {
+ super(CLIENT, HttpMethod.POST, "subnets", Entity.json(subnet), Subnet.class);
+ }
+ }
+
+ public class Update extends OpenStackRequest<Subnet> {
+
+ public Update(Subnet subnet) {
+ super(CLIENT, HttpMethod.PUT, buildPath("subnets/", subnet.getId()), Entity.json(subnet), Subnet.class);
+ }
+ }
+
+ public class Show extends OpenStackRequest<Subnet> {
+
+ public Show(String id) {
+ super(CLIENT, HttpMethod.GET, buildPath("subnets/", id), null, Subnet.class);
+ }
+ }
+
+ public class Delete extends OpenStackRequest<Void> {
+
+ public Delete(String id){
+ super(CLIENT, HttpMethod.DELETE, buildPath("subnets/", id), null, Void.class);
+ }
+ }
+}
diff --git a/quantum-client/src/main/java/com/woorea/openstack/quantum/api/query/AbsOpenStackCmd.java b/quantum-client/src/main/java/com/woorea/openstack/quantum/api/query/AbsOpenStackCmd.java
new file mode 100644
index 0000000..8de5abf
--- /dev/null
+++ b/quantum-client/src/main/java/com/woorea/openstack/quantum/api/query/AbsOpenStackCmd.java
@@ -0,0 +1,80 @@
+package com.woorea.openstack.quantum.api.query;
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+import com.woorea.openstack.base.client.OpenStackRequest;
+
+public class AbsOpenStackCmd<T> extends OpenStackRequest<T> {
+
+ private T query;
+
+ protected AbsOpenStackCmd(T query)
+ {
+ this.setQuery(query);
+ }
+
+ /**
+ * @param query the query to set
+ */
+ public void setQuery(T query) {
+ this.query = query;
+ }
+
+ /**
+ * @return the query
+ */
+ public T getQuery() {
+ return query;
+ }
+
+ private String getFieldValue(Field field, T target)
+ {
+ try {
+ field.setAccessible(true);
+ Object obj = field.get(target);
+ if (obj == null)
+ return null;
+ return obj.toString();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private Map<String, String> getObjectParamMap(T target)
+ {
+ Map<String, String> resultMap = new HashMap<String, String>();
+ if (target == null)
+ return resultMap;
+
+ Field[] paramMap = target.getClass().getDeclaredFields();
+ for (Field field : paramMap) {
+ String resultName = field.getName();
+ String value = getFieldValue(field, target);
+ if (value != null) {
+ JsonProperty prop = field.getAnnotation(JsonProperty.class);
+ if (prop != null) {
+ resultMap.put(prop.value(), getFieldValue(field, target));
+ } else {
+ resultMap.put(resultName, getFieldValue(field, target));
+ }
+ }
+ }
+
+ return resultMap;
+ }
+
+ /*
+ public WebTarget queryParam(WebTarget target) {
+ Map<String, String> map = getObjectParamMap(this.query);
+ for (String fieldName : map.keySet()) {
+ target = target.queryParam(fieldName, map.get(fieldName));
+ }
+ return target;
+ }
+ */
+
+}