mirror of https://github.com/apache/jclouds.git
Issue 158: stubbed in compute service and tested datacenter -> location translation
This commit is contained in:
parent
6ad10cd185
commit
37c4da6489
|
@ -56,7 +56,7 @@
|
|||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<artifactId>jclouds-core</artifactId>
|
||||
<artifactId>jclouds-compute</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -67,9 +67,10 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.16</version>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<artifactId>jclouds-compute</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -78,6 +79,12 @@
|
|||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds.driver</groupId>
|
||||
<artifactId>jclouds-sshj</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<profiles>
|
||||
<profile>
|
||||
|
|
|
@ -21,7 +21,8 @@ package org.jclouds.softlayer;
|
|||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.rest.RestContextBuilder;
|
||||
import org.jclouds.compute.ComputeServiceContextBuilder;
|
||||
import org.jclouds.softlayer.compute.config.SoftLayerComputeServiceContextModule;
|
||||
import org.jclouds.softlayer.config.SoftLayerRestClientModule;
|
||||
|
||||
import com.google.inject.Module;
|
||||
|
@ -30,13 +31,18 @@ import com.google.inject.Module;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class SoftLayerContextBuilder extends
|
||||
RestContextBuilder<SoftLayerClient, SoftLayerAsyncClient> {
|
||||
public class SoftLayerContextBuilder extends ComputeServiceContextBuilder<SoftLayerClient, SoftLayerAsyncClient> {
|
||||
|
||||
public SoftLayerContextBuilder(Properties props) {
|
||||
super(SoftLayerClient.class, SoftLayerAsyncClient.class, props);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addContextModule(List<Module> modules) {
|
||||
modules.add(new SoftLayerComputeServiceContextModule());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addClientModule(List<Module> modules) {
|
||||
modules.add(new SoftLayerRestClientModule());
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
|||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.PropertiesBuilder;
|
||||
import org.jclouds.softlayer.reference.SoftLayerConstants;
|
||||
|
||||
/**
|
||||
* Builds properties used in SoftLayer Clients
|
||||
|
@ -36,6 +37,7 @@ public class SoftLayerPropertiesBuilder extends PropertiesBuilder {
|
|||
Properties properties = super.defaultProperties();
|
||||
properties.setProperty(PROPERTY_ENDPOINT, "https://api.softlayer.com/rest");
|
||||
properties.setProperty(PROPERTY_API_VERSION, "3");
|
||||
properties.setProperty(SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME, "Cloud Server");
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
* 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.softlayer.compute.config;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceAdapter;
|
||||
import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.location.suppliers.OnlyLocationOrFirstZone;
|
||||
import org.jclouds.softlayer.SoftLayerAsyncClient;
|
||||
import org.jclouds.softlayer.SoftLayerClient;
|
||||
import org.jclouds.softlayer.compute.functions.DatacenterToLocation;
|
||||
import org.jclouds.softlayer.compute.functions.ProductItemPriceToImage;
|
||||
import org.jclouds.softlayer.compute.functions.ProductItemPricesToHardware;
|
||||
import org.jclouds.softlayer.compute.functions.VirtualGuestToNodeMetadata;
|
||||
import org.jclouds.softlayer.compute.strategy.SoftLayerComputeServiceAdapter;
|
||||
import org.jclouds.softlayer.domain.Datacenter;
|
||||
import org.jclouds.softlayer.domain.ProductItemPrice;
|
||||
import org.jclouds.softlayer.domain.VirtualGuest;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class SoftLayerComputeServiceContextModule extends
|
||||
ComputeServiceAdapterContextModule<SoftLayerClient, SoftLayerAsyncClient, VirtualGuest, Set<ProductItemPrice>, ProductItemPrice, Datacenter> {
|
||||
|
||||
public SoftLayerComputeServiceContextModule() {
|
||||
super(SoftLayerClient.class, SoftLayerAsyncClient.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
bind(new TypeLiteral<ComputeServiceAdapter<VirtualGuest, Set<ProductItemPrice>, ProductItemPrice, Datacenter>>() {
|
||||
}).to(SoftLayerComputeServiceAdapter.class);
|
||||
bind(new TypeLiteral<Function<VirtualGuest, NodeMetadata>>() {
|
||||
}).to(VirtualGuestToNodeMetadata.class);
|
||||
bind(new TypeLiteral<Function<ProductItemPrice, org.jclouds.compute.domain.Image>>() {
|
||||
}).to(ProductItemPriceToImage.class);
|
||||
bind(new TypeLiteral<Function<Set<ProductItemPrice>, org.jclouds.compute.domain.Hardware>>() {
|
||||
}).to(ProductItemPricesToHardware.class);
|
||||
bind(new TypeLiteral<Function<Datacenter, Location>>() {
|
||||
}).to(DatacenterToLocation.class);
|
||||
bind(new TypeLiteral<Supplier<Location>>() {
|
||||
}).to(OnlyLocationOrFirstZone.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* 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.softlayer.compute.functions;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.ImageBuilder;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.softlayer.domain.ProductItemPrice;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ProductItemPriceToImage implements Function<ProductItemPrice, Image> {
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
@Override
|
||||
public Image apply(ProductItemPrice from) {
|
||||
|
||||
ImageBuilder builder = new ImageBuilder();
|
||||
//TODO
|
||||
// builder.ids(from.id + "");
|
||||
// builder.name(from.name);
|
||||
// builder.description(from.name);
|
||||
//
|
||||
// OsFamily family = null;
|
||||
// try {
|
||||
// family = OsFamily.fromValue(from.name);
|
||||
// builder.operatingSystem(new OperatingSystem.Builder().name(from.name).family(family).build());
|
||||
// } catch (IllegalArgumentException e) {
|
||||
// logger.debug("<< didn't match os(%s)", from);
|
||||
// }
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* 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.softlayer.compute.functions;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.HardwareBuilder;
|
||||
import org.jclouds.softlayer.domain.ProductItemPrice;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ProductItemPricesToHardware implements Function<Set<ProductItemPrice>, Hardware> {
|
||||
|
||||
@Override
|
||||
public Hardware apply(Set<ProductItemPrice> from) {
|
||||
HardwareBuilder builder = new HardwareBuilder();
|
||||
// builder.ids(from.id + "");
|
||||
// builder.name(from.name);
|
||||
// builder.processors(ImmutableList.of(new Processor(from.cores, 1.0)));
|
||||
// builder.ram(from.ram);
|
||||
// builder.volumes(ImmutableList.<Volume> of(new VolumeImpl(from.disk, true, false)));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
/**
|
||||
* 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.softlayer.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.collect.FindResourceInSet;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||
import org.jclouds.compute.domain.NodeState;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.softlayer.domain.VirtualGuest;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMetadata> {
|
||||
|
||||
public static final Map<VirtualGuest.State, NodeState> serverStateToNodeState = ImmutableMap
|
||||
.<VirtualGuest.State, NodeState> builder().put(VirtualGuest.State.RUNNING, NodeState.RUNNING)//
|
||||
.put(VirtualGuest.State.STARTING, NodeState.PENDING)//
|
||||
.put(VirtualGuest.State.DESTROYED, NodeState.TERMINATED)//
|
||||
// TODO other states
|
||||
.put(VirtualGuest.State.UNRECOGNIZED, NodeState.UNRECOGNIZED)//
|
||||
.build();
|
||||
|
||||
private final FindHardwareForVirtualGuest findHardwareForVirtualGuest;
|
||||
private final FindLocationForVirtualGuest findLocationForVirtualGuest;
|
||||
private final FindImageForVirtualGuest findImageForVirtualGuest;
|
||||
private final Map<String, Credentials> credentialStore;
|
||||
|
||||
@Inject
|
||||
VirtualGuestToNodeMetadata(Map<String, Credentials> credentialStore, FindHardwareForVirtualGuest findHardwareForVirtualGuest,
|
||||
FindLocationForVirtualGuest findLocationForVirtualGuest, FindImageForVirtualGuest findImageForVirtualGuest) {
|
||||
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
||||
this.findHardwareForVirtualGuest = checkNotNull(findHardwareForVirtualGuest, "findHardwareForVirtualGuest");
|
||||
this.findLocationForVirtualGuest = checkNotNull(findLocationForVirtualGuest, "findLocationForVirtualGuest");
|
||||
this.findImageForVirtualGuest = checkNotNull(findImageForVirtualGuest, "findImageForVirtualGuest");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata apply(VirtualGuest from) {
|
||||
// convert the result object to a jclouds NodeMetadata
|
||||
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
||||
builder.ids(from.getId() + "");
|
||||
builder.name(from.getNotes());
|
||||
builder.location(findLocationForVirtualGuest.apply(from));
|
||||
builder.group(parseGroupFromName(from.getNotes()));
|
||||
//TODO determine image id (product price)from virtual guest
|
||||
// builder.imageId(from.imageId + "");
|
||||
Image image = findImageForVirtualGuest.apply(from);
|
||||
if (image != null)
|
||||
builder.operatingSystem(image.getOperatingSystem());
|
||||
builder.hardware(findHardwareForVirtualGuest.apply(from));
|
||||
// TODO get state
|
||||
// builder.state(serverStateToNodeState.get(from.getState()));
|
||||
builder.publicAddresses(ImmutableSet.<String> of(from.getPrimaryIpAddress()));
|
||||
builder.privateAddresses(ImmutableSet.<String> of(from.getPrimaryBackendIpAddress()));
|
||||
builder.credentials(credentialStore.get("node#"+ from.getId()));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class FindHardwareForVirtualGuest extends FindResourceInSet<VirtualGuest, Hardware> {
|
||||
|
||||
@Inject
|
||||
public FindHardwareForVirtualGuest(@Memoized Supplier<Set<? extends Hardware>> hardware) {
|
||||
super(hardware);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(VirtualGuest from, Hardware input) {
|
||||
return input.getProviderId().equals(from.getId() + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class FindImageForVirtualGuest extends FindResourceInSet<VirtualGuest, Image> {
|
||||
|
||||
@Inject
|
||||
public FindImageForVirtualGuest(@Memoized Supplier<Set<? extends Image>> hardware) {
|
||||
super(hardware);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(VirtualGuest from, Image input) {
|
||||
// TODO determine the price list from the virtual guest which would have the image in it.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class FindLocationForVirtualGuest extends FindResourceInSet<VirtualGuest, Location> {
|
||||
|
||||
@Inject
|
||||
public FindLocationForVirtualGuest(@Memoized Supplier<Set<? extends Location>> hardware) {
|
||||
super(hardware);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(VirtualGuest from, Location input) {
|
||||
// TODO determine the price list from the virtual guest which would have the image in it.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
/**
|
||||
* 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.softlayer.compute.strategy;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceAdapter;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.softlayer.SoftLayerClient;
|
||||
import org.jclouds.softlayer.domain.Datacenter;
|
||||
import org.jclouds.softlayer.domain.ProductItemPrice;
|
||||
import org.jclouds.softlayer.domain.ProductPackage;
|
||||
import org.jclouds.softlayer.domain.VirtualGuest;
|
||||
import org.jclouds.softlayer.predicates.ProductPackagePredicates;
|
||||
import org.jclouds.softlayer.reference.SoftLayerConstants;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* defines the connection between the {@link SoftLayerClient} implementation and the jclouds
|
||||
* {@link ComputeService}
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class SoftLayerComputeServiceAdapter implements
|
||||
ComputeServiceAdapter<VirtualGuest, Set<ProductItemPrice>, ProductItemPrice, Datacenter> {
|
||||
private final SoftLayerClient client;
|
||||
private final String virtualGuestPackageName;
|
||||
|
||||
@Inject
|
||||
public SoftLayerComputeServiceAdapter(SoftLayerClient client,
|
||||
@Named(SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME) String virtualGuestPackageName) {
|
||||
this.client = checkNotNull(client, "client");
|
||||
this.virtualGuestPackageName = checkNotNull(virtualGuestPackageName, "virtualGuestPackageName");
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualGuest createNodeWithGroupEncodedIntoNameThenStoreCredentials(String tag, String name,
|
||||
Template template, Map<String, Credentials> credentialStore) {
|
||||
VirtualGuest from = null; // TODO create the backend object using parameters from the
|
||||
// template. ex.
|
||||
// VirtualGuest from =
|
||||
// client.getVirtualGuestClient().createServerInDC(template.getLocation().getId(), name,
|
||||
// Long.parseLong(template.getImage().getProviderId()),
|
||||
// Long.parseLong(template.getHardware().getProviderId()));
|
||||
// store the credentials so that later functions can use them
|
||||
// credentialStore.put("node#"+ from.getId() + "", new Credentials(from.loginUser,
|
||||
// from.password));
|
||||
return from;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Set<ProductItemPrice>> listHardwareProfiles() {
|
||||
// TODO: get the set of product item prices corresponding to the hardware profiles
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<ProductItemPrice> listImages() {
|
||||
// TODO: get the list of product item prices corresponding to images
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<VirtualGuest> listNodes() {
|
||||
return client.getVirtualGuestClient().listVirtualGuests();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Datacenter> listLocations() {
|
||||
// TODO we should be able to specify a filter that gets the datacenters here.
|
||||
ProductPackage virtualGuestPackage = Iterables.find(client.getAccountClient().getActivePackages(),
|
||||
ProductPackagePredicates.named(virtualGuestPackageName));
|
||||
return client.getProductPackageClient().getProductPackage(virtualGuestPackage.getId()).getDatacenters();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualGuest getNode(String id) {
|
||||
long serverId = Long.parseLong(id);
|
||||
return client.getVirtualGuestClient().getVirtualGuest(serverId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyNode(String id) {
|
||||
// TODO
|
||||
// client.getVirtualGuestClient().destroyVirtualGuest(Long.parseLong(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebootNode(String id) {
|
||||
client.getVirtualGuestClient().rebootHardVirtualGuest(Long.parseLong(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resumeNode(String id) {
|
||||
client.getVirtualGuestClient().resumeVirtualGuest(Long.parseLong(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void suspendNode(String id) {
|
||||
client.getVirtualGuestClient().pauseVirtualGuest(Long.parseLong(id));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* 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.softlayer.reference;
|
||||
|
||||
/**
|
||||
* Configuration properties and constants used in SoftLayer connections.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public interface SoftLayerConstants {
|
||||
/**
|
||||
* Name of the product package corresponding to cloud servers
|
||||
*/
|
||||
public static final String PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME = "jclouds.softlayer.virtualguest.package-name";
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/**
|
||||
* 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.softlayer.compute;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.sshj.config.SshjSshClientModule;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", testName = "SoftLayerExperimentLiveTest")
|
||||
public class SoftLayerExperimentLiveTest {
|
||||
protected String provider = "softlayer";
|
||||
protected String identity;
|
||||
protected String credential;
|
||||
protected String endpoint;
|
||||
protected String apiversion;
|
||||
|
||||
@BeforeClass
|
||||
protected void setupCredentials() {
|
||||
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
|
||||
credential = System.getProperty("test." + provider + ".credential");
|
||||
endpoint = System.getProperty("test." + provider + ".endpoint");
|
||||
apiversion = System.getProperty("test." + provider + ".apiversion");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAndExperiment() {
|
||||
ComputeServiceContext context = null;
|
||||
try {
|
||||
String identity = checkNotNull(System.getProperty("test.softlayer.identity"), "test.softlayer.identity");
|
||||
String credential = checkNotNull(System.getProperty("test.softlayer.credential"), "test.softlayer.credential");
|
||||
|
||||
context = new ComputeServiceContextFactory().createContext("softlayer", identity, credential, ImmutableSet
|
||||
.<Module> of(new Log4JLoggingModule(), new SshjSshClientModule()));
|
||||
|
||||
assertEquals(context.getComputeService().listAssignableLocations().size(), 5);
|
||||
|
||||
} finally {
|
||||
if (context != null)
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -20,15 +20,11 @@ package org.jclouds.softlayer.features;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.softlayer.SoftLayerAsyncClient;
|
||||
import org.jclouds.softlayer.SoftLayerClient;
|
||||
import org.jclouds.softlayer.SoftLayerContextBuilder;
|
||||
import org.jclouds.softlayer.SoftLayerPropertiesBuilder;
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -51,12 +47,9 @@ public class BaseSoftLayerClientLiveTest {
|
|||
String identity = checkNotNull(System.getProperty("test.softlayer.identity"), "test.softlayer.identity");
|
||||
String credential = checkNotNull(System.getProperty("test.softlayer.credential"), "test.softlayer.credential");
|
||||
|
||||
Properties restProperties = new Properties();
|
||||
restProperties.setProperty("softlayer.contextbuilder", SoftLayerContextBuilder.class.getName());
|
||||
restProperties.setProperty("softlayer.propertiesbuilder", SoftLayerPropertiesBuilder.class.getName());
|
||||
|
||||
context = new RestContextFactory(restProperties).createContext("softlayer", identity, credential,
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule()));
|
||||
context = new ComputeServiceContextFactory().createContext("softlayer", identity, credential,
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule())).getProviderSpecificContext();
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue