Deleted nova project. Use openstack-nova instead.

This commit is contained in:
Everett Toews 2012-12-29 12:05:56 -06:00
parent d4953191d5
commit 5a3c2449a1
85 changed files with 0 additions and 9093 deletions

View File

@ -65,11 +65,6 @@
<artifactId>openstack-nova-ec2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>nova</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>byon</artifactId>

View File

@ -1,137 +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.api</groupId>
<artifactId>nova</artifactId>
<name>jcloud nova api</name>
<description>jclouds components to access an implementation of OpenStack Nova</description>
<packaging>bundle</packaging>
<properties>
<test.nova.endpoint>http://localhost:8773/services/Cloud</test.nova.endpoint>
<test.nova.api-version>1.1</test.nova.api-version>
<test.nova.build-version></test.nova.build-version>
<test.nova.identity>FIXME_IDENTITY</test.nova.identity>
<test.nova.credential>FIXME_CREDENTIALS</test.nova.credential>
<test.nova.template></test.nova.template>
<test.ssh.keyfile.public></test.ssh.keyfile.public>
<test.ssh.keyfile.private></test.ssh.keyfile.private>
<jclouds.osgi.export>org.jclouds.openstack.nova*;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.common</groupId>
<artifactId>openstack-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
</dependency>
<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.common</groupId>
<artifactId>openstack-common</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>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-sshj</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-log4j</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>
<systemPropertyVariables>
<test.nova.endpoint>${test.nova.endpoint}</test.nova.endpoint>
<test.nova.api-version>${test.nova.api-version}</test.nova.api-version>
<test.nova.build-version>${test.nova.build-version}</test.nova.build-version>
<test.nova.identity>${test.nova.identity}</test.nova.identity>
<test.nova.credential>${test.nova.credential}</test.nova.credential>
<test.nova.template>${test.nova.template}</test.nova.template>
<test.ssh.keyfile.public>${test.ssh.keyfile.public}</test.ssh.keyfile.public>
<test.ssh.keyfile.private>${test.ssh.keyfile.private}</test.ssh.keyfile.private>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -1,101 +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.openstack.nova;
import java.net.URI;
import java.util.Properties;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.openstack.nova.compute.config.NovaComputeServiceContextModule;
import org.jclouds.openstack.nova.config.NovaRestClientModule;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.BaseRestApiMetadata;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
import com.google.inject.Module;
/**
* Implementation of {@link ApiMetadata} for Nova 1.0 API
*
* @author Adrian Cole
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.NovaApiMetadata} in openstack-nova.
*/
@Deprecated
public class NovaApiMetadata extends BaseRestApiMetadata {
@Deprecated
public static final TypeToken<RestContext<NovaClient, NovaAsyncClient>> CONTEXT_TOKEN = new TypeToken<RestContext<NovaClient, NovaAsyncClient>>() {
};
@Override
@Deprecated
public Builder toBuilder() {
return new Builder().fromApiMetadata(this);
}
@Deprecated
public NovaApiMetadata() {
this(new Builder());
}
@Deprecated
protected NovaApiMetadata(Builder builder) {
super(builder);
}
@Deprecated
public static Properties defaultProperties() {
Properties properties = BaseRestApiMetadata.defaultProperties();
return properties;
}
@Deprecated
public static class Builder extends BaseRestApiMetadata.Builder {
protected Builder() {
super(NovaClient.class, NovaAsyncClient.class);
id("nova")
.name("OpenStack Nova Pre-Diablo API")
.identityName("accessKey")
.credentialName("secretKey")
.documentation(URI.create("http://api.openstack.org/"))
.version("1.1")
.defaultEndpoint("http://localhost:5000")
.defaultProperties(NovaApiMetadata.defaultProperties())
.view(TypeToken.of(ComputeServiceContext.class))
.defaultModules(ImmutableSet.<Class<? extends Module>>of(NovaRestClientModule.class, NovaComputeServiceContextModule.class));
}
@Override
public NovaApiMetadata build() {
return new NovaApiMetadata(this);
}
@Override
public Builder fromApiMetadata(ApiMetadata in) {
super.fromApiMetadata(in);
return this;
}
}
}

View File

@ -1,479 +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.openstack.nova;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import javax.ws.rs.Consumes;
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.Produces;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
import org.jclouds.Fallbacks.FalseOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.openstack.filters.AddTimestampQuery;
import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.openstack.nova.domain.Addresses;
import org.jclouds.openstack.nova.domain.Flavor;
import org.jclouds.openstack.nova.domain.FloatingIP;
import org.jclouds.openstack.nova.domain.Image;
import org.jclouds.openstack.nova.domain.RebootType;
import org.jclouds.openstack.nova.domain.SecurityGroup;
import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.options.CreateServerOptions;
import org.jclouds.openstack.nova.options.ListOptions;
import org.jclouds.openstack.nova.options.RebuildServerOptions;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.Payload;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.Unwrap;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides asynchronous access to OpenStack Nova via their REST API.
* <p/>
* All commands return a ListenableFuture of the result from OpenStack Nova. Any exceptions incurred
* during processing will be backend in an {@link ExecutionException} as documented in
* {@link ListenableFuture#get()}.
*
* @author Adrian Cole
* @see NovaClient
* @see <a href="http://wiki.openstack.org/OpenStackAPI_1-1" />
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See NovaAsyncApi.
*/
@RequestFilters({AuthenticateRequest.class, AddTimestampQuery.class})
@Endpoint(ServerManagement.class)
@Deprecated
public interface NovaAsyncClient {
/**
* @see NovaClient#listServers
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerAsyncApi#list()} in openstack-nova.
*/
@GET
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Path("/servers")
@Fallback(EmptySetOnNotFoundOr404.class)
@Deprecated
ListenableFuture<? extends Set<Server>> listServers(ListOptions... options);
/**
* @see NovaClient#getServer
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerAsyncApi#get(String)} in openstack-nova.
*/
@GET
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Fallback(NullOnNotFoundOr404.class)
@Path("/servers/{id}")
@Deprecated
ListenableFuture<Server> getServer(@PathParam("id") int id);
/**
* @see NovaClient#getServer
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerAsyncApi#get(String)} in openstack-nova.
*/
@GET
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Fallback(NullOnNotFoundOr404.class)
@Path("/servers/{uuid}")
@Deprecated
ListenableFuture<Server> getServer(@PathParam("uuid") String uuid);
/**
* @see NovaClient#deleteServer
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerAsyncApi#delete(String)} in openstack-nova.
*/
@DELETE
@Consumes
@Fallback(FalseOnNotFoundOr404.class)
@Path("/servers/{id}")
@Deprecated
ListenableFuture<Boolean> deleteServer(@PathParam("id") int id);
/**
* @see NovaClient#deleteServer
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerAsyncApi#delete(String)} in openstack-nova.
*/
@DELETE
@Consumes
@Fallback(FalseOnNotFoundOr404.class)
@Path("/servers/{uuid}")
@Deprecated
ListenableFuture<Boolean> deleteServer(@PathParam("uuid") String uuid);
/**
* @see NovaClient#rebootServer
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerAsyncApi#reboot(String, RebootType)} in openstack-nova.
*/
@POST
@QueryParams(keys = "format", values = "json")
@Path("/servers/{id}/action")
@Consumes
@Produces(MediaType.APPLICATION_JSON)
@Payload("%7B\"reboot\":%7B\"type\":\"{type}\"%7D%7D")
@Deprecated
ListenableFuture<Void> rebootServer(@PathParam("id") int id, @PayloadParam("type") RebootType rebootType);
/**
* @see NovaClient#resizeServer
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerAsyncApi#resize(String, String)} in openstack-nova.
*/
@POST
@QueryParams(keys = "format", values = "json")
@Path("/servers/{id}/action")
@Consumes
@Produces(MediaType.APPLICATION_JSON)
@Payload("%7B\"resize\":%7B\"flavorId\":{flavorId}%7D%7D")
@Deprecated
ListenableFuture<Void> resizeServer(@PathParam("id") int id, @PayloadParam("flavorId") int flavorId);
/**
* @see NovaClient#confirmResizeServer
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerAsyncApi#confirmResize(String)} in openstack-nova.
*/
@POST
@QueryParams(keys = "format", values = "json")
@Path("/servers/{id}/action")
@Consumes
@Produces(MediaType.APPLICATION_JSON)
@Payload("{\"confirmResize\":null}")
@Deprecated
ListenableFuture<Void> confirmResizeServer(@PathParam("id") int id);
/**
* @see NovaClient#revertResizeServer
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerAsyncApi#revertResize(String)} in openstack-nova.
*/
@POST
@QueryParams(keys = "format", values = "json")
@Path("/servers/{id}/action")
@Consumes
@Produces(MediaType.APPLICATION_JSON)
@Payload("{\"revertResize\":null}")
@Deprecated
ListenableFuture<Void> revertResizeServer(@PathParam("id") int id);
/**
* @see NovaClient#createServer
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerAsyncApi#create(String, String, String, CreateServerOptions)} in openstack-nova.
*/
@POST
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Path("/servers")
@MapBinder(CreateServerOptions.class)
@Deprecated
ListenableFuture<Server> createServer(@PayloadParam("name") String name, @PayloadParam("imageRef") String imageRef,
@PayloadParam("flavorRef") String flavorRef, CreateServerOptions... options);
/**
* @see NovaClient#rebuildServer
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerAsyncApi#rebuild(String, RebuildServerOptions)} in openstack-nova.
*/
@POST
@QueryParams(keys = "format", values = "json")
@Path("/servers/{id}/action")
@Consumes
@MapBinder(RebuildServerOptions.class)
@Deprecated
ListenableFuture<Void> rebuildServer(@PathParam("id") int id, RebuildServerOptions... options);
/**
* @see NovaClient#changeAdminPass
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerAsyncApi#changeAdminPass(String, String)} in openstack-nova.
*/
@POST
@Path("/servers/{id}/action")
@Consumes
@Produces(MediaType.APPLICATION_JSON)
@Payload("%7B\"changePassword\":%7B\"adminPass\":\"{adminPass}\"%7D%7D")
@Deprecated
ListenableFuture<Void> changeAdminPass(@PathParam("id") int id, @PayloadParam("adminPass") String adminPass);
/**
* @see NovaClient#renameServer
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerAsyncApi#rename(String, String)} in openstack-nova.
*/
@PUT
@Path("/servers/{id}")
@Consumes
@Produces(MediaType.APPLICATION_JSON)
@Payload("%7B\"server\":%7B\"name\":\"{name}\"%7D%7D")
@Deprecated
ListenableFuture<Void> renameServer(@PathParam("id") int id, @PayloadParam("name") String newName);
/**
* @see NovaClient#listFlavors
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.FlavorAsyncApi#list()} in openstack-nova.
*/
@GET
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Path("/flavors")
@Fallback(EmptySetOnNotFoundOr404.class)
@Deprecated
ListenableFuture<? extends Set<Flavor>> listFlavors(ListOptions... options);
/**
* @see NovaClient#getFlavor
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.FlavorAsyncApi#get(String)} in openstack-nova.
*/
@GET
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Path("/flavors/{id}")
@Fallback(NullOnNotFoundOr404.class)
@Deprecated
ListenableFuture<Flavor> getFlavor(@PathParam("id") int id);
/**
* @see NovaClient#getFlavor
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.FlavorAsyncApi#get(String)} in openstack-nova.
*/
@GET
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Path("/flavors/{uuid}")
@Fallback(NullOnNotFoundOr404.class)
@Deprecated
ListenableFuture<Flavor> getFlavor(@PathParam("uuid") String uuid);
/**
* @see NovaClient#listImages
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ImageAsyncApi#list()} in openstack-nova.
*/
@GET
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Path("/images")
@Fallback(EmptySetOnNotFoundOr404.class)
@Deprecated
ListenableFuture<? extends Set<Image>> listImages(ListOptions... options);
/**
* @see NovaClient#getImage
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ImageAsyncApi#get(String)} in openstack-nova.
*/
@GET
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(NullOnNotFoundOr404.class)
@QueryParams(keys = "format", values = "json")
@Path("/images/{id}")
@Deprecated
ListenableFuture<Image> getImage(@PathParam("id") int id);
/**
* @see NovaClient#getImage
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ImageAsyncApi#get(String)} in openstack-nova.
*/
@GET
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(NullOnNotFoundOr404.class)
@QueryParams(keys = "format", values = "json")
@Path("/images/{uuid}")
@Deprecated
ListenableFuture<Image> getImage(@PathParam("uuid") String uuid);
/**
* @see NovaClient#deleteImage
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ImageAsyncApi#delete(String)} in openstack-nova.
*/
@DELETE
@Fallback(FalseOnNotFoundOr404.class)
@Consumes
@Path("/images/{id}")
@Deprecated
ListenableFuture<Boolean> deleteImage(@PathParam("id") int id);
/**
* @see NovaClient#deleteImage
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ImageAsyncApi#delete(String)} in openstack-nova.
*/
@DELETE
@Fallback(FalseOnNotFoundOr404.class)
@Consumes
@Path("/images/{id}")
@Deprecated
ListenableFuture<Boolean> deleteImage(@PathParam("id") String id);
/**
* @see NovaClient#createImageFromServer
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerAsyncApi#createImageFromServer(String, String)} in openstack-nova.
*/
@POST
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Path("/images")
@Produces(MediaType.APPLICATION_JSON)
@Payload("%7B\"image\":%7B\"serverId\":{serverId},\"name\":\"{name}\"%7D%7D")
@Deprecated
ListenableFuture<Image> createImageFromServer(@PayloadParam("name") String imageName,
@PayloadParam("serverId") int serverId);
/**
* @see NovaClient#getAddresses
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerAsyncApi#get(String)} in openstack-nova.
*/
@GET
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Path("/servers/{id}/ips")
@Deprecated
ListenableFuture<Addresses> getAddresses(@PathParam("id") int serverId);
/**
* @see NovaClient#listPublicAddresses
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerAsyncApi#get(String)} in openstack-nova.
*/
@GET
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Path("/servers/{id}/ips/public")
@Fallback(EmptySetOnNotFoundOr404.class)
@Deprecated
ListenableFuture<? extends Set<String>> listPublicAddresses(@PathParam("id") int serverId);
/**
* @see NovaClient#listPrivateAddresses
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerAsyncApi#get(String)} in openstack-nova.
*/
@GET
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Path("/servers/{id}/ips/private")
@Fallback(EmptySetOnNotFoundOr404.class)
@Deprecated
ListenableFuture<? extends Set<String>> listPrivateAddresses(@PathParam("id") int serverId);
/**
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.extensions.FloatingIPAsyncApi#addToServer(String, String)} in openstack-nova.
*/
@POST
@Path("/servers/{id}/action")
@Consumes
@Produces(MediaType.APPLICATION_JSON)
@Payload("%7B\"addFloatingIp\":%7B\"address\":\"{address}\"%7D%7D")
@Deprecated
ListenableFuture<Void> addFloatingIP(@PathParam("id") int serverId, @PayloadParam("address") String ip);
/**
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.extensions.FloatingIPAsyncApi#list()} in openstack-nova.
*/
@GET
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Path("/os-floating-ips")
@Fallback(EmptySetOnNotFoundOr404.class)
@Deprecated
ListenableFuture<? extends Set<FloatingIP>> listFloatingIPs();
/**
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.extensions.FloatingIPAsyncApi#get(String)} in openstack-nova.
*/
@GET
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Path("/os-floating-ips/{id}")
@Fallback(NullOnNotFoundOr404.class)
@Deprecated
ListenableFuture<FloatingIP> getFloatingIP(@PathParam("id") int id);
/**
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.extensions.SecurityGroupAsyncApi#list()} in openstack-nova.
*/
@GET
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Path("/os-security-groups")
@Fallback(EmptySetOnNotFoundOr404.class)
@Deprecated
ListenableFuture<? extends Set<SecurityGroup>> listSecurityGroups();
/**
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.extensions.SecurityGroupAsyncApi#get(String)} in openstack-nova.
*/
@GET
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Path("/os-security-groups/{id}")
@Fallback(NullOnNotFoundOr404.class)
@Deprecated
ListenableFuture<SecurityGroup> getSecurityGroup(@PathParam("id") int id);
}

View File

@ -1,415 +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.openstack.nova;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.openstack.nova.domain.Addresses;
import org.jclouds.openstack.nova.domain.Flavor;
import org.jclouds.openstack.nova.domain.FloatingIP;
import org.jclouds.openstack.nova.domain.Image;
import org.jclouds.openstack.nova.domain.RebootType;
import org.jclouds.openstack.nova.domain.SecurityGroup;
import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.options.CreateServerOptions;
import org.jclouds.openstack.nova.options.ListOptions;
import org.jclouds.openstack.nova.options.RebuildServerOptions;
/**
* Provides access to OpenStack Nova via their REST API.
* <p/>
* All commands return a Future of the result from OpenStack Nova. Any exceptions incurred
* during processing will be backend in an {@link ExecutionException} as documented in
* {@link Future#get()}.
*
* @see NovaAsyncClient
* @see <a href="http://wiki.openstack.org/OpenStackAPI_1-1" />
* @author Adrian Cole
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerApi} in openstack-nova.
*/
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
@Deprecated
public interface NovaClient {
/**
*
* List all servers (IDs and names only)
*
* This operation provides a list of servers associated with your identity. Servers that have been
* deleted are not included in this list.
* <p/>
* in order to retrieve all details, pass the option {@link ListOptions#withDetails()
* withDetails()}
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerApi#list()} in openstack-nova.
*/
@Deprecated
Set<Server> listServers(ListOptions... options);
/**
*
* This operation returns details of the specified server.
*
* @return null, if the server is not found
* @see Server
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerApi#get(String)} in openstack-nova.
*/
@Deprecated
Server getServer(int id);
@Deprecated
Server getServer(String uuid);
/**
*
* This operation deletes a cloud server instance from the system.
* <p/>
* Note: When a server is deleted, all images created from that server are also removed.
*
* @return false if the server is not found
* @see Server
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerApi#delete(String)} in openstack-nova.
*/
@Deprecated
boolean deleteServer(int id);
@Deprecated
boolean deleteServer(String id);
/**
* The reboot function allows for either a soft or hard reboot of a server.
* <p/>
* Status Transition:
* <p/>
* ACTIVE - REBOOT - ACTIVE (soft reboot)
* <p/>
* ACTIVE - HARD_REBOOT - ACTIVE (hard reboot)
*
* @param rebootType
* With a soft reboot, the operating system is signaled to restart, which allows for a
* graceful shutdown of all processes. A hard reboot is the equivalent of power cycling
* the server.
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerApi#reboot(String, RebootType)} in openstack-nova.
*/
@Deprecated
void rebootServer(int id, RebootType rebootType);
/**
* The resize function converts an existing server to a different flavor, in essence, scaling the
* server up or down. The original server is saved for a period of time to allow rollback if
* there is a problem. All resizes should be tested and explicitly confirmed, at which time the
* original server is removed. All resizes are automatically confirmed after 24 hours if they are
* not confirmed or reverted.
* <p/>
* Status Transition:
* <p/>
* ACTIVE - QUEUE_RESIZE - PREP_RESIZE - VERIFY_RESIZE
* <p/>
* ACTIVE - QUEUE_RESIZE - ACTIVE (on error)
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerApi#resize(String, String)} in openstack-nova.
*/
@Deprecated
void resizeServer(int id, int flavorId);
/**
* The resize function converts an existing server to a different flavor, in essence, scaling the
* server up or down. The original server is saved for a period of time to allow rollback if
* there is a problem. All resizes should be tested and explicitly confirmed, at which time the
* original server is removed. All resizes are automatically confirmed after 24 hours if they are
* not confirmed or reverted.
* <p/>
* Status Transition:
* <p/>
* VERIFY_RESIZE - ACTIVE
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerApi#confirmResize(String)} in openstack-nova.
*/
@Deprecated
void confirmResizeServer(int id);
/**
* The resize function converts an existing server to a different flavor, in essence, scaling the
* server up or down. The original server is saved for a period of time to allow rollback if
* there is a problem. All resizes should be tested and explicitly reverted, at which time the
* original server is removed. All resizes are automatically reverted after 24 hours if they are
* not reverted or reverted.
* <p/>
* Status Transition:
* <p/>
* VERIFY_RESIZE - ACTIVE
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerApi#revertResize(String)} in openstack-nova.
*/
@Deprecated
void revertResizeServer(int id);
/**
* This operation asynchronously provisions a new server. The progress of this operation depends
* on several factors including location of the requested image, network i/o, host load, and the
* selected flavor. The progress of the request can be checked by performing a GET on /server/id,
* which will return a progress attribute (0-100% completion). A password will be randomly
* generated for you and returned in the response object. For security reasons, it will not be
* returned in subsequent GET calls against a given server ID.
*
* @param options
* - used to specify extra files, metadata, or ip parameters during server creation.
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerApi#create(String, String, String, CreateServerOptions)} in openstack-nova.
*/
@Deprecated
Server createServer(String name, String imageRef, String flavorRef, CreateServerOptions... options);
/**
* The rebuild function removes all data on the server and replaces it with the specified image.
* Server ID and IP addresses remain the same.
* <p/>
* Status Transition:
* <p/>
* ACTIVE - REBUILD - ACTIVE
* <p/>
* ACTIVE - REBUILD - ERROR (on error)
* <p/>
*
* @param options
* - imageId is an optional argument. If it is not specified, the server is rebuilt
* with the original imageId.
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerApi#rebuild(String, RebuildServerOptions)} in openstack-nova.
*/
@Deprecated
void rebuildServer(int id, RebuildServerOptions... options);
/**
* This operation allows you to change the administrative password.
* <p/>
* Status Transition: ACTIVE - PASSWORD - ACTIVE
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerApi#changeAdminPass(String, String)} in openstack-nova.
*/
@Deprecated
void changeAdminPass(int id, String adminPass);
/**
* This operation allows you to update the name of the server. This operation changes the name of
* the server in the OpenStack Nova system and does not change the server host name itself.
* <p/>
* Status Transition: ACTIVE - PASSWORD - ACTIVE
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerApi#rename(String, String)} in openstack-nova.
*/
@Deprecated
void renameServer(int id, String newName);
/**
*
* List available flavors (IDs and names only)
*
* in order to retrieve all details, pass the option {@link ListOptions#withDetails()
* withDetails()}
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.FlavorApi#list()} in openstack-nova.
*/
@Deprecated
Set<Flavor> listFlavors(ListOptions... options);
/**
*
* This operation returns details of the specified flavor.
*
* @return null, if the flavor is not found
* @see Flavor
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.FlavorApi#get(String)} in openstack-nova.
*/
@Deprecated
Flavor getFlavor(int id);
@Deprecated
Flavor getFlavor(String uuid);
/**
*
* List available images (IDs and names only)
*
* in order to retrieve all details, pass the option {@link ListOptions#withDetails()
* withDetails()}
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ImageApi#list()} in openstack-nova.
*/
@Deprecated
Set<Image> listImages(ListOptions... options);
/**
*
* This operation returns details of the specified image.
*
* @return null, if the image is not found
*
* @see Image
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ImageApi#get(String)} in openstack-nova.
*/
@Deprecated
Image getImage(int id);
@Deprecated
Image getImage(String id);
/**
*
* This operation deletes an image from the system.
* <p/>
* Note: Images are immediately removed. Currently, there are no state transitions to track the
* delete operation.
*
* @return false if the image is not found
* @see Image
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ImageApi#delete(String)} in openstack-nova.
*/
@Deprecated
boolean deleteImage(int id);
@Deprecated
boolean deleteImage(String id);
/**
*
* This operation creates a new image for the given server ID. Once complete, a new image will be
* available that can be used to rebuild or create servers. Specifying the same image name as an
* existing custom image replaces the image. The image creation status can be queried by
* performing a GET on /images/id and examining the status and progress attributes.
*
* Status Transition:
* <p/>
* QUEUED - PREPARING - SAVING - ACTIVE
* <p/>
* QUEUED - PREPARING - SAVING - FAILED (on error)
* <p/>
* Note: At present, image creation is an asynchronous operation, so coordinating the creation
* with data quiescence, etc. is currently not possible.
*
* @throws ResourceNotFoundException
* if the server is not found
* @see Image
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerApi#createImageFromServer(String, String)} in openstack-nova.
*/
@Deprecated
Image createImageFromServer(String imageName, int serverId);
/**
* List all server addresses
*
* returns empty set if the server doesn't exist
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerApi#get(String)} in openstack-nova.
*/
@Deprecated
Addresses getAddresses(int serverId);
/**
* List all public server addresses
*
* returns empty set if the server doesn't exist
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerApi#get(String)} in openstack-nova.
*/
@Deprecated
Set<String> listPublicAddresses(int serverId);
/**
* List all private server addresses
*
* returns empty set if the server doesn't exist
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.features.ServerApi#get(String)} in openstack-nova.
*/
@Deprecated
Set<String> listPrivateAddresses(int serverId);
/**
* Add a floating IP to the given server. The floating IP can just be added
* if the server has a fixed IP. It means that it is not possible to
* directly add the floating IP just after creating the server but have to
* poll if the server has an IP.
*
* @see <a href="http://wiki.openstack.org/os_api_floating_ip">http://wiki.openstack.org/os_api_floating_ip</a>
* @since 2011.3 "Diablo" release, OpenStack API 1.1
* @param serverId
* @param ip
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.extensions.FloatingIPApi#addToServer(String, String)} in openstack-nova.
*/
@Deprecated
void addFloatingIP(int serverId, String ip);
/**
* Get all the defined floating IPs in nova
*
* @see <a href="http://wiki.openstack.org/os_api_floating_ip">http://wiki.openstack.org/os_api_floating_ip</a>
* @since 2011.3 "Diablo" release, OpenStack API 1.1
* @return all the available floating IP for the current tenant
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.extensions.FloatingIPApi#list()} in openstack-nova.
*/
@Deprecated
Set<FloatingIP> listFloatingIPs();
/**
* Get floating IP details from its ID
*
* @see <a href="http://wiki.openstack.org/os_api_floating_ip">http://wiki.openstack.org/os_api_floating_ip</a>
* @since 2011.3 "Diablo" release, OpenStack API 1.1
* @param id the floating IP id
* @return the floating IP or null if not found
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.extensions.FloatingIPApi#get(String)} in openstack-nova.
*/
@Deprecated
FloatingIP getFloatingIP(int id);
/**
* Get all the security groups
*
* @see <a href="http://wiki.openstack.org/os-security-groups">http://wiki.openstack.org/os-security-groups</a>
* @since OpenStack API v1.1
* @return all the security groups for the current tenant
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.extensions.SecurityGroupApi#list()} in openstack-nova.
*/
@Deprecated
Set<SecurityGroup> listSecurityGroups();
/**
* Get a security group from its ID
*
* @see <a href="http://wiki.openstack.org/os-security-groups">http://wiki.openstack.org/os-security-groups</a>
* @since OpenStack API v1.1
* @param id the ID of the security group to get details from
* @return the security group or null if not found
*
* @deprecated Deprecated in jclouds 1.5.5, to be removed in jclouds 1.6. See {@link org.jclouds.openstack.nova.v2_0.extensions.SecurityGroupApi#get(String)} in openstack-nova.
*/
@Deprecated
SecurityGroup getSecurityGroup(int id);
}

View File

@ -1,40 +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.openstack.nova;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Represents a component related to Rackspace OpenStack Nova.
*
* @see <a href="http://wiki.openstack.org/OpenStackAPI_1-1" />
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface ServerManagement {
}

View File

@ -1,124 +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.openstack.nova.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.openstack.nova.compute.functions.FlavorToHardware;
import org.jclouds.openstack.nova.compute.functions.NovaImageToImage;
import org.jclouds.openstack.nova.compute.functions.NovaImageToOperatingSystem;
import org.jclouds.openstack.nova.compute.functions.ServerToNodeMetadata;
import org.jclouds.openstack.nova.compute.strategy.NovaComputeServiceAdapter;
import org.jclouds.openstack.nova.domain.Flavor;
import org.jclouds.openstack.nova.domain.ImageStatus;
import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.domain.ServerStatus;
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 NovaComputeServiceContext}; requires {@link BaseComputeService} bound.
*
* @author Adrian Cole
*/
public class NovaComputeServiceContextModule extends
ComputeServiceAdapterContextModule<Server, Flavor, org.jclouds.openstack.nova.domain.Image, Location> {
@SuppressWarnings("unchecked")
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<ComputeServiceAdapter<Server, Flavor, org.jclouds.openstack.nova.domain.Image, Location>>() {
}).to(NovaComputeServiceAdapter.class);
bind(new TypeLiteral<Function<Server, NodeMetadata>>() {
}).to(ServerToNodeMetadata.class);
bind(new TypeLiteral<Function<org.jclouds.openstack.nova.domain.Image, Image>>() {
}).to(NovaImageToImage.class);
bind(new TypeLiteral<Function<org.jclouds.openstack.nova.domain.Image, OperatingSystem>>() {
}).to(NovaImageToOperatingSystem.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<ServerStatus, Status> toPortableNodeStatus = ImmutableMap
.<ServerStatus, Status> builder().put(ServerStatus.ACTIVE, Status.RUNNING)//
.put(ServerStatus.SUSPENDED, Status.SUSPENDED)//
.put(ServerStatus.DELETED, Status.TERMINATED)//
.put(ServerStatus.QUEUE_RESIZE, Status.PENDING)//
.put(ServerStatus.PREP_RESIZE, Status.PENDING)//
.put(ServerStatus.RESIZE, Status.PENDING)//
.put(ServerStatus.VERIFY_RESIZE, Status.PENDING)//
.put(ServerStatus.RESCUE, Status.PENDING)//
.put(ServerStatus.BUILD, Status.PENDING)//
.put(ServerStatus.PASSWORD, Status.PENDING)//
.put(ServerStatus.REBUILD, Status.PENDING)//
.put(ServerStatus.DELETE_IP, Status.PENDING)//
.put(ServerStatus.REBOOT, Status.PENDING)//
.put(ServerStatus.HARD_REBOOT, Status.PENDING)//
.put(ServerStatus.UNKNOWN, Status.UNRECOGNIZED)//
.put(ServerStatus.UNRECOGNIZED, Status.UNRECOGNIZED).build();
@Singleton
@Provides
Map<ServerStatus, Status> toPortableNodeStatus() {
return toPortableNodeStatus;
}
@VisibleForTesting
public static final Map<ImageStatus, Image.Status> toPortableImageStatus = ImmutableMap
.<ImageStatus, Image.Status> builder()
.put(ImageStatus.ACTIVE, Image.Status.AVAILABLE)
.put(ImageStatus.SAVING, Image.Status.PENDING)
.put(ImageStatus.PREPARING, Image.Status.PENDING)
.put(ImageStatus.QUEUED, Image.Status.PENDING)
.put(ImageStatus.FAILED, Image.Status.ERROR)
.put(ImageStatus.UNKNOWN, Image.Status.UNRECOGNIZED)
.put(ImageStatus.UNRECOGNIZED, Image.Status.UNRECOGNIZED).build();
@Singleton
@Provides
Map<ImageStatus, Image.Status> toPortableImageStatus() {
return toPortableImageStatus;
}
}

View File

@ -1,48 +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.openstack.nova.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.openstack.nova.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())
.processors(ImmutableList.of(new Processor(from.getDisk() / 10.0, 1.0)))
.ram(from.getRam())
.volumes(ImmutableList.<Volume> of(new VolumeImpl((float) from.getDisk(), true, true)))
.uri(from.getURI())
.build();
}
}

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.openstack.nova.compute.functions;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Image.Status;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.openstack.nova.domain.ImageStatus;
import com.google.common.base.Function;
/**
*
* @author Adrian Cole
*/
@Singleton
public class NovaImageToImage implements Function<org.jclouds.openstack.nova.domain.Image, Image> {
private final Map<ImageStatus, Status> toPortableImageStatus;
private final Function<org.jclouds.openstack.nova.domain.Image, OperatingSystem> imageToOs;
@Inject
NovaImageToImage(Map<ImageStatus, Image.Status> toPortableImageStatus,
Function<org.jclouds.openstack.nova.domain.Image, OperatingSystem> imageToOs) {
this.toPortableImageStatus = toPortableImageStatus;
this.imageToOs = imageToOs;
}
public Image apply(org.jclouds.openstack.nova.domain.Image from) {
ImageBuilder builder = new ImageBuilder();
builder.ids(from.getId() + "");
builder.name(from.getName() != null ? from.getName() : "unspecified");
builder.description(from.getName() != null ? from.getName() : "unspecified");
builder.version(from.getUpdated() != null ? from.getUpdated().getTime() + "" : "-1");
builder.operatingSystem(imageToOs.apply(from)); //image name may not represent the OS type
builder.status(toPortableImageStatus.get(from.getStatus()));
builder.uri(from.getURI());
Image image = builder.build();
return image;
}
}

View File

@ -1,93 +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.openstack.nova.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 NovaImageToOperatingSystem implements
Function<org.jclouds.openstack.nova.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 NovaImageToOperatingSystem(Map<OsFamily, Map<String, String>> osVersionMap) {
this.osVersionMap = osVersionMap;
}
public OperatingSystem apply(final org.jclouds.openstack.nova.domain.Image from) {
OsFamily osFamily = null;
String osName = null;
String osArch = null;
String osVersion = null;
String osDescription = from.getName() != null ? from.getName() : "unspecified";
String name = from.getName() != null ? from.getName() : "unspecified";
boolean is64Bit = true;
if (name.indexOf("Red Hat EL") != -1) {
osFamily = OsFamily.RHEL;
} else if (name.indexOf("Oracle EL") != -1) {
osFamily = OsFamily.OEL;
} else if (name.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(name);
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,145 +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.openstack.nova.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.Named;
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.NodeMetadata.Status;
import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.functions.GroupNamingConvention;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.logging.Logger;
import org.jclouds.openstack.nova.domain.Address;
import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.domain.ServerStatus;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/**
* @author Adrian Cole
*/
@Singleton
public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
protected final Supplier<Location> location;
protected final Map<ServerStatus, Status> serverToNodeStatus;
protected final Supplier<Set<? extends Image>> images;
protected final Supplier<Set<? extends Hardware>> hardwares;
protected final GroupNamingConvention nodeNamingConvention;
private static class FindImageForServer implements Predicate<Image> {
private final Server instance;
private FindImageForServer(Server instance) {
this.instance = instance;
}
@Override
public boolean apply(Image input) {
return input.getUri().toString().equals(instance.getImageRef() + "");
}
}
private static class FindHardwareForServer implements Predicate<Hardware> {
private final Server instance;
private FindHardwareForServer(Server instance) {
this.instance = instance;
}
@Override
public boolean apply(Hardware input) {
return input.getUri().toString().equals(instance.getFlavorRef() + "");
}
}
@Inject
ServerToNodeMetadata(Map<ServerStatus, Status> serverStateToNodeStatus,
@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.serverToNodeStatus = checkNotNull(serverStateToNodeStatus, "serverStateToNodeStatus");
this.images = checkNotNull(images, "images");
this.location = checkNotNull(location, "location");
this.hardwares = checkNotNull(hardwares, "hardwares");
}
@Override
public NodeMetadata apply(Server from) {
NodeMetadataBuilder builder = new NodeMetadataBuilder();
builder.ids(from.getId() + "");
builder.name(from.getName());
builder.location(new LocationBuilder().scope(LocationScope.HOST).id(from.getHostId()).description(
from.getHostId()).parent(location.get()).build());
builder.userMetadata(from.getMetadata());
builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName()));
Image image = parseImage(from);
if (image != null) {
builder.imageId(image.getId());
builder.operatingSystem(image.getOperatingSystem());
}
builder.hardware(parseHardware(from));
builder.status(serverToNodeStatus.get(from.getStatus()));
builder.publicAddresses(Iterables.transform(from.getAddresses().getPublicAddresses(), Address.newAddress2StringFunction()));
builder.privateAddresses(Iterables.transform(from.getAddresses().getPrivateAddresses(), Address.newAddress2StringFunction()));
builder.uri(from.getURI());
return builder.build();
}
protected Hardware parseHardware(Server from) {
try {
return Iterables.find(hardwares.get(), new FindHardwareForServer(from));
} catch (NoSuchElementException e) {
logger.debug("could not find a matching hardware for server %s", from);
}
return null;
}
protected Image parseImage(Server from) {
try {
return Iterables.find(images.get(), new FindImageForServer(from));
} catch (NoSuchElementException e) {
logger.debug("could not find a matching image for server %s in location %s", from, location.get());
}
return null;
}
}

View File

@ -1,124 +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.openstack.nova.compute.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withMetadata;
import static org.jclouds.openstack.nova.options.ListOptions.Builder.withDetails;
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.openstack.nova.NovaClient;
import org.jclouds.openstack.nova.domain.Flavor;
import org.jclouds.openstack.nova.domain.Image;
import org.jclouds.openstack.nova.domain.RebootType;
import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.options.ListOptions;
import com.google.common.collect.ImmutableSet;
/**
* defines the connection between the {@link NovaClient} implementation and the jclouds
* {@link ComputeService}
*
*/
@Singleton
public class NovaComputeServiceAdapter implements ComputeServiceAdapter<Server, Flavor, Image, Location> {
protected final NovaClient client;
@Inject
protected NovaComputeServiceAdapter(NovaClient client) {
this.client = checkNotNull(client, "client");
}
@Override
public NodeAndInitialCredentials<Server> createNodeWithGroupEncodedIntoName(String group, String name,
Template template) {
Server server = client.createServer(name, template.getImage().getId(), template.getHardware().getId(),
withMetadata(template.getOptions().getUserMetadata()).withSecurityGroup(group));
return new NodeAndInitialCredentials<Server>(server, server.getId() + "", LoginCredentials.builder().password(
server.getAdminPass()).build());
}
@Override
public Iterable<Flavor> listHardwareProfiles() {
return client.listFlavors(withDetails());
}
@Override
public Iterable<Image> listImages() {
return client.listImages(withDetails());
}
@Override
public Iterable<Server> listNodes() {
return client.listServers(ListOptions.Builder.withDetails());
}
@Override
public Iterable<Location> listLocations() {
// Not using the adapter to determine locations
return ImmutableSet.<Location>of();
}
@Override
public Server getNode(String id) {
int serverId = Integer.parseInt(id);
return client.getServer(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.deleteServer(serverId);
}
@Override
public void rebootNode(String id) {
int serverId = Integer.parseInt(id);
// if false server wasn't around in the first place
client.rebootServer(serverId, RebootType.HARD);
}
@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,81 +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.openstack.nova.config;
import java.net.URI;
import javax.inject.Singleton;
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.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.openstack.config.OpenStackAuthenticationModule;
import org.jclouds.openstack.functions.URIFromAuthenticationResponseForService;
import org.jclouds.openstack.nova.NovaAsyncClient;
import org.jclouds.openstack.nova.NovaClient;
import org.jclouds.openstack.nova.ServerManagement;
import org.jclouds.openstack.nova.handlers.ParseNovaErrorFromHttpResponse;
import org.jclouds.openstack.reference.AuthHeaders;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import com.google.common.base.Supplier;
import com.google.inject.Provides;
/**
*
* @author Adrian Cole
*/
@ConfiguresRestClient
public class NovaRestClientModule extends RestClientModule<NovaClient, NovaAsyncClient> {
private final OpenStackAuthenticationModule module;
public NovaRestClientModule(OpenStackAuthenticationModule module) {
this.module = module;
}
public NovaRestClientModule() {
this(new OpenStackAuthenticationModule());
}
@Override
protected void configure() {
install(module);
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseNovaErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseNovaErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseNovaErrorFromHttpResponse.class);
}
@Provides
@Singleton
@ServerManagement
protected Supplier<URI> provideServerUrl(URIFromAuthenticationResponseForService.Factory factory) {
return factory.create(AuthHeaders.SERVER_MANAGEMENT_URL);
}
}

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.openstack.nova.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
*
* @author Adrian Cole
*/
public class AbsoluteLimit {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromAbsoluteLimit(this);
}
public abstract static class Builder<T extends Builder<T>> {
protected abstract T self();
protected String name;
protected int value;
/**
* @see AbsoluteLimit#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
/**
* @see AbsoluteLimit#getValue()
*/
public T value(int value) {
this.value = value;
return self();
}
public AbsoluteLimit build() {
return new AbsoluteLimit(name, value);
}
public T fromAbsoluteLimit(AbsoluteLimit in) {
return this
.name(in.getName())
.value(in.getValue());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final String name;
private final int value;
@ConstructorProperties({
"name", "value"
})
protected AbsoluteLimit(String name, int value) {
this.name = checkNotNull(name, "name");
this.value = value;
}
public String getName() {
return this.name;
}
public int getValue() {
return this.value;
}
@Override
public int hashCode() {
return Objects.hashCode(name, value);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
AbsoluteLimit that = AbsoluteLimit.class.cast(obj);
return Objects.equal(this.name, that.name)
&& Objects.equal(this.value, that.value);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("name", name).add("value", value);
}
@Override
public String toString() {
return string().toString();
}
}

View File

@ -1,27 +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.openstack.nova.domain;
/**
*
* @author Adrian Cole
*/
public enum Action {
CONFIRM_RESIZE, REBOOT, REBUILD, RESIZE, REVERT_RESIZE
}

View File

@ -1,149 +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.openstack.nova.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
* @author Dmitri Babaev
*/
public class Address {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromAddress(this);
}
public static Function<Address, String> newAddress2StringFunction() {
return new Function<Address, String>() {
@Override
public String apply(@Nullable Address input) {
return input.getAddress();
}
};
}
public static Address valueOf(String address) {
return new Address(address, address.startsWith("::") ? 6 : 4);
}
public static Function<String, Address> newString2AddressFunction() {
return new Function<String, Address>() {
@Override
public Address apply(@Nullable String input) {
return valueOf(input);
}
};
}
public abstract static class Builder<T extends Builder<T>> {
protected abstract T self();
protected String address;
protected int version;
/**
* @see Address#getAddress()
*/
public T address(String address) {
this.address = address;
return self();
}
/**
* @see Address#getVersion()
*/
public T version(int version) {
this.version = version;
return self();
}
public Address build() {
return new Address(address, version);
}
public T fromAddress(Address in) {
return this
.address(in.getAddress())
.version(in.getVersion());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final String address;
private final int version;
@ConstructorProperties({
"addr", "version"
})
protected Address(String address, int version) {
this.address = checkNotNull(address, "address");
this.version = version;
}
public String getAddress() {
return this.address;
}
public int getVersion() {
return this.version;
}
@Override
public int hashCode() {
return Objects.hashCode(address, version);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Address that = Address.class.cast(obj);
return Objects.equal(this.address, that.address)
&& Objects.equal(this.version, that.version);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("address", address).add("version", version);
}
@Override
public String toString() {
return string().toString();
}
}

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.openstack.nova.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.Collection;
import java.util.Set;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Adrian Cole
*/
public class Addresses {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromAddresses(this);
}
public abstract static class Builder<T extends Builder<T>> {
protected abstract T self();
protected Set<Address> publicAddresses = ImmutableSet.of();
protected Set<Address> privateAddresses = ImmutableSet.of();
/**
* @see Addresses#getPublicAddresses()
*/
public T publicAddresses(Collection<Address> publicAddresses) {
this.publicAddresses = ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses"));
return self();
}
public T publicAddresses(Address... in) {
return publicAddresses(ImmutableSet.copyOf(in));
}
/**
* @see Addresses#getPrivateAddresses()
*/
public T privateAddresses(Collection<Address> privateAddresses) {
this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses"));
return self();
}
public T privateAddresses(Address... in) {
return privateAddresses(ImmutableSet.copyOf(in));
}
public Addresses build() {
return new Addresses(publicAddresses, privateAddresses);
}
public T fromAddresses(Addresses in) {
return this
.publicAddresses(in.getPublicAddresses())
.privateAddresses(in.getPrivateAddresses());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final Set<Address> publicAddresses;
private final Set<Address> privateAddresses;
@ConstructorProperties({
"public", "private"
})
protected Addresses(Set<Address> publicAddresses, Set<Address> privateAddresses) {
this.publicAddresses = ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses"));
this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses"));
}
public Set<Address> getPublicAddresses() {
return this.publicAddresses;
}
public Set<Address> getPrivateAddresses() {
return this.privateAddresses;
}
@Override
public int hashCode() {
return Objects.hashCode(publicAddresses, privateAddresses);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Addresses that = Addresses.class.cast(obj);
return Objects.equal(this.publicAddresses, that.publicAddresses)
&& Objects.equal(this.privateAddresses, that.privateAddresses);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("publicAddresses", publicAddresses).add("privateAddresses", privateAddresses);
}
@Override
public String toString() {
return string().toString();
}
}

View File

@ -1,163 +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.openstack.nova.domain;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.List;
import java.util.Map;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
* A flavor is an available hardware configuration for a server. Each flavor has a unique
* combination of disk space and memory capacity.
*
* @author Adrian Cole
*/
public class Flavor extends Resource {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromFlavor(this);
}
public abstract static class Builder<T extends Builder<T>> extends Resource.Builder<T> {
protected String name;
protected Integer disk;
protected Integer ram;
protected Integer vcpus;
/**
* @see Flavor#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
/**
* @see Flavor#getDisk()
*/
public T disk(Integer disk) {
this.disk = disk;
return self();
}
/**
* @see Flavor#getRam()
*/
public T ram(Integer ram) {
this.ram = ram;
return self();
}
/**
* @see Flavor#getVcpus()
*/
public T vcpus(Integer vcpus) {
this.vcpus = vcpus;
return self();
}
public Flavor build() {
return new Flavor(id, links, orderedSelfReferences, name, disk, ram, vcpus);
}
public T fromFlavor(Flavor in) {
return super.fromResource(in)
.name(in.getName())
.disk(in.getDisk())
.ram(in.getRam())
.vcpus(in.getVcpus());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final String name;
private final Integer disk;
private final Integer ram;
private final Integer vcpus;
@ConstructorProperties({
"id", "links", "orderedSelfReferences", "name", "disk", "ram", "vcpus"
})
protected Flavor(int id, List<Map<String, String>> links, @Nullable Map<LinkType, URI> orderedSelfReferences,
@Nullable String name, @Nullable Integer disk, @Nullable Integer ram, @Nullable Integer vcpus) {
super(id, links, orderedSelfReferences);
this.name = name;
this.disk = disk;
this.ram = ram;
this.vcpus = vcpus;
}
@Nullable
public String getName() {
return this.name;
}
@Nullable
public Integer getDisk() {
return this.disk;
}
@Nullable
public Integer getRam() {
return this.ram;
}
@Nullable
public Integer getVcpus() {
return this.vcpus;
}
@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), name, disk, ram, vcpus);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Flavor that = Flavor.class.cast(obj);
return super.equals(that)
&& Objects.equal(this.name, that.name)
&& Objects.equal(this.disk, that.disk)
&& Objects.equal(this.ram, that.ram)
&& Objects.equal(this.vcpus, that.vcpus);
}
protected ToStringHelper string() {
return super.string().add("name", name).add("disk", disk).add("ram", ram).add("vcpus", vcpus);
}
}

View File

@ -1,151 +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.openstack.nova.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.List;
import java.util.Map;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
* Check <a href="http://wiki.openstack.org/os_api_floating_ip">Floating IP Wiki
* page</a>. Available since OpenStack Diablo release and API 1.1.
*
* @author chamerling
*/
public class FloatingIP extends Resource {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromFloatingIP(this);
}
public abstract static class Builder<T extends Builder<T>> extends Resource.Builder<T> {
protected String ip;
protected String fixedIP;
protected int instanceID;
/**
* @see FloatingIP#getIp()
*/
public T ip(String ip) {
this.ip = ip;
return self();
}
/**
* @see FloatingIP#getFixedIP()
*/
public T fixedIP(String fixedIP) {
this.fixedIP = fixedIP;
return self();
}
/**
* @see FloatingIP#getInstanceID()
*/
public T instanceID(int instanceID) {
this.instanceID = instanceID;
return self();
}
public FloatingIP build() {
return new FloatingIP(id, links, orderedSelfReferences, ip, fixedIP, instanceID);
}
public T fromFloatingIP(FloatingIP in) {
return super.fromResource(in)
.ip(in.getIp())
.fixedIP(in.getFixedIP())
.instanceID(in.getInstanceID());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final String ip;
private final String fixedIP;
private final int instanceID;
@ConstructorProperties({
"id", "links", "orderedSelfReferences", "ip", "fixed_ip", "instance_id"
})
protected FloatingIP(int id, List<Map<String, String>> links, Map<LinkType, URI> orderedSelfReferences, String ip,
String fixedIP, int instanceID) {
super(id, links, orderedSelfReferences);
this.ip = checkNotNull(ip, "ip");
this.fixedIP = checkNotNull(fixedIP, "fixedIP");
this.instanceID = instanceID;
}
/**
* @return the ip
*/
public String getIp() {
return this.ip;
}
/**
* @return the fixedIP
*/
public String getFixedIP() {
return this.fixedIP;
}
/**
* @return the instanceID
*/
public int getInstanceID() {
return this.instanceID;
}
@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), ip, fixedIP, instanceID);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
FloatingIP that = FloatingIP.class.cast(obj);
return super.equals(that)
&& Objects.equal(this.ip, that.ip)
&& Objects.equal(this.fixedIP, that.fixedIP)
&& Objects.equal(this.instanceID, that.instanceID);
}
protected ToStringHelper string() {
return super.string().add("ip", ip).add("fixedIP", fixedIP).add("instanceID", instanceID);
}
}

View File

@ -1,220 +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.openstack.nova.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableMap;
/**
* An image is a collection of files used to create or rebuild a server. Rackspace provides a number
* of pre-built OS images by default. You may also create custom images from cloud servers you have
* launched. These custom images are useful for backup purposes or for producing gold server images
* if you plan to deploy a particular server configuration frequently.
*
* @author Adrian Cole
*/
public class Image extends Resource {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromImage(this);
}
public abstract static class Builder<T extends Builder<T>> extends Resource.Builder<T> {
protected String name;
protected Integer progress;
protected String serverRef;
protected ImageStatus status;
protected Map<String, String> metadata = ImmutableMap.of();
protected Date created;
protected Date updated;
/**
* @see Image#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
/**
* @see Image#getProgress()
*/
public T progress(Integer progress) {
this.progress = progress;
return self();
}
/**
* @see Image#getServerRef()
*/
public T serverRef(String serverRef) {
this.serverRef = serverRef;
return self();
}
/**
* @see Image#getStatus()
*/
public T status(ImageStatus status) {
this.status = status;
return self();
}
/**
* @see Image#getMetadata()
*/
public T metadata(Map<String, String> metadata) {
this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
return self();
}
/**
* @see Image#getCreated()
*/
public T created(Date created) {
this.created = created;
return self();
}
/**
* @see Image#getUpdated()
*/
public T updated(Date updated) {
this.updated = updated;
return self();
}
public Image build() {
return new Image(id, links, orderedSelfReferences, name, progress, serverRef, status, metadata, created, updated);
}
public T fromImage(Image in) {
return super.fromResource(in)
.id(in.getId())
.name(in.getName())
.progress(in.getProgress())
.serverRef(in.getServerRef())
.status(in.getStatus())
.metadata(in.getMetadata())
.created(in.getCreated())
.updated(in.getUpdated());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final String name;
private final Integer progress;
private final String serverRef;
private final ImageStatus status;
private final Map<String, String> metadata;
private final Date created;
private final Date updated;
@ConstructorProperties({
"id", "links", "orderedSelfReferences", "name", "progress", "serverRef", "status", "metadata", "created", "updated"
})
protected Image(int id, List<Map<String, String>> links, @Nullable Map<LinkType, URI> orderedSelfReferences, @Nullable String name,
@Nullable Integer progress, @Nullable String serverRef, @Nullable ImageStatus status, @Nullable Map<String, String> metadata,
@Nullable Date created, @Nullable Date updated) {
super(id, links, orderedSelfReferences);
this.name = name;
this.progress = progress;
this.serverRef = serverRef;
this.status = status == null ? ImageStatus.UNKNOWN : status;
this.metadata = metadata == null ? ImmutableMap.<String, String>of() : ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
this.created = created;
this.updated = updated;
}
@Nullable
public String getName() {
return this.name;
}
@Nullable
public Integer getProgress() {
return this.progress;
}
@Nullable
public String getServerRef() {
return this.serverRef;
}
@Nullable
public ImageStatus getStatus() {
return this.status;
}
public Map<String, String> getMetadata() {
return this.metadata;
}
@Nullable
public Date getCreated() {
return this.created;
}
@Nullable
public Date getUpdated() {
return this.updated;
}
@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), name, serverRef);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Image that = Image.class.cast(obj);
return super.equals(that)
&& Objects.equal(this.name, that.name)
&& Objects.equal(this.serverRef, that.serverRef);
}
protected ToStringHelper string() {
return super.string().add("name", name).add("progress", progress).add("serverRef", serverRef).add("status", status)
.add("metadata", metadata).add("created", created).add("updated", updated);
}
}

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.openstack.nova.domain;
/**
* In-flight images will have the status attribute set to SAVING and the conditional progress
* element (0- 100% completion) will also be returned. Other possible values for the status
* attribute include: UNKNOWN, PREPARING, ACTIVE QUEUED, FAILED. Images with an ACTIVE status are
* available for install.
*
* @author Adrian Cole
*/
public enum ImageStatus {
UNRECOGNIZED, UNKNOWN, ACTIVE, SAVING, PREPARING, QUEUED, FAILED;
public String value() {
return name();
}
public static ImageStatus fromValue(String v) {
try {
return valueOf(v);
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}

View File

@ -1,131 +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.openstack.nova.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.List;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableList;
public class Limits {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromLimits(this);
}
public abstract static class Builder<T extends Builder<T>> {
protected abstract T self();
protected List<RateLimit> rate = ImmutableList.of();
protected List<AbsoluteLimit> absolute = ImmutableList.of();
/**
* @see Limits#getRate()
*/
public T rate(List<RateLimit> rate) {
this.rate = ImmutableList.copyOf(checkNotNull(rate, "rate"));
return self();
}
public T rate(RateLimit... in) {
return rate(ImmutableList.copyOf(in));
}
/**
* @see Limits#getAbsolute()
*/
public T absolute(List<AbsoluteLimit> absolute) {
this.absolute = ImmutableList.copyOf(checkNotNull(absolute, "absolute"));
return self();
}
public T absolute(AbsoluteLimit... in) {
return absolute(ImmutableList.copyOf(in));
}
public Limits build() {
return new Limits(rate, absolute);
}
public T fromLimits(Limits in) {
return this
.rate(in.getRate())
.absolute(in.getAbsolute());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final List<RateLimit> rate;
private final List<AbsoluteLimit> absolute;
@ConstructorProperties({
"rate", "absolute"
})
protected Limits(List<RateLimit> rate, List<AbsoluteLimit> absolute) {
this.rate = ImmutableList.copyOf(checkNotNull(rate, "rate"));
this.absolute = ImmutableList.copyOf(checkNotNull(absolute, "absolute"));
}
public List<RateLimit> getRate() {
return this.rate;
}
public List<AbsoluteLimit> getAbsolute() {
return this.absolute;
}
@Override
public int hashCode() {
return Objects.hashCode(rate, absolute);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Limits that = Limits.class.cast(obj);
return Objects.equal(this.rate, that.rate)
&& Objects.equal(this.absolute, that.absolute);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("rate", rate).add("absolute", absolute);
}
@Override
public String toString() {
return string().toString();
}
}

View File

@ -1,224 +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.openstack.nova.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import javax.ws.rs.HttpMethod;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
* RateLimit.
* <p/>
* we specify rate limits in terms of both a human readable wild-card URI and a machine processable
* regular expression. The regular expression boundary matcher '^' takes affect after the root URI
* path. For example, the regular expression ^/servers would match the bolded portion of the
* following URI: https://servers.api.rackspacecloud.com/v1.0/3542812 /servers .
* <p/>
* Rate limits are applied in order relative to the verb, going from least to most specific. For
* example, although the threshold for POST to /servers is 25 per day, one cannot POST to /servers
* more than 10 times within a single minute because the rate limits for any POST is 10/min. In the
* event you exceed the thresholds established for your identity, a 413 Rate Control HTTP response
* will be returned with a Reply-After header to notify the client when theyagain.
*
* @author Adrian Cole
*/
public class RateLimit {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromRateLimit(this);
}
public abstract static class Builder<T extends Builder<T>> {
protected abstract T self();
protected String uri;
protected String regex;
protected int remaining;
protected long resetTime;
protected RateLimitUnit unit;
protected int value;
protected HttpMethod verb;
/**
* @see RateLimit#getUri()
*/
public T uri(String uri) {
this.uri = uri;
return self();
}
/**
* @see RateLimit#getRegex()
*/
public T regex(String regex) {
this.regex = regex;
return self();
}
/**
* @see RateLimit#getRemaining()
*/
public T remaining(int remaining) {
this.remaining = remaining;
return self();
}
/**
* @see RateLimit#getResetTime()
*/
public T resetTime(long resetTime) {
this.resetTime = resetTime;
return self();
}
/**
* @see RateLimit#getUnit()
*/
public T unit(RateLimitUnit unit) {
this.unit = unit;
return self();
}
/**
* @see RateLimit#getValue()
*/
public T value(int value) {
this.value = value;
return self();
}
/**
* @see RateLimit#getVerb()
*/
public T verb(HttpMethod verb) {
this.verb = verb;
return self();
}
public RateLimit build() {
return new RateLimit(uri, regex, remaining, resetTime, unit, value, verb);
}
public T fromRateLimit(RateLimit in) {
return this
.uri(in.getUri())
.regex(in.getRegex())
.remaining(in.getRemaining())
.resetTime(in.getResetTime())
.unit(in.getUnit())
.value(in.getValue())
.verb(in.getVerb());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final String uri;
private final String regex;
private final int remaining;
private final long resetTime;
private final RateLimitUnit unit;
private final int value;
private final HttpMethod verb;
@ConstructorProperties({
"uri", "regex", "remaining", "resetTime", "unit", "value", "verb"
})
protected RateLimit(String uri, String regex, int remaining, long resetTime, RateLimitUnit unit, int value, HttpMethod verb) {
this.uri = checkNotNull(uri, "uri");
this.regex = checkNotNull(regex, "regex");
this.remaining = remaining;
this.resetTime = resetTime;
this.unit = checkNotNull(unit, "unit");
this.value = value;
this.verb = checkNotNull(verb, "verb");
}
public String getUri() {
return this.uri;
}
public String getRegex() {
return this.regex;
}
public int getRemaining() {
return this.remaining;
}
public long getResetTime() {
return this.resetTime;
}
public RateLimitUnit getUnit() {
return this.unit;
}
public int getValue() {
return this.value;
}
public HttpMethod getVerb() {
return this.verb;
}
@Override
public int hashCode() {
return Objects.hashCode(uri, regex, remaining, resetTime, unit, value, verb);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
RateLimit that = RateLimit.class.cast(obj);
return Objects.equal(this.uri, that.uri)
&& Objects.equal(this.regex, that.regex)
&& Objects.equal(this.remaining, that.remaining)
&& Objects.equal(this.resetTime, that.resetTime)
&& Objects.equal(this.unit, that.unit)
&& Objects.equal(this.value, that.value)
&& Objects.equal(this.verb, that.verb);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("uri", uri).add("regex", regex).add("remaining", remaining).add("resetTime", resetTime).add("unit", unit).add("value", value).add("verb", verb);
}
@Override
public String toString() {
return string().toString();
}
}

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.openstack.nova.domain;
public enum RateLimitUnit {
MINUTE, HOUR, DAY, UNRECOGNIZED;
public String value() {
return name();
}
public static RateLimitUnit fromValue(String v) {
try {
return valueOf(v);
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}

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.openstack.nova.domain;
/**
*
* @author Adrian Cole
*/
public enum RebootType {
HARD, SOFT;
public String value() {
return name();
}
public static RebootType fromValue(String v) {
return valueOf(v);
}
}

View File

@ -1,190 +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.openstack.nova.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentSkipListMap;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Functions;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
/**
* @author Dmitri Babaev
* @author Matt Stephenson
*/
public abstract class Resource {
public static enum LinkType {
BOOKMARK_JSON(new Predicate<Map<String, String>>() {
@Override
public boolean apply(@Nullable Map<String, String> linkMap) {
return Functions.forMap(linkMap, "").apply("rel").equals("bookmark") &&
Functions.forMap(linkMap, "").apply("type").contains("json");
}
}),
BOOKMARK_ANY(new Predicate<Map<String, String>>() {
@Override
public boolean apply(@Nullable Map<String, String> linkMap) {
return Functions.forMap(linkMap, "").apply("rel").equals("bookmark");
}
}),
SELF(new Predicate<Map<String, String>>() {
@Override
public boolean apply(@Nullable Map<String, String> linkMap) {
return Functions.forMap(linkMap, "").apply("rel").equals("self");
}
});
Predicate<Map<String, String>> linkPredicate;
LinkType(Predicate<Map<String, String>> linkPredicate) {
this.linkPredicate = linkPredicate;
}
}
public abstract static class Builder<T extends Builder<T>> {
protected abstract T self();
protected int id;
protected List<Map<String, String>> links = ImmutableList.of();
protected Map<Resource.LinkType, URI> orderedSelfReferences;
/**
* @see Resource#getId()
*/
public T id(int id) {
this.id = id;
return self();
}
/**
* @see Resource#getLinks()
*/
public T links(List<Map<String, String>> links) {
this.links = ImmutableList.copyOf(checkNotNull(links, "links"));
return self();
}
public T links(Map<String, String>... in) {
return links(ImmutableList.copyOf(in));
}
/**
* @see Resource#getOrderedSelfReferences()
*/
public T orderedSelfReferences(Map<Resource.LinkType, URI> orderedSelfReferences) {
this.orderedSelfReferences = ImmutableMap.copyOf(orderedSelfReferences);
return self();
}
public T fromResource(Resource in) {
return this
.links(in.getLinks())
.orderedSelfReferences(in.getOrderedSelfReferences());
}
}
private final int id;
private final List<Map<String, String>> links;
private final ConcurrentSkipListMap<Resource.LinkType, URI> orderedSelfReferences;
protected Resource(int id, List<Map<String, String>> links, @Nullable Map<Resource.LinkType, URI> orderedSelfReferences) {
this.id = id;
this.links = links == null ? ImmutableList.<Map<String, String>>of() : ImmutableList.copyOf(checkNotNull(links, "links"));
this.orderedSelfReferences = orderedSelfReferences == null ? new ConcurrentSkipListMap<LinkType, URI>() : new ConcurrentSkipListMap<LinkType, URI>(orderedSelfReferences);
}
public int getId() {
return id;
}
public List<Map<String, String>> getLinks() {
return this.links;
}
public Map<Resource.LinkType, URI> getOrderedSelfReferences() {
return this.orderedSelfReferences;
}
private void populateOrderedSelfReferences() {
for (Map<String, String> linkProperties : links) {
for (LinkType type : LinkType.values()) {
if (type.linkPredicate.apply(linkProperties)) {
try {
orderedSelfReferences.put(type, new URI(linkProperties.get("href")));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
}
}
if (orderedSelfReferences.isEmpty())
throw new IllegalStateException("URI is not available");
}
public URI getURI() {
if (orderedSelfReferences.isEmpty())
populateOrderedSelfReferences();
return orderedSelfReferences.firstEntry().getValue();
}
public URI getSelfURI() {
if (orderedSelfReferences.isEmpty())
populateOrderedSelfReferences();
return orderedSelfReferences.get(LinkType.SELF);
}
@Override
public int hashCode() {
return Objects.hashCode(id, orderedSelfReferences);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Resource that = Resource.class.cast(obj);
return Objects.equal(id, that.id) && Objects.equal(this.orderedSelfReferences, that.orderedSelfReferences);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("id", id).add("links", links).add("orderedSelfReferences", orderedSelfReferences);
}
@Override
public String toString() {
return string().toString();
}
}

View File

@ -1,176 +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.openstack.nova.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/**
* Defines a security group
*
* @author chamerling
*/
public class SecurityGroup {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromSecurityGroup(this);
}
public abstract static class Builder<T extends Builder<T>> {
protected abstract T self();
protected int id;
protected String name;
protected String description;
protected String tenantId;
/**
* @see SecurityGroup#getId()
*/
public T id(int id) {
this.id = id;
return self();
}
/**
* @see SecurityGroup#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
/**
* @see SecurityGroup#getDescription()
*/
public T description(String description) {
this.description = description;
return self();
}
/**
* @see SecurityGroup#getTenantId()
*/
public T tenantId(String tenantId) {
this.tenantId = tenantId;
return self();
}
public SecurityGroup build() {
return new SecurityGroup(id, name, description, tenantId);
}
public T fromSecurityGroup(SecurityGroup in) {
return this
.id(in.getId())
.name(in.getName())
.description(in.getDescription())
.tenantId(in.getTenantId());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final int id;
private final String name;
private final String description;
private final String tenantId;
@ConstructorProperties({
"id", "name", "description", "tenant_id"
})
protected SecurityGroup(int id, String name, @Nullable String description, @Nullable String tenantId) {
this.id = id;
this.name = checkNotNull(name, "name");
this.description = description;
this.tenantId = tenantId;
}
/**
* @return the id
*/
public int getId() {
return this.id;
}
/**
* @return the name
*/
public String getName() {
return this.name;
}
/**
* @return the description
*/
@Nullable
public String getDescription() {
return this.description;
}
/**
* @return the tenantId
*/
@Nullable
public String getTenantId() {
return this.tenantId;
}
@Override
public int hashCode() {
return Objects.hashCode(id, name, description, tenantId);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
SecurityGroup that = SecurityGroup.class.cast(obj);
return Objects.equal(this.id, that.id)
&& Objects.equal(this.name, that.name)
&& Objects.equal(this.description, that.description)
&& Objects.equal(this.tenantId, that.tenantId);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("id", id).add("name", name).add("description", description).add("tenantId", tenantId);
}
@Override
public String toString() {
return string().toString();
}
}

View File

@ -1,480 +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.openstack.nova.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
/**
* A server is a virtual machine instance in the OpenStack Nova system. Flavor and image are
* requisite elements when creating a server.
*
* @author Adrian Cole
*/
public class Server extends Resource {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromServer(this);
}
public abstract static class Builder<T extends Builder<T>> extends Resource.Builder<T> {
protected String name;
protected Map<String, String> metadata = ImmutableMap.of();
protected Addresses addresses;
protected String accessIPv4;
protected String accessIPv6;
protected String adminPass;
protected String flavorRef;
protected String hostId;
protected String imageRef;
protected String affinityId;
protected String uuid;
protected Flavor flavor;
protected Image image;
protected String keyName;
protected Set<SecurityGroup> securityGroups = ImmutableSet.of();
protected Date created;
protected Date updated;
protected Integer progress;
protected ServerStatus status;
/**
* @see Server#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
/**
* @see Server#getMetadata()
*/
public T metadata(Map<String, String> metadata) {
this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
return self();
}
/**
* @see Server#getAddresses()
*/
public T addresses(Addresses addresses) {
this.addresses = addresses;
return self();
}
/**
* @see Server#getAccessIPv4()
*/
public T accessIPv4(String accessIPv4) {
this.accessIPv4 = accessIPv4;
return self();
}
/**
* @see Server#getAccessIPv6()
*/
public T accessIPv6(String accessIPv6) {
this.accessIPv6 = accessIPv6;
return self();
}
/**
* @see Server#getAdminPass()
*/
public T adminPass(String adminPass) {
this.adminPass = adminPass;
return self();
}
/**
* @see Server#getFlavorRef()
*/
public T flavorRef(String flavorRef) {
this.flavorRef = flavorRef;
return self();
}
/**
* @see Server#getHostId()
*/
public T hostId(String hostId) {
this.hostId = hostId;
return self();
}
/**
* @see Server#getImageRef()
*/
public T imageRef(String imageRef) {
this.imageRef = imageRef;
return self();
}
/**
* @see Server#getAffinityId()
*/
public T affinityId(String affinityId) {
this.affinityId = affinityId;
return self();
}
/**
* @see Server#getUuid()
*/
public T uuid(String uuid) {
this.uuid = uuid;
return self();
}
/**
* @see Server#getFlavor()
*/
public T flavor(Flavor flavor) {
this.flavor = flavor;
return self();
}
/**
* @see Server#getImage()
*/
public T image(Image image) {
this.image = image;
return self();
}
/**
* @see Server#getKeyName()
*/
public T keyName(String keyName) {
this.keyName = keyName;
return self();
}
/**
* @see Server#getSecurityGroups()
*/
public T securityGroups(Set<SecurityGroup> securityGroups) {
this.securityGroups = ImmutableSet.copyOf(checkNotNull(securityGroups, "securityGroups"));
return self();
}
public T securityGroups(SecurityGroup... in) {
return securityGroups(ImmutableSet.copyOf(in));
}
/**
* @see Server#getCreated()
*/
public T created(Date created) {
this.created = created;
return self();
}
/**
* @see Server#getUpdated()
*/
public T updated(Date updated) {
this.updated = updated;
return self();
}
/**
* @see Server#getProgress()
*/
public T progress(Integer progress) {
this.progress = progress;
return self();
}
/**
* @see Server#getStatus()
*/
public T status(ServerStatus status) {
this.status = status;
return self();
}
public Server build() {
return new Server(id, links, orderedSelfReferences, name, metadata, addresses, accessIPv4, accessIPv6, adminPass,
flavorRef, hostId, imageRef, affinityId, uuid, flavor, image, keyName, securityGroups, created, updated,
progress, status);
}
public T fromServer(Server in) {
return super.fromResource(in)
.id(in.getId())
.name(in.getName())
.metadata(in.getMetadata())
.addresses(in.getAddresses())
.accessIPv4(in.getAccessIPv4())
.accessIPv6(in.getAccessIPv6())
.adminPass(in.getAdminPass())
.flavorRef(in.getFlavorRef())
.hostId(in.getHostId())
.imageRef(in.getImageRef())
.affinityId(in.getAffinityId())
.uuid(in.getUuid())
.flavor(in.getFlavor())
.image(in.getImage())
.keyName(in.getKeyName())
.securityGroups(in.getSecurityGroups())
.created(in.getCreated())
.updated(in.getUpdated())
.progress(in.getProgress())
.status(in.getStatus());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final String name;
private final Map<String, String> metadata;
private final Addresses addresses;
private final String accessIPv4;
private final String accessIPv6;
private final String adminPass;
private final String flavorRef;
private final String hostId;
private final String imageRef;
private final String affinityId;
private final String uuid;
private final Flavor flavor;
private final Image image;
private final String keyName;
private final Set<SecurityGroup> securityGroups;
private final Date created;
private final Date updated;
private final Integer progress;
private final ServerStatus status;
@ConstructorProperties({
"id", "links", "orderedSelfReferences", "name", "metadata", "addresses", "accessIPv4", "accessIPv6", "adminPass",
"flavorRef", "hostId", "imageRef", "affinityId", "uuid", "flavor", "image", "key_name", "security_groups",
"created", "updated", "progress", "status"
})
protected Server(int id, List<Map<String, String>> links, Map<LinkType, URI> orderedSelfReferences, String name,
@Nullable Map<String, String> metadata, @Nullable Addresses addresses, @Nullable String accessIPv4,
@Nullable String accessIPv6, @Nullable String adminPass, @Nullable String flavorRef, @Nullable String hostId,
@Nullable String imageRef, @Nullable String affinityId, @Nullable String uuid, @Nullable Flavor flavor,
@Nullable Image image, @Nullable String keyName, @Nullable Set<SecurityGroup> securityGroups,
@Nullable Date created, @Nullable Date updated, @Nullable Integer progress, @Nullable ServerStatus status) {
super(id, links, orderedSelfReferences);
this.name = checkNotNull(name, "name");
this.metadata = metadata == null ? ImmutableMap.<String, String>of() : ImmutableMap.copyOf(metadata);
this.addresses = addresses;
this.accessIPv4 = accessIPv4;
this.accessIPv6 = accessIPv6;
this.adminPass = adminPass;
this.flavorRef = flavorRef;
this.hostId = hostId;
this.imageRef = imageRef;
this.affinityId = affinityId;
this.uuid = uuid;
this.flavor = flavor;
this.image = image;
this.keyName = keyName;
this.securityGroups = securityGroups == null ? ImmutableSet.<SecurityGroup>of() : ImmutableSet.copyOf(securityGroups);
this.created = created;
this.updated = updated;
this.progress = progress;
this.status = status == null ? ServerStatus.UNKNOWN : status;
}
public String getName() {
return this.name;
}
public Map<String, String> getMetadata() {
return this.metadata;
}
@Nullable
public Addresses getAddresses() {
return this.addresses;
}
/**
* @return the accessIPv4
*/
@Nullable
public String getAccessIPv4() {
return this.accessIPv4;
}
/**
* @return the accessIPv6
*/
@Nullable
public String getAccessIPv6() {
return this.accessIPv6;
}
@Nullable
public String getAdminPass() {
return this.adminPass;
}
/**
* @deprecated in nova 1.1 api at the Diablo release, replaced by {@link #getFlavor()}
*/
@Nullable
public String getFlavorRef() {
return this.flavorRef;
}
/**
* The OpenStack Nova provisioning algorithm has an anti-affinity property that attempts to spread
* out customer VMs across hosts. Under certain situations, VMs from the same customer may be
* placed on the same host. hostId represents the host your cloud server runs on and can be used
* to determine this scenario if it's relevant to your application.
* <p/>
* Note: hostId is unique PER ACCOUNT and is not globally unique.
*/
@Nullable
public String getHostId() {
return this.hostId;
}
/**
* @deprecated in nova 1.1 api at the Diablo release, replaced by {@link #getImage()}.
*/
@Nullable
public String getImageRef() {
return this.imageRef;
}
@Nullable
public String getAffinityId() {
return this.affinityId;
}
@Nullable
public String getUuid() {
return this.uuid;
}
@Nullable
public Flavor getFlavor() {
return this.flavor;
}
public Image getImage() {
return this.image;
}
@Nullable
public String getKeyName() {
return this.keyName;
}
/**
* Actually, security groups are not returned by nova on server query but is
* needed when creating a server to specify a set of groups
*/
public Set<SecurityGroup> getSecurityGroups() {
return this.securityGroups;
}
@Nullable
public Date getCreated() {
return this.created;
}
@Nullable
public Date getUpdated() {
return this.updated;
}
@Nullable
public Integer getProgress() {
return this.progress;
}
/**
* Servers contain a status attribute that can be used as an indication of the current server
* state. Servers with an ACTIVE status are available for use.
*/
public ServerStatus getStatus() {
return this.status;
}
@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), name, metadata, addresses, accessIPv4, accessIPv6, adminPass, flavorRef,
hostId, imageRef, affinityId, uuid, flavor, image, keyName, securityGroups, created, updated);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Server that = Server.class.cast(obj);
return super.equals(that)
&& Objects.equal(this.name, that.name)
&& Objects.equal(this.metadata, that.metadata)
&& Objects.equal(this.addresses, that.addresses)
&& Objects.equal(this.accessIPv4, that.accessIPv4)
&& Objects.equal(this.accessIPv6, that.accessIPv6)
&& Objects.equal(this.adminPass, that.adminPass)
&& Objects.equal(this.flavorRef, that.flavorRef)
&& Objects.equal(this.hostId, that.hostId)
&& Objects.equal(this.imageRef, that.imageRef)
&& Objects.equal(this.affinityId, that.affinityId)
&& Objects.equal(this.uuid, that.uuid)
&& Objects.equal(this.flavor, that.flavor)
&& Objects.equal(this.image, that.image)
&& Objects.equal(this.keyName, that.keyName)
&& Objects.equal(this.securityGroups, that.securityGroups)
&& Objects.equal(this.created, that.created)
&& Objects.equal(this.updated, that.updated);
}
protected ToStringHelper string() {
return super.string()
.add("name", name).add("metadata", metadata).add("addresses", addresses)
.add("accessIPv4", accessIPv4).add("accessIPv6", accessIPv6).add("adminPass", adminPass)
.add("flavorRef", flavorRef).add("hostId", hostId).add("imageRef", imageRef).add("affinityId", affinityId)
.add("uuid", uuid).add("flavor", flavor).add("image", image).add("keyName", keyName)
.add("securityGroups", securityGroups).add("created", created).add("updated", updated)
.add("progress", progress).add("status", status);
}
}

View File

@ -1,54 +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.openstack.nova.domain;
/**
*
* Servers contain a status attribute that can be used as an indication of the current server state.
* Servers with an ACTIVE status are available for use.
* <p/>
* <h2>Note</h2>
* When the system changes a server's status from BUILD to ACTIVE the system will not be immediately
* available. The 'ACTIVE' label is really misleading in the fact that it just means the system
* doesn't have any activity going on related to it's configuration.
* <p/>
* Processes such as ssh will not be available until 5-10 seconds following the phase ACTIVE
* <ul>
* <li>[Web Hosting #119335]</li>
* </ul>
*
* @author Adrian Cole
*/
public enum ServerStatus {
ACTIVE, SUSPENDED, QUEUE_RESIZE, PREP_RESIZE, RESIZE, VERIFY_RESIZE, RESCUE, BUILD, PASSWORD, REBUILD, REBOOT, HARD_REBOOT, UNKNOWN, DELETE_IP, UNRECOGNIZED, DELETED;
public String value() {
return name();
}
public static ServerStatus fromValue(String v) {
try {
return valueOf(v);
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}

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.openstack.nova.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 org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException;
import org.jclouds.logging.Logger;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.util.Strings2;
/**
* This will parse and set an appropriate exception on the command object.
*
* @author Adrian Cole
*
*/
public class ParseNovaErrorFromHttpResponse implements HttpErrorHandler {
@Resource
protected Logger logger = Logger.NULL;
public static final Pattern RESOURCE_PATTERN = Pattern
.compile("^/v1[^/]*/[0-9]+/([^/]+)/([0-9]+)");
public void handleError(HttpCommand command, HttpResponse response) {
Exception exception = new HttpResponseException(command, response);
try {
String content = parseErrorFromContentOrNull(command, response);
exception = content != null ? new HttpResponseException(command, response, content) : exception;
switch (response.getStatusCode()) {
case 401:
exception = new AuthorizationException(exception.getMessage(), exception);
break;
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 409:
exception = new IllegalStateException(content);
break;
default:
exception = new HttpResponseException(command, response, content);
break;
}
} finally {
releasePayload(response);
command.setException(exception);
}
}
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
if (response.getPayload() != null) {
try {
return Strings2.toString(response.getPayload());
} catch (IOException e) {
logger.warn(e, "exception reading error from response", response);
}
}
return null;
}
}

View File

@ -1,244 +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.openstack.nova.options;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.beans.ConstructorProperties;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Named;
import org.jclouds.crypto.CryptoStreams;
import org.jclouds.http.HttpRequest;
import org.jclouds.openstack.nova.domain.SecurityGroup;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToJsonPayload;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class CreateServerOptions implements MapBinder {
@Inject
private BindToJsonPayload jsonBinder;
static class File {
private final String path;
private final String contents;
public File(String path, byte[] contents) {
this.path = checkNotNull(path, "path");
this.contents = CryptoStreams.base64(checkNotNull(contents, "contents"));
checkArgument(path.getBytes().length < 255, String.format(
"maximum length of path is 255 bytes. Path specified %s is %d bytes", path, path.getBytes().length));
checkArgument(contents.length < 10 * 1024, String.format(
"maximum size of the file is 10KB. Contents specified is %d bytes", contents.length));
}
public String getContents() {
return contents;
}
public String getPath() {
return path;
}
}
private class ServerRequest {
final String name;
final String imageRef;
final String flavorRef;
final String adminPass;
final Map<String, String> metadata;
final List<File> personality;
@Named("key_name")
final String keyName;
@Named("security_groups")
final Set<SecurityGroup> securityGroups;
@ConstructorProperties({"name", "imageRef", "flavorRef", "adminPass", "metadata", "personality", "key_name", "security_groups"})
private ServerRequest(String name, String imageRef, String flavorRef, String adminPass, Map<String, String> metadata,
List<File> personality, String keyName, Set<SecurityGroup> securityGroups) {
this.name = name;
this.imageRef = imageRef;
this.flavorRef = flavorRef;
this.adminPass = adminPass;
this.metadata = metadata.isEmpty() ? null : metadata;
this.personality = personality.isEmpty() ? null : personality;
this.keyName = keyName;
this.securityGroups = securityGroups.isEmpty() ? null : securityGroups;
}
}
private Map<String, String> metadata = Maps.newHashMap();
private List<File> files = Lists.newArrayList();
private Set<String> securityGroups = Sets.newHashSet();
private String keyName;
private String adminPass;
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
Set<SecurityGroup> groups = Sets.newLinkedHashSet();
for (String groupName : securityGroups) {
groups.add(SecurityGroup.builder().name(groupName).build());
}
ServerRequest server = new ServerRequest(
checkNotNull(postParams.get("name"), "name parameter not present").toString(),
checkNotNull(postParams.get("imageRef"), "imageRef parameter not present").toString(),
checkNotNull(postParams.get("flavorRef"), "flavorRef parameter not present").toString(),
adminPass,
metadata,
files,
keyName,
groups);
return bindToRequest(request, ImmutableMap.of("server", server));
}
/**
* You may further customize a cloud server by injecting data into the file system of the cloud
* server itself. This is useful, for example, for inserting ssh keys, setting configuration
* files, or storing data that you want to retrieve from within the instance itself. It is
* intended to provide a minimal amount of launch-time personalization. If significant
* customization is required, a custom image should be created. The max size of the file path
* data is 255 bytes while the max size of the file contents is 10KB. Note that the file contents
* should be encoded as a Base64 string and the 10KB limit refers to the number of bytes in the
* decoded data not the number of characters in the encoded data. The maximum number of file
* path/content pairs that can be supplied is 5. Any existing files that match the specified file
* will be renamed to include the extension bak followed by a time stamp. For example, the file
* /etc/passwd will be backed up as /etc/passwd.bak.1246036261.5785. All files will have root and
* the root group as owner and group owner, respectively and will allow user and group read
* access only (-r--r-----).
*/
public CreateServerOptions withFile(String path, byte[] contents) {
checkState(files.size() < 5, "maximum number of files allowed is 5");
files.add(new File(path, contents));
return this;
}
public CreateServerOptions withAdminPass(String adminPass) {
checkNotNull(adminPass, "adminPass");
this.adminPass = adminPass;
return this;
}
/**
* Custom cloud server metadata can also be supplied at launch time. This metadata is stored in
* the API system where it is retrievable by querying the API for server status. The maximum size
* of the metadata key and value is each 255 bytes and the maximum number of key-value pairs that
* can be supplied per server is 5.
*/
public CreateServerOptions withMetadata(Map<String, String> metadata) {
checkNotNull(metadata, "metadata");
checkArgument(metadata.size() <= 5, "you cannot have more then 5 metadata values. You specified: "
+ metadata.size());
for (Entry<String, String> entry : metadata.entrySet()) {
checkArgument(entry.getKey().getBytes().length < 255, String.format(
"maximum length of metadata key is 255 bytes. Key specified %s is %d bytes", entry.getKey(), entry
.getKey().getBytes().length));
checkArgument(entry.getKey().getBytes().length < 255, String.format(
"maximum length of metadata value is 255 bytes. Value specified for %s (%s) is %d bytes", entry
.getKey(), entry.getValue(), entry.getValue().getBytes().length));
}
this.metadata = metadata;
return this;
}
/**
* A keypair name can be defined when creating a server. This key will be
* linked to the server and used to SSH connect to the machine
*
* @param keyName
* @return
*/
public CreateServerOptions withKeyName(String keyName) {
checkNotNull(keyName, "keyName");
this.keyName = keyName;
return this;
}
/**
* Defines the security group name to be used when creating a server.
*
* @param groupName
* @return
*/
public CreateServerOptions withSecurityGroup(String groupName) {
checkNotNull(groupName, "groupName");
this.securityGroups.add(groupName);
return this;
}
public static class Builder {
/**
* @see CreateServerOptions#withFile(String,byte[])
*/
public static CreateServerOptions withFile(String path, byte[] contents) {
CreateServerOptions options = new CreateServerOptions();
return options.withFile(path, contents);
}
public static CreateServerOptions withAdminPass(String adminPass) {
CreateServerOptions options = new CreateServerOptions();
return options.withAdminPass(adminPass);
}
/**
* @see CreateServerOptions#withMetadata(Map<String, String>)
*/
public static CreateServerOptions withMetadata(Map<String, String> metadata) {
CreateServerOptions options = new CreateServerOptions();
return options.withMetadata(metadata);
}
/**
* @see CreateServerOptions#withKeyName(String)
*/
public static CreateServerOptions withKeyName(String keyName) {
CreateServerOptions options = new CreateServerOptions();
return options.withKeyName(keyName);
}
/**
* @see CreateServerOptions#withSecurityGroup(String)
*/
public static CreateServerOptions withSecurityGroup(String name) {
CreateServerOptions options = new CreateServerOptions();
return options.withSecurityGroup(name);
}
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
return jsonBinder.bindToRequest(request, input);
}
}

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.openstack.nova.options;
import java.util.Date;
import org.jclouds.openstack.options.BaseListOptions;
/**
* Options used to control the amount of detail in the request.
*
* @see BaseListOptions
* @see <a href="http://wiki.openstack.org/OpenStackAPI_1-1" />
* @author Adrian Cole
*/
public class ListOptions extends BaseListOptions {
public static final ListOptions NONE = new ListOptions();
/**
* unless used, only the name and id will be returned per row.
*
* @return
*/
public ListOptions withDetails() {
this.pathSuffix = "/detail";
return this;
}
/**
* {@inheritDoc}
*/
@Override
public ListOptions changesSince(Date ifModifiedSince) {
super.changesSince(ifModifiedSince);
return this;
}
/**
* {@inheritDoc}
*/
@Override
public ListOptions maxResults(int limit) {
super.maxResults(limit);
return this;
}
/**
* {@inheritDoc}
*/
@Override
public ListOptions startAt(long offset) {
super.startAt(offset);
return this;
}
public static class Builder {
/**
* @see ListOptions#withDetails()
*/
public static ListOptions withDetails() {
ListOptions options = new ListOptions();
return options.withDetails();
}
/**
* @see BaseListOptions#startAt(long)
*/
public static ListOptions startAt(long prefix) {
ListOptions options = new ListOptions();
return options.startAt(prefix);
}
/**
* @see BaseListOptions#maxResults(long)
*/
public static ListOptions maxResults(int maxKeys) {
ListOptions options = new ListOptions();
return options.maxResults(maxKeys);
}
/**
* @see BaseListOptions#changesSince(Date)
*/
public static ListOptions changesSince(Date since) {
ListOptions options = new ListOptions();
return options.changesSince(since);
}
}
}

View File

@ -1,80 +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.openstack.nova.options;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import javax.inject.Inject;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToJsonPayload;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
/**
*
*
* @author Adrian Cole
*
*/
public class RebuildServerOptions implements MapBinder {
@Inject
private BindToJsonPayload jsonBinder;
String imageRef;
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
Map<String, String> image = Maps.newHashMap();
if (imageRef != null)
image.put("imageRef", imageRef);
return jsonBinder.bindToRequest(request, ImmutableMap.of("rebuild", image));
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object toBind) {
throw new IllegalStateException("RebuildServer is a POST operation");
}
/**
* @param ref
* - reference of the image to rebuild the server with.
*/
public RebuildServerOptions withImage(String ref) {
checkNotNull(ref, "image reference should not be null");
checkArgument(!ref.isEmpty(), "image reference should not be empty");
this.imageRef = ref;
return this;
}
public static class Builder {
/**
* @see RebuildServerOptions#withImage(String)
*/
public static RebuildServerOptions withImage(String ref) {
RebuildServerOptions options = new RebuildServerOptions();
return options.withImage(ref);
}
}
}

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.openstack.nova.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.openstack.nova.NovaClient;
import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.domain.ServerStatus;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
*
* Tests to see if a task succeeds.
*
* @author Adrian Cole
*/
@Singleton
public class ServerActive implements Predicate<Server> {
private final NovaClient client;
@Resource
protected Logger logger = Logger.NULL;
@Inject
public ServerActive(NovaClient client) {
this.client = client;
}
public boolean apply(Server server) {
logger.trace("looking for state on server %s", checkNotNull(server, "server"));
server = refresh(server);
if (server == null)
return false;
logger.trace("%s: looking for server state %s: currently: %s", server.getId(),
ServerStatus.ACTIVE, server.getStatus());
return server.getStatus() == ServerStatus.ACTIVE;
}
private Server refresh(Server server) {
return client.getServer(server.getId());
}
}

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.openstack.nova.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.openstack.nova.NovaClient;
import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.domain.ServerStatus;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
*
* Tests to see if a task succeeds.
*
* @author Adrian Cole
*/
@Singleton
public class ServerDeleted implements Predicate<Server> {
private final NovaClient client;
@Resource
protected Logger logger = Logger.NULL;
@Inject
public ServerDeleted(NovaClient client) {
this.client = client;
}
public boolean apply(Server server) {
logger.trace("looking for state on server %s", checkNotNull(server, "server"));
server = refresh(server);
if (server == null)
return true;
logger.trace("%s: looking for server state %s: currently: %s", server.getId(),
ServerStatus.DELETED, server.getStatus());
return server.getStatus() == ServerStatus.DELETED;
}
private Server refresh(Server server) {
return client.getServer(server.getId());
}
}

View File

@ -1 +0,0 @@
org.jclouds.openstack.nova.NovaApiMetadata

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.openstack.nova;
import org.jclouds.compute.internal.BaseComputeServiceApiMetadataTest;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "NovaApiMetadataTest")
public class NovaApiMetadataTest extends BaseComputeServiceApiMetadataTest {
public NovaApiMetadataTest() {
super(new NovaApiMetadata());
}
}

View File

@ -1,782 +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.openstack.nova;
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withFile;
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withMetadata;
import static org.jclouds.openstack.nova.options.ListOptions.Builder.changesSince;
import static org.jclouds.openstack.nova.options.ListOptions.Builder.withDetails;
import static org.jclouds.openstack.nova.options.RebuildServerOptions.Builder.withImage;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Date;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
import org.jclouds.Fallbacks.FalseOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.openstack.filters.AddTimestampQuery;
import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.openstack.internal.TestOpenStackAuthenticationModule;
import org.jclouds.openstack.nova.config.NovaRestClientModule;
import org.jclouds.openstack.nova.domain.RebootType;
import org.jclouds.openstack.nova.options.CreateServerOptions;
import org.jclouds.openstack.nova.options.ListOptions;
import org.jclouds.openstack.nova.options.RebuildServerOptions;
import org.jclouds.providers.AnonymousProviderMetadata;
import org.jclouds.providers.ProviderMetadata;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.internal.BaseAsyncClientTest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code NovaAsyncClient}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", singleThreaded = true, testName = "NovaAsyncClientTest")
public class NovaAsyncClientTest extends BaseAsyncClientTest<NovaAsyncClient> {
private static final Class<? extends ListOptions[]> listOptionsVarargsClass = new ListOptions[]{}.getClass();
private static final Class<? extends CreateServerOptions[]> createServerOptionsVarargsClass = new CreateServerOptions[]{}
.getClass();
@Test
public void testCreateServer() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("createServer", String.class, String.class, String.class,
createServerOptionsVarargsClass);
HttpRequest request = processor.createRequest(method, "ralphie", 2, 1);
assertRequestLineEquals(request, "POST http://endpoint/vapi-version/servers?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, "{\"server\":{\"name\":\"ralphie\",\"imageRef\":\"2\",\"flavorRef\":\"1\"}}",
"application/json", false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
@Test
public void testCreateServerWithFile() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("createServer", String.class, String.class, String.class,
createServerOptionsVarargsClass);
HttpRequest request = processor
.createRequest(method, "ralphie", 2, 1, withFile("/etc/jclouds", "foo".getBytes()));
assertRequestLineEquals(request, "POST http://endpoint/vapi-version/servers?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(
request,
"{\"server\":{\"name\":\"ralphie\",\"imageRef\":\"2\",\"flavorRef\":\"1\",\"personality\":[{\"path\":\"/etc/jclouds\",\"contents\":\"Zm9v\"}]}}",
"application/json", false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
@Test
public void testCreateServerWithMetadata() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("createServer", String.class, String.class, String.class,
createServerOptionsVarargsClass);
HttpRequest request = processor.createRequest(method, "ralphie", 2, 1,
withMetadata(ImmutableMap.of("foo", "bar")));
assertRequestLineEquals(request, "POST http://endpoint/vapi-version/servers?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request,
"{\"server\":{\"name\":\"ralphie\",\"imageRef\":\"2\",\"flavorRef\":\"1\",\"metadata\":{\"foo\":\"bar\"}}}",
"application/json", false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
@Test
public void testCreateServerWithKeyName() throws Exception {
Method method = NovaAsyncClient.class.getMethod("createServer", String.class, String.class, String.class,
createServerOptionsVarargsClass);
HttpRequest request = processor.createRequest(method, "ralphie", 2, 1,
withMetadata(ImmutableMap.of("foo", "bar")).withKeyName("mykey"));
assertRequestLineEquals(request, "POST http://endpoint/vapi-version/servers?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request,
"{\"server\":{\"name\":\"ralphie\",\"imageRef\":\"2\",\"flavorRef\":\"1\",\"metadata\":{\"foo\":\"bar\"},\"key_name\":\"mykey\"}}",
"application/json", false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
@Test
public void testCreateServerWithAdminPass() throws Exception {
Method method = NovaAsyncClient.class.getMethod("createServer", String.class, String.class, String.class,
createServerOptionsVarargsClass);
HttpRequest request = processor.createRequest(method, "ralphie", 2, 1,
withMetadata(ImmutableMap.of("foo", "bar")).withAdminPass("mypass"));
assertRequestLineEquals(request, "POST http://endpoint/vapi-version/servers?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request,
"{\"server\":{\"name\":\"ralphie\",\"imageRef\":\"2\",\"flavorRef\":\"1\",\"adminPass\":\"mypass\",\"metadata\":{\"foo\":\"bar\"}}}",
"application/json", false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
public void testDeleteImage() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("deleteImage", int.class);
HttpRequest request = processor.createRequest(method, 2);
assertRequestLineEquals(request, "DELETE http://endpoint/vapi-version/images/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: */*\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, FalseOnNotFoundOr404.class);
checkFilters(request);
}
public void testListServers() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("listServers", listOptionsVarargsClass);
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, "GET http://endpoint/vapi-version/servers?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
Date now = new Date(10000000l);
public void testListServersOptions() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("listServers", listOptionsVarargsClass);
HttpRequest request = processor.createRequest(method, changesSince(now).maxResults(1).startAt(2));
assertRequestLineEquals(request,
"GET http://endpoint/vapi-version/servers?format=json&changes-since=10000&limit=1&offset=2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testListServersDetail() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("listServers", listOptionsVarargsClass);
HttpRequest request = processor.createRequest(method, withDetails());
assertRequestLineEquals(request, "GET http://endpoint/vapi-version/servers/detail?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetServer() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("getServer", int.class);
HttpRequest request = processor.createRequest(method, 2);
assertRequestLineEquals(request, "GET http://endpoint/vapi-version/servers/2?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetServerByUUID() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("getServer", String.class);
HttpRequest request = processor.createRequest(method, "dfdcd0a6-0a2f-11e1-8505-2837371c69ae");
assertRequestLineEquals(request, "GET http://endpoint/vapi-version/servers/dfdcd0a6-0a2f-11e1-8505-2837371c69ae?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
checkFilters(request);
}
public void testListFlavors() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("listFlavors", listOptionsVarargsClass);
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, "GET http://endpoint/vapi-version/flavors?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testListFlavorsOptions() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("listFlavors", listOptionsVarargsClass);
HttpRequest request = processor.createRequest(method, changesSince(now).maxResults(1).startAt(2));
assertRequestLineEquals(request,
"GET http://endpoint/vapi-version/flavors?format=json&changes-since=10000&limit=1&offset=2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testListFlavorsDetail() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("listFlavors", listOptionsVarargsClass);
HttpRequest request = processor.createRequest(method, withDetails());
assertRequestLineEquals(request, "GET http://endpoint/vapi-version/flavors/detail?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testListFlavorsDetailOptions() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("listFlavors", listOptionsVarargsClass);
HttpRequest request = processor.createRequest(method, withDetails().changesSince(now).maxResults(1).startAt(2));
assertRequestLineEquals(request,
"GET http://endpoint/vapi-version/flavors/detail?format=json&changes-since=10000&limit=1&offset=2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetFlavor() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("getFlavor", int.class);
HttpRequest request = processor.createRequest(method, 2);
assertRequestLineEquals(request, "GET http://endpoint/vapi-version/flavors/2?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetFlavorByUUID() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("getFlavor", String.class);
HttpRequest request = processor.createRequest(method, "209904b6-0a30-11e1-a0f0-2837371c69ae");
assertRequestLineEquals(request, "GET http://endpoint/vapi-version/flavors/209904b6-0a30-11e1-a0f0-2837371c69ae?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
checkFilters(request);
}
public void testListImages() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("listImages", listOptionsVarargsClass);
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, "GET http://endpoint/vapi-version/images?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testListImagesDetail() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("listImages", listOptionsVarargsClass);
HttpRequest request = processor.createRequest(method, withDetails());
assertRequestLineEquals(request, "GET http://endpoint/vapi-version/images/detail?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testListImagesOptions() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("listImages", listOptionsVarargsClass);
HttpRequest request = processor.createRequest(method, changesSince(now).maxResults(1).startAt(2));
assertRequestLineEquals(request,
"GET http://endpoint/vapi-version/images?format=json&changes-since=10000&limit=1&offset=2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testListImagesDetailOptions() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("listImages", listOptionsVarargsClass);
HttpRequest request = processor.createRequest(method, withDetails().changesSince(now).maxResults(1).startAt(2));
assertRequestLineEquals(request,
"GET http://endpoint/vapi-version/images/detail?format=json&changes-since=10000&limit=1&offset=2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetImage() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("getImage", int.class);
HttpRequest request = processor.createRequest(method, 2);
assertRequestLineEquals(request, "GET http://endpoint/vapi-version/images/2?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetImageByUUID() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("getImage", int.class);
HttpRequest request = processor.createRequest(method, "3bd52d90-0a30-11e1-83f5-2837371c69ae");
assertRequestLineEquals(request, "GET http://endpoint/vapi-version/images/3bd52d90-0a30-11e1-83f5-2837371c69ae?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
checkFilters(request);
}
public void testDeleteServer() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("deleteServer", int.class);
HttpRequest request = processor.createRequest(method, 2);
assertRequestLineEquals(request, "DELETE http://endpoint/vapi-version/servers/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: */*\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, FalseOnNotFoundOr404.class);
checkFilters(request);
}
public void testDeleteServerByUUID() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("deleteServer", String.class);
HttpRequest request = processor.createRequest(method, "db8a1ac6-0a35-11e1-a42f-2837371c69ae");
assertRequestLineEquals(request, "DELETE http://endpoint/vapi-version/servers/db8a1ac6-0a35-11e1-a42f-2837371c69ae HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: */*\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, FalseOnNotFoundOr404.class);
checkFilters(request);
}
public void testChangeAdminPass() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("changeAdminPass", int.class, String.class);
HttpRequest request = processor.createRequest(method, 2, "foo");
assertRequestLineEquals(request, "POST http://endpoint/vapi-version/servers/2/action HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: */*\n");
assertPayloadEquals(request, "{\"changePassword\":{\"adminPass\":\"foo\"}}", MediaType.APPLICATION_JSON, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
public void testChangeServerName() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("renameServer", int.class, String.class);
HttpRequest request = processor.createRequest(method, 2, "foo");
assertRequestLineEquals(request, "PUT http://endpoint/vapi-version/servers/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: */*\n");
assertPayloadEquals(request, "{\"server\":{\"name\":\"foo\"}}", MediaType.APPLICATION_JSON, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
public void testListAddresses() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("getAddresses", int.class);
HttpRequest request = processor.createRequest(method, 2);
assertRequestLineEquals(request, "GET http://endpoint/vapi-version/servers/2/ips?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
public void testListPublicAddresses() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("listPublicAddresses", int.class);
HttpRequest request = processor.createRequest(method, 2);
assertRequestLineEquals(request, "GET http://endpoint/vapi-version/servers/2/ips/public?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
@Test
public void testListPrivateAddresses() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("listPrivateAddresses", int.class);
HttpRequest request = processor.createRequest(method, 2);
assertRequestLineEquals(request, "GET http://endpoint/vapi-version/servers/2/ips/private?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
@Test
public void testCreateImageWithIpGroup() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("createImageFromServer", String.class, int.class);
HttpRequest request = processor.createRequest(method, "ralphie", 2);
assertRequestLineEquals(request, "POST http://endpoint/vapi-version/images?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, "{\"image\":{\"serverId\":2,\"name\":\"ralphie\"}}", MediaType.APPLICATION_JSON,
false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
private static final Class<? extends RebuildServerOptions[]> rebuildServerOptionsVarargsClass = new RebuildServerOptions[]{}
.getClass();
@Test
public void testRebuildServer() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("rebuildServer", int.class,
rebuildServerOptionsVarargsClass);
HttpRequest request = processor.createRequest(method, 3);
assertRequestLineEquals(request, "POST http://endpoint/vapi-version/servers/3/action?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: */*\n");
assertPayloadEquals(request, "{\"rebuild\":{}}", MediaType.APPLICATION_JSON, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
@Test
public void testRebuildServerWithImage() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("rebuildServer", int.class,
rebuildServerOptionsVarargsClass);
HttpRequest request = processor.createRequest(method, 3, withImage("2"));
assertRequestLineEquals(request, "POST http://endpoint/vapi-version/servers/3/action?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: */*\n");
assertPayloadEquals(request, "{\"rebuild\":{\"imageRef\":\"2\"}}", MediaType.APPLICATION_JSON, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
@Test
public void testReboot() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("rebootServer", int.class, RebootType.class);
HttpRequest request = processor.createRequest(method, 2, RebootType.HARD);
assertRequestLineEquals(request, "POST http://endpoint/vapi-version/servers/2/action?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: */*\n");
assertPayloadEquals(request, "{\"reboot\":{\"type\":\"HARD\"}}", MediaType.APPLICATION_JSON, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
@Test
public void testResize() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("resizeServer", int.class, int.class);
HttpRequest request = processor.createRequest(method, 2, 3);
assertRequestLineEquals(request, "POST http://endpoint/vapi-version/servers/2/action?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: */*\n");
assertPayloadEquals(request, "{\"resize\":{\"flavorId\":3}}", MediaType.APPLICATION_JSON, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
public void testConfirmResize() throws IOException, IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("confirmResizeServer", int.class);
HttpRequest request = processor.createRequest(method, 2);
assertRequestLineEquals(request, "POST http://endpoint/vapi-version/servers/2/action?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: */*\n");
assertPayloadEquals(request, "{\"confirmResize\":null}", MediaType.APPLICATION_JSON, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
public void testRevertResize() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("revertResizeServer", int.class);
HttpRequest request = processor.createRequest(method, 2);
assertRequestLineEquals(request, "POST http://endpoint/vapi-version/servers/2/action?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: */*\n");
assertPayloadEquals(request, "{\"revertResize\":null}", MediaType.APPLICATION_JSON, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null);
checkFilters(request);
}
public void testGetFloatingIP() throws SecurityException,
NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("getFloatingIP",
int.class);
HttpRequest request = processor.createRequest(method, 2);
assertRequestLineEquals(request,
"GET http://endpoint/vapi-version/os-floating-ips/2?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request,
UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method,
NullOnNotFoundOr404.class);
checkFilters(request);
}
public void testListFloatingIPs() throws SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("listFloatingIPs");
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request,
"GET http://endpoint/vapi-version/os-floating-ips?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetSecurityGroup() throws SecurityException,
NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("getSecurityGroup",
int.class);
HttpRequest request = processor.createRequest(method, 2);
assertRequestLineEquals(request,
"GET http://endpoint/vapi-version/os-security-groups/2?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request,
UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method,
NullOnNotFoundOr404.class);
checkFilters(request);
}
public void testListSecurityGroups() throws SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("listSecurityGroups");
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request,
"GET http://endpoint/vapi-version/os-security-groups?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<NovaAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<NovaAsyncClient>>() {
};
}
@Override
protected void checkFilters(HttpRequest request) {
assertEquals(request.getFilters().size(), 2);
assertEquals(request.getFilters().get(0).getClass(), AuthenticateRequest.class);
assertEquals(request.getFilters().get(1).getClass(), AddTimestampQuery.class);
}
@Override
protected Module createModule() {
return new TestNovaRestClientModule();
}
@ConfiguresRestClient
protected static class TestNovaRestClientModule extends NovaRestClientModule {
private TestNovaRestClientModule() {
super(new TestOpenStackAuthenticationModule());
}
}
protected String provider = "nova";
@Override
protected ProviderMetadata createProviderMetadata() {
return AnonymousProviderMetadata.forApiWithEndpoint(new NovaApiMetadata(), "http://endpoint");
}
}

View File

@ -1,415 +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.openstack.nova;
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withFile;
import static org.jclouds.openstack.nova.options.ListOptions.Builder.withDetails;
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.Map;
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.Payload;
import org.jclouds.openstack.nova.domain.Flavor;
import org.jclouds.openstack.nova.domain.Image;
import org.jclouds.openstack.nova.domain.ImageStatus;
import org.jclouds.openstack.nova.domain.RebootType;
import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.domain.ServerStatus;
import org.jclouds.openstack.nova.options.RebuildServerOptions;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen;
import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshException;
import org.jclouds.util.Strings2;
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.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.net.HostAndPort;
import com.google.inject.Injector;
/**
* Tests behavior of {@code NovaClient}
*
* @author Adrian Cole
*/
@Test(groups = "live", singleThreaded = true, testName = "NovaClientLiveTest")
public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest {
public NovaClientLiveTest() {
provider = "nova";
}
protected NovaClient client;
protected SshClient.Factory sshFactory;
protected Predicate<HostAndPort> socketTester;
@BeforeGroups(groups = { "integration", "live" })
@Override
public void setupContext() {
super.setupContext();
Injector injector = view.utils().injector();
client = injector.getInstance(NovaClient.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 testListServers() throws Exception {
Set<Server> response = client.listServers();
assert null != response;
long initialContainerCount = response.size();
assertTrue(initialContainerCount >= 0);
}
public void testListServersDetail() throws Exception {
Set<Server> response = client.listServers(withDetails());
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(withDetails());
assert null != response;
long imageCount = response.size();
assertTrue(imageCount >= 0);
for (Image image : response) {
assertTrue(image.getId() >= 1);
assert null != image.getName() : image;
assert null != image.getStatus() : image;
}
}
public void testGetImagesDetail() throws Exception {
Set<Image> response = client.listImages(withDetails());
assert null != response;
long imageCount = response.size();
assertTrue(imageCount >= 0);
for (Image image : response) {
Image newDetails = client.getImage(image.getId());
assertEquals(image, newDetails);
}
}
@Test
public void testGetImageDetailsNotFound() throws Exception {
assert client.getImage(12312987) == null;
}
@Test
public void testGetServerDetailsNotFound() throws Exception {
assert client.getServer(12312987) == null;
}
public void testGetServersDetail() throws Exception {
Set<Server> response = client.listServers(withDetails());
assert null != response;
long serverCount = response.size();
assertTrue(serverCount >= 0);
for (Server server : response) {
Server newDetails = client.getServer(server.getId());
assertEquals(server, 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(withDetails());
assert null != response;
long flavorCount = response.size();
assertTrue(flavorCount >= 0);
for (Flavor flavor : response) {
assertTrue(flavor.getId() >= 1);
assert null != flavor.getName() : flavor;
assert null != flavor.getDisk() : flavor;
assert null != flavor.getRam() : flavor;
}
}
public void testGetFlavorsDetail() throws Exception {
Set<Flavor> response = client.listFlavors(withDetails());
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;
}
// Server name must start with one or more alphabet and/or space and/or number. E.g. server 10,
// server, server1
private String serverPrefix = System.getProperty("user.name").replace('.', ' ');
private int serverId;
private String adminPass;
Map<String, String> metadata = ImmutableMap.of("jclouds", "nova");
private int serverId2;
private String createdImageRef;
public void testCreateServer() throws Exception {
String flavorId = "1";
Server server = null;
while (server == null) {
String serverName = serverPrefix + "createserver" + new SecureRandom().nextInt();
try {
server = client.createServer(serverName, template.getImageId(), flavorId, withFile("/etc/jclouds.txt",
"nova".getBytes()).withMetadata(metadata));
} catch (UndeclaredThrowableException e) {
HttpResponseException htpe = (HttpResponseException) e.getCause().getCause();
if (htpe.getResponse().getStatusCode() == 400)
continue;
throw e;
}
}
assertNotNull(server.getAdminPass());
serverId = server.getId();
adminPass = server.getAdminPass();
assertEquals(server.getStatus(), ServerStatus.BUILD);
blockUntilServerActive(serverId);
}
private void blockUntilServerActive(int serverId) throws InterruptedException {
Server currentDetails = null;
for (currentDetails = client.getServer(serverId); currentDetails.getStatus() != ServerStatus.ACTIVE; currentDetails = client
.getServer(serverId)) {
System.out.printf("blocking on status active%n%s%n", currentDetails);
Thread.sleep(5 * 1000);
}
}
private void blockUntilServerVerifyResize(int serverId) throws InterruptedException {
Server currentDetails = null;
for (currentDetails = client.getServer(serverId); currentDetails.getStatus() != ServerStatus.VERIFY_RESIZE; currentDetails = client
.getServer(serverId)) {
System.out.printf("blocking on status verify resize%n%s%n", currentDetails);
Thread.sleep(5 * 1000);
}
}
private void blockUntilImageActive(String imageRef) throws InterruptedException {
Image currentDetails = null;
for (currentDetails = client.getImage(imageRef); currentDetails.getStatus() != ImageStatus.ACTIVE; currentDetails = client
.getImage(imageRef)) {
System.out.printf("blocking on status active%n%s%n", currentDetails);
Thread.sleep(5 * 1000);
}
}
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer")
public void testServerDetails() throws Exception {
Server server = client.getServer(serverId);
assertNotNull(server.getHostId());
assertEquals(server.getStatus(), ServerStatus.ACTIVE);
assert server.getProgress() >= 0 : "newDetails.getProgress()" + server.getProgress();
assertEquals(Integer.valueOf(14362), server.getImage());
assertEquals(Integer.valueOf(1), server.getFlavor());
assertNotNull(server.getAddresses());
// listAddresses tests..
assertEquals(client.getAddresses(serverId), server.getAddresses());
assertEquals(server.getAddresses().getPublicAddresses().size(), 1);
assertEquals(client.listPublicAddresses(serverId), server.getAddresses().getPublicAddresses());
assertEquals(server.getAddresses().getPrivateAddresses().size(), 1);
assertEquals(client.listPrivateAddresses(serverId), server.getAddresses().getPrivateAddresses());
// check metadata
assertEquals(server.getMetadata(), metadata);
checkPassOk(server, adminPass);
}
/**
* this tests "personality" as the file looked up was sent during server creation
*/
private void checkPassOk(Server newDetails, String pass) throws IOException {
try {
doCheckPass(newDetails, pass);
} catch (SshException e) {// try twice in case there is a network timeout
try {
Thread.sleep(10 * 1000);
} catch (InterruptedException e1) {
}
doCheckPass(newDetails, pass);
}
}
private void doCheckPass(Server newDetails, String pass) throws IOException {
HostAndPort socket = HostAndPort.fromParts(Iterables.get(newDetails.getAddresses().getPublicAddresses(), 0).getAddress(), 22);
socketTester.apply(socket);
SshClient client = sshFactory.create(socket, LoginCredentials.builder().user("root").password(pass).build());
try {
client.connect();
Payload etcPasswd = client.get("/etc/jclouds.txt");
String etcPasswdContents = Strings2.toString(etcPasswd);
assertEquals("nova", etcPasswdContents.trim());
} finally {
if (client != null)
client.disconnect();
}
}
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer")
public void testRenameServer() throws Exception {
Server server = client.getServer(serverId);
String oldName = server.getName();
client.renameServer(serverId, oldName + "new");
blockUntilServerActive(serverId);
assertEquals(oldName + "new", client.getServer(serverId).getName());
}
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer")
public void testChangePassword() throws Exception {
client.changeAdminPass(serverId, "elmo");
blockUntilServerActive(serverId);
checkPassOk(client.getServer(serverId), "elmo");
this.adminPass = "elmo";
}
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testChangePassword")
public void testCreateImage() throws Exception {
Image image = client.createImageFromServer("hoofie", serverId);
assertEquals("hoofie", image.getName());
assertEquals(Integer.valueOf(serverId), image.getServerRef());
createdImageRef = image.getId()+"";
blockUntilImageActive(createdImageRef);
}
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateImage")
public void testRebuildServer() throws Exception {
client.rebuildServer(serverId, new RebuildServerOptions().withImage(createdImageRef));
blockUntilServerActive(serverId);
assertEquals(Integer.valueOf(createdImageRef).intValue(),client.getServer(serverId).getImage().getId());
}
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebuildServer")
public void testRebootHard() throws Exception {
client.rebootServer(serverId, RebootType.HARD);
blockUntilServerActive(serverId);
}
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootHard")
public void testRebootSoft() throws Exception {
client.rebootServer(serverId, RebootType.SOFT);
blockUntilServerActive(serverId);
}
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft")
public void testRevertResize() throws Exception {
client.resizeServer(serverId, 2);
blockUntilServerVerifyResize(serverId);
client.revertResizeServer(serverId);
blockUntilServerActive(serverId);
assertEquals(Integer.valueOf(1), client.getServer(serverId).getFlavorRef());
}
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft")
public void testConfirmResize() throws Exception {
client.resizeServer(serverId2, 2);
blockUntilServerVerifyResize(serverId2);
client.confirmResizeServer(serverId2);
blockUntilServerActive(serverId2);
assertEquals(Integer.valueOf(2), client.getServer(serverId2).getFlavorRef());
}
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = { "testRebootSoft", "testRevertResize", "testConfirmResize" })
void deleteServer2() {
if (serverId2 > 0) {
client.deleteServer(serverId2);
assert client.getServer(serverId2) == null;
}
}
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "deleteServer2")
void testDeleteImage() {
if (createdImageRef != null) {
client.deleteImage(createdImageRef);
assert client.getImage(createdImageRef) == null;
}
}
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testDeleteImage")
void deleteServer1() {
if (serverId > 0) {
client.deleteServer(serverId);
assert client.getServer(serverId) == null;
}
}
@AfterTest
void deleteServersOnEnd() {
if (serverId > 0) {
client.deleteServer(serverId);
}
if (serverId2 > 0) {
client.deleteServer(serverId2);
}
if (createdImageRef != null) {
client.deleteImage(createdImageRef);
assert client.getImage(createdImageRef) == null;
}
}
}

View File

@ -1,80 +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.openstack.nova.compute;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.internal.BaseComputeServiceLiveTest;
import org.jclouds.domain.LocationScope;
import org.jclouds.sshj.config.SshjSshClientModule;
import org.testng.annotations.Test;
import com.google.inject.Module;
/**
*
*
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, singleThreaded = true, testName = "NovaComputeServiceLiveTest")
public class NovaComputeServiceLiveTest extends BaseComputeServiceLiveTest {
public NovaComputeServiceLiveTest() {
provider = "nova";
}
@Override
protected Module getSshModule() {
return new SshjSshClientModule();
}
@Override
protected void checkNodes(Iterable<? extends NodeMetadata> nodes, String group, String task) throws IOException {
super.checkNodes(nodes, group, task);
for (NodeMetadata node : nodes) {
assertEquals(node.getLocation().getScope(), LocationScope.HOST);
}
}
@Test(enabled = true, dependsOnMethods = "testReboot", 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,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.openstack.nova.compute.config;
import org.jclouds.openstack.nova.domain.ServerStatus;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName ="NovaComputeServiceContextModuleTest")
public class NovaComputeServiceContextModuleTest {
public void testAllStatusCovered() {
for (ServerStatus state : ServerStatus.values()) {
assert NovaComputeServiceContextModule.toPortableNodeStatus.containsKey(state) : state;
}
}
}

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.openstack.nova.compute.functions;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.net.URISyntaxException;
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.openstack.nova.domain.Flavor;
import org.jclouds.openstack.nova.functions.ParseFlavorFromJsonResponseTest;
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, URISyntaxException {
Hardware flavor = convertFlavor();
Hardware tempFlavor = new HardwareBuilder().ids("1").name("256 MB Server")
.processors(ImmutableList.of(new Processor(2.0, 2.0)))
.ram(256)
.volumes(ImmutableList.of(
new VolumeBuilder().type(Volume.Type.LOCAL).size(10.0f).durable(true).bootDevice(true).build()))
.uri(new URI("http://servers.api.openstack.org/1234/flavors/1"))
.build();
assertEquals(flavor, tempFlavor);
}
public static Hardware convertFlavor() {
Flavor flavor = ParseFlavorFromJsonResponseTest.parseFlavor();
FlavorToHardware parser = new FlavorToHardware();
return parser.apply(flavor);
}
}

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.openstack.nova.compute.functions;
import static org.testng.Assert.assertEquals;
import java.net.URI;
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.json.Json;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.compute.config.NovaComputeServiceContextModule;
import org.jclouds.openstack.nova.functions.ParseImageFromJsonResponseTest;
import org.testng.annotations.Test;
import com.google.inject.Guice;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "NovaImageToImageTest")
public class NovaImageToImageTest {
@Test
public void test() {
Image image = 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").version("1286712000000")
.status(Image.Status.PENDING)
.uri(URI.create("https://servers.api.rackspacecloud.com/v1.1/1234/images/1")).build();
Image parsedImage = convertImage();
assertEquals(parsedImage, image);
assertEquals(parsedImage.getStatus(), Image.Status.PENDING);
}
public static Image convertImage() {
org.jclouds.openstack.nova.domain.Image image = ParseImageFromJsonResponseTest.parseImage();
NovaImageToImage parser = new NovaImageToImage(NovaComputeServiceContextModule.toPortableImageStatus,
new NovaImageToOperatingSystem(new BaseComputeServiceContextModule() {
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice
.createInjector(new GsonModule()).getInstance(Json.class))));
return parser.apply(image);
}
}

View File

@ -1,158 +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.openstack.nova.compute.functions;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
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.openstack.nova.compute.config.NovaComputeServiceContextModule;
import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.domain.ServerStatus;
import org.jclouds.openstack.nova.functions.ParseServerFromJsonResponseTest;
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")
public class ServerToNodeMetadataTest {
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() throws UnknownHostException, NoSuchMethodException,
ClassNotFoundException, URISyntaxException {
Map<ServerStatus, Status> serverStateToNodeStatus = NovaComputeServiceContextModule.toPortableNodeStatus;
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of();
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
Server server = ParseServerFromJsonResponseTest.parseServer();
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeStatus,
Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers.ofInstance(provider),
Suppliers.<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
NodeMetadata metadata = parser.apply(server);
NodeMetadata constructedMetadata = newNodeMetadataBuilder().build();
assertEquals(metadata, constructedMetadata);
}
private NodeMetadataBuilder newNodeMetadataBuilder() throws URISyntaxException {
return new NodeMetadataBuilder()
.status(Status.PENDING)
.publicAddresses(ImmutableSet.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"))
.privateAddresses(ImmutableSet.of("10.176.42.16", "::babe:10.176.42.16"))
.id("1234")
.providerId("1234")
.group("sample")
.name("sample-server")
.location(
new LocationBuilder().scope(LocationScope.HOST).id("e4d909c290d0fb1ca068ffaddf22cbd0")
.description("e4d909c290d0fb1ca068ffaddf22cbd0").parent(provider).build())
.userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"))
.uri(new URI("http://servers.api.openstack.org/1234/servers/1234"));
}
@Test
public void testApplyWhereImageFoundAndHardwareNotFound() throws UnknownHostException, NoSuchMethodException,
ClassNotFoundException, URISyntaxException {
Map<ServerStatus, Status> serverStateToNodeStatus = NovaComputeServiceContextModule.toPortableNodeStatus;
org.jclouds.compute.domain.Image jcImage = NovaImageToImageTest.convertImage();
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(jcImage);
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
Server server = ParseServerFromJsonResponseTest.parseServer();
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeStatus,
Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers.ofInstance(provider),
Suppliers.<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
NodeMetadata metadata = parser.apply(server);
NodeMetadata constructedMetadata = newNodeMetadataBuilder()
.imageId("2")
.operatingSystem(
new OperatingSystem.Builder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2")
.is64Bit(true).build()).build();
assertEquals(metadata, constructedMetadata);
}
@Test
public void testApplyWhereImageAndHardwareFound() throws UnknownHostException, NoSuchMethodException,
ClassNotFoundException, URISyntaxException {
Map<ServerStatus, Status> serverStateToNodeStatus = NovaComputeServiceContextModule.toPortableNodeStatus;
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(NovaImageToImageTest.convertImage());
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of(FlavorToHardwareTest.convertFlavor());
Server server = ParseServerFromJsonResponseTest.parseServer();
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeStatus,
Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers.ofInstance(provider),
Suppliers.<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
NodeMetadata metadata = parser.apply(server);
NodeMetadata constructedMetadata = newNodeMetadataBuilder()
.imageId("2")
.group("sample")
.operatingSystem(
new OperatingSystem.Builder().family(OsFamily.CENTOS).description("CentOS 5.2").version("5.2")
.is64Bit(true).build())
.hardware(
new HardwareBuilder()
.ids("1")
.name("256 MB Server")
.processors(ImmutableList.of(new Processor(1.0, 1.0)))
.ram(256)
.volumes(
ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(10.0f).durable(true)
.bootDevice(true).build()))
.uri(new URI("http://servers.api.openstack.org/1234/flavors/1")).build()).build();
assertEquals(metadata, constructedMetadata);
}
}

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.openstack.nova.domain;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import org.testng.annotations.Test;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
/**
* Tests behavior of {@code CreateImageBinder}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ServerStatusTest {
@Test
public void testAllKnownStatusesIsRecognized() {
List<String> knownStatuses = Arrays.asList(
"ACTIVE", "BUILD", "REBUILD", "SUSPENDED", "QUEUE_RESIZE",
"PREP_RESIZE", "RESIZE", "VERIFY_RESIZE",
"PASSWORD", "RESCUE", "REBOOT",
"HARD_REBOOT", "DELETE_IP", "UNKNOWN", "DELETED");
for (String status : knownStatuses) {
assertNotEquals(ServerStatus.UNRECOGNIZED, ServerStatus.fromValue(status));
}
List<String> allStatuses = Lists.newArrayList(knownStatuses);
allStatuses.add("UNRECOGNIZED");
Set<ServerStatus> enumValues = Sets.newHashSet(ServerStatus.values());
assertEquals(enumValues.size(), allStatuses.size());
for (String status : allStatuses) {
assertTrue(enumValues.contains(ServerStatus.valueOf(status)));
}
}
}

View File

@ -1,46 +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.openstack.nova.domain;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code CreateImageBinder}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ServerTest {
public void testStatusDoesntAffectEquals() {
Server server1 = Server.builder().id(1).name("hello").status(ServerStatus.ACTIVE).build();
Server server2 = Server.builder().id(1).name("hello").status(ServerStatus.BUILD).build();
assertEquals(server1, server2);
assertEquals(server1.hashCode(), server2.hashCode());
}
public void testProgressDoesntAffectEquals() {
Server server1 = Server.builder().id(1).name("hello").progress(1).build();
Server server2 = Server.builder().id(1).name("hello").progress(2).build();
assertEquals(server1, server2);
assertEquals(server1.hashCode(), server2.hashCode());
}
}

View File

@ -1,69 +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.openstack.nova.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.util.List;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.domain.Address;
import org.jclouds.openstack.nova.domain.Addresses;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code ParseAddressesFromJsonResponse}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ParseAddressesFromJsonResponseTest {
Injector i = Guice.createInjector(new GsonModule());
@Test
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/test_list_addresses.json");
UnwrapOnlyJsonValue<Addresses> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Addresses>>() {
}));
Addresses response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
List<Address> publicAddresses = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
Address.newString2AddressFunction()));
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
assertEquals(Sets.newHashSet(publicAddresses), response.getPublicAddresses());
assertEquals(Sets.newHashSet(privateAddresses), response.getPrivateAddresses());
}
}

View File

@ -1,148 +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.openstack.nova.functions;
import java.io.InputStream;
import java.util.List;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.handlers.ParseNovaErrorFromHttpResponse;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code ParseServerListFromJsonResponse}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ParseFaultFromJsonResponseTest")
public class ParseFaultFromJsonResponseTest {
Injector i = Guice.createInjector(new GsonModule());
@Test
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/test_list_servers.json");
@SuppressWarnings("unused")
UnwrapOnlyJsonValue<List<Server>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Server>>>() {
}));
// List<Server> response = parser.apply(new HttpResponse(413, "Over limit",
// Payloads.newInputStreamPayload(is)));
new ParseNovaErrorFromHttpResponse().handleError(createHttpCommand(), HttpResponse.builder().statusCode(413)
.message("Over limit").payload(is).build());
// assertEquals(response, expects);
}
@Test
public void testHandler() {
// InputStream is = getClass().getResourceAsStream("/test_error_handler.json");
//
//
// NovaErrorHandler handler = Guice.createInjector(new
// GsonModule()).getInstance(GoGridErrorHandler.class);
//
// HttpCommand command = createHttpCommand();
// handler.handleError(command,
// HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
//
// Exception createdException = command.getException();
//
// assertNotNull(createdException, "There should've been an exception generated");
// String message = createdException.getMessage();
// assertTrue(message.contains("No object found that matches your input criteria."),
// "Didn't find the expected error cause in the exception message");
// assertTrue(message.contains("IllegalArgumentException"),
// "Didn't find the expected error code in the exception message");
//
// // make sure the InputStream is closed
// try {
// is.available();
// throw new
// TestException("Stream wasn't closed by the GoGridErrorHandler when it should've");
// } catch (IOException e) {
// // this is the excepted output
// }
}
HttpCommand createHttpCommand() {
return new HttpCommand() {
private Exception exception;
@Override
public int incrementRedirectCount() {
return 0; // To change body of implemented methods use File | Settings | File Templates.
}
@Override
public int getRedirectCount() {
return 0; // To change body of implemented methods use File | Settings | File Templates.
}
@Override
public boolean isReplayable() {
return false; // To change body of implemented methods use File | Settings | File
// Templates.
}
@Override
public int incrementFailureCount() {
return 0; // To change body of implemented methods use File | Settings | File Templates.
}
@Override
public int getFailureCount() {
return 0; // To change body of implemented methods use File | Settings | File Templates.
}
@Override
public HttpRequest getCurrentRequest() {
return HttpRequest.builder().method("method").endpoint("http://endpoint").build();
}
@Override
public void setCurrentRequest(HttpRequest request) {
// To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void setException(Exception exception) {
this.exception = exception;
}
@Override
public Exception getException() {
return exception;
}
};
}
}

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.openstack.nova.functions;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.io.IOException;
import java.io.InputStream;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.domain.Flavor;
import org.testng.annotations.Test;
import com.google.gson.Gson;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code ParseFlavorFromJsonResponse}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ParseFlavorFromJsonResponseTest {
@Test
public void testParseFlavorFromJsonResponseTest() throws IOException {
Flavor response = parseFlavor();
String json = new Gson().toJson(response);
assertNotNull(json);
assertEquals(response.getId(), 1);
assertEquals(response.getName(), "256 MB Server");
assertEquals(response.getDisk().intValue(), 10);
assertEquals(response.getRam().intValue(), 256);
assertEquals(response.getVcpus().intValue(), 2);
}
public static Flavor parseFlavor() {
Injector i = Guice.createInjector(new GsonModule());
InputStream is = ParseFlavorFromJsonResponseTest.class.getResourceAsStream("/test_get_flavor_details.json");
UnwrapOnlyJsonValue<Flavor> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Flavor>>() {
}));
return parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
}
}

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.openstack.nova.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.util.List;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.domain.Flavor;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code ParseFlavorListFromJsonResponse}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ParseFlavorListFromJsonResponseTest {
Injector i = Guice.createInjector(new GsonModule());
@Test
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/test_list_flavors.json");
List<Flavor> expects = ImmutableList.of(Flavor.builder().id(1).name("256 MB Server").build(),
Flavor.builder().id(2).name("512 MB Server").build());
UnwrapOnlyJsonValue<List<Flavor>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Flavor>>>() {
}));
List<Flavor> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
assertEquals(response, expects);
}
@Test
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/test_list_flavors_detail.json");
UnwrapOnlyJsonValue<List<Flavor>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Flavor>>>() {
}));
List<Flavor> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
assertEquals(response.get(0).getId(), 1);
assertEquals(response.get(0).getName(), "256 MB Server");
assertEquals(response.get(0).getDisk(), Integer.valueOf(10));
assertEquals(response.get(0).getRam(), Integer.valueOf(256));
assertEquals(response.get(0).getVcpus(), Integer.valueOf(2));
assertEquals(response.get(1).getId(), 2);
assertEquals(response.get(1).getName(), "512 MB Server");
assertEquals(response.get(1).getDisk(), Integer.valueOf(20));
assertEquals(response.get(1).getRam(), Integer.valueOf(512));
assertEquals(response.get(1).getVcpus(), Integer.valueOf(5));
}
}

View File

@ -1,69 +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.openstack.nova.functions;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.io.IOException;
import java.io.InputStream;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.domain.FloatingIP;
import org.testng.annotations.Test;
import com.google.gson.Gson;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* @author chamerling
*
*/
@Test(groups = "unit")
public class ParseFloatingIPFromJsonResponse {
@Test
public void testParseFloatingIPFromJsonResponseTest() throws IOException {
FloatingIP response = parseFLoatingIP();
String json = new Gson().toJson(response);
assertNotNull(json);
assertEquals(response.getId(), 1);
assertEquals(response.getFixedIP(), "10.0.0.2");
assertEquals(response.getInstanceID(), 123);
assertEquals(response.getIp(), "10.0.0.3");
}
public static FloatingIP parseFLoatingIP() {
Injector i = Guice.createInjector(new GsonModule());
InputStream is = ParseFloatingIPFromJsonResponse.class.getResourceAsStream("/test_get_floatingip.json");
UnwrapOnlyJsonValue<FloatingIP> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<FloatingIP>>() {
}));
return parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
}
}

View File

@ -1,60 +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.openstack.nova.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.util.List;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.domain.FloatingIP;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* @author chamerling
*
*/
@Test(groups = "unit", testName = "ParseFloatingIPListFromJsonResponse")
public class ParseFloatingIPListFromJsonResponse {
Injector i = Guice.createInjector(new GsonModule());
@Test
public void testParseFloatingIPListFromJsonResponseTest() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/test_list_floatingips.json");
UnwrapOnlyJsonValue<List<FloatingIP>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<FloatingIP>>>() {
}));
List<FloatingIP> response = parser
.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
assertEquals(response.size(), 1);
FloatingIP floatingIP = FloatingIP.builder().id(1).ip("10.0.0.3").fixedIP("11.0.0.1").instanceID(12).build();
assertEquals(response.get(0), floatingIP);
}
}

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.openstack.nova.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.UnknownHostException;
import org.jclouds.date.DateService;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.json.config.GsonModule;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.openstack.nova.domain.Image;
import org.jclouds.openstack.nova.domain.ImageStatus;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code ParseImageFromJsonResponse}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ParseImageFromJsonResponseTest {
Injector i = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
}
}, new GsonModule());
DateService dateService = i.getInstance(DateService.class);
@Test
public void testApplyInputStreamDetails() throws UnknownHostException {
Image response = parseImage();
assertEquals(response.getId(), 2);
assertEquals(response.getName(), "CentOS 5.2");
assertEquals(response.getCreated(), dateService.iso8601SecondsDateParse("2010-08-10T12:00:00Z"));
assertEquals(response.getProgress(), Integer.valueOf(80));
assertEquals(response.getStatus(), ImageStatus.SAVING);
assertEquals(response.getUpdated(), dateService.iso8601SecondsDateParse(("2010-10-10T12:00:00Z")));
assertEquals(response.getServerRef(), "http://servers.api.openstack.org/v1.1/1234/servers/12");
assertEquals(response.getMetadata().get("ImageVersion"), "1.5");
assertEquals(response.getMetadata().get("ImageType"), "Gold");
assertEquals(response.getMetadata().size(), 2);
}
public static Image parseImage() {
Injector i = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
}
}, new GsonModule());
InputStream is = ParseImageFromJsonResponseTest.class.getResourceAsStream("/test_get_image_details.json");
UnwrapOnlyJsonValue<Image> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Image>>() {
}));
Image response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
return response;
}
}

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.openstack.nova.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.util.List;
import org.jclouds.date.DateService;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.json.config.GsonModule;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.openstack.nova.domain.Image;
import org.jclouds.openstack.nova.domain.ImageStatus;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code ParseImageListFromJsonResponse}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ParseImageListFromJsonResponseTest {
Injector i = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
}
}, new GsonModule());
DateService dateService = i.getInstance(DateService.class);
@Test
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/test_list_images.json");
List<Image> expects = ImmutableList.of(Image.builder().id(1).name("CentOS 5.2").build(),
Image.builder().id(743).name("My Server Backup").build());
UnwrapOnlyJsonValue<List<Image>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Image>>>() {
}));
List<Image> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
assertEquals(response, expects);
}
@Test
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/test_list_images_detail.json");
UnwrapOnlyJsonValue<List<Image>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Image>>>() {
}));
List<Image> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
assertEquals(response.get(0).getId(), 1);
assertEquals(response.get(0).getName(), "CentOS 5.2");
assertEquals(response.get(0).getCreated(), dateService.iso8601SecondsDateParse("2010-08-10T12:00:00Z"));
assertEquals(response.get(0).getProgress(), null);
assertEquals(response.get(0).getServerRef(), null);
assertEquals(response.get(0).getStatus(), ImageStatus.ACTIVE);
assertEquals(response.get(0).getUpdated(), dateService.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));
assertEquals(response.get(0).getMetadata().get("ImageType"), "Gold");
assertEquals(response.get(0).getMetadata().get("ImageVersion"), "1.5");
assertEquals(response.get(0).getMetadata().size(), 2);
assertEquals(response.get(1).getId(), 743);
assertEquals(response.get(1).getName(), "My Server Backup");
assertEquals(response.get(1).getCreated(), dateService.iso8601SecondsDateParse("2009-07-07T09:56:16Z"));
assertEquals(response.get(1).getProgress(), Integer.valueOf(80));
assertEquals(response.get(1).getStatus(), ImageStatus.SAVING);
assertEquals(response.get(1).getUpdated(), dateService.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));
assertEquals(response.get(1).getServerRef(), "http://servers.api.openstack.org/v1.1/1234/servers/12");
// short form of reference
assertEquals(response.get(2).getServerRef(), "12");
}
}

View File

@ -1,79 +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.openstack.nova.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.util.List;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.domain.Address;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code ParseInetAddressListFromJsonResponse}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ParseInetAddressListFromJsonResponseTest {
Injector i = Guice.createInjector(new GsonModule());
@Test
public void testPublic() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/test_list_addresses_public.json");
UnwrapOnlyJsonValue<List<Address>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Address>>>() {
}));
List<Address> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
assertEquals(
response,
ImmutableList.of(Address.valueOf("67.23.10.132"), Address.valueOf("::babe:67.23.10.132"),
Address.valueOf("67.23.10.131"), Address.valueOf("::babe:4317:0A83")));
}
@Test
public void testPrivate() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/test_list_addresses_private.json");
UnwrapOnlyJsonValue<List<Address>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Address>>>() {
}));
List<Address> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
assertEquals(
response,
ImmutableList.of(Address.valueOf("67.23.10.132"), Address.valueOf("::babe:67.23.10.132"),
Address.valueOf("67.23.10.131"), Address.valueOf("::babe:4317:0A83")));
}
}

View File

@ -1,70 +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.openstack.nova.functions;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.io.IOException;
import java.io.InputStream;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.domain.SecurityGroup;
import org.testng.annotations.Test;
import com.google.gson.Gson;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* @author chamerling
*
*/
@Test(groups = "unit")
public class ParseSecurityGroupFromJsonResponse {
@Test
public void testParseSecurityGroupFromJsonResponseTest() throws IOException {
SecurityGroup response = parseSecurityGroup();
String json = new Gson().toJson(response);
assertNotNull(json);
assertNotNull(response);
assertEquals(response.getId(), 0);
assertEquals(response.getName(), "name0");
assertEquals(response.getDescription(), "description0");
assertEquals(response.getTenantId(), "tenant0");
}
public static SecurityGroup parseSecurityGroup() {
Injector i = Guice.createInjector(new GsonModule());
InputStream is = ParseFloatingIPFromJsonResponse.class.getResourceAsStream("/test_get_security_group.json");
UnwrapOnlyJsonValue<SecurityGroup> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<SecurityGroup>>() {
}));
return parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
}
}

View File

@ -1,73 +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.openstack.nova.functions;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.domain.SecurityGroup;
import org.testng.annotations.Test;
import com.google.gson.Gson;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* @author chamerling
*
*/
@Test(groups = "unit")
public class ParseSecurityGroupsListFromJsonResponse {
Injector i = Guice.createInjector(new GsonModule());
@Test
public void testParseSecurityGroupsFromJsonResponseTest() throws IOException {
List<SecurityGroup> response = parseSecurityGroups();
String json = new Gson().toJson(response);
assertNotNull(json);
assertEquals(response.size(), 1);
assertEquals(response.get(0).getId(), 1);
assertEquals(response.get(0).getName(), "name1");
assertEquals(response.get(0).getDescription(), "description1");
assertEquals(response.get(0).getTenantId(), "tenant1");
}
public static List<SecurityGroup> parseSecurityGroups() {
Injector i = Guice.createInjector(new GsonModule());
InputStream is = ParseFloatingIPFromJsonResponse.class.getResourceAsStream("/test_list_security_groups.json");
UnwrapOnlyJsonValue<List<SecurityGroup>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<SecurityGroup>>>() {
}));
return parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
}
}

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.openstack.nova.functions;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.text.ParseException;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.domain.ServerStatus;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
@Test(groups = "unit")
public class ParseServerFromJsonNoAddressesResponseTest {
@Test
public void testApplyInputStreamDetails() throws UnknownHostException, NoSuchMethodException,
ClassNotFoundException, ParseException {
Server response = parseServer();
assertEquals(response.getId(), 847);
assertEquals(response.getName(), "cmsNode-fa2");
assertEquals(response.getImageRef(), "http://dragon004.hw.griddynamics.net:8774/v1.1/images/106");
assertEquals(response.getFlavorRef(), "http://dragon004.hw.griddynamics.net:8774/v1.1/flavors/2");
assertEquals(response.getStatus(), ServerStatus.BUILD);
assertTrue(response.getAddresses().getPublicAddresses().isEmpty());
assertTrue(response.getAddresses().getPrivateAddresses().isEmpty());
}
public static Server parseServer() throws NoSuchMethodException, ClassNotFoundException {
Injector i = Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
super.configure();
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
}
});
InputStream is = ParseServerFromJsonNoAddressesResponseTest.class
.getResourceAsStream("/test_get_server_detail_no_addresses.json");
UnwrapOnlyJsonValue<Server> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Server>>() {
}));
return parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
}
}

View File

@ -1,105 +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.openstack.nova.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Locale;
import java.util.SimpleTimeZone;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.domain.Address;
import org.jclouds.openstack.nova.domain.Addresses;
import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.domain.ServerStatus;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code ParseServerFromJsonResponse} for the transitional nova api 1.1 in the
* Diablo release
*
* @author Matt Stephenson
*/
@Test(groups = "unit")
public class ParseServerFromJsonResponseDiabloTest {
@Test
public void testApplyInputStreamDetails() throws Exception {
Server response = parseServer();
assertEquals(response.getId(), 15);
assertEquals(response.getName(), "sample-server");
assertEquals(response.getImage().getURI(), new URI("http://servers.api.openstack.org/1234/images/1"));
assertEquals(response.getFlavor().getURI(), new URI("http://servers.api.openstack.org/1234/flavors/1"));
assertEquals(response.getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
assertEquals(response.getStatus(), ServerStatus.BUILD);
assertEquals(response.getProgress(), Integer.valueOf(60));
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
dateFormat.setTimeZone(new SimpleTimeZone(0, "GMT"));
assertEquals(response.getCreated(), dateFormat.parse("2010-08-10T12:00:00Z"));
assertEquals(response.getUpdated(), dateFormat.parse("2010-10-10T12:00:00Z"));
List<Address> publicAddresses = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
Address.newString2AddressFunction()));
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
Addresses addresses1 = Addresses.builder().publicAddresses(publicAddresses).privateAddresses(privateAddresses).build();
assertEquals(response.getAddresses(), addresses1);
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
assertEquals(response.getAddresses(), addresses1);
assertEquals(response.getAccessIPv4(), "67.23.10.132");
assertEquals(response.getAccessIPv6(), "::babe:67.23.10.132");
}
public static Server parseServer() throws NoSuchMethodException, ClassNotFoundException {
Injector i = Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
super.configure();
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
}
});
InputStream is = ParseServerFromJsonResponseDiabloTest.class
.getResourceAsStream("/test_get_server_detail_diablo.json");
UnwrapOnlyJsonValue<Server> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Server>>() {
}));
return parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
}
}

View File

@ -1,102 +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.openstack.nova.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Locale;
import java.util.SimpleTimeZone;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.domain.Address;
import org.jclouds.openstack.nova.domain.Addresses;
import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.domain.ServerStatus;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code ParseServerFromJsonResponse}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ParseServerFromJsonResponseTest {
@Test
public void testApplyInputStreamDetails() throws UnknownHostException, NoSuchMethodException,
ClassNotFoundException, ParseException {
Server response = parseServer();
assertEquals(response.getId(), 1234);
assertEquals(response.getName(), "sample-server");
assertEquals(response.getImageRef(), "https://servers.api.rackspacecloud.com/v1.1/1234/images/1");
assertEquals(response.getFlavorRef(), "http://servers.api.openstack.org/1234/flavors/1");
assertEquals(response.getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
assertEquals(response.getStatus(), ServerStatus.BUILD);
assertEquals(response.getProgress(), Integer.valueOf(60));
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
dateFormat.setTimeZone(new SimpleTimeZone(0, "GMT"));
assertEquals(response.getCreated(), dateFormat.parse("2010-08-10T12:00:00Z"));
assertEquals(response.getUpdated(), dateFormat.parse("2010-10-10T12:00:00Z"));
List<Address> publicAddresses = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
Address.newString2AddressFunction()));
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
Addresses addresses1 = Addresses.builder().publicAddresses(publicAddresses).privateAddresses(privateAddresses).build();
assertEquals(response.getAddresses(), addresses1);
assertEquals(response.getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
assertEquals(response.getAddresses(), addresses1);
}
public static Server parseServer() throws NoSuchMethodException, ClassNotFoundException {
Injector i = Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
super.configure();
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
}
});
InputStream is = ParseServerFromJsonResponseTest.class.getResourceAsStream("/test_get_server_detail.json");
UnwrapOnlyJsonValue<Server> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Server>>() {
}));
return parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
}
}

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.openstack.nova.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.util.List;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.domain.Address;
import org.jclouds.openstack.nova.domain.Addresses;
import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.domain.ServerStatus;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code ParseServerListFromJsonResponse}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ParseServerListFromJsonResponseTest {
Injector i = Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
super.configure();
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
}
});
@Test
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/test_list_servers.json");
List<Server> expects = ImmutableList.of(Server.builder().id(1234).name("sample-server").build(),
Server.builder().id(5678).name("sample-server2").build());
UnwrapOnlyJsonValue<List<Server>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Server>>>() {
}));
List<Server> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
assertEquals(response, expects);
}
@Test
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/test_list_servers_detail.json");
UnwrapOnlyJsonValue<List<Server>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Server>>>() {
}));
List<Server> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
assertEquals(response.get(0).getId(), 1234);
assertEquals(response.get(0).getName(), "sample-server");
assertEquals(response.get(0).getImageRef(), "https://servers.api.rackspacecloud.com/v1.1/32278/images/1234");
assertEquals(response.get(0).getFlavorRef(), "https://servers.api.rackspacecloud.com/v1.1/32278/flavors/1");
assertEquals(response.get(0).getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
assertEquals(response.get(0).getUuid(), "d84e2086-fc0d-11e0-8e08-2837371c69ae");
assertEquals(response.get(0).getStatus(), ServerStatus.BUILD);
assertEquals(response.get(0).getProgress(), Integer.valueOf(60));
List<Address> publicAddresses = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
Address.newString2AddressFunction()));
List<Address> privateAddresses = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"), Address.newString2AddressFunction()));
Addresses addresses1 = Addresses.builder().publicAddresses(publicAddresses).privateAddresses(privateAddresses).build();
assertEquals(response.get(0).getAddresses(), addresses1);
assertEquals(response.get(0).getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
assertEquals(response.get(1).getId(), 5678);
assertEquals(response.get(1).getName(), "sample-server2");
assertEquals(response.get(1).getImageRef(), "https://servers.api.rackspacecloud.com/v1.1/32278/images/1");
assertEquals(response.get(1).getFlavorRef(), "1");
assertEquals(response.get(1).getAffinityId(), "b414fa41cb37b97dcb58d6c76112af1258e9eae2");
assertEquals(response.get(1).getHostId(), "9e107d9d372bb6826bd81d3542a419d6");
assertEquals(response.get(1).getUuid(), "e66d54d4-fc0d-11e0-b93f-2837371c69ae");
assertEquals(response.get(1).getStatus(), ServerStatus.ACTIVE);
assertEquals(response.get(1).getProgress(), null);
List<Address> publicAddresses2 = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("67.23.10.133", "::babe:67.23.10.133"), Address.newString2AddressFunction()));
List<Address> privateAddresses2 = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("10.176.42.17", "::babe:10.176.42.17"), Address.newString2AddressFunction()));
Addresses addresses2 = Addresses.builder().publicAddresses(publicAddresses2).privateAddresses(privateAddresses2).build();
assertEquals(response.get(1).getAddresses(), addresses2);
assertEquals(response.get(1).getMetadata(), ImmutableMap.of("Server Label", "DB 1"));
assertEquals(response.get(1).getURI().toString(), "http://servers.api.openstack.org/1234/servers/56789");
}
}

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.openstack.nova.options;
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withAdminPass;
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withFile;
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withSecurityGroup;
import static org.testng.Assert.assertEquals;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseFlavorFromJsonResponse}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class CreateServerOptionsTest {
Injector injector = Guice.createInjector(new GsonModule());
@Test
public void testAddPayloadToRequestMapOfStringStringHttpRequest() {
CreateServerOptions options = new CreateServerOptions();
HttpRequest request = buildRequest(options);
assertEquals("{\"server\":{\"name\":\"foo\",\"imageRef\":\"1\",\"flavorRef\":\"2\"}}", request.getPayload().getRawContent());
}
private HttpRequest buildRequest(CreateServerOptions options) {
injector.injectMembers(options);
HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost").build();;
options.bindToRequest(request, ImmutableMap.<String,Object>of("name", "foo", "imageRef", "1", "flavorRef", "2"));
return request;
}
@Test
public void testWithFile() {
CreateServerOptions options = new CreateServerOptions();
options.withFile("/tmp/rhubarb", "foo".getBytes());
HttpRequest request = buildRequest(options);
assertFile(request);
}
@Test
public void testWithFileStatic() {
CreateServerOptions options = withFile("/tmp/rhubarb", "foo".getBytes());
HttpRequest request = buildRequest(options);
assertFile(request);
}
@Test
public void testWithSecurityGroup() {
CreateServerOptions options = withSecurityGroup("mygroup");
HttpRequest request = buildRequest(options);
assertEquals(
request.getPayload().getRawContent(),
"{\"server\":{\"name\":\"foo\",\"imageRef\":\"1\",\"flavorRef\":\"2\",\"security_groups\":[{\"id\":0,\"name\":\"mygroup\"}]}}");
}
@Test
public void testWithSecurityGroups() {
CreateServerOptions options = withSecurityGroup("mygroup").withSecurityGroup("myothergroup");
HttpRequest request = buildRequest(options);
assertEquals(
request.getPayload().getRawContent(),
"{\"server\":{\"name\":\"foo\",\"imageRef\":\"1\",\"flavorRef\":\"2\",\"security_groups\":[{\"id\":0,\"name\":\"myothergroup\"},{\"id\":0,\"name\":\"mygroup\"}]}}");
}
@Test
public void testWithAdminPass() {
CreateServerOptions options = withAdminPass("mypassword");
HttpRequest request = buildRequest(options);
assertEquals(
request.getPayload().getRawContent(),
"{\"server\":{\"name\":\"foo\",\"imageRef\":\"1\",\"flavorRef\":\"2\",\"adminPass\":\"mypassword\"}}");
}
private void assertFile(HttpRequest request) {
assertEquals(request.getPayload().getRawContent(),
"{\"server\":{\"name\":\"foo\",\"imageRef\":\"1\",\"flavorRef\":\"2\",\"personality\":[{\"path\":\"/tmp/rhubarb\",\"contents\":\"Zm9v\"}]}}");
}
@Test
public void testWithMetadata() {
}
}

View File

@ -1,88 +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.openstack.nova.options;
import static org.jclouds.openstack.nova.options.ListOptions.Builder.changesSince;
import static org.jclouds.openstack.nova.options.ListOptions.Builder.maxResults;
import static org.jclouds.openstack.nova.options.ListOptions.Builder.startAt;
import static org.jclouds.openstack.nova.options.ListOptions.Builder.withDetails;
import static org.testng.Assert.assertEquals;
import java.util.Date;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
/**
* Tests behavior of {@code ListOptions}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ListOptionsTest {
public void testWithDetails() {
ListOptions options = new ListOptions().withDetails();
assertEquals(options.buildPathSuffix(), "/detail");
}
public void testWithDetailsStatic() {
ListOptions options = withDetails();
assertEquals(options.buildPathSuffix(), "/detail");
}
public void testChangesSince() {
Date ifModifiedSince = new Date();
ListOptions options = new ListOptions().changesSince(ifModifiedSince);
assertEquals(ImmutableList.of(ifModifiedSince.getTime() / 1000 + ""), options
.buildQueryParameters().get("changes-since"));
}
public void testStartAt() {
long offset = 1;
ListOptions options = new ListOptions().startAt(offset);
assertEquals(ImmutableList.of("1"), options.buildQueryParameters().get("offset"));
}
public void testMaxResults() {
int limit = 1;
ListOptions options = new ListOptions().maxResults(limit);
assertEquals(ImmutableList.of("1"), options.buildQueryParameters().get("limit"));
}
public void testChangesSinceStatic() {
Date ifModifiedSince = new Date();
ListOptions options = changesSince(ifModifiedSince);
assertEquals(ImmutableList.of(ifModifiedSince.getTime() / 1000 + ""), options
.buildQueryParameters().get("changes-since"));
}
public void testStartAtStatic() {
long offset = 1;
ListOptions options = startAt(offset);
assertEquals(ImmutableList.of("1"), options.buildQueryParameters().get("offset"));
}
public void testMaxResultsStatic() {
int limit = 1;
ListOptions options = maxResults(limit);
assertEquals(ImmutableList.of("1"), options.buildQueryParameters().get("limit"));
}
}

View File

@ -1,76 +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.openstack.nova.options;
import static org.jclouds.openstack.nova.options.RebuildServerOptions.Builder.withImage;
import static org.testng.Assert.assertEquals;
import java.util.HashMap;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseFlavorFromJsonResponse}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class RebuildServerOptionsTest {
Injector injector = Guice.createInjector(new GsonModule());
@Test
public void testAddPayloadToRequestMapOfStringStringHttpRequest() {
RebuildServerOptions options = new RebuildServerOptions();
HttpRequest request = buildRequest(options);
assertEquals("{\"rebuild\":{}}", request.getPayload().getRawContent());
}
private HttpRequest buildRequest(RebuildServerOptions options) {
injector.injectMembers(options);
HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost").build();;
options.bindToRequest(request, new HashMap<String, Object>());
return request;
}
@Test
public void testWithServer() {
RebuildServerOptions options = new RebuildServerOptions();
options.withImage("3");
HttpRequest request = buildRequest(options);
assertRebuild(request);
}
@Test
public void testWithServerStatic() {
RebuildServerOptions options = withImage("3");
HttpRequest request = buildRequest(options);
assertRebuild(request);
}
private void assertRebuild(HttpRequest request) {
assertEquals("{\"rebuild\":{\"imageRef\":\"3\"}}", request.getPayload().getRawContent());
}
}

View File

@ -1,166 +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="BLOBSTOREFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-blobstore.log" />
<param name="Append" value="true" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %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>
<!-- A time/date based rolling appender -->
<appender name="SSHFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-ssh.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="ASYNCSSH" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="SSHFILE" />
</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>
<appender name="ASYNCBLOBSTORE" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="BLOBSTOREFILE" />
</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.ssh">
<priority value="DEBUG" />
<appender-ref ref="ASYNCSSH" />
</category>
<category name="jclouds.wire">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<category name="jclouds.blobstore">
<priority value="DEBUG" />
<appender-ref ref="ASYNCBLOBSTORE" />
</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,9 +0,0 @@
{
"overLimit" : {
"code" : 413,
"message" : "OverLimit Retry...",
"details" : "Error Details...",
"retryAt" : "2010-08-01T00:00:00Z"
}
}

View File

@ -1,25 +0,0 @@
{
"flavor" : {
"id" : 1,
"name" : "256 MB Server",
"ram" : 256,
"disk" : 10,
"vcpus" : 2,
"links": [
{
"rel" : "self",
"href" : "http://servers.api.openstack.org/v1.1/1234/flavors/1"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.computev1.1+xml",
"href" : "http://servers.api.openstack.org/1234/flavors/1"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.computev1.1+json",
"href" : "http://servers.api.openstack.org/1234/flavors/1"
}
]
}
}

View File

@ -1,9 +0,0 @@
{
"floating_ip" :
{
"id" : 1,
"ip" : "10.0.0.3",
"fixed_ip" : "10.0.0.2",
"instance_id" : 123
}
}

View File

@ -1,31 +0,0 @@
{
"image" : {
"id" : 2,
"name" : "CentOS 5.2",
"serverRef" : "http://servers.api.openstack.org/v1.1/1234/servers/12",
"updated" : "2010-10-10T12:00:00Z",
"created" : "2010-08-10T12:00:00Z",
"status" : "SAVING",
"progress" : 80,
"metadata" : {
"ImageVersion" : "1.5",
"ImageType" : "Gold"
},
"links": [
{
"rel" : "self",
"href" : "http://servers.api.openstack.org/v1.1/1234/images/1"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.computev1.1+xml",
"href" : "http://servers.api.openstack.org/1234/images/1"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.computev1.1+json",
"href" : "https://servers.api.rackspacecloud.com/v1.1/1234/images/1"
}
]
}
}

View File

@ -1,34 +0,0 @@
{
"security_group":
{
"rules": [
{
"from_port": 22,
"group": {},
"ip_protocol": "tcp",
"to_port": 22,
"parent_group_id": 28,
"ip_range": {
"cidr": "10.2.6.0/24"
},
"id": 108
},
{
"from_port": 22,
"group": {
"tenant_id": "admin",
"name": "11111"
},
"ip_protocol": "tcp",
"to_port": 22,
"parent_group_id": 28,
"ip_range": {},
"id": 109
}
],
"tenant_id": "tenant0",
"id": 0,
"name": "name0",
"description": "description0"
}
}

View File

@ -1,46 +0,0 @@
{
"server" : {
"id" : 1234,
"name" : "sample-server",
"imageRef" : "https://servers.api.rackspacecloud.com/v1.1/1234/images/1",
"flavorRef" : "http://servers.api.openstack.org/1234/flavors/1",
"updated" : "2010-10-10T12:00:00Z",
"created" : "2010-08-10T12:00:00Z",
"hostId" : "e4d909c290d0fb1ca068ffaddf22cbd0",
"affinityId" : "fc88bcf8394db9c8d0564e08ca6a9724188a84d1",
"status" : "BUILD",
"progress" : 60,
"addresses" : {
"public": [
{"version" : 4, "addr" : "67.23.10.132"},
{"version" : 6, "addr" : "::babe:67.23.10.132"},
{"version" : 4, "addr" : "67.23.10.131"},
{"version" : 6, "addr" : "::babe:4317:0A83"}
],
"private" : [
{"version" : 4, "addr" : "10.176.42.16"},
{"version" : 6, "addr" : "::babe:10.176.42.16"}
]
},
"metadata" : {
"Server Label" : "Web Head 1",
"Image Version" : "2.1"
},
"links": [
{
"rel" : "self",
"href" : "http://servers.api.openstack.org/v1.1/1234/servers/1234"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+xml",
"href" : "http://servers.api.openstack.org/1234/servers/1234"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+json",
"href" : "http://servers.api.openstack.org/1234/servers/1234"
}
]
}
}

View File

@ -1,80 +0,0 @@
{
"server": {
"id": 15,
"uuid": "52415800-8b69-11e0-9b19-734f000004d2",
"tenant_id": "1234",
"user_id": "5678",
"name": "sample-server",
"updated": "2010-10-10T12:00:00Z",
"created": "2010-08-10T12:00:00Z",
"hostId": "e4d909c290d0fb1ca068ffaddf22cbd0",
"accessIPv4" : "67.23.10.132",
"accessIPv6" : "::babe:67.23.10.132",
"status": "BUILD",
"progress": 60,
"key_name": null,
"config_drive": "",
"image" : {
"id": "1",
"links": [
{
"rel": "bookmark",
"href": "http://servers.api.openstack.org/1234/images/1"
}
]
},
"flavor" : {
"id": "1",
"links": [
{
"rel": "bookmark",
"href": "http://servers.api.openstack.org/1234/flavors/1"
}
]
},
"addresses": {
"public" : [
{
"version": 4,
"addr": "67.23.10.132"
},
{
"version": 6,
"addr": "::babe:67.23.10.132"
},
{
"version": 4,
"addr": "67.23.10.131"
},
{
"version": 6,
"addr": "::babe:4317:0A83"
}
],
"private" : [
{
"version": 4,
"addr": "10.176.42.16"
},
{
"version": 6,
"addr": "::babe:10.176.42.16"
}
]
},
"metadata": {
"Server Label": "Web Head 1",
"Image Version": "2.1"
},
"links": [
{
"rel": "self",
"href": "http://servers.api.openstack.org/v1.1/1234/servers/52415800-8b69-11e0-9b19-734f000004d2"
},
{
"rel": "bookmark",
"href": "http://servers.api.openstack.org/1234/servers/52415800-8b69-11e0-9b19-734f000004d2"
}
]
}
}

View File

@ -1,20 +0,0 @@
{
"server" : {
"status":"BUILD",
"hostId":"",
"addresses": {
"public":[],
"private":[]
},
"imageRef":"http://dragon004.hw.griddynamics.net:8774/v1.1/images/106",
"adminPass":"MHfyHXPoj88on737",
"flavorRef":"http://dragon004.hw.griddynamics.net:8774/v1.1/flavors/2",
"links" : [
{"href":"http://dragon004.hw.griddynamics.net:8774/v1.1/servers/847","rel":"self"},
{"href":"http://dragon004.hw.griddynamics.net:8774/v1.1/servers/847","type":"application/json","rel":"bookmark"},
{"href":"http://dragon004.hw.griddynamics.net:8774/v1.1/servers/847","type":"application/xml","rel":"bookmark"}],
"name" : "cmsNode-fa2",
"id":847,
"metadata" : {}
}
}

View File

@ -1,15 +0,0 @@
{
"addresses" : {
"public" : [
{"version" : 4, "addr" : "67.23.10.132"},
{"version" : 6, "addr" : "::babe:67.23.10.132"},
{"version" : 4, "addr" : "67.23.10.131"},
{"version" : 6, "addr" : "::babe:4317:0A83"}
],
"private" : [
{"version" : 4, "addr" : "10.176.42.16"},
{"version" : 6, "addr" : "::babe:10.176.42.16"}
]
}
}

View File

@ -1,8 +0,0 @@
{
"private":[
{"version" : 4, "addr" : "67.23.10.132"},
{"version" : 6, "addr" : "::babe:67.23.10.132"},
{"version" : 4, "addr" : "67.23.10.131"},
{"version" : 6, "addr" : "::babe:4317:0A83"}
]
}

View File

@ -1,8 +0,0 @@
{
"public" : [
{"version" : 4, "addr" : "67.23.10.132"},
{"version" : 6, "addr" : "::babe:67.23.10.132"},
{"version" : 4, "addr" : "67.23.10.131"},
{"version" : 6, "addr" : "::babe:4317:0A83"}
]
}

View File

@ -1,46 +0,0 @@
{
"flavors" : [
{
"id" : 1,
"name" : "256 MB Server",
"links": [
{
"rel" : "self",
"href" : "http://servers.api.openstack.org/v1.1/1234/flavors/1"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+xml",
"href" : "http://servers.api.openstack.org/1234/flavors/1"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+json",
"href" : "http://servers.api.openstack.org/1234/flavors/1"
}
]
},
{
"id" : 2,
"name" : "512 MB Server",
"links": [
{
"rel" : "self",
"href" : "http://servers.api.openstack.org/v1.1/1234/flavors/2"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+xml",
"href" : "http://servers.api.openstack.org/1234/flavors/2"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+json",
"href" : "http://servers.api.openstack.org/1234/flavors/2"
}
]
}
]
}

View File

@ -1,50 +0,0 @@
{
"flavors" : [
{
"id" : 1,
"name" : "256 MB Server",
"ram" : 256,
"disk" : 10,
"vcpus" : 2,
"links": [
{
"rel" : "self",
"href" : "http://servers.api.openstack.org/v1.1/1234/flavors/1"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+xml",
"href" : "http://servers.api.openstack.org/1234/flavors/1"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+json",
"href" : "http://servers.api.openstack.org/1234/flavors/1"
}
]
},
{
"id" : 2,
"name" : "512 MB Server",
"ram" : 512,
"disk" : 20,
"vcpus" : 5,
"links": [
{
"rel" : "self",
"href" : "http://servers.api.openstack.org/v1.1/1234/flavors/2"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+xml",
"href" : "http://servers.api.openstack.org/1234/flavors/2"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+json",
"href" : "http://servers.api.openstack.org/1234/flavors/2"
}
]
}
]
}

View File

@ -1,10 +0,0 @@
{
"floating_ips" : [
{
"id" : 1,
"ip" : "10.0.0.3",
"fixed_ip": "11.0.0.1",
"instance_id": 12
}
]
}

View File

@ -1,44 +0,0 @@
{
"images" : [
{
"id" : 1,
"name" : "CentOS 5.2",
"links": [
{
"rel" : "self",
"href" : "http://servers.api.openstack.org/v1.1/1234/images/1"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+xml",
"href" : "http://servers.api.openstack.org/1234/images/1"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+json",
"href" : "http://servers.api.openstack.org/1234/images/1"
}
]
},
{
"id" : 743,
"name" : "My Server Backup",
"links": [
{
"rel" : "self",
"href" : "http://servers.api.openstack.org/v1.1/1234/images/743"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+xml",
"href" : "http://servers.api.openstack.org/1234/images/743"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+json",
"href" : "http://servers.api.openstack.org/1234/images/743"
}
]
}
]
}

View File

@ -1,84 +0,0 @@
{
"images" : [
{
"id" : 1,
"name" : "CentOS 5.2",
"updated" : "2010-10-10T12:00:00Z",
"created" : "2010-08-10T12:00:00Z",
"status" : "ACTIVE",
"metadata" : {
"ImageType" : "Gold",
"ImageVersion" : "1.5"
},
"links": [
{
"rel" : "self",
"href" : "http://servers.api.openstack.org/v1.1/1234/images/1"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+xml",
"href" : "http://servers.api.openstack.org/1234/images/1"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+json",
"href" : "http://servers.api.openstack.org/1234/images/1"
}
]
},
{
"id" : 743,
"name" : "My Server Backup",
"serverRef" : "http://servers.api.openstack.org/v1.1/1234/servers/12",
"updated" : "2010-10-10T12:00:00Z",
"created" : "2009-07-07T09:56:16Z",
"status" : "SAVING",
"progress" : 80,
"links": [
{
"rel" : "self",
"href" : "http://servers.api.openstack.org/v1.1/1234/images/743"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+xml",
"href" : "http://servers.api.openstack.org/1234/images/743"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+json",
"href" : "http://servers.api.openstack.org/1234/images/743"
}
]
},
{
"id" : 5,
"name" : "CentOS 5.2",
"serverRef" : 12,
"updated" : "2010-10-10T12:00:00Z",
"created" : "2010-08-10T12:00:00Z",
"status" : "ACTIVE",
"metadata" : {
"ImageType" : "Gold",
"ImageVersion" : "1.5"
},
"links": [
{
"rel" : "self",
"href" : "http://servers.api.openstack.org/v1.1/1234/images/1"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+xml",
"href" : "http://servers.api.openstack.org/1234/images/1"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+json",
"href" : "http://servers.api.openstack.org/1234/images/1"
}
]
}
]
}

View File

@ -1,51 +0,0 @@
{
"security_groups":[
{
"rules":[
{
"from_port":22,
"group":{
},
"ip_protocol":"tcp",
"to_port":22,
"parent_group_id":3,
"ip_range":{
"cidr":"0.0.0.0/0"
},
"id":107
},
{
"from_port":7600,
"group":{
},
"ip_protocol":"tcp",
"to_port":7600,
"parent_group_id":3,
"ip_range":{
"cidr":"0.0.0.0/0"
},
"id":118
},
{
"from_port":8084,
"group":{
},
"ip_protocol":"tcp",
"to_port":8084,
"parent_group_id":3,
"ip_range":{
"cidr":"0.0.0.0/0"
},
"id":119
}
],
"tenant_id":"tenant1",
"id":1,
"name":"name1",
"description":"description1"
}
]
}

View File

@ -1,45 +0,0 @@
{
"servers" : [
{
"id" : 1234,
"name" : "sample-server",
"links": [
{
"rel" : "self",
"href" : "http://servers.api.openstack.org/v1.1/1234/servers/1234"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+xml",
"href" : "http://servers.api.openstack.org/1234/servers/1234"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+json",
"href" : "http://servers.api.openstack.org/1234/servers/1234"
}
]
},
{
"id" : 5678,
"name" : "sample-server2",
"links": [
{
"rel" : "self",
"href" : "http://servers.api.openstack.org/v1.1/1234/servers/5678"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+xml",
"href" : "http://servers.api.openstack.org/1234/servers/5678"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+json",
"href" : "http://servers.api.openstack.org/1234/servers/5678"
}
]
}
]
}

View File

@ -1,85 +0,0 @@
{
"servers" : [
{
"id" : 1234,
"name" : "sample-server",
"imageRef" : "https://servers.api.rackspacecloud.com/v1.1/32278/images/1234",
"flavorRef" : "https://servers.api.rackspacecloud.com/v1.1/32278/flavors/1",
"updated" : "2010-10-10T12:00:00Z",
"created" : "2010-08-10T12:00:00Z",
"hostId" : "e4d909c290d0fb1ca068ffaddf22cbd0",
"affinityId" : "fc88bcf8394db9c8d0564e08ca6a9724188a84d1",
"uuid" : "d84e2086-fc0d-11e0-8e08-2837371c69ae",
"status" : "BUILD",
"progress" : 60,
"addresses" : {
"public" : [
{"version" : 4, "addr" : "67.23.10.132"},
{"version" : 6, "addr" : "::babe:67.23.10.132"},
{"version" : 4, "addr" : "67.23.10.131"},
{"version" : 6, "addr" : "::babe:4317:0A83"}
],
"private" : [
{"version" : 4, "addr" : "10.176.42.16"},
{"version" : 6, "addr" : "::babe:10.176.42.16"}
]
},
"metadata" : {
"Server Label" : "Web Head 1",
"Image Version" : "2.1"
},
"links": [
{
"rel" : "self",
"href" : "http://servers.api.openstack.org/v1.1/1234/servers/1234"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+xml",
"href" : "http://servers.api.openstack.org/1234/servers/1234"
},
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+json",
"href" : "http://servers.api.openstack.org/1234/servers/1234"
}
]
},
{
"id" : 5678,
"name" : "sample-server2",
"imageRef" : "https://servers.api.rackspacecloud.com/v1.1/32278/images/1",
"flavorRef" : 1,
"updated" : "2010-10-10T12:00:00Z",
"created" : "2010-08-10T12:00:00Z",
"hostId" : "9e107d9d372bb6826bd81d3542a419d6",
"affinityId" : "b414fa41cb37b97dcb58d6c76112af1258e9eae2",
"uuid" : "e66d54d4-fc0d-11e0-b93f-2837371c69ae",
"status" : "ACTIVE",
"addresses" : {
"public" : [
{"version" : 4, "addr" : "67.23.10.133"},
{"version" : 6, "addr" : "::babe:67.23.10.133"}
],
"private" : [
{"version" : 4, "addr" : "10.176.42.17"},
{"version" : 6, "addr" : "::babe:10.176.42.17"}
]
},
"metadata" : {
"Server Label" : "DB 1"
},
"links": [
{
"rel" : "self",
"href" : "http://servers.api.openstack.org/v1.1/1234/servers/5678"
},
{
"rel" : "bookmark",
"href" : "http://servers.api.openstack.org/1234/servers/56789"
}
]
}
]
}

View File

@ -46,7 +46,6 @@
<module>vcloud</module>
<module>elasticstack</module>
<module>atmos</module>
<module>nova</module>
<module>swift</module>
<module>openstack-keystone</module>
<module>openstack-cinder</module>