mirror of https://github.com/apache/jclouds.git
JCLOUDS-348
list quotas for cinder + expected and live tests
This commit is contained in:
parent
725b7c5c2c
commit
1c9d1676cd
|
@ -21,6 +21,7 @@ import java.util.Set;
|
|||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.location.Zone;
|
||||
import org.jclouds.location.functions.ZoneToEndpoint;
|
||||
import org.jclouds.openstack.cinder.v1.features.QuotaApi;
|
||||
import org.jclouds.openstack.cinder.v1.features.SnapshotApi;
|
||||
import org.jclouds.openstack.cinder.v1.features.VolumeApi;
|
||||
import org.jclouds.openstack.cinder.v1.features.VolumeTypeApi;
|
||||
|
@ -33,7 +34,6 @@ import com.google.inject.Provides;
|
|||
/**
|
||||
* Provides synchronous access to Cinder.
|
||||
*
|
||||
* @see CinderAsyncApi
|
||||
* @see <a href="http://api.openstack.org/">API Doc</a>
|
||||
* @author Everett Toews
|
||||
*/
|
||||
|
@ -72,4 +72,12 @@ public interface CinderApi extends Closeable {
|
|||
@Delegate
|
||||
SnapshotApi getSnapshotApiForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to quotas features.
|
||||
*/
|
||||
@Delegate
|
||||
QuotaApi getQuotaApi(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,167 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.cinder.v1.domain;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author Inbar Stolberg
|
||||
*/
|
||||
public class VolumeQuota {
|
||||
|
||||
private final String id;
|
||||
private final int volumes;
|
||||
private final int gigabytes;
|
||||
private final int snapshots;
|
||||
|
||||
protected VolumeQuota(String id, int volumes, int gigabytes, int snapshots) {
|
||||
this.id = checkNotNull(id, "id");
|
||||
this.volumes = volumes;
|
||||
this.gigabytes = gigabytes;
|
||||
this.snapshots = snapshots;
|
||||
}
|
||||
|
||||
/**
|
||||
* The id of the tenant this set of limits applies to
|
||||
*/
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* The limit of the number of volumes that can be created for the tenant
|
||||
*/
|
||||
public int getVolumes() {
|
||||
return this.volumes;
|
||||
}
|
||||
|
||||
/**
|
||||
* The limit of the total size of all volumes for the tenant
|
||||
*/
|
||||
public int getGigabytes() {
|
||||
return this.gigabytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* The limit of the number of snapshots that can be used by the tenant
|
||||
*/
|
||||
public int getSnapshots() {
|
||||
return this.snapshots;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(id, volumes, gigabytes, snapshots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
VolumeQuota that = VolumeQuota.class.cast(obj);
|
||||
return Objects.equal(this.id, that.id)
|
||||
&& Objects.equal(this.volumes, that.volumes)
|
||||
&& Objects.equal(this.gigabytes, that.gigabytes)
|
||||
&& Objects.equal(this.snapshots, that.snapshots);
|
||||
}
|
||||
|
||||
protected Objects.ToStringHelper string() {
|
||||
return Objects.toStringHelper(this)
|
||||
.add("id", id).add("volumes", volumes).add("gigabytes", gigabytes).add("snapshots", snapshots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return string().toString();
|
||||
}
|
||||
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromVolumeQuota(this);
|
||||
}
|
||||
|
||||
public static abstract class Builder<T extends Builder<T>> {
|
||||
protected abstract T self();
|
||||
|
||||
protected String id;
|
||||
protected int volumes;
|
||||
protected int gigabytes;
|
||||
protected int snapshots;
|
||||
|
||||
|
||||
/**
|
||||
* @see VolumeQuota#getId()
|
||||
*/
|
||||
public T id(String id) {
|
||||
this.id = id;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see VolumeQuota#getVolumes()
|
||||
*/
|
||||
public T volumes(int volumes) {
|
||||
this.volumes = volumes;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see VolumeQuota#getGigabytes()
|
||||
*/
|
||||
public T gigabytes(int gigabytes) {
|
||||
this.gigabytes = gigabytes;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see VolumeQuota#getSnapshots()
|
||||
*/
|
||||
public T snapshots(int snapshots) {
|
||||
this.snapshots = snapshots;
|
||||
return self();
|
||||
}
|
||||
|
||||
|
||||
public VolumeQuota build() {
|
||||
return new VolumeQuota(id, volumes, gigabytes, snapshots);
|
||||
}
|
||||
|
||||
public T fromVolumeQuota(VolumeQuota in) {
|
||||
return this
|
||||
.id(in.getId())
|
||||
.volumes(in.getVolumes())
|
||||
.gigabytes(in.getGigabytes())
|
||||
.snapshots(in.getSnapshots());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||
@Override
|
||||
protected ConcreteBuilder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.cinder.v1.features;
|
||||
|
||||
import org.jclouds.Fallbacks;
|
||||
import org.jclouds.openstack.cinder.v1.domain.VolumeQuota;
|
||||
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
|
||||
import org.jclouds.rest.annotations.Fallback;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.jclouds.rest.annotations.SkipEncoding;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Quota via their REST API.
|
||||
*
|
||||
* @author Inbar Stolberg
|
||||
* @see QuotaApi
|
||||
* @see <a href="http://api.openstack.org/">API Doc</a>
|
||||
*/
|
||||
@SkipEncoding({'/', '='})
|
||||
@RequestFilters(AuthenticateRequest.class)
|
||||
@Path("/os-quota-sets")
|
||||
public interface QuotaApi {
|
||||
|
||||
|
||||
@GET
|
||||
@SelectJson("quota_set")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Path("/{tenant_id}")
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
VolumeQuota getByTenant(@PathParam("tenant_id") String tenantId);
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.cinder.v1.features;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.openstack.cinder.v1.domain.VolumeQuota;
|
||||
import org.jclouds.openstack.cinder.v1.internal.BaseCinderApiExpectTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author inbar stolberg
|
||||
*/
|
||||
@Test(groups = "unit", testName = "QuotaApiExpectTest")
|
||||
public class QuotasApiExpectTest extends BaseCinderApiExpectTest {
|
||||
|
||||
public void testGetQuotas() throws Exception {
|
||||
URI endpoint = URI.create("http://172.16.0.1:8776/v1/50cdb4c60374463198695d9f798fa34d/os-quota-sets/demo");
|
||||
QuotaApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName,
|
||||
responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/quotas.json")).build()
|
||||
).getQuotaApi("RegionOne");
|
||||
|
||||
assertEquals(api.getByTenant("demo"), getTestQuotas());
|
||||
}
|
||||
|
||||
public static VolumeQuota getTestQuotas() {
|
||||
return VolumeQuota.builder()
|
||||
.gigabytes(1000)
|
||||
.volumes(10)
|
||||
.snapshots(20)
|
||||
.id("demo").build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.cinder.v1.features;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.jclouds.openstack.cinder.v1.domain.VolumeQuota;
|
||||
import org.jclouds.openstack.cinder.v1.internal.BaseCinderApiLiveTest;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author inbar stolberg
|
||||
*/
|
||||
@Test(groups = "live", testName = "QuotasApiLiveTest", singleThreaded = true)
|
||||
public class QuotasApiLiveTest extends BaseCinderApiLiveTest {
|
||||
|
||||
private QuotaApi quotaApi;
|
||||
|
||||
public QuotasApiLiveTest() {
|
||||
super();
|
||||
provider = "openstack-cinder";
|
||||
}
|
||||
|
||||
@BeforeClass(groups = {"integration", "live"})
|
||||
public void setupContext() {
|
||||
super.setup();
|
||||
String zone = Iterables.getFirst(api.getConfiguredZones(), "nova");
|
||||
quotaApi = api.getQuotaApi(zone);
|
||||
}
|
||||
|
||||
public void testGetStorageQuotas() throws ExecutionException, InterruptedException {
|
||||
VolumeQuota volumeQuota = quotaApi.getByTenant("demo");
|
||||
|
||||
assertTrue(volumeQuota.getGigabytes() >= 0);
|
||||
assertTrue(volumeQuota.getVolumes() >= 0);
|
||||
assertTrue(volumeQuota.getSnapshots() >= 0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{"quota_set": {
|
||||
"gigabytes": 1000,
|
||||
"volumes": 10,
|
||||
"snapshots": 20,
|
||||
"id": "demo"
|
||||
}}
|
Loading…
Reference in New Issue