Hyunsun Moon
Committed by Gerrit Code Review

Added wrapper application of openstack4j

It is impossible to use openstack4j directly from ONOS apps
due to the Jersey version conflict.

Change-Id: I2df32430de42d627b03e0a2f8d8d2b9067ad3e14
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<app name="org.onosproject.openstack4j" origin="ON.Lab" version="${project.version}"
18 + category="default" url="http://onosproject.org"
19 + featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
20 + features="${project.artifactId}" apps="">
21 + <description>${project.description}</description>
22 + <artifact>mvn:${project.groupId}/onos-app-openstack4j/${project.version}</artifact>
23 +</app>
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 +<!--
3 + ~ Copyright 2016 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
18 + <feature name="${project.artifactId}" version="${project.version}" description="${project.description}">
19 + <bundle>mvn:${project.groupId}/onos-app-openstack4j/${project.version}</bundle>
20 + <bundle>wrap:mvn:org.pacesys/openstack4j/2.10/jar/withdeps$Bundle-SymbolicName=openstack4j&amp;Bundle-Version=2.10</bundle>
21 + </feature>
22 +</features>
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-apps</artifactId>
25 + <version>1.5.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-app-openstack4j</artifactId>
30 + <packaging>bundle</packaging>
31 +
32 + <description>Wrapper application of openstack4j.</description>
33 +
34 + <properties>
35 + <onos.app.name>org.onosproject.openstack4j</onos.app.name>
36 + <onos.app.category>default</onos.app.category>
37 + <onos.app.url>http://onosproject.org</onos.app.url>
38 + <onos.app.readme>Wrapper application of openstack4j.</onos.app.readme>
39 + </properties>
40 +
41 + <dependencies>
42 + <dependency>
43 + <groupId>org.osgi</groupId>
44 + <artifactId>org.osgi.compendium</artifactId>
45 + </dependency>
46 + <dependency>
47 + <groupId>org.pacesys</groupId>
48 + <artifactId>openstack4j</artifactId>
49 + <version>2.10</version>
50 + <classifier>withdeps</classifier>
51 + </dependency>
52 + </dependencies>
53 +
54 + <build>
55 + <plugins>
56 + <plugin>
57 + <groupId>org.apache.felix</groupId>
58 + <artifactId>maven-bundle-plugin</artifactId>
59 + <extensions>true</extensions>
60 + <configuration>
61 + <instructions>
62 + <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
63 + <Import-Package>
64 + org.slf4j,
65 + javax.xml.*,
66 + javax.net.*,
67 + javax.activation,
68 + org.w3c.dom.*,
69 + org.xml.sax.*,
70 + !com.sun.jdi,
71 + !org.openstack4j.*
72 + </Import-Package>
73 + <Export-Package>
74 + org.onosproject.openstack4j,
75 + org.openstack4j.api,
76 + org.openstack4j.model.network.*
77 + </Export-Package>
78 + <Embed-Transitive>true</Embed-Transitive>
79 + <Embed-Dependency>openstack4j</Embed-Dependency>
80 + </instructions>
81 + </configuration>
82 + </plugin>
83 + </plugins>
84 + </build>
85 +</project>
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.openstack4j;
17 +
18 +import org.apache.felix.scr.annotations.Activate;
19 +import org.apache.felix.scr.annotations.Component;
20 +import org.apache.felix.scr.annotations.Deactivate;
21 +import org.apache.felix.scr.annotations.Service;
22 +import org.openstack4j.api.OSClient;
23 +import org.openstack4j.api.exceptions.AuthenticationException;
24 +import org.openstack4j.model.network.Network;
25 +import org.openstack4j.model.network.Port;
26 +import org.openstack4j.model.network.Subnet;
27 +import org.openstack4j.model.network.options.PortListOptions;
28 +import org.openstack4j.openstack.OSFactory;
29 +import org.slf4j.Logger;
30 +import org.slf4j.LoggerFactory;
31 +
32 +import java.util.List;
33 +import java.util.stream.Collectors;
34 +
35 +import static com.google.common.base.Preconditions.checkNotNull;
36 +
37 +/**
38 + * Wrapper implementation of openstack4j.
39 + */
40 +@Component(immediate = true)
41 +@Service
42 +public class OpenStack4jManager implements OpenStack4jService {
43 +
44 + private final Logger log = LoggerFactory.getLogger(getClass());
45 +
46 + @Activate
47 + protected void activate() {
48 + log.info("Started");
49 + }
50 +
51 + @Deactivate
52 + protected void deactivate() {
53 + log.info("Stopped");
54 + }
55 +
56 + @Override
57 + public OSClient getClient(String endpoint, String tenant, String user, String password) {
58 + try {
59 + return OSFactory.builder()
60 + .endpoint(endpoint)
61 + .credentials(user, password)
62 + .tenantName(tenant)
63 + .authenticate();
64 + } catch (AuthenticationException e) {
65 + log.warn("Failed to authenticate");
66 + return null;
67 + }
68 + }
69 +
70 + @Override
71 + public List<Network> getNetworks(OSClient client) {
72 + checkNotNull(client, "OSClient is null");
73 + return client.networking().network().list()
74 + .stream()
75 + .collect(Collectors.toList());
76 + }
77 +
78 + @Override
79 + public Network getNetwork(OSClient client, String networkId) {
80 + checkNotNull(client, "OSClient is null");
81 + return client.networking().network().get(networkId);
82 + }
83 +
84 + @Override
85 + public List<Port> getPorts(OSClient client) {
86 + checkNotNull(client, "OSClient is null");
87 + return client.networking().port().list()
88 + .stream()
89 + .collect(Collectors.toList());
90 + }
91 +
92 + @Override
93 + public List<Port> getPorts(OSClient client, PortListOptions options) {
94 + checkNotNull(client, "OSClient is null");
95 + return client.networking().port().list(options)
96 + .stream()
97 + .collect(Collectors.toList());
98 + }
99 +
100 + @Override
101 + public Port getPort(OSClient client, String portId) {
102 + checkNotNull(client, "OSClient is null");
103 + return client.networking().port().get(portId);
104 + }
105 +
106 + @Override
107 + public List<Subnet> getSubnets(OSClient client) {
108 + checkNotNull(client, "OSClient is null");
109 + return client.networking().subnet().list()
110 + .stream()
111 + .collect(Collectors.toList());
112 + }
113 +
114 + @Override
115 + public Subnet getSubnet(OSClient client, String subnetId) {
116 + checkNotNull(client, "OSClient is null");
117 + return client.networking().subnet().get(subnetId);
118 + }
119 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.openstack4j;
17 +
18 +import org.openstack4j.api.OSClient;
19 +import org.openstack4j.model.network.Network;
20 +import org.openstack4j.model.network.Port;
21 +import org.openstack4j.model.network.Subnet;
22 +import org.openstack4j.model.network.options.PortListOptions;
23 +
24 +import java.util.List;
25 +
26 +/**
27 + * Wrapper service of openstack4j.
28 + */
29 +public interface OpenStack4jService {
30 +
31 + /**
32 + * Returns OpenStack REST client.
33 + *
34 + * @param endpoint endpoint URL
35 + * @param tenant tenant name
36 + * @param user user name
37 + * @param password password
38 + * @return openstack rest client or null if auth failed
39 + */
40 + OSClient getClient(String endpoint, String tenant, String user, String password);
41 +
42 + /**
43 + * Returns list of networks with a client information.
44 + *
45 + * @param client openstack rest client
46 + * @return list of networks or empty list if no networks
47 + */
48 + List<Network> getNetworks(OSClient client);
49 +
50 + /**
51 + * Returns network information.
52 + *
53 + * @param client openstack rest client
54 + * @param networkId network id
55 + * @return network or null if not found
56 + */
57 + Network getNetwork(OSClient client, String networkId);
58 +
59 + /**
60 + * Returns all ports.
61 + *
62 + * @param client openstack rest client
63 + * @return list of port or empty list if no ports
64 + */
65 + List<Port> getPorts(OSClient client);
66 +
67 + /**
68 + * Returns ports with a given options.
69 + *
70 + * @param client openstack rest client
71 + * @param options port list options
72 + * @return port list or empty list if no ports
73 + */
74 + List<Port> getPorts(OSClient client, PortListOptions options);
75 +
76 + /**
77 + * Returns port with a given port ID.
78 + *
79 + * @param client openstack rest client
80 + * @param portId port id
81 + * @return port or null if not found
82 + */
83 + Port getPort(OSClient client, String portId);
84 +
85 + /**
86 + * Returns all subnets.
87 + *
88 + * @param client openstack rest client
89 + * @return subnet list or empty list if no subnets
90 + */
91 + List<Subnet> getSubnets(OSClient client);
92 +
93 + /**
94 + * Returns subnet with a given subnet ID.
95 + *
96 + * @param client openstack rest client
97 + * @param subnetId subnet id
98 + * @return subnet or null if not found
99 + */
100 + Subnet getSubnet(OSClient client, String subnetId);
101 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/**
18 + * Wrapper application of openstack4j.
19 + */
20 +package org.onosproject.openstack4j;
...\ No newline at end of file ...\ No newline at end of file
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
68 <module>vpls</module> 68 <module>vpls</module>
69 <module>openstacknode</module> 69 <module>openstacknode</module>
70 <module>openstacknetworking</module> 70 <module>openstacknetworking</module>
71 + <module>openstack4j</module>
71 </modules> 72 </modules>
72 73
73 <properties> 74 <properties>
......