Merge pull request #1114 from rackspace/slicehost-deleted

Deleted slicehost project. Use rackspace-cloudservers-us/uk instead.
This commit is contained in:
Adrian Cole 2012-12-29 12:21:59 -08:00
commit c8d17e9c7b
60 changed files with 0 additions and 4553 deletions

View File

@ -125,11 +125,6 @@
<artifactId>gogrid</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.provider</groupId>
<artifactId>slicehost</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>elasticstack</artifactId>

View File

@ -33,7 +33,6 @@
<name>jclouds providers project</name>
<modules>
<module>gogrid</module>
<module>slicehost</module>
<module>cloudsigma-zrh</module>
<module>cloudsigma-lvs</module>
<module>azureblob</module>

View File

@ -1,25 +0,0 @@
====
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.
====
#
# The jclouds provider for Slicehost (http://www.slicehost.com/).
#
# TODO: Implementation status.
# TODO: Supported features.
# TODO: Usage example.

View File

@ -1,120 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-project</artifactId>
<version>1.6.0-SNAPSHOT</version>
<relativePath>../../project/pom.xml</relativePath>
</parent>
<groupId>org.jclouds.provider</groupId>
<artifactId>slicehost</artifactId>
<name>jclouds Slicehost provider</name>
<description>ComputeService implementation of Slicehost datacenters</description>
<packaging>bundle</packaging>
<properties>
<test.slicehost.endpoint>https://api.slicehost.com</test.slicehost.endpoint>
<test.slicehost.api-version>1.4.1.1</test.slicehost.api-version>
<test.slicehost.build-version></test.slicehost.build-version>
<test.slicehost.identity>FIXME</test.slicehost.identity>
<test.slicehost.template></test.slicehost.template>
<jclouds.osgi.export>org.jclouds.slicehost*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import>
org.jclouds.compute.internal;version="${project.version}",
org.jclouds.rest.internal;version="${project.version}",
org.jclouds*;version="${project.version}",
*
</jclouds.osgi.import>
</properties>
<dependencies>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-log4j</artifactId>
<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>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<!-- beat up the slicehost server less -->
<threadCount>1</threadCount>
<systemPropertyVariables>
<test.slicehost.endpoint>${test.slicehost.endpoint}</test.slicehost.endpoint>
<test.slicehost.api-version>${test.slicehost.api-version}</test.slicehost.api-version>
<test.slicehost.build-version>${test.slicehost.build-version}</test.slicehost.build-version>
<test.slicehost.identity>${test.slicehost.identity}</test.slicehost.identity>
<test.slicehost.template>${test.slicehost.template}</test.slicehost.template>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -1,94 +0,0 @@
/**
* 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.slicehost;
import java.net.URI;
import java.util.Properties;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.BaseRestApiMetadata;
import org.jclouds.slicehost.compute.config.SlicehostComputeServiceContextModule;
import org.jclouds.slicehost.config.SlicehostRestClientModule;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
import com.google.inject.Module;
/**
* Implementation of {@link ApiMetadata} for Slicehost 1.0 API
*
* @author Adrian Cole
*/
public class SlicehostApiMetadata extends BaseRestApiMetadata {
public static final TypeToken<RestContext<SlicehostClient, SlicehostAsyncClient>> CONTEXT_TOKEN = new TypeToken<RestContext<SlicehostClient, SlicehostAsyncClient>>() {
};
@Override
public Builder toBuilder() {
return new Builder().fromApiMetadata(this);
}
public SlicehostApiMetadata() {
this(new Builder());
}
protected SlicehostApiMetadata(Builder builder) {
super(builder);
}
public static Properties defaultProperties() {
Properties properties = BaseRestApiMetadata.defaultProperties();
properties.setProperty("jclouds.ssh.max-retries", "8");
return properties;
}
public static class Builder
extends
BaseRestApiMetadata.Builder {
protected Builder() {
super(SlicehostClient.class, SlicehostAsyncClient.class);
id("slicehost")
.name("Slicehost API")
.identityName("API password")
.documentation(URI.create("http://articles.slicehost.com/api"))
.version("https://api.slicehost.com")
.defaultEndpoint("https://api.slicehost.com")
.defaultProperties(SlicehostApiMetadata.defaultProperties())
.view(TypeToken.of(ComputeServiceContext.class))
.defaultModules(ImmutableSet.<Class<? extends Module>>of(SlicehostRestClientModule.class, SlicehostComputeServiceContextModule.class));
}
@Override
public SlicehostApiMetadata build() {
return new SlicehostApiMetadata(this);
}
@Override
public Builder fromApiMetadata(ApiMetadata in) {
super.fromApiMetadata(in);
return this;
}
}
}

View File

@ -1,189 +0,0 @@
/**
* 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.slicehost;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.Fallbacks.VoidOnNotFoundOr404;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.slicehost.binders.BindCreateSliceToXmlPayload;
import org.jclouds.slicehost.domain.Backup;
import org.jclouds.slicehost.domain.Flavor;
import org.jclouds.slicehost.domain.Image;
import org.jclouds.slicehost.domain.Slice;
import org.jclouds.slicehost.filters.SlicehostBasic;
import org.jclouds.slicehost.xml.BackupHandler;
import org.jclouds.slicehost.xml.BackupsHandler;
import org.jclouds.slicehost.xml.FlavorHandler;
import org.jclouds.slicehost.xml.FlavorsHandler;
import org.jclouds.slicehost.xml.ImageHandler;
import org.jclouds.slicehost.xml.ImagesHandler;
import org.jclouds.slicehost.xml.SliceHandler;
import org.jclouds.slicehost.xml.SlicesHandler;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides asynchronous access to Slicehost via their REST API.
* <p/>
* All commands return a ListenableFuture of the result from Slicehost. Any exceptions incurred
* during processing will be backend in an {@link ExecutionException} as documented in
* {@link ListenableFuture#get()}.
*
* @see SlicehostClient
* @see <a href="http://www.slicehost.com/docs/Slicehost_API.pdf" />
* @author Adrian Cole
*/
@RequestFilters(SlicehostBasic.class)
public interface SlicehostAsyncClient {
/**
* @see SlicehostClient#listSlices
*/
@GET
@Path("/slices.xml")
@Fallback(EmptySetOnNotFoundOr404.class)
@XMLResponseParser(SlicesHandler.class)
ListenableFuture<? extends Set<Slice>> listSlices();
/**
* @see SlicehostClient#getSlice
*/
@GET
@Fallback(NullOnNotFoundOr404.class)
@Path("/slices/{id}.xml")
@XMLResponseParser(SliceHandler.class)
ListenableFuture<Slice> getSlice(@PathParam("id") int id);
/**
* @see SlicehostClient#destroySlice
*/
@DELETE
@Fallback(VoidOnNotFoundOr404.class)
@Path("/slices/{id}/destroy.xml")
ListenableFuture<Void> destroySlice(@PathParam("id") int id);
/**
* @see SlicehostClient#rebootSlice
*/
@PUT
@Path("/slices/{id}/reboot.xml")
ListenableFuture<Void> rebootSlice(@PathParam("id") int id);
/**
* @see SlicehostClient#hardRebootSlice
*/
@PUT
@Path("/slices/{id}/hard_reboot.xml")
ListenableFuture<Void> hardRebootSlice(@PathParam("id") int id);
/**
* @see SlicehostClient#createSlice
*/
@POST
@Path("/slices.xml")
@MapBinder(BindCreateSliceToXmlPayload.class)
@XMLResponseParser(SliceHandler.class)
ListenableFuture<Slice> createSlice(@PayloadParam("name") String name, @PayloadParam("image_id") int imageId,
@PayloadParam("flavor_id") int flavorId);
/**
* @see SlicehostClient#rebuildSliceFromImage
*/
@PUT
@Path("/slices/{id}/rebuild.xml")
ListenableFuture<Void> rebuildSliceFromImage(@PathParam("id") int id, @QueryParam("image_id") int imageId);
/**
* @see SlicehostClient#rebuildSliceFromBackup
*/
@PUT
@Path("/slices/{id}/rebuild.xml")
ListenableFuture<Void> rebuildSliceFromBackup(@PathParam("id") int id, @QueryParam("backup_id") int imageId);
/**
* @see SlicehostClient#listFlavors
*/
@GET
@Path("/flavors.xml")
@Fallback(EmptySetOnNotFoundOr404.class)
@XMLResponseParser(FlavorsHandler.class)
ListenableFuture<? extends Set<Flavor>> listFlavors();
/**
* @see SlicehostClient#getFlavor
*/
@GET
@Path("/flavors/{id}.xml")
@Fallback(NullOnNotFoundOr404.class)
@XMLResponseParser(FlavorHandler.class)
ListenableFuture<Flavor> getFlavor(@PathParam("id") int id);
/**
* @see SlicehostClient#listImages
*/
@GET
@Path("/images.xml")
@Fallback(EmptySetOnNotFoundOr404.class)
@XMLResponseParser(ImagesHandler.class)
ListenableFuture<? extends Set<Image>> listImages();
/**
* @see SlicehostClient#getImage
*/
@GET
@Fallback(NullOnNotFoundOr404.class)
@Path("/images/{id}.xml")
@XMLResponseParser(ImageHandler.class)
ListenableFuture<Image> getImage(@PathParam("id") int id);
/**
* @see SlicehostClient#listBackups
*/
@GET
@Path("/backups.xml")
@Fallback(EmptySetOnNotFoundOr404.class)
@XMLResponseParser(BackupsHandler.class)
ListenableFuture<? extends Set<Backup>> listBackups();
/**
* @see SlicehostClient#getBackup
*/
@GET
@Fallback(NullOnNotFoundOr404.class)
@Path("/backups/{id}.xml")
@XMLResponseParser(BackupHandler.class)
ListenableFuture<Backup> getBackup(@PathParam("id") int id);
}

View File

@ -1,71 +0,0 @@
/**
* 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.slicehost;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.slicehost.domain.Backup;
import org.jclouds.slicehost.domain.Flavor;
import org.jclouds.slicehost.domain.Image;
import org.jclouds.slicehost.domain.Slice;
/**
* Provides access to Slicehost via their REST API.
* <p/>
* All commands return a ListenableFuture of the result from Slicehost. Any exceptions incurred
* during processing will be backend in an {@link ExecutionException} as documented in
* {@link ListenableFuture#get()}.
*
* @see SlicehostAsyncClient
* @see <a href="http://www.slicehost.com/docs/Slicehost_API.pdf" />
* @author Adrian Cole
*/
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface SlicehostClient {
Set<Slice> listSlices();
Slice getSlice(int id);
Void destroySlice(int id);
Void rebootSlice(int id);
Void hardRebootSlice(int id);
Slice createSlice(String name, int imageId, int flavorId);
Void rebuildSliceFromImage(int id, int imageId);
Void rebuildSliceFromBackup(int id, int imageId);
Set<Flavor> listFlavors();
Flavor getFlavor(int id);
Set<Image> listImages();
Image getImage(int id);
Set<Backup> listBackups();
Backup getBackup(int id);
}

View File

@ -1,64 +0,0 @@
package org.jclouds.slicehost;
import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE;
import java.net.URI;
import java.util.Properties;
import org.jclouds.providers.ProviderMetadata;
import org.jclouds.providers.internal.BaseProviderMetadata;
/**
* Implementation of {@link org.jclouds.types.ProviderMetadata} for Slicehost
*
* @author Adrian Cole
*/
public class SlicehostProviderMetadata extends BaseProviderMetadata {
public static Builder builder() {
return new Builder();
}
@Override
public Builder toBuilder() {
return builder().fromProviderMetadata(this);
}
public SlicehostProviderMetadata() {
super(builder());
}
public SlicehostProviderMetadata(Builder builder) {
super(builder);
}
public static Properties defaultProperties() {
Properties properties = new Properties();
properties.setProperty(TEMPLATE, "osFamily=UBUNTU,osVersionMatches=1[012].[01][04],os64Bit=true,osDescriptionMatches=^((?!MGC).)*$");
return properties;
}
public static class Builder extends BaseProviderMetadata.Builder {
protected Builder(){
id("slicehost")
.name("Slicehost")
.apiMetadata(new SlicehostApiMetadata())
.homepage(URI.create("http://www.slicehost.com"))
.console(URI.create("https://manage.slicehost.com/"))
.iso3166Codes("US-IL", "US-TX", "US-MO");
}
@Override
public SlicehostProviderMetadata build() {
return new SlicehostProviderMetadata(this);
}
@Override
public Builder fromProviderMetadata(
ProviderMetadata in) {
super.fromProviderMetadata(in);
return this;
}
}
}

View File

@ -1,65 +0,0 @@
/**
* 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.slicehost.binders;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload;
/**
*
* @author Adrian Cole
*
*/
@Singleton
public class BindCreateBackupToXmlPayload implements MapBinder {
private final BindToStringPayload binder;
@Inject
BindCreateBackupToXmlPayload(BindToStringPayload binder) {
this.binder = binder;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
String sliceId = checkNotNull(postParams.get("slice_id"), "slice_id").toString();
String name = checkNotNull(postParams.get("name"), "name").toString();
StringBuilder builder = new StringBuilder();
builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><backup>");
builder.append("<slice-id type=\"integer\">").append(sliceId).append("</slice-id>");
builder.append("<name>").append(name).append("</name>");
builder.append("</backup>");
request = binder.bindToRequest(request, builder.toString());
request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_XML);
return request;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
throw new UnsupportedOperationException("should use map params");
}
}

View File

@ -1,66 +0,0 @@
/**
* 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.slicehost.binders;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload;
/**
*
* @author Adrian Cole
*
*/
@Singleton
public class BindCreateSliceToXmlPayload implements MapBinder {
private final BindToStringPayload binder;
@Inject
BindCreateSliceToXmlPayload(BindToStringPayload binder) {
this.binder = binder;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
String flavorId = checkNotNull(postParams.get("flavor_id"), "flavor_id").toString();
String imageId = checkNotNull(postParams.get("image_id"), "image_id").toString();
String name = checkNotNull(postParams.get("name"), "name").toString();
StringBuilder builder = new StringBuilder();
builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><slice>");
builder.append("<flavor-id type=\"integer\">").append(flavorId).append("</flavor-id>");
builder.append("<image-id type=\"integer\">").append(imageId).append("</image-id>");
builder.append("<name>").append(name).append("</name>");
builder.append("</slice>");
request = binder.bindToRequest(request, builder.toString());
request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_XML);
return request;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
throw new UnsupportedOperationException("should use map params");
}
}

View File

@ -1,95 +0,0 @@
/**
* 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.slicehost.compute.config;
import java.util.Map;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.NodeMetadata.Status;
import org.jclouds.domain.Location;
import org.jclouds.functions.IdentityFunction;
import org.jclouds.slicehost.compute.functions.FlavorToHardware;
import org.jclouds.slicehost.compute.functions.SliceToNodeMetadata;
import org.jclouds.slicehost.compute.functions.SlicehostImageToImage;
import org.jclouds.slicehost.compute.functions.SlicehostImageToOperatingSystem;
import org.jclouds.slicehost.compute.strategy.SlicehostComputeServiceAdapter;
import org.jclouds.slicehost.domain.Flavor;
import org.jclouds.slicehost.domain.Slice;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
/**
* Configures the {@link SlicehostComputeServiceContext}; requires {@link BaseComputeService} bound.
*
* @author Adrian Cole
*/
public class SlicehostComputeServiceContextModule extends
ComputeServiceAdapterContextModule<Slice, Flavor, org.jclouds.slicehost.domain.Image, Location> {
@SuppressWarnings("unchecked")
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<ComputeServiceAdapter<Slice, Flavor, org.jclouds.slicehost.domain.Image, Location>>() {
}).to(SlicehostComputeServiceAdapter.class);
bind(new TypeLiteral<Function<Slice, NodeMetadata>>() {
}).to(SliceToNodeMetadata.class);
bind(new TypeLiteral<Function<org.jclouds.slicehost.domain.Image, Image>>() {
}).to(SlicehostImageToImage.class);
bind(new TypeLiteral<Function<org.jclouds.slicehost.domain.Image, OperatingSystem>>() {
}).to(SlicehostImageToOperatingSystem.class);
bind(new TypeLiteral<Function<Flavor, Hardware>>() {
}).to(FlavorToHardware.class);
// we aren't converting location from a provider-specific type
bind(new TypeLiteral<Function<Location, Location>>() {
}).to(Class.class.cast(IdentityFunction.class));
}
@VisibleForTesting
public static final Map<Slice.Status, Status> sliceStatusToNodeStatus = ImmutableMap
.<Slice.Status, Status> builder().put(Slice.Status.ACTIVE, Status.RUNNING)//
.put(Slice.Status.BUILD, Status.PENDING)//
.put(Slice.Status.REBOOT, Status.PENDING)//
.put(Slice.Status.HARD_REBOOT, Status.PENDING)//
.put(Slice.Status.TERMINATED, Status.TERMINATED)//
.put(Slice.Status.UNRECOGNIZED, Status.UNRECOGNIZED)//
.build();
@Singleton
@Provides
Map<Slice.Status, Status> provideSliceToNodeStatus() {
return sliceStatusToNodeStatus;
}
}

View File

@ -1,43 +0,0 @@
/**
* 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.slicehost.compute.functions;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.internal.VolumeImpl;
import org.jclouds.slicehost.domain.Flavor;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
/**
* @author Adrian Cole
*/
@Singleton
public class FlavorToHardware implements Function<Flavor, Hardware> {
public Hardware apply(Flavor from) {
return new HardwareBuilder().ids(from.getId() + "").name(from.getName()).hypervisor("xen")
.processors(ImmutableList.of(new Processor(from.getRam() / 1024.0, 1.0))).ram(from.getRam())
.volumes(ImmutableList.<Volume> of(new VolumeImpl((from.getRam() * 4) / 1024.0f, true, true))).build();
}
}

View File

@ -1,136 +0,0 @@
/**
* 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.slicehost.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Singleton;
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.OperatingSystem;
import org.jclouds.compute.domain.NodeMetadata.Status;
import org.jclouds.compute.functions.GroupNamingConvention;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.slicehost.domain.Slice;
import org.jclouds.util.Predicates2;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/**
* @author Adrian Cole
*/
@Singleton
public class SliceToNodeMetadata implements Function<Slice, NodeMetadata> {
protected final Supplier<Location> location;
protected final Map<Slice.Status, Status> sliceToNodeStatus;
protected final Supplier<Set<? extends Image>> images;
protected final Supplier<Set<? extends Hardware>> hardwares;
protected final GroupNamingConvention nodeNamingConvention;
@Resource
protected Logger logger = Logger.NULL;
private static class FindImageForSlice implements Predicate<Image> {
private final Slice slice;
private FindImageForSlice(Slice slice) {
this.slice = slice;
}
@Override
public boolean apply(Image input) {
return input.getProviderId().equals(slice.getImageId() + "");
}
}
private static class FindHardwareForSlice implements Predicate<Hardware> {
private final Slice slice;
private FindHardwareForSlice(Slice slice) {
this.slice = slice;
}
@Override
public boolean apply(Hardware input) {
return input.getProviderId().equals(slice.getFlavorId() + "");
}
}
@Inject
SliceToNodeMetadata(Map<Slice.Status, Status> sliceStateToNodeStatus,
@Memoized Supplier<Set<? extends Image>> images, Supplier<Location> location,
@Memoized Supplier<Set<? extends Hardware>> hardwares,
GroupNamingConvention.Factory namingConvention) {
this.nodeNamingConvention = checkNotNull(namingConvention, "namingConvention").createWithoutPrefix();
this.sliceToNodeStatus = checkNotNull(sliceStateToNodeStatus, "sliceStateToNodeStatus");
this.images = checkNotNull(images, "images");
this.location = checkNotNull(location, "location");
this.hardwares = checkNotNull(hardwares, "hardwares");
}
@Override
public NodeMetadata apply(Slice from) {
NodeMetadataBuilder builder = new NodeMetadataBuilder();
builder.ids(from.getId() + "");
builder.name(from.getName());
builder.hostname(from.getName());
builder.location(location.get());
builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName()));
builder.imageId(from.getImageId() + "");
builder.operatingSystem(parseOperatingSystem(from));
builder.hardware(parseHardware(from));
builder.status(sliceToNodeStatus.get(from.getStatus()));
builder.publicAddresses(Iterables.filter(from.getAddresses(), Predicates.not(Predicates2.startsWith("10."))));
builder.privateAddresses(Iterables.filter(from.getAddresses(), Predicates2.startsWith("10.")));
return builder.build();
}
protected Hardware parseHardware(Slice from) {
try {
return Iterables.find(hardwares.get(), new FindHardwareForSlice(from));
} catch (NoSuchElementException e) {
logger.debug("could not find a matching hardware for slice %s", from);
}
return null;
}
protected OperatingSystem parseOperatingSystem(Slice from) {
try {
return Iterables.find(images.get(), new FindImageForSlice(from)).getOperatingSystem();
} catch (NoSuchElementException e) {
logger.debug("could not find a matching image for slice %s in location %s", from, location);
}
return null;
}
}

View File

@ -1,53 +0,0 @@
/**
* 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.slicehost.compute.functions;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystem;
import com.google.common.base.Function;
/**
*
* @author Adrian Cole
*/
@Singleton
public class SlicehostImageToImage implements Function<org.jclouds.slicehost.domain.Image, Image> {
private final Function<org.jclouds.slicehost.domain.Image, OperatingSystem> imageToOs;
@Inject
SlicehostImageToImage(Function<org.jclouds.slicehost.domain.Image, OperatingSystem> imageToOs) {
this.imageToOs = imageToOs;
}
public Image apply(org.jclouds.slicehost.domain.Image from) {
ImageBuilder builder = new ImageBuilder();
builder.ids(from.getId() + "");
builder.name(from.getName());
builder.description(from.getName());
builder.operatingSystem(imageToOs.apply(from));
builder.status(Image.Status.AVAILABLE);
Image image = builder.build();
return image;
}
}

View File

@ -1,90 +0,0 @@
/**
* 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.slicehost.compute.functions;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.logging.Logger;
import com.google.common.base.Function;
/**
*
* @author Adrian Cole
*/
@Singleton
public class SlicehostImageToOperatingSystem implements Function<org.jclouds.slicehost.domain.Image, OperatingSystem> {
public static final Pattern DEFAULT_PATTERN = Pattern.compile("(([^ ]*) ([0-9.]+) ?.*)");
// Windows Server 2008 R2 x64
public static final Pattern WINDOWS_PATTERN = Pattern.compile("Windows (.*) (x[86][64])");
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
private final Map<OsFamily, Map<String, String>> osVersionMap;
@Inject
public SlicehostImageToOperatingSystem(Map<OsFamily, Map<String, String>> osVersionMap) {
this.osVersionMap = osVersionMap;
}
public OperatingSystem apply(final org.jclouds.slicehost.domain.Image from) {
OsFamily osFamily = null;
String osName = null;
String osArch = null;
String osVersion = null;
String osDescription = from.getName();
boolean is64Bit = !from.getName().endsWith("32-bit");
if (from.getName().indexOf("Red Hat EL") != -1) {
osFamily = OsFamily.RHEL;
} else if (from.getName().indexOf("Oracle EL") != -1) {
osFamily = OsFamily.OEL;
} else if (from.getName().indexOf("Windows") != -1) {
osFamily = OsFamily.WINDOWS;
Matcher matcher = WINDOWS_PATTERN.matcher(from.getName());
if (matcher.find()) {
osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(1), osVersionMap);
is64Bit = matcher.group(2).equals("x64");
}
} else {
Matcher matcher = DEFAULT_PATTERN.matcher(from.getName());
if (matcher.find()) {
try {
osFamily = OsFamily.fromValue(matcher.group(2).toLowerCase());
} catch (IllegalArgumentException e) {
logger.debug("<< didn't match os(%s)", matcher.group(2));
}
osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(3), osVersionMap);
}
}
return new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit);
}
}

View File

@ -1,119 +0,0 @@
/**
* 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.slicehost.compute.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.domain.Template;
import org.jclouds.domain.Location;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.slicehost.SlicehostClient;
import org.jclouds.slicehost.domain.Flavor;
import org.jclouds.slicehost.domain.Image;
import org.jclouds.slicehost.domain.Slice;
import com.google.common.collect.ImmutableSet;
/**
* defines the connection between the {@link SlicehostClient} implementation and the jclouds
* {@link ComputeService}
*
*/
@Singleton
public class SlicehostComputeServiceAdapter implements ComputeServiceAdapter<Slice, Flavor, Image, Location> {
protected final SlicehostClient client;
@Inject
protected SlicehostComputeServiceAdapter(SlicehostClient client) {
this.client = checkNotNull(client, "client");
}
@Override
public NodeAndInitialCredentials<Slice> createNodeWithGroupEncodedIntoName(String group, String name,
Template template) {
Slice server = client
.createSlice(name, Integer.parseInt(template.getImage().getProviderId()), Integer.parseInt(template
.getHardware().getProviderId()));
return new NodeAndInitialCredentials<Slice>(server, server.getId() + "", LoginCredentials.builder().password(
server.getRootPassword()).build());
}
@Override
public Iterable<Flavor> listHardwareProfiles() {
return client.listFlavors();
}
@Override
public Iterable<Image> listImages() {
return client.listImages();
}
@Override
public Iterable<Slice> listNodes() {
return client.listSlices();
}
@Override
public Iterable<Location> listLocations() {
// Not using the adapter to determine locations
return ImmutableSet.<Location>of();
}
@Override
public Slice getNode(String id) {
int serverId = Integer.parseInt(id);
return client.getSlice(serverId);
}
@Override
public Image getImage(String id) {
int imageId = Integer.parseInt(id);
return client.getImage(imageId);
}
@Override
public void destroyNode(String id) {
int serverId = Integer.parseInt(id);
// if false server wasn't around in the first place
client.destroySlice(serverId);
}
@Override
public void rebootNode(String id) {
int sliceId = Integer.parseInt(id);
client.hardRebootSlice(sliceId);
}
@Override
public void resumeNode(String id) {
throw new UnsupportedOperationException("suspend not supported");
}
@Override
public void suspendNode(String id) {
throw new UnsupportedOperationException("suspend not supported");
}
}

View File

@ -1,45 +0,0 @@
/**
* 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.slicehost.config;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import org.jclouds.slicehost.SlicehostAsyncClient;
import org.jclouds.slicehost.SlicehostClient;
import org.jclouds.slicehost.handlers.ParseSlicehostErrorFromHttpResponse;
/**
*
* @author Adrian Cole
*/
@ConfiguresRestClient
public class SlicehostRestClientModule extends RestClientModule<SlicehostClient, SlicehostAsyncClient> {
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseSlicehostErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseSlicehostErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseSlicehostErrorFromHttpResponse.class);
}
}

View File

@ -1,115 +0,0 @@
/**
* 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.slicehost.domain;
import java.util.Date;
/**
*
*
* @author Adrian Cole
*/
public class Backup {
private final int id;
private final String name;
private final String sliceId;
private final Date date;
public Backup(int id, String name, String sliceId, Date date) {
this.id = id;
this.name = name;
this.sliceId = sliceId;
this.date = date;
}
/**
* @return id of the backup
*/
public int getId() {
return id;
}
/**
* @return Examples: weekly, my snapshot
*/
public String getName() {
return name;
}
/**
* @return The Slice this backup was made from
*/
public String getSliceId() {
return sliceId;
}
/**
* @return The time the backup was taken
*/
public Date getDate() {
return date;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((date == null) ? 0 : date.hashCode());
result = prime * result + id;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((sliceId == null) ? 0 : sliceId.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Backup other = (Backup) obj;
if (date == null) {
if (other.date != null)
return false;
} else if (!date.equals(other.date))
return false;
if (id != other.id)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (sliceId == null) {
if (other.sliceId != null)
return false;
} else if (!sliceId.equals(other.sliceId))
return false;
return true;
}
@Override
public String toString() {
return "[date=" + date + ", id=" + id + ", name=" + name + ", sliceId=" + sliceId + "]";
}
}

View File

@ -1,109 +0,0 @@
/**
* 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.slicehost.domain;
/**
*
* A flavor is an available hardware configuration for a slice.
*
* @author Adrian Cole
*/
public class Flavor {
private final int id;
private final String name;
private final int price;
private final int ram;
public Flavor(int id, String name, int price, int ram) {
this.id = id;
this.name = name;
this.price = price;
this.ram = ram;
}
/**
* @return id of the flavor
*/
public int getId() {
return id;
}
/**
* @return Verbose name for the flavor, e.g. 256 slice
*/
public String getName() {
return name;
}
/**
* @return The price as an integer of cents. For example: 2000 equals $20.00.
* Note that all prices are in USD
*/
public int getPrice() {
return price;
}
/**
* @return The amount of RAM (in Megabytes) included with the plan
*/
public int getRam() {
return ram;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + Float.floatToIntBits(price);
result = prime * result + ram;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Flavor other = (Flavor) obj;
if (id != other.id)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (Float.floatToIntBits(price) != Float.floatToIntBits(other.price))
return false;
if (ram != other.ram)
return false;
return true;
}
@Override
public String toString() {
return "[id=" + id + ", name=" + name + ", price=" + price + ", ram=" + ram + "]";
}
}

View File

@ -1,85 +0,0 @@
/**
* 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.slicehost.domain;
/**
*
*
* @author Adrian Cole
*/
public class Image {
private final int id;
private final String name;
public Image(int id, String name) {
this.id = id;
this.name = name;
}
/**
* @return id of the image
*/
public int getId() {
return id;
}
/**
* @return Example: Ubuntu 8.04 LTS (hardy)
*/
public String getName() {
return name;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Image other = (Image) obj;
if (id != other.id)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
@Override
public String toString() {
return "[id=" + id + ", name=" + name + "]";
}
}

View File

@ -1,252 +0,0 @@
/**
* 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.slicehost.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.CaseFormat;
/**
* A slice is a virtual machine instance in the Slicehost system. Flavor and image are requisite
* elements when creating a slice.
*
* @author Adrian Cole
*/
public class Slice {
/**
* The current status of the slice
*
*/
public enum Status {
ACTIVE, BUILD, REBOOT, HARD_REBOOT, TERMINATED, UNRECOGNIZED;
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_UNDERSCORE, name());
}
@Override
public String toString() {
return value();
}
public static Status fromValue(String state) {
try {
return valueOf(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(state, "state")));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}
private final int id;
private final String name;
private final int flavorId;
@Nullable
private final Integer imageId;
@Nullable
private final Integer backupId;
private final Status status;
@Nullable
private final Integer progress;
private final float bandwidthIn;
private final float bandwidthOut;
private final Set<String> addresses;
@Nullable
private final String rootPassword;
public Slice(int id, String name, int flavorId, @Nullable Integer imageId, @Nullable Integer backupId,
Status status, @Nullable Integer progress, float bandwidthIn, float bandwidthOut, Set<String> addresses,
@Nullable String rootPassword) {
this.id = id;
this.name = name;
this.flavorId = flavorId;
this.imageId = imageId;
this.backupId = backupId;
this.status = status;
this.progress = progress;
this.bandwidthIn = bandwidthIn;
this.bandwidthOut = bandwidthOut;
this.addresses = addresses;
this.rootPassword = rootPassword;
}
/**
* @return unique id within slicehost
*/
public int getId() {
return id;
}
/**
* @return A string to identify the slice
*/
public String getName() {
return name;
}
/**
* @return the flavor of a slice
*/
public int getFlavorId() {
return flavorId;
}
/**
* @return the image used to create the slice or null
*/
public Integer getImageId() {
return imageId;
}
/**
* @return The current status of the slice
*/
public Status getStatus() {
return status;
}
/**
* @return The percentage of current action in percentage
*/
public Integer getProgress() {
return progress;
}
/**
* @return The incoming bandwidth total for this billing cycle, in Gigabytes
*/
public float getBandwidthIn() {
return bandwidthIn;
}
/**
* @return The outgoing bandwidth total for this billing cycle, in Gigabytes
*/
public float getBandwidthOut() {
return bandwidthOut;
}
/**
* @return an array of strings representing the Slice's IPs, including private IPs
*/
public Set<String> getAddresses() {
return addresses;
}
/**
* @return root password, if just created
*/
public String getRootPassword() {
return rootPassword;
}
/**
* @return backup used to create this instance or null
*/
public Integer getBackupId() {
return backupId;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((addresses == null) ? 0 : addresses.hashCode());
result = prime * result + ((backupId == null) ? 0 : backupId.hashCode());
result = prime * result + Float.floatToIntBits(bandwidthIn);
result = prime * result + Float.floatToIntBits(bandwidthOut);
result = prime * result + flavorId;
result = prime * result + id;
result = prime * result + ((imageId == null) ? 0 : imageId.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((progress == null) ? 0 : progress.hashCode());
result = prime * result + ((rootPassword == null) ? 0 : rootPassword.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Slice other = (Slice) obj;
if (addresses == null) {
if (other.addresses != null)
return false;
} else if (!addresses.equals(other.addresses))
return false;
if (backupId == null) {
if (other.backupId != null)
return false;
} else if (!backupId.equals(other.backupId))
return false;
if (Float.floatToIntBits(bandwidthIn) != Float.floatToIntBits(other.bandwidthIn))
return false;
if (Float.floatToIntBits(bandwidthOut) != Float.floatToIntBits(other.bandwidthOut))
return false;
if (flavorId != other.flavorId)
return false;
if (id != other.id)
return false;
if (imageId == null) {
if (other.imageId != null)
return false;
} else if (!imageId.equals(other.imageId))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (progress == null) {
if (other.progress != null)
return false;
} else if (!progress.equals(other.progress))
return false;
if (rootPassword == null) {
if (other.rootPassword != null)
return false;
} else if (!rootPassword.equals(other.rootPassword))
return false;
if (status == null) {
if (other.status != null)
return false;
} else if (!status.equals(other.status))
return false;
return true;
}
@Override
public String toString() {
return "[id=" + id + ", name=" + name + ", flavorId=" + flavorId + ", imageId=" + imageId + ", backupId="
+ backupId + ", status=" + status + ", progress=" + progress + ", bandwidthIn=" + bandwidthIn
+ ", bandwidthOut=" + bandwidthOut + ", addresses=" + addresses + ", rootPassword="
+ (rootPassword != null) + "]";
}
}

View File

@ -1,51 +0,0 @@
/**
* 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.slicehost.filters;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.core.HttpHeaders;
import org.jclouds.crypto.CryptoStreams;
import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter;
import org.jclouds.rest.annotations.Identity;
/**
*
* @author Adrian Cole
*/
@Singleton
public class SlicehostBasic implements HttpRequestFilter {
private final String apikey;
@Inject
public SlicehostBasic(@Identity String apikey) {
this.apikey = checkNotNull(apikey, "apikey");
}
@Override
public HttpRequest filter(HttpRequest request) throws HttpException {
return request.toBuilder().replaceHeader(HttpHeaders.AUTHORIZATION,
String.format("Basic %s", CryptoStreams.base64(apikey.getBytes()))).build();
}
}

View File

@ -1,128 +0,0 @@
/**
* 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.slicehost.handlers;
import static org.jclouds.http.HttpUtils.releasePayload;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.logging.Logger;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.slicehost.xml.ErrorHandler;
import org.jclouds.util.Strings2;
/**
* This will parse and set an appropriate exception on the command object.
*
* @author Adrian Cole
*
*/
@Singleton
public class ParseSlicehostErrorFromHttpResponse implements HttpErrorHandler {
@Resource
protected Logger logger = Logger.NULL;
public static final Pattern RESOURCE_PATTERN = Pattern.compile("^/v1[^/]*/[0-9]+/([^/]+)/([0-9]+)");
private final ErrorParser errorParser;
@Inject
ParseSlicehostErrorFromHttpResponse(ErrorParser errorParser) {
this.errorParser = errorParser;
}
public void handleError(HttpCommand command, HttpResponse response) {
Exception exception = new HttpResponseException(command, response);
try {
String content = response.getStatusCode() != 401 ? parseErrorFromContentOrNull(command, response) : null;
exception = content != null ? new HttpResponseException(command, response, content) : exception;
switch (response.getStatusCode()) {
case 401:
exception = new AuthorizationException(exception.getMessage(), exception);
break;
case 403:
case 404:
if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
String path = command.getCurrentRequest().getEndpoint().getPath();
Matcher matcher = RESOURCE_PATTERN.matcher(path);
String message;
if (matcher.find()) {
message = String.format("%s %s not found", matcher.group(1), matcher.group(2));
} else {
message = path;
}
exception = new ResourceNotFoundException(message);
}
break;
case 422:
exception = new IllegalStateException(content);
break;
default:
exception = new HttpResponseException(command, response, content);
}
} finally {
releasePayload(response);
command.setException(exception);
}
}
@Singleton
static class ErrorParser {
final ParseSax.Factory factory;
final Provider<ErrorHandler> errorHandlerProvider;
@Resource
protected Logger logger = Logger.NULL;
@Inject
ErrorParser(Factory factory, Provider<ErrorHandler> errorHandlerProvider) {
this.factory = factory;
this.errorHandlerProvider = errorHandlerProvider;
}
String parse(String in) {
return factory.create(errorHandlerProvider.get()).parse(in);
}
}
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
// slicehost returns " " which is unparsable
if (response.getPayload() != null) {
try {
String payload = Strings2.toString(response.getPayload()).trim();
return payload.indexOf("xml") != -1 ? errorParser.parse(payload) : payload;
} catch (IOException e) {
}
}
return null;
}
}

View File

@ -1,64 +0,0 @@
/**
* 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.slicehost.predicates;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Resource;
import javax.inject.Singleton;
import org.jclouds.logging.Logger;
import org.jclouds.slicehost.SlicehostClient;
import org.jclouds.slicehost.domain.Slice;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
*
*
* @author Adrian Cole
*/
@Singleton
public class SliceActive implements Predicate<Slice> {
private final SlicehostClient client;
@Resource
protected Logger logger = Logger.NULL;
@Inject
public SliceActive(SlicehostClient client) {
this.client = client;
}
public boolean apply(Slice slice) {
logger.trace("looking for state on slice %s", checkNotNull(slice, "slice"));
slice = refresh(slice);
if (slice == null)
return false;
logger.trace("%s: looking for slice state %s: currently: %s", slice.getId(), Slice.Status.ACTIVE, slice
.getStatus());
return slice.getStatus() == Slice.Status.ACTIVE;
}
private Slice refresh(Slice slice) {
return client.getSlice(slice.getId());
}
}

View File

@ -1,63 +0,0 @@
/**
* 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.slicehost.predicates;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Resource;
import javax.inject.Singleton;
import org.jclouds.logging.Logger;
import org.jclouds.slicehost.SlicehostClient;
import org.jclouds.slicehost.domain.Slice;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
*
* @author Adrian Cole
*/
@Singleton
public class SliceTerminated implements Predicate<Slice> {
private final SlicehostClient client;
@Resource
protected Logger logger = Logger.NULL;
@Inject
public SliceTerminated(SlicehostClient client) {
this.client = client;
}
public boolean apply(Slice slice) {
logger.trace("looking for state on slice %s", checkNotNull(slice, "slice"));
slice = refresh(slice);
if (slice == null)
return true;
logger.trace("%s: looking for slice state %s: currently: %s", slice.getId(), Slice.Status.TERMINATED, slice
.getStatus());
return slice.getStatus() == Slice.Status.TERMINATED;
}
private Slice refresh(Slice slice) {
return client.getSlice(slice.getId());
}
}

View File

@ -1,78 +0,0 @@
/**
* 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.slicehost.xml;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import javax.annotation.Resource;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger;
import org.jclouds.slicehost.domain.Backup;
import org.xml.sax.SAXException;
/**
* @author Adrian Cole
*/
public class BackupHandler extends ParseSax.HandlerWithResult<Backup> {
private StringBuilder currentText = new StringBuilder();
private int id;
private String name;
private String sliceId;
private Date date;
private Backup backup;
@Resource
protected Logger logger = Logger.NULL;
public Backup getResult() {
return backup;
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equalsIgnoreCase("id")) {
id = Integer.parseInt(currentText.toString().trim());
} else if (qName.equalsIgnoreCase("name")) {
this.name = currentText.toString().trim();
} else if (qName.equalsIgnoreCase("slice_id")) {
sliceId = currentText.toString().trim();
} else if (qName.equalsIgnoreCase("date")) {
try {
date = DateFormat.getInstance().parse(currentText.toString().trim());
} catch (ParseException e) {
logger.warn(e, "error parsing: %s", currentText.toString().trim());
}
} else if (qName.equalsIgnoreCase("backup")) {
this.backup = new Backup(id, name, sliceId, date);
this.id = -1;
this.name = null;
this.sliceId = null;
this.date = null;
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -1,68 +0,0 @@
/**
* 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.slicehost.xml;
import java.util.Set;
import javax.inject.Inject;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.slicehost.domain.Backup;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class BackupsHandler extends ParseSax.HandlerWithResult<Set<? extends Backup>> {
private StringBuilder currentText = new StringBuilder();
private Set<Backup> backups = Sets.newLinkedHashSet();
private final BackupHandler locationHandler;
@Inject
public BackupsHandler(BackupHandler locationHandler) {
this.locationHandler = locationHandler;
}
public Set<? extends Backup> getResult() {
return backups;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
locationHandler.startElement(uri, localName, qName, attributes);
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
locationHandler.endElement(uri, localName, qName);
if (qName.equals("backup") && currentText.toString().trim().equals("")) {
this.backups.add(locationHandler.getResult());
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
locationHandler.characters(ch, start, length);
currentText.append(ch, start, length);
}
}

View File

@ -1,47 +0,0 @@
/**
* 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.slicehost.xml;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.SAXException;
/**
* @author Adrian Cole
*/
public class ErrorHandler extends ParseSax.HandlerWithResult<String> {
private StringBuilder currentText = new StringBuilder();
private String error;
public String getResult() {
return error;
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equalsIgnoreCase("error")) {
this.error = currentText.toString().trim();
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -1,65 +0,0 @@
/**
* 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.slicehost.xml;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.slicehost.domain.Flavor;
import org.xml.sax.SAXException;
/**
* @author Adrian Cole
*/
public class FlavorHandler extends ParseSax.HandlerWithResult<Flavor> {
private StringBuilder currentText = new StringBuilder();
private int id;
private String name;
private int price;
private int ram;
private Flavor flavor;
public Flavor getResult() {
return flavor;
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equalsIgnoreCase("id")) {
id = Integer.parseInt(currentText.toString().trim());
} else if (qName.equalsIgnoreCase("name")) {
this.name = currentText.toString().trim();
} else if (qName.equalsIgnoreCase("ram")) {
ram = Integer.parseInt(currentText.toString().trim());
} else if (qName.equalsIgnoreCase("price")) {
price = Integer.parseInt(currentText.toString().trim());
} else if (qName.equalsIgnoreCase("flavor")) {
this.flavor = new Flavor(id, name, price, ram);
this.id = -1;
this.name = null;
this.ram = -1;
this.price = 0;
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -1,68 +0,0 @@
/**
* 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.slicehost.xml;
import java.util.Set;
import javax.inject.Inject;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.slicehost.domain.Flavor;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class FlavorsHandler extends ParseSax.HandlerWithResult<Set<? extends Flavor>> {
private StringBuilder currentText = new StringBuilder();
private Set<Flavor> slices = Sets.newLinkedHashSet();
private final FlavorHandler locationHandler;
@Inject
public FlavorsHandler(FlavorHandler locationHandler) {
this.locationHandler = locationHandler;
}
public Set<? extends Flavor> getResult() {
return slices;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
locationHandler.startElement(uri, localName, qName, attributes);
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
locationHandler.endElement(uri, localName, qName);
if (qName.equals("flavor") && currentText.toString().trim().equals("")) {
this.slices.add(locationHandler.getResult());
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
locationHandler.characters(ch, start, length);
currentText.append(ch, start, length);
}
}

View File

@ -1,62 +0,0 @@
/**
* 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.slicehost.xml;
import javax.annotation.Resource;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger;
import org.jclouds.slicehost.domain.Image;
import org.xml.sax.SAXException;
/**
* @author Adrian Cole
*/
public class ImageHandler extends ParseSax.HandlerWithResult<Image> {
private StringBuilder currentText = new StringBuilder();
private int id;
private String name;
private Image image;
@Resource
protected Logger logger = Logger.NULL;
public Image getResult() {
return image;
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equalsIgnoreCase("id")) {
id = Integer.parseInt(currentText.toString().trim());
} else if (qName.equalsIgnoreCase("name")) {
this.name = currentText.toString().trim();
} else if (qName.equalsIgnoreCase("image")) {
this.image = new Image(id, name);
this.id = -1;
this.name = null;
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -1,68 +0,0 @@
/**
* 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.slicehost.xml;
import java.util.Set;
import javax.inject.Inject;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.slicehost.domain.Image;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class ImagesHandler extends ParseSax.HandlerWithResult<Set<? extends Image>> {
private StringBuilder currentText = new StringBuilder();
private Set<Image> images = Sets.newLinkedHashSet();
private final ImageHandler locationHandler;
@Inject
public ImagesHandler(ImageHandler locationHandler) {
this.locationHandler = locationHandler;
}
public Set<? extends Image> getResult() {
return images;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
locationHandler.startElement(uri, localName, qName, attributes);
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
locationHandler.endElement(uri, localName, qName);
if (qName.equals("image") && currentText.toString().trim().equals("")) {
this.images.add(locationHandler.getResult());
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
locationHandler.characters(ch, start, length);
currentText.append(ch, start, length);
}
}

View File

@ -1,108 +0,0 @@
/**
* 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.slicehost.xml;
import java.util.Set;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.slicehost.domain.Slice;
import org.jclouds.slicehost.domain.Slice.Status;
import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class SliceHandler extends ParseSax.HandlerWithResult<Slice> {
private StringBuilder currentText = new StringBuilder();
private int id;
private String name;
private int flavorId;
@Nullable
private Integer imageId;
@Nullable
private Integer backupId;
private Status status;
@Nullable
private Integer progress;
private float bandwidthIn;
private float bandwidthOut;
private Set<String> addresses = Sets.newLinkedHashSet();
@Nullable
private String rootPassword;
private Slice slice;
public Slice getResult() {
return slice;
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equalsIgnoreCase("id")) {
id = Integer.parseInt(currentText.toString().trim());
} else if (qName.equalsIgnoreCase("name")) {
this.name = currentText.toString().trim();
} else if (qName.equalsIgnoreCase("flavor-id")) {
flavorId = Integer.parseInt(currentText.toString().trim());
} else if (qName.equalsIgnoreCase("image-id")) {
imageId = Integer.parseInt(currentText.toString().trim());
} else if (qName.equalsIgnoreCase("backup-id")) {
backupId = Integer.parseInt(currentText.toString().trim());
} else if (qName.equalsIgnoreCase("status")) {
this.status = Slice.Status.fromValue(currentText.toString().trim());
} else if (qName.equalsIgnoreCase("progress")) {
try {
progress = Integer.parseInt(currentText.toString().trim());
} catch (NumberFormatException e) {
}
} else if (qName.equalsIgnoreCase("bw-in")) {
bandwidthIn = Float.parseFloat(currentText.toString().trim());
} else if (qName.equalsIgnoreCase("bw-out")) {
bandwidthOut = Float.parseFloat(currentText.toString().trim());
} else if (qName.equalsIgnoreCase("address")) {
this.addresses.add(currentText.toString().trim());
} else if (qName.equalsIgnoreCase("root-password")) {
this.rootPassword = currentText.toString().trim();
} else if (qName.equalsIgnoreCase("slice")) {
this.slice = new Slice(id, name, flavorId, imageId, backupId, status, progress, bandwidthIn, bandwidthOut,
addresses, rootPassword);
this.id = -1;
this.name = null;
this.flavorId = -1;
this.imageId = null;
this.backupId = null;
this.status = null;
this.progress = null;
this.bandwidthIn = 0;
this.bandwidthOut = 0;
this.addresses = Sets.newLinkedHashSet();
this.rootPassword = null;
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -1,68 +0,0 @@
/**
* 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.slicehost.xml;
import java.util.Set;
import javax.inject.Inject;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.slicehost.domain.Slice;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class SlicesHandler extends ParseSax.HandlerWithResult<Set<? extends Slice>> {
private StringBuilder currentText = new StringBuilder();
private Set<Slice> slices = Sets.newLinkedHashSet();
private final SliceHandler locationHandler;
@Inject
public SlicesHandler(SliceHandler locationHandler) {
this.locationHandler = locationHandler;
}
public Set<? extends Slice> getResult() {
return slices;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
locationHandler.startElement(uri, localName, qName, attributes);
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
locationHandler.endElement(uri, localName, qName);
if (qName.equals("slice") && currentText.toString().trim().equals("")) {
this.slices.add(locationHandler.getResult());
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
locationHandler.characters(ch, start, length);
currentText.append(ch, start, length);
}
}

View File

@ -1 +0,0 @@
org.jclouds.slicehost.SlicehostProviderMetadata

View File

@ -1,258 +0,0 @@
/**
* 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.slicehost;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.Fallbacks.VoidOnNotFoundOr404;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.providers.ProviderMetadata;
import org.jclouds.rest.internal.BaseAsyncClientTest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.slicehost.filters.SlicehostBasic;
import org.jclouds.slicehost.xml.FlavorHandler;
import org.jclouds.slicehost.xml.FlavorsHandler;
import org.jclouds.slicehost.xml.ImageHandler;
import org.jclouds.slicehost.xml.ImagesHandler;
import org.jclouds.slicehost.xml.SliceHandler;
import org.jclouds.slicehost.xml.SlicesHandler;
import org.testng.annotations.Test;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code SlicehostAsyncClient}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "SlicehostAsyncClientTest")
public class SlicehostAsyncClientTest extends BaseAsyncClientTest<SlicehostAsyncClient> {
public void testCreateSlice() throws IOException, SecurityException, NoSuchMethodException {
Method method = SlicehostAsyncClient.class.getMethod("createSlice", String.class, int.class, int.class);
HttpRequest request = processor.createRequest(method, "ralphie", 2, 1);
assertRequestLineEquals(request, "POST https://api.slicehost.com/slices.xml HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(
request,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><slice><flavor-id type=\"integer\">1</flavor-id><image-id type=\"integer\">2</image-id><name>ralphie</name></slice>",
"application/xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, SliceHandler.class);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
public void testDestroySlice() throws IOException, SecurityException, NoSuchMethodException {
Method method = SlicehostAsyncClient.class.getMethod("destroySlice", int.class);
HttpRequest request = processor.createRequest(method, 2);
assertRequestLineEquals(request, "DELETE https://api.slicehost.com/slices/2/destroy.xml HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, VoidOnNotFoundOr404.class);
checkFilters(request);
}
public void testListSlices() throws IOException, SecurityException, NoSuchMethodException {
Method method = SlicehostAsyncClient.class.getMethod("listSlices");
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, "GET https://api.slicehost.com/slices.xml HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, SlicesHandler.class);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetSlice() throws IOException, SecurityException, NoSuchMethodException {
Method method = SlicehostAsyncClient.class.getMethod("getSlice", int.class);
HttpRequest request = processor.createRequest(method, 2);
assertRequestLineEquals(request, "GET https://api.slicehost.com/slices/2.xml HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, SliceHandler.class);
assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
checkFilters(request);
}
public void testListFlavors() throws IOException, SecurityException, NoSuchMethodException {
Method method = SlicehostAsyncClient.class.getMethod("listFlavors");
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, "GET https://api.slicehost.com/flavors.xml HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, FlavorsHandler.class);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetFlavor() throws IOException, SecurityException, NoSuchMethodException {
Method method = SlicehostAsyncClient.class.getMethod("getFlavor", int.class);
HttpRequest request = processor.createRequest(method, 2);
assertRequestLineEquals(request, "GET https://api.slicehost.com/flavors/2.xml HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, FlavorHandler.class);
assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
checkFilters(request);
}
public void testListImages() throws IOException, SecurityException, NoSuchMethodException {
Method method = SlicehostAsyncClient.class.getMethod("listImages");
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, "GET https://api.slicehost.com/images.xml HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ImagesHandler.class);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetImage() throws IOException, SecurityException, NoSuchMethodException {
Method method = SlicehostAsyncClient.class.getMethod("getImage", int.class);
HttpRequest request = processor.createRequest(method, 2);
assertRequestLineEquals(request, "GET https://api.slicehost.com/images/2.xml HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ImageHandler.class);
assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
checkFilters(request);
}
public void testRebuildSliceFromImage() throws IOException, SecurityException, NoSuchMethodException {
Method method = SlicehostAsyncClient.class.getMethod("rebuildSliceFromImage", int.class, int.class);
HttpRequest request = processor.createRequest(method, 3, 1);
assertRequestLineEquals(request, "PUT https://api.slicehost.com/slices/3/rebuild.xml?image_id=1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
public void testRebuildSliceFromBackup() throws IOException, SecurityException, NoSuchMethodException {
Method method = SlicehostAsyncClient.class.getMethod("rebuildSliceFromBackup", int.class, int.class);
HttpRequest request = processor.createRequest(method, 3, 1);
assertRequestLineEquals(request, "PUT https://api.slicehost.com/slices/3/rebuild.xml?backup_id=1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
public void testReboot() throws IOException, SecurityException, NoSuchMethodException {
Method method = SlicehostAsyncClient.class.getMethod("rebootSlice", int.class);
HttpRequest request = processor.createRequest(method, 2);
assertRequestLineEquals(request, "PUT https://api.slicehost.com/slices/2/reboot.xml HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
public void testHardReboot() throws IOException, SecurityException, NoSuchMethodException {
Method method = SlicehostAsyncClient.class.getMethod("hardRebootSlice", int.class);
HttpRequest request = processor.createRequest(method, 2);
assertRequestLineEquals(request, "PUT https://api.slicehost.com/slices/2/hard_reboot.xml HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<SlicehostAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<SlicehostAsyncClient>>() {
};
}
@Override
protected void checkFilters(HttpRequest request) {
assertEquals(request.getFilters().size(), 1);
assertEquals(request.getFilters().get(0).getClass(), SlicehostBasic.class);
}
@Override
public ProviderMetadata createProviderMetadata() {
return new SlicehostProviderMetadata();
}
}

View File

@ -1,303 +0,0 @@
/**
* 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.slicehost;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.io.IOException;
import java.lang.reflect.UndeclaredThrowableException;
import java.security.SecureRandom;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.http.HttpResponseException;
import org.jclouds.io.Payloads;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen;
import org.jclouds.slicehost.domain.Flavor;
import org.jclouds.slicehost.domain.Image;
import org.jclouds.slicehost.domain.Slice;
import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshException;
import org.jclouds.util.Predicates2;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.google.common.net.HostAndPort;
import com.google.inject.Injector;
/**
* Tests behavior of {@code SlicehostClient}
*
* @author Adrian Cole
*/
@Test(groups = "live", singleThreaded = true, testName = "SlicehostClientLiveTest")
public class SlicehostClientLiveTest extends BaseComputeServiceContextLiveTest {
public SlicehostClientLiveTest() {
provider = "slicehost";
}
protected SlicehostClient client;
protected SshClient.Factory sshFactory;
private Predicate<HostAndPort> socketTester;
@BeforeGroups(groups = { "integration", "live" })
@Override
public void setupContext() {
super.setupContext();
Injector injector = view.utils().injector();
client = injector.getInstance(SlicehostClient.class);
sshFactory = injector.getInstance(SshClient.Factory.class);
SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
socketTester = new RetryablePredicate<HostAndPort>(socketOpen, 120, 1, TimeUnit.SECONDS);
injector.injectMembers(socketOpen); // add logger
}
public void testListSlices() throws Exception {
Set<Slice> response = client.listSlices();
assert null != response;
long initialContainerCount = response.size();
assertTrue(initialContainerCount >= 0);
}
public void testListSlicesDetail() throws Exception {
Set<Slice> response = client.listSlices();
assert null != response;
long initialContainerCount = response.size();
assertTrue(initialContainerCount >= 0);
}
public void testListImages() throws Exception {
Set<Image> response = client.listImages();
assert null != response;
long imageCount = response.size();
assertTrue(imageCount >= 1);
for (Image image : response) {
assertTrue(image.getId() >= 0);
assert null != image.getName() : image;
}
}
public void testListImagesDetail() throws Exception {
Set<Image> response = client.listImages();
assert null != response;
long imageCount = response.size();
assertTrue(imageCount >= 0);
for (Image image : response) {
assertTrue(image.getId() >= 1);
assert null != image.getName() : image;
}
}
public void testGetImagesDetail() throws Exception {
Set<Image> response = client.listImages();
assert null != response;
long imageCount = response.size();
assertTrue(imageCount >= 0);
for (Image image : response) {
try {
Image newDetails = client.getImage(image.getId());
assertEquals(image, newDetails);
} catch (HttpResponseException e) {// Ticket #9867
if (e.getResponse().getStatusCode() != 400)
throw e;
}
}
}
@Test
public void testGetImageDetailsNotFound() throws Exception {
assert client.getImage(12312987) == null;
}
@Test
public void testGetSliceDetailsNotFound() throws Exception {
assert client.getSlice(12312987) == null;
}
public void testGetSlicesDetail() throws Exception {
Set<Slice> response = client.listSlices();
assert null != response;
long sliceCount = response.size();
assertTrue(sliceCount >= 0);
for (Slice slice : response) {
Slice newDetails = client.getSlice(slice.getId());
assertEquals(slice, newDetails);
}
}
public void testListFlavors() throws Exception {
Set<Flavor> response = client.listFlavors();
assert null != response;
long flavorCount = response.size();
assertTrue(flavorCount >= 1);
for (Flavor flavor : response) {
assertTrue(flavor.getId() >= 0);
assert null != flavor.getName() : flavor;
}
}
public void testListFlavorsDetail() throws Exception {
Set<Flavor> response = client.listFlavors();
assert null != response;
long flavorCount = response.size();
assertTrue(flavorCount >= 0);
for (Flavor flavor : response) {
assertTrue(flavor.getId() >= 1);
assert null != flavor.getName() : flavor;
assert -1 != flavor.getRam() : flavor;
}
}
public void testGetFlavorsDetail() throws Exception {
Set<Flavor> response = client.listFlavors();
assert null != response;
long flavorCount = response.size();
assertTrue(flavorCount >= 0);
for (Flavor flavor : response) {
Flavor newDetails = client.getFlavor(flavor.getId());
assertEquals(flavor, newDetails);
}
}
@Test
public void testGetFlavorDetailsNotFound() throws Exception {
assert client.getFlavor(12312987) == null;
}
private String slicePrefix = System.getProperty("user.name") + ".sh";
private int sliceId;
private String rootPassword;
@Test(enabled = true)
public void testCreateSlice() throws Exception {
int imageId = 14362;
int flavorId = 1;
Slice slice = null;
while (slice == null) {
String sliceName = slicePrefix + "createslice" + new SecureRandom().nextInt();
try {
slice = client.createSlice(sliceName, imageId, flavorId);
} catch (UndeclaredThrowableException e) {
HttpResponseException htpe = (HttpResponseException) e.getCause().getCause();
if (htpe.getResponse().getStatusCode() == 400)
continue;
throw e;
}
}
assertNotNull(slice.getRootPassword());
sliceId = slice.getId();
rootPassword = slice.getRootPassword();
assertEquals(slice.getStatus(), Slice.Status.BUILD);
blockUntilSliceActive(sliceId);
}
private void blockUntilSliceActive(int sliceId) throws InterruptedException {
Slice currentDetails = null;
for (currentDetails = client.getSlice(sliceId); currentDetails.getStatus() != Slice.Status.ACTIVE; currentDetails = client
.getSlice(sliceId)) {
System.out.printf("blocking on status active%n%s%n", currentDetails);
Thread.sleep(5 * 1000);
}
}
@Test(enabled = true, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateSlice")
public void testSliceDetails() throws Exception {
Slice slice = client.getSlice(sliceId);
assertEquals(slice.getStatus(), Slice.Status.ACTIVE);
assert slice.getProgress() >= 0 : "newDetails.getProgress()" + slice.getProgress();
assertEquals(Integer.valueOf(14362), slice.getImageId());
assertEquals(1, slice.getFlavorId());
assertNotNull(slice.getAddresses());
checkPassOk(slice, rootPassword);
}
private void checkPassOk(Slice newDetails, String pass) throws IOException {
try {
doCreateMarkerFile(newDetails, pass);
} catch (SshException e) {// try twice in case there is a network timeout
try {
Thread.sleep(10 * 1000);
} catch (InterruptedException e1) {
}
doCreateMarkerFile(newDetails, pass);
}
}
private void doCreateMarkerFile(Slice newDetails, String pass) throws IOException {
String ip = getIp(newDetails);
HostAndPort socket = HostAndPort.fromParts(ip, 22);
socketTester.apply(socket);
SshClient client = sshFactory.create(socket, LoginCredentials.builder().user("root").password(pass).build());
try {
client.connect();
client.put("/etc/jclouds.txt", Payloads.newStringPayload("slicehost"));
} finally {
if (client != null)
client.disconnect();
}
}
private String getIp(Slice newDetails) {
return Iterables.find(newDetails.getAddresses(), Predicates.not(Predicates2.startsWith("10.")));
}
@Test(enabled = true, timeOut = 10 * 60 * 1000, dependsOnMethods = "testSliceDetails")
public void testRebootHard() throws Exception {
client.hardRebootSlice(sliceId);
blockUntilSliceActive(sliceId);
}
@Test(enabled = true, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootHard")
public void testRebootSoft() throws Exception {
client.rebootSlice(sliceId);
blockUntilSliceActive(sliceId);
}
@Test(enabled = true, timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft")
void destroySlice1() {
if (sliceId > 0) {
client.destroySlice(sliceId);
assert client.getSlice(sliceId) == null;
}
}
@AfterTest
void destroySlicesOnEnd() {
if (sliceId > 0) {
client.destroySlice(sliceId);
}
}
}

View File

@ -1,34 +0,0 @@
/**
* 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.slicehost;
import org.jclouds.providers.internal.BaseProviderMetadataTest;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "SlicehostProviderTest")
public class SlicehostProviderTest extends BaseProviderMetadataTest {
public SlicehostProviderTest() {
super(new SlicehostProviderMetadata(), new SlicehostApiMetadata());
}
}

View File

@ -1,74 +0,0 @@
/**
* 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.slicehost.compute;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.internal.BaseComputeServiceLiveTest;
import org.jclouds.sshj.config.SshjSshClientModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
/**
*
* Generally disabled, as it incurs higher fees.
*
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, singleThreaded = true)
public class SlicehostComputeServiceLiveTest extends BaseComputeServiceLiveTest {
public SlicehostComputeServiceLiveTest() {
provider = "slicehost";
}
@Override
protected SshjSshClientModule getSshModule() {
return new SshjSshClientModule();
}
// slicehost does not support metadata
@Override
protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap<String, String> userMetadata) {
assert node.getUserMetadata().equals(ImmutableMap.<String, String> of()) : String.format(
"node userMetadata did not match %s %s", userMetadata, node);
}
@Test(expectedExceptions = UnsupportedOperationException.class)
public void testSuspendResume() throws Exception {
super.testSuspendResume();
}
@Test(enabled = true, dependsOnMethods = "testSuspendResume")
@Override
public void testGetNodesWithDetails() throws Exception {
super.testGetNodesWithDetails();
}
@Test(enabled = true, dependsOnMethods = "testSuspendResume")
@Override
public void testListNodes() throws Exception {
super.testListNodes();
}
@Test(enabled = true, dependsOnMethods = { "testListNodes", "testGetNodesWithDetails" })
@Override
public void testDestroyNodes() {
super.testDestroyNodes();
}
}

View File

@ -1,92 +0,0 @@
/**
* 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.slicehost.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.Set;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.OsFamilyVersion64Bit;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live")
public class SlicehostTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
public SlicehostTemplateBuilderLiveTest() {
provider = "slicehost";
}
@Override
protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
return Predicates.not(new Predicate<OsFamilyVersion64Bit>() {
@Override
public boolean apply(OsFamilyVersion64Bit input) {
switch (input.family) {
case UBUNTU:
return (input.version.equals("") || input.version.equals("10.04") || input.version.startsWith("11"))
&& input.is64Bit;
case DEBIAN:
return input.is64Bit;
case CENTOS:
return (input.version.equals("") || input.version.matches("5.[0456]") || input.version.equals("6.0"))
&& input.is64Bit;
case WINDOWS:
return input.version.equals("2008 SP2") || input.version.equals("")
|| ((input.version.equals("2003") || input.version.equals("2008 R2")) && input.is64Bit);
default:
return false;
}
}
});
}
@Override
public void testFromTemplate() {
// TODO: multiple servers match
}
@Test
public void testDefaultTemplateBuilder() throws IOException {
Template defaultTemplate = view.getComputeService().templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "11.10");
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(getCores(defaultTemplate.getHardware()), 0.25d);
}
@Override
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of("US-IL", "US-TX", "US-MO");
}
}

View File

@ -1,37 +0,0 @@
/**
* 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.slicehost.compute.config;
import org.jclouds.slicehost.domain.Slice;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = "unit")
public class SlicehostComputeServiceContextModuleTest {
public void testAllStatusCovered() {
for (Slice.Status state : Slice.Status.values()) {
assert SlicehostComputeServiceContextModule.sliceStatusToNodeStatus.containsKey(state) : state;
}
}
}

View File

@ -1,67 +0,0 @@
/**
* 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.slicehost.compute.functions;
import static org.testng.Assert.assertEquals;
import java.net.UnknownHostException;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.VolumeBuilder;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.slicehost.domain.Flavor;
import org.jclouds.slicehost.xml.FlavorHandlerTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
/**
* @author Adrian Cole
*/
@Test(groups = "unit")
public class FlavorToHardwareTest {
Location provider = new LocationBuilder().scope(LocationScope.ZONE).id("dallas").description("description").build();
@Test
public void test() throws UnknownHostException {
assertEquals(
convertFlavor(),
new HardwareBuilder()
.ids("1")
.name("256 slice")
.processors(ImmutableList.of(new Processor(0.25, 1.0)))
.ram(256)
.volumes(
ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(1.0f).durable(true)
.bootDevice(true).build())).build());
}
public static Hardware convertFlavor() {
Flavor flavor = FlavorHandlerTest.parseFlavor();
FlavorToHardware parser = new FlavorToHardware();
return parser.apply(flavor);
}
}

View File

@ -1,125 +0,0 @@
/**
* 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.slicehost.compute.functions;
import static org.testng.Assert.assertEquals;
import java.util.Map;
import java.util.Set;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.VolumeBuilder;
import org.jclouds.compute.domain.NodeMetadata.Status;
import org.jclouds.compute.functions.GroupNamingConvention;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.slicehost.compute.config.SlicehostComputeServiceContextModule;
import org.jclouds.slicehost.domain.Slice;
import org.jclouds.slicehost.xml.SliceHandlerTest;
import org.testng.annotations.Test;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "SliceToNodeMetadataTest")
public class SliceToNodeMetadataTest {
Location provider = new LocationBuilder().scope(LocationScope.ZONE).id("dallas").description("description").build();
GroupNamingConvention.Factory namingConvention = Guice.createInjector().getInstance(GroupNamingConvention.Factory.class);
@Test
public void testApplyWhereImageAndHardwareNotFound() {
Map<Slice.Status, Status> sliceStateToNodeStatus = SlicehostComputeServiceContextModule.sliceStatusToNodeStatus;
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of();
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
Slice slice = SliceHandlerTest.parseSlice();
SliceToNodeMetadata parser = new SliceToNodeMetadata(sliceStateToNodeStatus, Suppliers
.<Set<? extends Image>> ofInstance(images), Suppliers.ofInstance(provider), Suppliers
.<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
NodeMetadata metadata = parser.apply(slice);
assertEquals(metadata, new NodeMetadataBuilder().status(Status.PENDING).publicAddresses(
ImmutableSet.of("174.143.212.229")).privateAddresses(ImmutableSet.of("10.176.164.199")).group("jclouds")
.imageId("2").id("1").providerId("1").name("jclouds-foo").hostname("jclouds-foo").location(provider)
.userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
}
@Test
public void testApplyWhereImageFoundAndHardwareNotFound() {
Map<Slice.Status, Status> sliceStateToNodeStatus = SlicehostComputeServiceContextModule.sliceStatusToNodeStatus;
org.jclouds.compute.domain.Image jcImage = SlicehostImageToImageTest.convertImage();
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(jcImage);
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
Slice slice = SliceHandlerTest.parseSlice();
SliceToNodeMetadata parser = new SliceToNodeMetadata(sliceStateToNodeStatus, Suppliers
.<Set<? extends Image>> ofInstance(images), Suppliers.ofInstance(provider), Suppliers
.<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
NodeMetadata metadata = parser.apply(slice);
assertEquals(metadata, new NodeMetadataBuilder().status(Status.PENDING).publicAddresses(
ImmutableSet.of("174.143.212.229")).privateAddresses(ImmutableSet.of("10.176.164.199")).group("jclouds")
.imageId("2").operatingSystem(
new OperatingSystem.Builder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2")
.is64Bit(true).build()).id("1").providerId("1").name("jclouds-foo").hostname(
"jclouds-foo").location(provider).userMetadata(
ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
}
@Test
public void testApplyWhereImageAndHardwareFound() {
Map<Slice.Status, Status> sliceStateToNodeStatus = SlicehostComputeServiceContextModule.sliceStatusToNodeStatus;
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(SlicehostImageToImageTest.convertImage());
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of(FlavorToHardwareTest.convertFlavor());
Slice slice = SliceHandlerTest.parseSlice();
SliceToNodeMetadata parser = new SliceToNodeMetadata(sliceStateToNodeStatus, Suppliers
.<Set<? extends Image>> ofInstance(images), Suppliers.ofInstance(provider), Suppliers
.<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
NodeMetadata metadata = parser.apply(slice);
assertEquals(metadata, new NodeMetadataBuilder().status(Status.PENDING).publicAddresses(
ImmutableSet.of("174.143.212.229")).privateAddresses(ImmutableSet.of("10.176.164.199")).group("jclouds")
.imageId("2").hardware(
new HardwareBuilder().ids("1").name("256 slice").processors(
ImmutableList.of(new Processor(0.25, 1.0))).ram(256).volumes(
ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(1.0f).durable(true)
.bootDevice(true).build())).build()).operatingSystem(
new OperatingSystem.Builder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2")
.is64Bit(true).build()).id("1").providerId("1").name("jclouds-foo").hostname(
"jclouds-foo").location(provider).userMetadata(
ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
}
}

View File

@ -1,92 +0,0 @@
/**
* 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.slicehost.compute.functions;
import static org.testng.Assert.assertEquals;
import java.net.UnknownHostException;
import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule;
import org.jclouds.slicehost.xml.ImageHandlerTest;
import org.testng.annotations.Test;
import com.google.inject.Guice;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "SlicehostImageToImageTest")
public class SlicehostImageToImageTest {
Location provider = new LocationBuilder().scope(LocationScope.ZONE).id("dallas").description("description").build();
@Test
public void test() throws UnknownHostException {
Image toTest = convertImage();
assertEquals(
toTest,
new ImageBuilder()
.name("CentOS 5.2")
.operatingSystem(
new OperatingSystem.Builder().family(OsFamily.CENTOS).version("5.2").description("CentOS 5.2")
.is64Bit(true).build()).description("CentOS 5.2").ids("2")
.status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build());
assertEquals(toTest.getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
}
@Test
public void test32() throws UnknownHostException {
Image toTest = convertImage("/test_get_image32.xml");
assertEquals(
toTest,
new ImageBuilder()
.name("Ubuntu 10.10 (maverick) 32-bit")
.operatingSystem(
new OperatingSystem.Builder().family(OsFamily.UBUNTU).version("10.10")
.description("Ubuntu 10.10 (maverick) 32-bit").build())
.description("Ubuntu 10.10 (maverick) 32-bit").ids("70")
.status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build());
assertEquals(toTest.getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
}
public static Image convertImage() {
return convertImage("/test_get_image.xml");
}
public static Image convertImage(String resource) {
org.jclouds.slicehost.domain.Image image = ImageHandlerTest.parseImage(resource);
SlicehostImageToImage parser = new SlicehostImageToImage(new SlicehostImageToOperatingSystem(
new BaseComputeServiceContextModule() {
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
.getInstance(Json.class))));
return parser.apply(image);
}
}

View File

@ -1,59 +0,0 @@
/**
* 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.slicehost.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.slicehost.domain.Flavor;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code FlavorHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class FlavorHandlerTest {
static ParseSax<Flavor> createParser() {
Injector injector = Guice.createInjector(new SaxParserModule());
ParseSax<Flavor> parser = (ParseSax<Flavor>) injector.getInstance(ParseSax.Factory.class).create(
injector.getInstance(FlavorHandler.class));
return parser;
}
public static Flavor parseFlavor() {
InputStream is = FlavorHandlerTest.class.getResourceAsStream("/test_get_flavor.xml");
return createParser().parse(is);
}
public void test() {
Flavor expects = new Flavor(1, "256 slice", 2000, 256);
assertEquals(parseFlavor(), expects);
}
}

View File

@ -1,55 +0,0 @@
/**
* 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.slicehost.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.util.Set;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.slicehost.domain.Flavor;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* Tests behavior of {@code FlavorsHandler}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "FlavorsHandlerTest")
public class FlavorsHandlerTest extends BaseHandlerTest {
ParseSax<Set<? extends Flavor>> createParser() {
ParseSax<Set<? extends Flavor>> parser = (ParseSax<Set<? extends Flavor>>) factory.create(injector
.getInstance(FlavorsHandler.class));
return parser;
}
public void test() {
InputStream is = getClass().getResourceAsStream("/test_list_flavors.xml");
Set<? extends Flavor> expects = ImmutableSet.of(new Flavor(1, "256 slice", 2000, 256), new Flavor(2, "512 slice",
3800, 512), new Flavor(3, "1GB slice", 7000, 1024), new Flavor(4, "2GB slice", 13000, 2048));
assertEquals(createParser().parse(is), expects);
}
}

View File

@ -1,67 +0,0 @@
/**
* 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.slicehost.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.slicehost.domain.Image;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ImageHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ImageHandlerTest {
static ParseSax<Image> createParser() {
Injector injector = Guice.createInjector(new SaxParserModule());
ParseSax<Image> parser = (ParseSax<Image>) injector.getInstance(ParseSax.Factory.class).create(
injector.getInstance(ImageHandler.class));
return parser;
}
public static Image parseImage() {
return parseImage("/test_get_image.xml");
}
public static Image parseImage(String resource) {
InputStream is = ImageHandlerTest.class.getResourceAsStream(resource);
return createParser().parse(is);
}
public void test() {
Image expects = new Image(2, "CentOS 5.2");
assertEquals(parseImage(), expects);
}
public void test32() {
Image expects = new Image(70, "Ubuntu 10.10 (maverick) 32-bit");
assertEquals(parseImage("/test_get_image32.xml"), expects);
}
}

View File

@ -1,77 +0,0 @@
/**
* 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.slicehost.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.util.Set;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.slicehost.domain.Image;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* Tests behavior of {@code ImagesHandler}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "ImagesHandlerTest")
public class ImagesHandlerTest extends BaseHandlerTest {
ParseSax<Set<? extends Image>> createParser() {
ParseSax<Set<? extends Image>> parser = (ParseSax<Set<? extends Image>>) factory.create(injector
.getInstance(ImagesHandler.class));
return parser;
}
public void test() {
InputStream is = getClass().getResourceAsStream("/test_list_images.xml");
Set<? extends Image> expects = ImmutableSet.of(
new Image(2, "CentOS 5.2"), new Image(3, "Gentoo 2008.0"),
new Image(4, "Debian 5.0 (lenny)"),
new Image(5, "Fedora 10 (Cambridge)"),
new Image(7, "CentOS 5.3"),
new Image(8, "Ubuntu 9.04 (jaunty)"),
new Image(9, "Arch 2009.02"),
new Image(10, "Ubuntu 8.04.2 LTS (hardy)"),
new Image(11, "Ubuntu 8.10 (intrepid)"),
new Image(70, "Ubuntu 10.10 (maverick) 32-bit"),
new Image(12, "Red Hat EL 5.3"),
new Image(13, "Fedora 11 (Leonidas)")
);
assertEquals(createParser().parse(is), expects);
}
}

View File

@ -1,75 +0,0 @@
/**
* 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.slicehost.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.slicehost.domain.Slice;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code SliceHandler}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "SliceHandlerTest")
public class SliceHandlerTest extends BaseHandlerTest {
static ParseSax<Slice> createParser() {
Injector injector = Guice.createInjector(new SaxParserModule());
ParseSax<Slice> parser = (ParseSax<Slice>) injector.getInstance(ParseSax.Factory.class).create(
injector.getInstance(SliceHandler.class));
return parser;
}
public static Slice parseSlice() {
return parseSlice("/test_get_slice.xml");
}
public static Slice parseSlice(String resource) {
InputStream is = SliceHandlerTest.class.getResourceAsStream(resource);
return createParser().parse(is);
}
public void test() {
Slice expects = new Slice(1, "jclouds-foo", 1, 2, null, Slice.Status.BUILD, 0, 0, 0, ImmutableSet.<String> of(
"174.143.212.229", "10.176.164.199"), null);
assertEquals(parseSlice("/test_get_slice.xml"), expects);
}
public void testNew() {
Slice expects = new Slice(71907, "slicetest", 1, 11, null, Slice.Status.BUILD, 0, 0, 0, ImmutableSet.<String> of(
"10.176.168.15", "67.23.20.114"), "fooadfa1231");
assertEquals(parseSlice("/test_new_slice.xml"), expects);
}
}

View File

@ -1,56 +0,0 @@
/**
* 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.slicehost.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.util.Set;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.slicehost.domain.Slice;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* Tests behavior of {@code SlicesHandler}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "SlicesHandlerTest")
public class SlicesHandlerTest extends BaseHandlerTest {
ParseSax<Set<? extends Slice>> createParser() {
ParseSax<Set<? extends Slice>> parser = (ParseSax<Set<? extends Slice>>) factory.create(injector
.getInstance(SlicesHandler.class));
return parser;
}
public void test() {
InputStream is = getClass().getResourceAsStream("/test_get_slice.xml");
Set<? extends Slice> expects = ImmutableSet.of(new Slice(1, "jclouds-foo", 1, 2, null, Slice.Status.BUILD, 0, 0,
0, ImmutableSet.<String> of("174.143.212.229", "10.176.164.199"), null));
assertEquals(createParser().parse(is), expects);
}
}

View File

@ -1,117 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--
For more configuration infromation and examples see the Apache
Log4j website: http://logging.apache.org/log4j/
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
<!-- A time/date based rolling appender -->
<appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-wire.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="COMPUTEFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-compute.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<appender name="ASYNCCOMPUTE" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="COMPUTEFILE" />
</appender>
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
<appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="WIREFILE" />
</appender>
<!-- ================ -->
<!-- Limit categories -->
<!-- ================ -->
<category name="org.jclouds">
<priority value="DEBUG" />
<appender-ref ref="ASYNC" />
</category>
<category name="jclouds.headers">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<category name="jclouds.wire">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<category name="jclouds.compute">
<priority value="TRACE" />
<appender-ref ref="ASYNCCOMPUTE" />
</category>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root>
<priority value="WARN" />
</root>
</log4j:configuration>

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<errors>
<error>Slice parameters are not properly nested</error>
</errors>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<flavor>
<id type="integer">1</id>
<name>256 slice</name>
<price type="integer">2000</price>
<ram type="integer">256</ram>
</flavor>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<images type="array">
<image>
<name>CentOS 5.2</name>
<id type="integer">2</id>
</image>
</images>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<images type="array">
<image>
<name>Ubuntu 10.10 (maverick) 32-bit</name>
<id type="integer">70</id>
</image>
</images>

View File

@ -1,17 +0,0 @@
<slices type="array">
<slice>
<name>jclouds-foo</name>
<image-id type="integer">2</image-id>
<addresses type="array">
<address>174.143.212.229</address>
<address>10.176.164.199</address>
</addresses>
<progress type="integer">0</progress>
<id type="integer">1</id>
<bw-out type="float">0.0</bw-out>
<bw-in type="float">0.0</bw-in>
<flavor-id type="integer">1</flavor-id>
<status>build</status>
<ip-address>174.143.212.229</ip-address>
</slice>
</slices>

View File

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<flavors type="array">
<flavor>
<id type="integer">1</id>
<name>256 slice</name>
<price type="integer">2000</price>
<ram type="integer">256</ram>
</flavor>
<flavor>
<id type="integer">2</id>
<name>512 slice</name>
<price type="integer">3800</price>
<ram type="integer">512</ram>
</flavor>
<flavor>
<id type="integer">3</id>
<name>1GB slice</name>
<price type="integer">7000</price>
<ram type="integer">1024</ram>
</flavor>
<flavor>
<id type="integer">4</id>
<name>2GB slice</name>
<price type="integer">13000</price>
<ram type="integer">2048</ram>
</flavor>
</flavors>

View File

@ -1,51 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<images type="array">
<image>
<name>CentOS 5.2</name>
<id type="integer">2</id>
</image>
<image>
<name>Gentoo 2008.0</name>
<id type="integer">3</id>
</image>
<image>
<name>Debian 5.0 (lenny)</name>
<id type="integer">4</id>
</image>
<image>
<name>Fedora 10 (Cambridge)</name>
<id type="integer">5</id>
</image>
<image>
<name>CentOS 5.3</name>
<id type="integer">7</id>
</image>
<image>
<name>Ubuntu 9.04 (jaunty)</name>
<id type="integer">8</id>
</image>
<image>
<name>Arch 2009.02</name>
<id type="integer">9</id>
</image>
<image>
<name>Ubuntu 8.04.2 LTS (hardy)</name>
<id type="integer">10</id>
</image>
<image>
<name>Ubuntu 8.10 (intrepid)</name>
<id type="integer">11</id>
</image>
<image>
<name>Ubuntu 10.10 (maverick) 32-bit</name>
<id type="integer">70</id>
</image>
<image>
<name>Red Hat EL 5.3</name>
<id type="integer">12</id>
</image>
<image>
<name>Fedora 11 (Leonidas)</name>
<id type="integer">13</id>
</image>
</images>

View File

@ -1,48 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<slices type="array">
<slice>
<name>slicehost-1</name>
<image-id type="integer">50</image-id>
<addresses type="array">
<address>10.179.78.86</address>
<address>173.203.51.27</address>
</addresses>
<progress type="integer">100</progress>
<id type="integer">281343</id>
<bw-out type="float">0.0</bw-out>
<bw-in type="float">0.07</bw-in>
<flavor-id type="integer">1</flavor-id>
<status>active</status>
<ip-address>10.179.78.86</ip-address>
</slice>
<slice>
<name>slicehost-602</name>
<image-id type="integer">50</image-id>
<addresses type="array">
<address>10.179.78.89</address>
<address>173.203.51.32</address>
</addresses>
<progress type="integer">100</progress>
<id type="integer">281347</id>
<bw-out type="float">0.0</bw-out>
<bw-in type="float">0.07</bw-in>
<flavor-id type="integer">1</flavor-id>
<status>active</status>
<ip-address>10.179.78.89</ip-address>
</slice>
<slice>
<name>slicehostblock-a7</name>
<image-id type="integer">50</image-id>
<addresses type="array">
<address>10.179.78.91</address>
<address>173.203.51.33</address>
</addresses>
<progress type="integer">100</progress>
<id type="integer">281357</id>
<bw-out type="float">0.0</bw-out>
<bw-in type="float">0.0</bw-in>
<flavor-id type="integer">1</flavor-id>
<status>build</status>
<ip-address>10.179.78.91</ip-address>
</slice>
</slices>

View File

@ -1,16 +0,0 @@
<slice>
<name>slicetest</name>
<image-id type="integer">11</image-id>
<addresses type="array">
<address>10.176.168.15</address>
<address>67.23.20.114</address>
</addresses>
<root-password>fooadfa1231</root-password>
<progress type="integer">0</progress>
<id type="integer">71907</id>
<bw-out type="float">0.0</bw-out>
<bw-in type="float">0.0</bw-in>
<flavor-id type="integer">1</flavor-id>
<status>build</status>
<ip-address>10.176.168.15</ip-address>
</slice>