unit test fixes

This commit is contained in:
Dmitri Babaev 2011-04-18 04:01:18 +04:00 committed by Dmitri Babaev
parent cf82aab594
commit 69462fb51c
27 changed files with 1187 additions and 1241 deletions

View File

@ -18,26 +18,14 @@
*/
package org.jclouds.openstack.nova.domain;
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import javax.annotation.Nullable;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.google.common.collect.Maps;
/**
* 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.
* An image is a collection of files used to create or rebuild a server.
*
* @author Adrian Cole
*/
@ -47,7 +35,7 @@ public class Image extends Resource {
private int id;
private String name;
private Integer progress;
private Integer serverId;
private String serverRef;
private ImageStatus status;
private Date updated;
private Map<String, String> metadata = Maps.newHashMap();
@ -92,12 +80,12 @@ public class Image extends Resource {
return progress;
}
public void setServerId(Integer serverId) {
this.serverId = serverId;
public void setServerRef(String serverRef) {
this.serverRef = serverRef;
}
public Integer getServerId() {
return serverId;
public String getServerRef() {
return serverRef;
}
public void setStatus(ImageStatus status) {
@ -133,7 +121,7 @@ public class Image extends Resource {
int result = 1;
result = prime * result + id;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((serverId == null) ? 0 : serverId.hashCode());
result = prime * result + ((serverRef == null) ? 0 : serverRef.hashCode());
return result;
}
@ -162,7 +150,7 @@ public class Image extends Resource {
@Override
public String toString() {
return "Image [created=" + created + ", id=" + id + ", name=" + name + ", serverId="
+ serverId + "]";
+ serverRef + "]";
}
}

View File

@ -22,14 +22,12 @@ 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.net.URI;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.jclouds.encryption.internal.Base64;
import org.jclouds.http.HttpRequest;
import org.jclouds.openstack.nova.domain.Addresses;
import org.jclouds.rest.binders.BindToJsonPayload;
import com.google.common.collect.ImmutableMap;
@ -75,8 +73,6 @@ public class CreateServerOptions extends BindToJsonPayload {
final String flavorRef;
Map<String, String> metadata;
List<File> personality;
Integer sharedIpGroupId;
Addresses addresses;
private ServerRequest(String name, String imageRef, String flavorRef) {
this.name = name;
@ -88,7 +84,6 @@ public class CreateServerOptions extends BindToJsonPayload {
private Map<String, String> metadata = Maps.newHashMap();
private List<File> files = Lists.newArrayList();
private String publicIp;
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
@ -100,13 +95,9 @@ public class CreateServerOptions extends BindToJsonPayload {
server.metadata = metadata;
if (files.size() > 0)
server.personality = files;
if (publicIp != null) {
server.addresses = new Addresses();
server.addresses.getPublicAddresses().add(publicIp);
server.addresses.setPrivateAddresses(null);
}
return bindToRequest(request, ImmutableMap.of("server", server));
}
return bindToRequest(request, ImmutableMap.of("server", server));
}
/**
* You may further customize a cloud server by injecting data into the file system of the cloud

View File

@ -19,6 +19,7 @@
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;
@ -35,13 +36,13 @@ import com.google.common.collect.Maps;
*
*/
public class RebuildServerOptions extends BindToJsonPayload {
Integer imageId;
String imageRef;
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
Map<String, Integer> image = Maps.newHashMap();
if (imageId != null)
image.put("imageId", imageId);
Map<String, String> image = Maps.newHashMap();
if (imageRef != null)
image.put("imageRef", imageRef);
return super.bindToRequest(request, ImmutableMap.of("rebuild", image));
}
@ -51,24 +52,23 @@ public class RebuildServerOptions extends BindToJsonPayload {
}
/**
*
* @param id
* of the image to rebuild the server with.
* @param ref - reference of the image to rebuild the server with.
*/
public RebuildServerOptions withImage(int id) {
checkArgument(id > 0, "server id must be a positive number");
this.imageId = id;
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(int)
* @see RebuildServerOptions#withImage(String)
*/
public static RebuildServerOptions withImage(int id) {
public static RebuildServerOptions withImage(String ref) {
RebuildServerOptions options = new RebuildServerOptions();
return options.withImage(id);
return options.withImage(ref);
}
}
}

View File

@ -39,7 +39,9 @@ import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.functions.*;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
@ -78,7 +80,7 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
assertRequestLineEquals(request, "POST http://endpoint/vapiversion/servers?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, "{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1}}",
assertPayloadEquals(request, "{\"server\":{\"name\":\"ralphie\",\"imageRef\":2,\"flavorRef\":1}}",
"application/json", false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
@ -100,7 +102,7 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(
request,
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"personality\":[{\"path\":\"/etc/jclouds\",\"contents\":\"Zm9v\"}]}}",
"{\"server\":{\"name\":\"ralphie\",\"imageRef\":2,\"flavorRef\":1,\"personality\":[{\"path\":\"/etc/jclouds\",\"contents\":\"Zm9v\"}]}}",
"application/json", false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
@ -121,7 +123,7 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
assertRequestLineEquals(request, "POST http://endpoint/vapiversion/servers?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request,
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"metadata\":{\"foo\":\"bar\"}}}",
"{\"server\":{\"name\":\"ralphie\",\"imageRef\":2,\"flavorRef\":1,\"metadata\":{\"foo\":\"bar\"}}}",
"application/json", false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
@ -499,11 +501,11 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
public void testRebuildServerWithImage() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("rebuildServer", int.class,
rebuildServerOptionsVarargsClass);
HttpRequest request = processor.createRequest(method, 3, withImage(2));
HttpRequest request = processor.createRequest(method, 3, withImage("2"));
assertRequestLineEquals(request, "POST http://endpoint/vapiversion/servers/3/action?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, "{\"rebuild\":{\"imageId\":2}}", MediaType.APPLICATION_JSON, false);
assertPayloadEquals(request, "{\"rebuild\":{\"imageRef\":2}}", MediaType.APPLICATION_JSON, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);

View File

@ -18,20 +18,33 @@
*/
package org.jclouds.openstack.nova;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.inject.Injector;
import com.google.inject.Module;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.openstack.nova.PropertyHelper.overridePropertyFromSystemProperty;
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.security.SecureRandom;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.Constants;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.domain.Credentials;
import org.jclouds.http.HttpResponseException;
import org.jclouds.io.Payload;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.openstack.nova.domain.*;
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;
@ -43,18 +56,12 @@ import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import java.io.IOException;
import java.security.SecureRandom;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.openstack.nova.PropertyHelper.overridePropertyFromSystemProperty;
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.*;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.inject.Injector;
import com.google.inject.Module;
/**
* Tests behavior of {@code NovaClient}
@ -74,15 +81,6 @@ public class NovaClientLiveTest {
protected String endpoint;
protected String apiversion;
private String serverPrefix = System.getProperty("user.name") + ".cs";
private int serverId;
private String adminPass;
Map<String, String> metadata = ImmutableMap.of("jclouds", "rackspace");
private String ip;
private int serverId2;
private String adminPass2;
private int imageId;
protected Properties setupProperties() throws IOException {
Properties overrides = new Properties();
@ -214,14 +212,14 @@ public class NovaClientLiveTest {
public void testGetServersDetail() throws Exception {
Set<Server> response = client.listServers(withDetails());
assert null != response;
assertTrue(response.size() >= 0);
long serverCount = response.size();
assertTrue(serverCount >= 0);
for (Server server : response) {
Server newDetails = client.getServer(server.getId());
assertEquals(server, newDetails);
}
}
@Test
public void testListFlavors() throws Exception {
Set<Flavor> response = client.listFlavors();
assert null != response;
@ -234,7 +232,6 @@ public class NovaClientLiveTest {
}
@Test
public void testListFlavorsDetail() throws Exception {
Set<Flavor> response = client.listFlavors(withDetails());
assert null != response;
@ -248,7 +245,6 @@ public class NovaClientLiveTest {
}
}
@Test
public void testGetFlavorsDetail() throws Exception {
Set<Flavor> response = client.listFlavors(withDetails());
assert null != response;
@ -265,10 +261,17 @@ public class NovaClientLiveTest {
assert client.getFlavor(12312987) == null;
}
private String serverPrefix = System.getProperty("user.name") + ".cs";
private int serverId;
private String adminPass;
Map<String, String> metadata = ImmutableMap.of("jclouds", "rackspace");
private int serverId2;
private int imageId;
@Test(enabled = true)
public void testCreateServer() throws Exception {
String imageRef = client.getImage(13).getURI().toASCIIString();
String flavorRef = client.getFlavor(1).getURI().toASCIIString();
String imageRef = "3";
String flavorRef = "1";
String serverName = serverPrefix + "createserver" + new SecureRandom().nextInt();
Server server = client.createServer(serverName, imageRef, flavorRef, withFile("/etc/jclouds.txt",
"rackspace".getBytes()).withMetadata(metadata));
@ -278,7 +281,7 @@ public class NovaClientLiveTest {
serverId = server.getId();
adminPass = server.getAdminPass();
blockUntilServerActive(serverId);
ip = client.getServer(serverId).getAddresses().getPublicAddresses().iterator().next();
client.getServer(serverId).getAddresses().getPublicAddresses().iterator().next().getAddress();
}
private void blockUntilServerActive(int serverId) throws InterruptedException {
@ -308,23 +311,16 @@ public class NovaClientLiveTest {
}
}
@Test(enabled = true, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer")
@Test(enabled = false, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer")
public void testServerDetails() throws Exception {
Server server = client.getServer(serverId);
assertNotNull(server.getHostId());
assertEquals(server.getStatus(), ServerStatus.ACTIVE);
assertNotNull(server.getAddresses());
// check metadata
assertEquals(server.getMetadata(), metadata);
assertPassword(server, adminPass);
assertEquals(server.getFlavorRef(), endpoint + "/flavors/1");
assert server.getProgress() >= 0 : "newDetails.getProgress()" + server.getProgress();
assertEquals(server.getImageRef(), endpoint + "/images/13");
assertEquals("3", server.getImageRef());
assertEquals("1", server.getFlavorRef());
assertNotNull(server.getAddresses());
// listAddresses tests..
assertEquals(client.getAddresses(serverId), server.getAddresses());
assertEquals(server.getAddresses().getPublicAddresses().size(), 1);
@ -332,11 +328,14 @@ public class NovaClientLiveTest {
assertEquals(server.getAddresses().getPrivateAddresses().size(), 1);
assertEquals(client.listPrivateAddresses(serverId), server.getAddresses().getPrivateAddresses());
// check metadata
assertEquals(server.getMetadata(), metadata);
assertPassword(server, adminPass);
}
private void assertPassword(Server server, String pass) throws IOException {
IPSocket socket = new IPSocket(Iterables.get(server.getAddresses().getPublicAddresses(), 0), 22);
IPSocket socket = new IPSocket(Iterables.get(server.getAddresses().getPublicAddresses(), 0).getAddress(), 22);
socketTester.apply(socket);
SshClient client = sshFactory.create(socket, new Credentials("root", pass));
@ -351,19 +350,6 @@ public class NovaClientLiveTest {
}
}
private ExecResponse exec(Server details, String pass, String command) throws IOException {
IPSocket socket = new IPSocket(Iterables.get(details.getAddresses().getPublicAddresses(), 0), 22);
socketTester.apply(socket);
SshClient client = sshFactory.create(socket, new Credentials("root", pass));
try {
client.connect();
return client.exec(command);
} finally {
if (client != null)
client.disconnect();
}
}
@Test(enabled = false, timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer")
public void testRenameServer() throws Exception {
Server server = client.getServer(serverId);
@ -381,37 +367,18 @@ public class NovaClientLiveTest {
this.adminPass = "elmo";
}
private void assertIpConfigured(Server server, String password) {
try {
ExecResponse response = exec(server, password, "ifconfig -a");
assert response.getOutput().indexOf(ip) > 0 : String.format("server %s didn't get ip %s%n%s", server, ip,
response);
} catch (Exception e) {
e.printStackTrace();
} catch (AssertionError e) {
e.printStackTrace();
}
}
private void assertIpNotConfigured(Server server, String password) throws IOException {
ExecResponse response = exec(server, password, "ifconfig -a");
assert response.getOutput().indexOf(ip) == -1 : String.format("server %s still has get ip %s%n%s", server, ip,
response);
}
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testBackup")
public void testCreateImage() throws Exception {
Image image = client.createImageFromServer("hoofie", serverId);
assertEquals("hoofie", image.getName());
assertEquals(new Integer(serverId), image.getServerId());
assertEquals(new Integer(serverId), image.getServerRef());
imageId = image.getId();
blockUntilImageActive(imageId);
}
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateImage")
public void testRebuildServer() throws Exception {
client.rebuildServer(serverId, new RebuildServerOptions().withImage(imageId));
client.rebuildServer(serverId, new RebuildServerOptions().withImage(String.valueOf(imageId)));
blockUntilServerActive(serverId);
// issue Web Hosting #119580 imageId comes back incorrect after rebuild
assertEquals(imageId, client.getServer(serverId).getImageRef());
@ -475,7 +442,7 @@ public class NovaClientLiveTest {
@AfterTest
void deleteServersOnEnd() {
if (serverId > 0) {
//client.deleteServer(serverId);
client.deleteServer(serverId);
}
if (serverId2 > 0) {
client.deleteServer(serverId2);

View File

@ -10,6 +10,8 @@ import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import com.google.common.collect.ImmutableSet;
import java.util.Arrays;
import java.util.Properties;
import java.util.Set;
@ -30,7 +32,7 @@ public class _NovaClient {
Properties overrides = new Properties();
overrides.setProperty(PROPERTY_ENDPOINT, endpoint);
ComputeServiceContext context = contextFactory.createContext("nova", identity, credential,
Arrays.asList(new JschSshClientModule(), new SLF4JLoggingModule()), overrides);
ImmutableSet.of(new JschSshClientModule(), new SLF4JLoggingModule()), overrides);
ComputeService cs = context.getComputeService();
@ -39,7 +41,7 @@ public class _NovaClient {
System.out.println(cs.listAssignableLocations());
System.out.println(cs.listNodes());
/*TemplateOptions options = new TemplateOptions();
/*TemplateOptions options = new TemplateOptions().blockUntilRunning(false);
Template template = cs.templateBuilder().imageId("13").options(options).build();
try {
Set<? extends NodeMetadata> metedata = cs.runNodesWithTag("test", 1, template);
@ -48,6 +50,8 @@ public class _NovaClient {
e.printStackTrace();
}*/
//System.out.println(cs.getNodeMetadata("64"));
//cs.destroyNode("64");
context.close();

View File

@ -20,6 +20,8 @@ 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.openstack.nova.domain.Flavor;
@ -44,11 +46,16 @@ public class FlavorToHardwareTest {
Location provider = new LocationBuilder().scope(LocationScope.ZONE).id("dallas").description("description").build();
@Test
public void test() throws UnknownHostException {
assertEquals(convertFlavor(), new HardwareBuilder().ids("1").name("256 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())).build());
public void test() throws UnknownHostException, URISyntaxException {
Hardware flavor = convertFlavor();
Hardware tempFlavor = 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/v1.1/1234/flavors/1"))
.build();
assertEquals(flavor, tempFlavor);
}
public static Hardware convertFlavor() {

View File

@ -18,12 +18,12 @@
*/
package org.jclouds.openstack.nova.functions;
import com.google.common.collect.ImmutableList;
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;
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.io.Payloads;
@ -32,11 +32,13 @@ import org.jclouds.openstack.nova.domain.Address;
import org.jclouds.openstack.nova.domain.Addresses;
import org.testng.annotations.Test;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.util.List;
import static org.testng.Assert.assertEquals;
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}
@ -51,8 +53,7 @@ public class ParseAddressesFromJsonResponseTest {
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/test_list_addresses.json");
UnwrapOnlyJsonValue<Addresses> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Addresses>>() {
}));
UnwrapOnlyJsonValue<Addresses> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Addresses>>() {}));
Addresses response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
List<Address> publicAddresses = ImmutableList.copyOf(
@ -63,7 +64,7 @@ public class ParseAddressesFromJsonResponseTest {
Iterables.transform(ImmutableList.of("10.176.42.16", "::babe:10.176.42.16"),
Address.newString2AddressFunction()));
assertEquals(response.getPublicAddresses(), publicAddresses);
assertEquals(response.getPrivateAddresses(), privateAddresses);
assertEquals(response.getPublicAddresses(), Sets.newHashSet(publicAddresses));
assertEquals(response.getPrivateAddresses(), Sets.newHashSet(privateAddresses));
}
}

View File

@ -19,10 +19,11 @@
package org.jclouds.openstack.nova.functions;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
@ -33,10 +34,10 @@ import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.handlers.ParseNovaErrorFromHttpResponse;
import org.testng.annotations.Test;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
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}

View File

@ -18,23 +18,22 @@
*/
package org.jclouds.openstack.nova.functions;
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;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.io.InputStream;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.domain.Flavor;
import org.jclouds.util.Strings2;
import org.testng.annotations.Test;
import java.io.IOException;
import java.io.InputStream;
import static org.testng.Assert.assertEquals;
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}
@ -48,18 +47,10 @@ public class ParseFlavorFromJsonResponseTest {
public void testParseFlavorFromJsonResponseTest() throws IOException {
Flavor response = parseFlavor();
String json = new Gson().toJson(response);
String expectedJson = Strings2.toStringAndClose(
ParseFlavorFromJsonResponseTest.class.getResourceAsStream("/test_get_flavor_details.json"))
.replace("\n", "").replace("\t", "").replace("\r", "").replace(" ", "");
assertEquals(response.getId(), 1);
assertEquals(response.getName(), "256 MB Server");
assertEquals(response.getDisk().intValue(), 10);
assertEquals(response.getRam().intValue(), 256);
assertEquals(json, expectedJson);
}
public static Flavor parseFlavor() {

View File

@ -57,14 +57,13 @@ public class ParseImageFromJsonResponseTest {
public void testApplyInputStreamDetails() throws UnknownHostException {
Image response = parseImage();
assertEquals(response.getId(), 2);
assertEquals(response.getId(), 1);
assertEquals(response.getName(), "CentOS 5.2");
assertEquals(response.getServerId(), new Integer(12));
assertEquals(response.getCreated(), dateService.iso8601SecondsDateParse("2010-08-10T12:00:00Z"));
assertEquals(response.getProgress(), new Integer(80));
assertEquals(response.getStatus(), ImageStatus.SAVING);
assertEquals(response.getUpdated(), dateService.iso8601SecondsDateParse(("2010-10-10T12:00:00Z")));
assertEquals(response.getServerId(), "http://servers.api.openstack.org/v1.1/1234/servers/12", "Change serverId to serverRefs");
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);

View File

@ -60,9 +60,8 @@ public class ParseImageListFromJsonResponseTest {
List<Image> expects = ImmutableList.of(new Image(1, "CentOS 5.2"), new Image(743, "My Server Backup"));
UnwrapOnlyJsonValue<List<Image>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Image>>>() {
}));
UnwrapOnlyJsonValue<List<Image>> parser = i.getInstance(
Key.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Image>>>() {}));
List<Image> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(response, expects);
@ -81,26 +80,21 @@ public class ParseImageListFromJsonResponseTest {
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).getServerId(), 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(0).getServerId(), null, "Change serverId to serverRef");
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(), new Integer(80));
assertEquals(response.get(1).getServerId(), new Integer(12));
assertEquals(response.get(1).getStatus(), ImageStatus.SAVING);
assertEquals(response.get(1).getUpdated(), dateService.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));
assertEquals(response.get(1).getServerId(), "http://servers.api.openstack.org/v1.1/1234/servers/12", "Change serverId to serverRef");
//short form of reference
assertEquals(response.get(2).getServerId().intValue(), 12, "Change serverId to serverRef");
assertEquals(response.get(1).getServerRef(), "http://servers.api.openstack.org/v1.1/1234/servers/12");
}
}

View File

@ -19,6 +19,7 @@
package org.jclouds.openstack.nova.functions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
@ -27,11 +28,13 @@ import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.domain.Address;
import org.testng.annotations.Test;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Map;
import static org.testng.Assert.assertEquals;
@ -49,23 +52,30 @@ public class ParseInetAddressListFromJsonResponseTest {
public void testPublic() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/test_list_addresses_public.json");
UnwrapOnlyJsonValue<List<String>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<String>>>() {
}));
List<String> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
UnwrapOnlyJsonValue<Map<String, List<Address>>> parser = i.getInstance(
Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Map<String, List<Address>>>>() {}));
List<Address> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)))
.get("public");
assertEquals(response, ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"));
List<Address> addresses = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
Address.newString2AddressFunction()));
assertEquals(response, addresses);
}
@Test
public void testPrivate() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/test_list_addresses_private.json");
UnwrapOnlyJsonValue<List<String>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<String>>>() {
}));
List<String> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
UnwrapOnlyJsonValue<Map<String, List<Address>>> parser = i.getInstance(
Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Map<String, List<Address>>>>() {}));
List<Address> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)))
.get("private");
List<Address> addresses = ImmutableList.copyOf(Iterables.transform(
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
Address.newString2AddressFunction()));
assertEquals(response, ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"));
assertEquals(response, addresses);
}
}

View File

@ -51,7 +51,7 @@ import static org.testng.Assert.assertEquals;
public class ParseServerFromJsonResponseTest {
@Test
public void testApplyInputStreamDetails() throws UnknownHostException {
public void testApplyInputStreamDetails() throws UnknownHostException, NoSuchMethodException, ClassNotFoundException {
Server response = parseServer();
assertEquals(response.getId(), 1234);
@ -62,22 +62,26 @@ public class ParseServerFromJsonResponseTest {
assertEquals(response.getStatus(), ServerStatus.BUILD);
assertEquals(response.getProgress(), new Integer(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()));
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 = new Addresses(new HashSet<Address>(publicAddresses), new HashSet<Address>(privateAddresses));
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() {
public static Server parseServer() throws NoSuchMethodException, ClassNotFoundException {
Injector i = Guice.createInjector(new GsonModule());
InputStream is = ParseServerFromJsonResponseTest.class.getResourceAsStream("/test_get_server_detail.json");
UnwrapOnlyJsonValue<Server> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Server>>() {
}));
Server response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
return response;
UnwrapOnlyJsonValue<Server> parser = i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<Server>>() {}));
return (Server) parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
}
}

View File

@ -36,6 +36,8 @@ import org.jclouds.openstack.nova.domain.ServerStatus;
import org.testng.annotations.Test;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.HashSet;
import java.util.List;
@ -67,7 +69,7 @@ public class ParseServerListFromJsonResponseTest {
}
@Test
public void testApplyInputStreamDetails() throws UnknownHostException {
public void testApplyInputStreamDetails() throws UnknownHostException, URISyntaxException {
InputStream is = getClass().getResourceAsStream("/test_list_servers_detail.json");
UnwrapOnlyJsonValue<List<Server>> parser = i.getInstance(Key
@ -83,29 +85,35 @@ public class ParseServerListFromJsonResponseTest {
assertEquals(response.get(0).getStatus(), ServerStatus.BUILD);
assertEquals(response.get(0).getProgress(), new Integer(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()));
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 = new Addresses(new HashSet<Address>(publicAddresses), new HashSet<Address>(privateAddresses));
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(0).getImageRef(), "https://servers.api.rackspacecloud.com/v1.1/32278/images/1");
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(true, false, "Uncomment next line");
//assertEquals(response.getAffinityId(), "b414fa41cb37b97dcb58d6c76112af1258e9eae2");
assertEquals(response.get(1).getHostId(), "9e107d9d372bb6826bd81d3542a419d6");
assertEquals(response.get(1).getStatus(), ServerStatus.ACTIVE);
assertEquals(response.get(1).getProgress(), null);
List<Address> publicAddresses2 = ImmutableList.of(new Address("67.23.10.133", 4), new Address("::babe:67.23.10.133", 4));
List<Address> privateAddresses2 = ImmutableList.of(new Address("10.176.42.17", 4), new Address("::babe:10.176.42.17", 4));
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 = new Addresses(new HashSet<Address>(publicAddresses2), new HashSet<Address>(privateAddresses2));
assertEquals(response.get(1).getAddresses(), addresses2);
assertEquals(response.get(1).getMetadata(), ImmutableMap.of("Server Label", "DB 1"));
assertEquals(response.get(1).getURI(), "http://servers.api.openstack.org/1234/servers/56789");
assertEquals(response.get(1).getURI(), new URI("http://servers.api.openstack.org/v1.1/1234/servers/5678"));
}

View File

@ -35,48 +35,47 @@ 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());
Injector injector = Guice.createInjector(new GsonModule());
@Test
public void testAddPayloadToRequestMapOfStringStringHttpRequest() {
CreateServerOptions options = new CreateServerOptions();
HttpRequest request = buildRequest(options);
assertEquals("{\"server\":{\"name\":\"foo\",\"imageId\":1,\"flavorId\":2}}", request.getPayload().getRawContent());
}
@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 = new HttpRequest(HttpMethod.POST, URI.create("http://localhost"));
options.bindToRequest(request, ImmutableMap.of("name", "foo", "imageId", "1", "flavorId", "2"));
return request;
}
private HttpRequest buildRequest(CreateServerOptions options) {
injector.injectMembers(options);
HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost"));
options.bindToRequest(request, ImmutableMap.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 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 testWithFileStatic() {
CreateServerOptions options = withFile("/tmp/rhubarb", "foo".getBytes());
HttpRequest request = buildRequest(options);
assertFile(request);
}
private void assertFile(HttpRequest request) {
assertEquals(
"{\"server\":{\"name\":\"foo\",\"imageId\":1,\"flavorId\":2,\"personality\":[{\"path\":\"/tmp/rhubarb\",\"contents\":\"Zm9v\"}]}}",
request.getPayload().getRawContent());
}
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

@ -60,20 +60,20 @@ public class RebuildServerOptionsTest {
@Test
public void testWithServer() {
RebuildServerOptions options = new RebuildServerOptions();
options.withImage(3);
options.withImage("3");
HttpRequest request = buildRequest(options);
assertRebuild(request);
}
@Test
public void testWithServerStatic() {
RebuildServerOptions options = withImage(3);
RebuildServerOptions options = withImage("3");
HttpRequest request = buildRequest(options);
assertRebuild(request);
}
private void assertRebuild(HttpRequest request) {
assertEquals("{\"rebuild\":{\"imageId\":3}}", request.getPayload().getRawContent());
assertEquals("{\"rebuild\":{\"imageRef\":\"3\"}}", request.getPayload().getRawContent());
}
}

View File

@ -7,12 +7,10 @@
"created" : "2010-08-10T12:00:00Z",
"status" : "SAVING",
"progress" : 80,
"metadata" : {
"values" : {
"ImageVersion" : "1.5",
"ImageType" : "Gold"
}
},
"metadata" : {
"ImageVersion" : "1.5",
"ImageType" : "Gold"
},
"links": [
{
"rel" : "self",

View File

@ -1,7 +1,6 @@
{
"network" {
"id" : "private",
"values" : [
"network" : {
"private" : [
{"version" : 4, "addr" : "67.23.10.132"},
{"version" : 6, "addr" : "::babe:67.23.10.132"},
{"version" : 4, "addr" : "67.23.10.131"},

View File

@ -1,7 +1,6 @@
{
"network" {
"id" : "public",
"values" : [
"network" : {
"public" : [
{"version" : 4, "addr" : "67.23.10.132"},
{"version" : 6, "addr" : "::babe:67.23.10.132"},
{"version" : 4, "addr" : "67.23.10.131"},

View File

@ -1,46 +1,44 @@
{
"flavors" : {
"values" : [
{
"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"
}
]
}
]
}
"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 +1,48 @@
{
"flavors" : {
"values" : [
{
"id" : 1,
"name" : "256 MB Server",
"ram" : 256,
"disk" : 10,
"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,
"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"
}
]
}
]
}
"flavors" : [
{
"id" : 1,
"name" : "256 MB Server",
"ram" : 256,
"disk" : 10,
"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,
"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,47 +1,44 @@
{
"images" : {
"values" : [
{
"id" : 1,
"name" : "CentOS 5.2",
"images" : [
{
"id" : 1,
"name" : "CentOS 5.2",
"links": [
{
"rel" : "self",
"href" : "http://servers.api.openstack.org/v1.1/1234/images/1"
},
"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"
}
]
}
]
}
{
"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,90 +1,84 @@
{
"images" : {
"values" : [
{
"id" : 1,
"name" : "CentOS 5.2",
"updated" : "2010-10-10T12:00:00Z",
"created" : "2010-08-10T12:00:00Z",
"status" : "ACTIVE",
"metadata" : {
"values" : {
"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"
}
]
"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"
},
{
"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" : {
"values" : {
"ImageType" : "Gold",
"ImageVersion" : "1.5"
}
"links": [
{
"rel" : "self",
"href" : "http://servers.api.openstack.org/v1.1/1234/images/1"
},
"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"
}
]
}
]
}
{
"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,47 +1,45 @@
{
"servers" : {
"values" : [
{
"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"
}
]
}
]
}
"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,111 +1,89 @@
{
"servers" : {
"values" : [
{
"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",
"status" : "BUILD",
"progress" : 60,
"addresses" : {
"values" : [
{
"id" : "public",
"values" : [
{"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"}
]
},
{
"id" : "private",
"values" : [
{"version" : 4, "addr" : "10.176.42.16"},
{"version" : 6, "addr" : "::babe:10.176.42.16"}
]
}
]
},
"metadata" : {
"values" : {
"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"
}
]
"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",
"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"
},
{
"id" : 5678,
"name" : "sample-server2",
"imageRef" : "https://servers.api.rackspacecloud.com/v1.1/32278/images/1",
"flavorRef" : "https://servers.api.rackspacecloud.com/v1.1/32278/flavors/1",
"updated" : "2010-10-10T12:00:00Z",
"created" : "2010-08-10T12:00:00Z",
"hostId" : "9e107d9d372bb6826bd81d3542a419d6",
"affinityId" : "b414fa41cb37b97dcb58d6c76112af1258e9eae2",
"status" : "ACTIVE",
"addresses" : {
"values" : [
{
"id" : "public",
"values" : [
{"version" : 4, "addr" : "67.23.10.133"},
{"version" : 6, "addr" : "::babe:67.23.10.133"}
]
},
{
"id" : "private",
"values" : [
{"version" : 4, "addr" : "10.176.42.17"},
{"version" : 6, "addr" : "::babe:10.176.42.17"}
]
}
]
"links": [
{
"rel" : "self",
"href" : "http://servers.api.openstack.org/v1.1/1234/servers/1234"
},
"metadata" : {
"values" : {
"Server Label" : "DB 1"
}
{
"rel" : "bookmark",
"type" : "application/vnd.openstack.compute-v1.1+xml",
"href" : "http://servers.api.openstack.org/1234/servers/1234"
},
"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/56789"
}
]
}
]
}
{
"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" : "https://servers.api.rackspacecloud.com/v1.1/32278/flavors/1",
"updated" : "2010-10-10T12:00:00Z",
"created" : "2010-08-10T12:00:00Z",
"hostId" : "9e107d9d372bb6826bd81d3542a419d6",
"affinityId" : "b414fa41cb37b97dcb58d6c76112af1258e9eae2",
"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",
"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/56789"
}
]
}
]
}