mirror of https://github.com/apache/jclouds.git
added vdc URI command to savvis, as well made email guard optional
This commit is contained in:
parent
41ed21d5b0
commit
4ae013c219
|
@ -1,3 +1,22 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.savvis.vpdc.compute.strategy;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
@ -8,7 +27,6 @@ import java.net.URI;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
|
@ -34,6 +52,7 @@ import com.google.common.base.Predicate;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
;
|
||||
|
||||
|
@ -46,16 +65,16 @@ import com.google.common.collect.ImmutableSet.Builder;
|
|||
public class VPDCComputeServiceAdapter implements ComputeServiceAdapter<VM, VMSpec, CIMOperatingSystem, Network> {
|
||||
private final VPDCClient client;
|
||||
private final RetryablePredicate<String> taskTester;
|
||||
private final String email;
|
||||
@Inject(optional = true)
|
||||
@Named(PROPERTY_VPDC_VDC_EMAIL)
|
||||
String email;
|
||||
|
||||
@Inject
|
||||
public VPDCComputeServiceAdapter(VPDCClient client, TaskSuccess taskSuccess,
|
||||
@Named(PROPERTY_VPDC_VDC_EMAIL) String email) {
|
||||
public VPDCComputeServiceAdapter(VPDCClient client, TaskSuccess taskSuccess) {
|
||||
this.client = checkNotNull(client, "client");
|
||||
// TODO: parameterize
|
||||
this.taskTester = new RetryablePredicate<String>(checkNotNull(taskSuccess, "taskSuccess"), 650, 10,
|
||||
TimeUnit.SECONDS);
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -136,7 +155,8 @@ public class VPDCComputeServiceAdapter implements ComputeServiceAdapter<VM, VMSp
|
|||
Org org = client.getBrowsingClient().getOrg(org1.getId());
|
||||
for (Resource vdc : org.getVDCs()) {
|
||||
VDC VDC = client.getBrowsingClient().getVDCInOrg(org.getId(), vdc.getId());
|
||||
if (VDC.getDescription().indexOf(email) != -1)
|
||||
// optionally constrain locations
|
||||
if (email != null && VDC.getDescription().indexOf(email) != -1)
|
||||
continue;
|
||||
for (Resource network : VDC.getAvailableNetworks()) {
|
||||
builder.add(client.getBrowsingClient().getNetworkInVDC(org.getId(), vdc.getId(), network.getId()));
|
||||
|
|
|
@ -66,6 +66,16 @@ public interface VMAsyncClient {
|
|||
@PathParam("vpdcId") String vpdcId, @PayloadParam("networkName") String networkTierName,
|
||||
@PayloadParam("name") String vAppName, VMSpec spec);
|
||||
|
||||
/**
|
||||
* @see VMClient#addVMIntoVDC
|
||||
*/
|
||||
@GET
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
@Path("vApp/")
|
||||
@MapBinder(BindVMSpecToXmlPayload.class)
|
||||
ListenableFuture<Task> addVMIntoVDC(@EndpointParam URI vpdc, @PayloadParam("networkName") String networkTierName,
|
||||
@PayloadParam("name") String vAppName, VMSpec spec);
|
||||
|
||||
/**
|
||||
* @see VMClient#removeVMFromVDC
|
||||
*/
|
||||
|
|
|
@ -52,6 +52,14 @@ public interface VMClient {
|
|||
*/
|
||||
Task addVMIntoVDC(String billingSiteId, String vpdcId, String networkTierName, String name, VMSpec spec);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param vpdc
|
||||
* href of the vpdc
|
||||
* @see #addVMIntoVDC
|
||||
*/
|
||||
Task addVMIntoVDC(URI vpdc, String networkTierName, String name, VMSpec spec);
|
||||
|
||||
/**
|
||||
* Remove a VM
|
||||
* <p/>
|
||||
|
|
|
@ -49,6 +49,37 @@ import com.google.inject.TypeLiteral;
|
|||
@Test(groups = "unit")
|
||||
public class VMAsyncClientTest extends BaseVPDCAsyncClientTest<VMAsyncClient> {
|
||||
|
||||
public void testAddVMIntoVDCURI() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VMAsyncClient.class
|
||||
.getMethod("addVMIntoVDC", URI.class, String.class, String.class, VMSpec.class);
|
||||
|
||||
CIMOperatingSystem os = Iterables.find(injector.getInstance(Key.get(new TypeLiteral<Set<CIMOperatingSystem>>() {
|
||||
})), new Predicate<CIMOperatingSystem>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(CIMOperatingSystem arg0) {
|
||||
return arg0.getOsType() == OSType.RHEL_64;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22"), "VM Tier01", "DemoHost-1",
|
||||
VMSpec.builder().operatingSystem(os).build());
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/vm-default.xml")),
|
||||
"application/xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, TaskHandler.class);
|
||||
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testAddVMIntoVDC() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VMAsyncClient.class.getMethod("addVMIntoVDC", String.class, String.class, String.class,
|
||||
String.class, VMSpec.class);
|
||||
|
|
Loading…
Reference in New Issue