Ray Milkey
Committed by Gerrit Code Review

XOS integration app

Change-Id: I2fc1cd5bec032ad027cbb685d8f03df732717fcc
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
48 <module>test</module> 48 <module>test</module>
49 <module>segmentrouting</module> 49 <module>segmentrouting</module>
50 <module>cordfabric</module> 50 <module>cordfabric</module>
51 + <module>xos-integration</module>
51 </modules> 52 </modules>
52 53
53 <properties> 54 <properties>
......
1 +<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 +<!--
3 + ~ Copyright 2015 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}-${short.version}">
18 + <repository>mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features</repository>
19 + <feature name="${project.artifactId}" version="${project.version}"
20 + description="${project.description}">
21 + <bundle>mvn:com.sun.jersey/jersey-client/1.19</bundle>
22 + <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
23 + </feature>
24 +</features>
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2014 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/maven-v4_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.2.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-app-xos-integration</artifactId>
30 + <packaging>bundle</packaging>
31 +
32 + <description>ONOS XOS integration application</description>
33 +
34 + <properties>
35 + <onos.app.name>org.onosproject.xosintegration</onos.app.name>
36 + </properties>
37 +
38 + <dependencies>
39 + <dependency>
40 + <groupId>org.osgi</groupId>
41 + <artifactId>org.osgi.compendium</artifactId>
42 + </dependency>
43 + <dependency>
44 + <groupId>com.sun.jersey</groupId>
45 + <artifactId>jersey-client</artifactId>
46 + <version>1.19</version>
47 + </dependency>
48 + <dependency>
49 + <groupId>org.onosproject</groupId>
50 + <artifactId>onos-cli</artifactId>
51 + <version>${project.version}</version>
52 + </dependency>
53 + <dependency>
54 + <groupId>org.osgi</groupId>
55 + <artifactId>org.osgi.core</artifactId>
56 + </dependency>
57 + <dependency>
58 + <groupId>org.apache.karaf.shell</groupId>
59 + <artifactId>org.apache.karaf.shell.console</artifactId>
60 + </dependency>
61 + <dependency>
62 + <groupId>org.onosproject</groupId>
63 + <artifactId>onlab-misc</artifactId>
64 + </dependency>
65 + </dependencies>
66 +
67 +</project>
1 +/*
2 + * Copyright 2014-2015 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.xosintegration;
17 +
18 +import java.util.Dictionary;
19 +import java.util.Set;
20 +import java.util.stream.Collectors;
21 +import java.util.stream.IntStream;
22 +
23 +import org.apache.felix.scr.annotations.Activate;
24 +import org.apache.felix.scr.annotations.Component;
25 +import org.apache.felix.scr.annotations.Deactivate;
26 +import org.apache.felix.scr.annotations.Modified;
27 +import org.apache.felix.scr.annotations.Property;
28 +import org.apache.felix.scr.annotations.Reference;
29 +import org.apache.felix.scr.annotations.ReferenceCardinality;
30 +import org.apache.felix.scr.annotations.Service;
31 +import org.onlab.util.Tools;
32 +import org.onosproject.cfg.ComponentConfigService;
33 +import org.onosproject.core.ApplicationId;
34 +import org.onosproject.core.CoreService;
35 +import org.osgi.service.component.ComponentContext;
36 +import org.slf4j.Logger;
37 +
38 +import com.eclipsesource.json.JsonArray;
39 +import com.eclipsesource.json.JsonObject;
40 +import com.sun.jersey.api.client.Client;
41 +import com.sun.jersey.api.client.ClientResponse;
42 +import com.sun.jersey.api.client.WebResource;
43 +import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
44 +
45 +import static com.google.common.base.Strings.isNullOrEmpty;
46 +import static com.google.common.net.MediaType.JSON_UTF_8;
47 +import static java.net.HttpURLConnection.HTTP_CREATED;
48 +import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
49 +import static java.net.HttpURLConnection.HTTP_OK;
50 +import static org.slf4j.LoggerFactory.getLogger;
51 +
52 +
53 +/**
54 + * XOS interface application.
55 + */
56 +@Component(immediate = true)
57 +@Service
58 +public class OnosXOSIntegrationManager implements VoltTenantService {
59 +
60 + private static final String TEST_XOS_SERVER_ADDRESS = "10.254.1.22";
61 + private static final int TEST_XOS_SERVER_PORT = 8000;
62 + private static final String XOS_TENANT_BASE_URI = "/xoslib/volttenant/";
63 +
64 + private final Logger log = getLogger(getClass());
65 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
66 + protected CoreService coreService;
67 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
68 + protected ComponentConfigService cfgService;
69 + @Property(name = "XOSServerAddress",
70 + value = TEST_XOS_SERVER_ADDRESS,
71 + label = "XOS Server address")
72 + protected String xosServerAddress = TEST_XOS_SERVER_ADDRESS;
73 + @Property(name = "XOSServerPort",
74 + intValue = TEST_XOS_SERVER_PORT,
75 + label = "XOS Server port")
76 + protected int xosServerPort = TEST_XOS_SERVER_PORT;
77 + private ApplicationId appId;
78 +
79 + @Activate
80 + public void activate(ComponentContext context) {
81 + log.info("XOS app is starting");
82 + cfgService.registerProperties(getClass());
83 + appId = coreService.registerApplication("org.onosproject.xosintegration");
84 + readComponentConfiguration(context);
85 +
86 + log.info("XOS({}) started", appId.id());
87 + }
88 +
89 + @Deactivate
90 + public void deactivate() {
91 + cfgService.unregisterProperties(getClass(), false);
92 + log.info("XOS({}) stopped", appId.id());
93 + }
94 +
95 + @Modified
96 + public void modified(ComponentContext context) {
97 + readComponentConfiguration(context);
98 + }
99 +
100 + /**
101 + * Converts a JSON representation of a tenant into a tenant object.
102 + *
103 + * @param jsonTenant JSON object representing the tenant
104 + * @return volt tenant object
105 + */
106 + private VoltTenant jsonToTenant(JsonObject jsonTenant) {
107 + return VoltTenant.builder()
108 + .withHumanReadableName(jsonTenant.get("humanReadableName").asString())
109 + .withId(jsonTenant.get("id").asInt())
110 + .withProviderService(jsonTenant.get("provider_service").asInt())
111 + .withServiceSpecificId(jsonTenant.get("service_specific_id").asString())
112 + .withVlanId(jsonTenant.get("vlan_id").asString())
113 + .build();
114 + }
115 +
116 + /**
117 + * Converts a tenant object into a JSON string.
118 + *
119 + * @param tenant volt tenant object to convert
120 + * @return JSON string for the tenant
121 + */
122 + private String tenantToJson(VoltTenant tenant) {
123 + return "{"
124 + + "\"humanReadableName\": \"" + tenant.humanReadableName() + "\","
125 + + "\"id\": \"" + tenant.id() + "\","
126 + + "\"provider_service\": \"" + tenant.providerService() + "\","
127 + + "\"service_specific_id\": \"" + tenant.serviceSpecificId() + "\","
128 + + "\"vlan_id\": \"" + tenant.vlanId() + "\""
129 + + "}";
130 + }
131 +
132 + /**
133 + * Gets a client web resource builder for the base XOS REST API
134 + * with no additional URI.
135 + *
136 + * @return web resource builder
137 + */
138 + private WebResource.Builder getClientBuilder() {
139 + return getClientBuilder("");
140 + }
141 +
142 + /**
143 + * Gets a client web resource builder for the base XOS REST API
144 + * with an optional additional URI.
145 + *
146 + * @return web resource builder
147 + */
148 + private WebResource.Builder getClientBuilder(String uri) {
149 + String baseUrl = "http://" + xosServerAddress + ":"
150 + + Integer.toString(xosServerPort);
151 + Client client = Client.create();
152 + client.addFilter(new HTTPBasicAuthFilter("padmin@vicci.org", "letmein"));
153 + WebResource resource = client.resource(baseUrl
154 + + XOS_TENANT_BASE_URI + uri);
155 + return resource.accept(JSON_UTF_8.toString())
156 + .type(JSON_UTF_8.toString());
157 + }
158 +
159 + /**
160 + * Performs a REST GET operation on the base XOS REST URI.
161 + *
162 + * @return JSON string fetched by the GET operation
163 + */
164 + private String getRest() {
165 + return getRest("");
166 + }
167 +
168 + /**
169 + * Performs a REST GET operation on the base XOS REST URI with
170 + * an optional additional URI.
171 + *
172 + * @return JSON string fetched by the GET operation
173 + */
174 + private String getRest(String uri) {
175 + WebResource.Builder builder = getClientBuilder(uri);
176 + ClientResponse response = builder.get(ClientResponse.class);
177 +
178 + if (response.getStatus() != HTTP_OK) {
179 + log.info("REST GET request returned error code {}",
180 + response.getStatus());
181 + }
182 + String jsonString = response.getEntity(String.class);
183 + log.info("JSON read:\n{}", jsonString);
184 +
185 + return jsonString;
186 + }
187 +
188 + /**
189 + * Performs a REST POST operation of a json string on the base
190 + * XOS REST URI with an optional additional URI.
191 + *
192 + * @param json JSON string to post
193 + */
194 + private void postRest(String json) {
195 + WebResource.Builder builder = getClientBuilder();
196 + ClientResponse response = builder.post(ClientResponse.class, json);
197 +
198 + if (response.getStatus() != HTTP_CREATED) {
199 + log.info("REST POST request returned error code {}",
200 + response.getStatus());
201 + }
202 + }
203 +
204 + /**
205 + * Performs a REST DELETE operation on the base
206 + * XOS REST URI with an optional additional URI.
207 + *
208 + * @param uri optional additional URI
209 + */
210 + private void deleteRest(String uri) {
211 + WebResource.Builder builder = getClientBuilder(uri);
212 + ClientResponse response = builder.delete(ClientResponse.class);
213 +
214 + if (response.getStatus() != HTTP_NO_CONTENT) {
215 + log.info("REST DELETE request returned error code {}",
216 + response.getStatus());
217 + }
218 + }
219 +
220 + /**
221 + * Deletes the tenant with the given ID.
222 + *
223 + * @param tenantId ID of tenant to delete
224 + */
225 + private void deleteTenant(long tenantId) {
226 + deleteRest(Long.toString(tenantId));
227 + }
228 +
229 + @Override
230 + public Set<VoltTenant> getAllTenants() {
231 + String jsonString = getRest();
232 +
233 + JsonArray voltTenantItems = JsonArray.readFrom(jsonString);
234 +
235 + return IntStream.range(0, voltTenantItems.size())
236 + .mapToObj(index -> jsonToTenant(voltTenantItems.get(index).asObject()))
237 + .collect(Collectors.toSet());
238 + }
239 +
240 + @Override
241 + public void removeTenant(long id) {
242 + deleteTenant(id);
243 + }
244 +
245 + @Override
246 + public VoltTenant addTenant(VoltTenant newTenant) {
247 + String json = tenantToJson(newTenant);
248 + postRest(json);
249 + return newTenant;
250 + }
251 +
252 + @Override
253 + public VoltTenant getTenant(long id) {
254 + String jsonString = getRest(Long.toString(id));
255 + JsonObject jsonTenant = JsonObject.readFrom(jsonString);
256 + if (jsonTenant.get("id") != null) {
257 + return jsonToTenant(jsonTenant);
258 + } else {
259 + return null;
260 + }
261 + }
262 +
263 + /**
264 + * Extracts properties from the component configuration context.
265 + *
266 + * @param context the component context
267 + */
268 + private void readComponentConfiguration(ComponentContext context) {
269 + Dictionary<?, ?> properties = context.getProperties();
270 +
271 + String newXosServerAddress = Tools.get(properties, "XOSServerAddress");
272 + if (!isNullOrEmpty(newXosServerAddress)) {
273 + xosServerAddress = newXosServerAddress;
274 + }
275 +
276 + String newXosServerPortString = Tools.get(properties, "XOSServerPort");
277 + if (!isNullOrEmpty(newXosServerPortString)) {
278 + xosServerPort = Integer.parseInt(newXosServerPortString);
279 + }
280 + log.info("XOS URL is now http://{}:{}", xosServerAddress, xosServerPort);
281 + }
282 +}
283 +
284 +
1 +/*
2 + * Copyright 2015 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.xosintegration;
17 +
18 +
19 +import com.google.common.base.MoreObjects;
20 +
21 +public final class VoltTenant {
22 +
23 + private final String humanReadableName;
24 + private final long id;
25 + private final long providerService;
26 + private final String serviceSpecificId;
27 + private final String vlanId;
28 +
29 + private VoltTenant(String humanReadableName, long id, long providerService,
30 + String serviceSpecificId, String vlanId) {
31 + this.humanReadableName = humanReadableName;
32 + this.id = id;
33 + this.providerService = providerService;
34 + this.serviceSpecificId = serviceSpecificId;
35 + this.vlanId = vlanId;
36 + }
37 +
38 + public static Builder builder() {
39 + return new Builder();
40 + }
41 +
42 + public String humanReadableName() {
43 + return humanReadableName;
44 + }
45 +
46 + public long id() {
47 + return id;
48 + }
49 +
50 + public long providerService() {
51 + return providerService;
52 + }
53 +
54 + public String serviceSpecificId() {
55 + return serviceSpecificId;
56 + }
57 +
58 + public String vlanId() {
59 + return vlanId;
60 + }
61 +
62 + public static final class Builder {
63 + private String humanReadableName = "unknown";
64 + private long id = 0;
65 + private long providerService = 0;
66 + private String serviceSpecificId = "unknown";
67 + private String vlanId = "unknown";
68 +
69 + public Builder withHumanReadableName(String humanReadableName) {
70 + this.humanReadableName = humanReadableName;
71 + return this;
72 + }
73 +
74 + public Builder withId(long id) {
75 + this.id = id;
76 + return this;
77 + }
78 +
79 + public Builder withProviderService(long providerService) {
80 + this.providerService = providerService;
81 + return this;
82 + }
83 +
84 + public Builder withServiceSpecificId(String serviceSpecificId) {
85 + this.serviceSpecificId = serviceSpecificId;
86 + return this;
87 + }
88 +
89 + public Builder withVlanId(String vlanId) {
90 + this.vlanId = vlanId;
91 + return this;
92 + }
93 +
94 + public VoltTenant build() {
95 + return new VoltTenant(humanReadableName, id, providerService,
96 + serviceSpecificId, vlanId);
97 + }
98 + }
99 +
100 + @Override
101 + public String toString() {
102 + return MoreObjects.toStringHelper(getClass())
103 + .add("humanReadableName", humanReadableName())
104 + .add("id", id())
105 + .add("providerService", providerService())
106 + .add("serviceSpecificId", serviceSpecificId())
107 + .add("vlanId", vlanId())
108 + .toString();
109 + }
110 +
111 +}
1 +/*
2 + * Copyright 2015 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.xosintegration;
17 +
18 +import java.util.Set;
19 +
20 +public interface VoltTenantService {
21 +
22 + /**
23 + * Queries all the tenants.
24 + *
25 + * @return Set of all of the tenants
26 + */
27 + Set<VoltTenant> getAllTenants();
28 +
29 + /**
30 + * Removes a tenant given its ID.
31 + *
32 + * @param id if od tenant to remove.
33 + */
34 + void removeTenant(long id);
35 +
36 + /**
37 + * Creates a new tenant and adds it to the XOS instance.
38 + *
39 + * @param newTenant tenant to add
40 + * @return the added tenant
41 + */
42 + VoltTenant addTenant(VoltTenant newTenant);
43 +
44 + /**
45 + * Gets a single tenant for the given ID.
46 + *
47 + * @param id ID of the tenant to fetch
48 + * @return tenant that was fetched
49 + */
50 + VoltTenant getTenant(long id);
51 +}
1 +/*
2 + * Copyright 2015 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.xosintegration.cli;
17 +
18 +import java.util.List;
19 +
20 +import org.onosproject.cli.AbstractChoicesCompleter;
21 +import org.onosproject.xosintegration.VoltTenant;
22 +import org.onosproject.xosintegration.VoltTenantService;
23 +import static java.util.stream.Collectors.toList;
24 +
25 +import static org.onosproject.cli.AbstractShellCommand.get;
26 +
27 +
28 +/**
29 + * Application command completer.
30 + */
31 +public class TenantIdCompleter extends AbstractChoicesCompleter {
32 + @Override
33 + public List<String> choices() {
34 + VoltTenantService service = get(VoltTenantService.class);
35 +
36 + return service.getAllTenants().stream()
37 + .map(VoltTenant::id)
38 + .map(Object::toString)
39 + .collect(toList());
40 +
41 + }
42 +
43 +}
1 +/*
2 + * Copyright 2015 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.xosintegration.cli;
17 +
18 +import org.apache.karaf.shell.commands.Argument;
19 +import org.apache.karaf.shell.commands.Command;
20 +import org.onosproject.cli.AbstractShellCommand;
21 +import org.onosproject.xosintegration.VoltTenantService;
22 +
23 +/**
24 + * CLI command to remove an existing tenant from the system.
25 + */
26 +@Command(scope = "onos", name = "remove-tenant",
27 + description = "Removes a tenant")
28 +public class VoltRemoveTenantCommand extends AbstractShellCommand {
29 +
30 + @Argument(index = 0, name = "tenant",
31 + description = "Tenant ID",
32 + required = true, multiValued = false)
33 + String tenantIdString = null;
34 +
35 + @Override
36 + protected void execute() {
37 + VoltTenantService service = get(VoltTenantService.class);
38 +
39 + service.removeTenant(Long.parseLong(tenantIdString));
40 + }
41 +}
1 +/*
2 + * Copyright 2015 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.xosintegration.cli;
17 +
18 +import org.apache.karaf.shell.commands.Argument;
19 +import org.apache.karaf.shell.commands.Command;
20 +import org.onosproject.cli.AbstractShellCommand;
21 +import org.onosproject.xosintegration.VoltTenant;
22 +import org.onosproject.xosintegration.VoltTenantService;
23 +
24 +/**
25 + * CLI command to create a new tenant.
26 + */
27 +@Command(scope = "onos", name = "add-tenant",
28 + description = "Lists the inventory of VOLT tenants and their contents")
29 +public class VoltTenantsCreateCommand extends AbstractShellCommand {
30 + @Argument(index = 0, name = "provider service",
31 + description = "Tenant ID",
32 + required = true, multiValued = false)
33 + long providerService;
34 +
35 + @Argument(index = 1, name = "service specific ID",
36 + description = "service specific ID",
37 + required = true, multiValued = false)
38 + String serviceSpecificId;
39 +
40 + @Argument(index = 2, name = "vlan ID",
41 + description = "vlan ID",
42 + required = true, multiValued = false)
43 + String vlanId;
44 +
45 + @Override
46 + protected void execute() {
47 + VoltTenantService service = get(VoltTenantService.class);
48 +
49 + VoltTenant newTenant = VoltTenant.builder()
50 + .withProviderService(providerService)
51 + .withServiceSpecificId(serviceSpecificId)
52 + .withVlanId(vlanId)
53 + .build();
54 + service.addTenant(newTenant);
55 + }
56 +}
1 +/*
2 + * Copyright 2015 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.xosintegration.cli;
17 +
18 +import java.util.Set;
19 +
20 +import org.apache.karaf.shell.commands.Argument;
21 +import org.apache.karaf.shell.commands.Command;
22 +import org.onosproject.cli.AbstractShellCommand;
23 +import org.onosproject.xosintegration.VoltTenant;
24 +import org.onosproject.xosintegration.VoltTenantService;
25 +
26 +/**
27 + * CLI command for listing VOLT tenant objects.
28 + */
29 +
30 +/**
31 + * CLI command to list the existing tenants.
32 + */
33 +@Command(scope = "onos", name = "tenants",
34 + description = "Lists the inventory of VOLT tenants and their contents")
35 +public class VoltTenantsListCommand extends AbstractShellCommand {
36 +
37 + @Argument(index = 0, name = "tenantId",
38 + description = "Tenant ID",
39 + required = false, multiValued = false)
40 + private String tenantId = null;
41 +
42 + @Override
43 + protected void execute() {
44 + VoltTenantService service = get(VoltTenantService.class);
45 +
46 + if (tenantId != null) {
47 + VoltTenant tenant = service.getTenant(Long.parseLong(tenantId));
48 + if (tenant != null) {
49 + print(tenant.toString());
50 + } else {
51 + error("Tenant not found {}", tenantId);
52 + }
53 + } else {
54 + Set<VoltTenant> tenants = service.getAllTenants();
55 + for (VoltTenant tenant : tenants) {
56 + print(tenant.toString());
57 + }
58 + }
59 + }
60 +
61 +}
1 +/*
2 + * Copyright 2014 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 + * Test Application that calls a REST API. One dat it might call XOS to
19 + * launch a VM.
20 + */
21 +package org.onosproject.xosintegration;
1 +<!--
2 + ~ Copyright 2014 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 +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
17 + <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
18 + <command>
19 + <action class="org.onosproject.xosintegration.cli.VoltTenantsListCommand"/>
20 + <completers>
21 + <ref component-id="tenantIdCompleter"/>
22 + <null/>
23 + </completers>
24 + </command>
25 + <command>
26 + <action class="org.onosproject.xosintegration.cli.VoltTenantsCreateCommand"/>
27 + </command>
28 + <command>
29 + <action class="org.onosproject.xosintegration.cli.VoltRemoveTenantCommand"/>
30 + <completers>
31 + <ref component-id="tenantIdCompleter"/>
32 + <null/>
33 + </completers>
34 + </command>
35 + </command-bundle>
36 + <bean id="tenantIdCompleter" class="org.onosproject.xosintegration.cli.TenantIdCompleter"/>
37 +</blueprint>