From 78511b74f3a82523bd8ee2d16f1a6911603120fc Mon Sep 17 00:00:00 2001 From: Mattias Holmqvist Date: Tue, 6 Sep 2011 23:16:38 +0200 Subject: [PATCH 1/2] Intermediate fix that fixes vnc:ip and nic:0:dhcp:ip for new API version of ElasticStack. Still some issues left to fix due to hanging tests. --- .../elasticstack/functions/MapToNICs.java | 20 +++++- .../functions/MapToServerInfo.java | 9 ++- .../elasticstack/functions/ServerToMap.java | 49 +++++++++----- .../BindServerToPlainTextStringTest.java | 67 +++++++++---------- ...DelimitedByBlankLinesToServerInfoTest.java | 2 + ...imitedByBlankLinesToServerInfoSetTest.java | 2 + .../functions/MapToServerInfoTest.java | 14 +++- .../functions/ServerToMapTest.java | 58 +++++++++++----- .../src/test/resources/new_server2.txt | 25 +++++++ .../src/test/resources/server2.txt | 41 ++++++++++++ ...ostsBlueSquareLondonPropertiesBuilder.java | 2 +- 11 files changed, 213 insertions(+), 76 deletions(-) create mode 100644 apis/elasticstack/src/test/resources/new_server2.txt create mode 100644 apis/elasticstack/src/test/resources/server2.txt diff --git a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToNICs.java b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToNICs.java index 0727fd6b31..2b65d92233 100644 --- a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToNICs.java +++ b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToNICs.java @@ -23,29 +23,43 @@ import java.util.Map; import javax.inject.Singleton; +import com.google.inject.Inject; import org.jclouds.elasticstack.domain.Model; import org.jclouds.elasticstack.domain.NIC; import com.google.common.base.Function; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableList; +import org.jclouds.rest.annotations.ApiVersion; /** - * * @author Adrian Cole */ @Singleton public class MapToNICs implements Function, List> { + private String apiVersion; + + @Inject + public MapToNICs(@ApiVersion String apiVersion) { + this.apiVersion = apiVersion; + } + @Override public List apply(Map from) { ImmutableList.Builder nics = ImmutableList.builder(); - NIC: for (int id : new int[] { 0, 1 }) { + NIC: + for (int id : new int[]{0, 1}) { String key = String.format("nic:%d", id); if (!from.containsKey(key + ":model")) break NIC; NIC.Builder nicBuilder = new NIC.Builder(); - nicBuilder.dhcp(from.get(key + ":dhcp")); + + if (apiVersion.equals("2.0")) { + nicBuilder.dhcp(from.get(key + ":dhcp:ip")); + } else { + nicBuilder.dhcp(from.get(key + ":dhcp")); + } nicBuilder.model(Model.fromValue(from.get(key + ":model"))); nicBuilder.vlan(from.get(key + ":vlan")); nicBuilder.mac(from.get(key + ":mac")); diff --git a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java index 1f466afd0a..7637f746d9 100644 --- a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java +++ b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java @@ -66,19 +66,24 @@ public class MapToServerInfo implements Function, ServerInfo builder.tags(Splitter.on(' ').split(from.get("tags"))); if (from.containsKey("status")) builder.status(ServerStatus.fromValue(from.get("status"))); + if (from.containsKey("smp") && !"auto".equals(from.get("smp"))) builder.smp(new Integer(from.get("smp"))); + builder.cpu(Integer.parseInt(from.get("cpu"))); builder.mem(Integer.parseInt(from.get("mem"))); builder.user(from.get("user")); if (from.containsKey("started")) builder.started(new Date(new Long(from.get("started")))); builder.uuid(from.get("server")); - builder.vnc(new VNC(from.get("vnc:ip"), from.get("vnc:password"), from.containsKey("vnc:tls") - && Boolean.valueOf(from.get("vnc:tls")))); if (from.containsKey("boot")) builder.bootDeviceIds(Splitter.on(' ').split(from.get("boot"))); + + builder.vnc(new VNC(from.get("vnc:ip") == null ? "auto" : from.get("vnc:ip"), from.get("vnc:password"), from.containsKey("vnc:tls") + && Boolean.valueOf(from.get("vnc:tls")))); + + Map metadata = Maps.newLinkedHashMap(); for (Entry entry : from.entrySet()) { if (entry.getKey().startsWith("user:")) diff --git a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ServerToMap.java b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ServerToMap.java index 0174971b22..8ad17a3b4c 100644 --- a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ServerToMap.java +++ b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/ServerToMap.java @@ -1,20 +1,20 @@ /** + * 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 * - * Copyright (C) 2011 Cloud Conscious, LLC. + * http://www.apache.org/licenses/LICENSE-2.0 * - * ==================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== + * 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.elasticstack.functions; @@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.util.Map; import java.util.Map.Entry; +import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.elasticstack.domain.Device; @@ -32,13 +33,22 @@ import org.jclouds.elasticstack.domain.Server; import com.google.common.base.Function; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableMap; +import org.jclouds.rest.annotations.ApiVersion; /** - * * @author Adrian Cole */ @Singleton public class ServerToMap implements Function> { + + @ApiVersion + private final String apiVersion; + + @Inject + public ServerToMap(@ApiVersion String apiVersion) { + this.apiVersion = apiVersion; + } + @Override public Map apply(Server from) { checkNotNull(from, "server"); @@ -68,7 +78,14 @@ public class ServerToMap implements Function> { builder.put("nic:" + nicId + ":mac", nic.getMac()); nicId++; } - builder.put("vnc:ip", from.getVnc().getIp() == null ? "auto" : from.getVnc().getIp()); + + String vncIp = from.getVnc().getIp(); + if (apiVersion.equals("2.0")) { + builder.put("vnc", "auto"); + } else { + builder.put("vnc:ip", vncIp == null ? "auto" : vncIp); + } + if (from.getVnc().getPassword() != null) builder.put("vnc:password", from.getVnc().getPassword()); if (from.getVnc().isTls()) diff --git a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindServerToPlainTextStringTest.java b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindServerToPlainTextStringTest.java index 7c63975378..16a760eaf2 100644 --- a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindServerToPlainTextStringTest.java +++ b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/binders/BindServerToPlainTextStringTest.java @@ -1,47 +1,43 @@ /** + * 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 * - * Copyright (C) 2011 Cloud Conscious, LLC. + * http://www.apache.org/licenses/LICENSE-2.0 * - * ==================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== + * 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.elasticstack.binders; -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.net.URI; -import java.util.Map; - -import javax.ws.rs.core.MediaType; - -import org.jclouds.elasticstack.domain.IDEDevice; -import org.jclouds.elasticstack.domain.Model; -import org.jclouds.elasticstack.domain.NIC; -import org.jclouds.elasticstack.domain.Server; -import org.jclouds.elasticstack.domain.VNC; -import org.jclouds.elasticstack.functions.ServerToMap; -import org.jclouds.http.HttpRequest; -import org.jclouds.util.Strings2; -import org.testng.annotations.Test; - import com.google.common.base.Function; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.inject.AbstractModule; import com.google.inject.Guice; +import com.google.inject.Injector; import com.google.inject.TypeLiteral; +import org.jclouds.elasticstack.domain.*; +import org.jclouds.elasticstack.functions.ServerToMap; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.annotations.ApiVersion; +import org.jclouds.util.Strings2; +import org.testng.annotations.Test; + +import javax.ws.rs.core.MediaType; +import java.io.IOException; +import java.net.URI; +import java.util.Map; + +import static org.testng.Assert.assertEquals; /** * @@ -69,19 +65,20 @@ public class BindServerToPlainTextStringTest { .nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000). build())).vnc(new VNC(null, "XXXXXXXX", false)).build(); - private static final BindServerToPlainTextString FN = Guice.createInjector(new AbstractModule() { + private Injector i = Guice.createInjector(new AbstractModule() { @Override protected void configure() { + bindConstant().annotatedWith(ApiVersion.class).to("1.0"); bind(new TypeLiteral>>() { }).to(ServerToMap.class); } - }).getInstance(BindServerToPlainTextString.class); + }); public void testSimple() throws IOException { HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create")); - FN.bindToRequest(request, SERVER); + i.getInstance(BindServerToPlainTextString.class).bindToRequest(request, SERVER); assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN); assertEquals(request.getPayload().getRawContent(), CREATED_SERVER); } diff --git a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java index db8155cb1f..2aa1b82f04 100644 --- a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java +++ b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java @@ -30,6 +30,7 @@ import org.jclouds.elasticstack.domain.ServerMetrics; import org.jclouds.elasticstack.functions.MapToDevices.DeviceToId; import org.jclouds.http.HttpResponse; import org.jclouds.io.Payloads; +import org.jclouds.rest.annotations.ApiVersion; import org.testng.annotations.Test; import com.google.common.base.Function; @@ -48,6 +49,7 @@ public class KeyValuesDelimitedByBlankLinesToServerInfoTest { @Override protected void configure() { + bindConstant().annotatedWith(ApiVersion.class).to("1.0"); bind(new TypeLiteral, List>>() { }).to(MapToNICs.class); bind(new TypeLiteral, Map>>() { diff --git a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java index 45b3f64865..218e221a45 100644 --- a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java +++ b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest.java @@ -31,6 +31,7 @@ import org.jclouds.elasticstack.domain.ServerMetrics; import org.jclouds.elasticstack.functions.MapToDevices.DeviceToId; import org.jclouds.http.HttpResponse; import org.jclouds.io.Payloads; +import org.jclouds.rest.annotations.ApiVersion; import org.testng.annotations.Test; import com.google.common.base.Function; @@ -51,6 +52,7 @@ public class ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest { @Override protected void configure() { + bindConstant().annotatedWith(ApiVersion.class).to("1.0"); bind(new TypeLiteral, List>>() { }).to(MapToNICs.class); bind(new TypeLiteral, Map>>() { diff --git a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToServerInfoTest.java b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToServerInfoTest.java index 8e9ef766ce..cdff044576 100644 --- a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToServerInfoTest.java +++ b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/MapToServerInfoTest.java @@ -42,7 +42,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; /** - * + * * @author Adrian Cole */ @Test(groups = { "unit" }) @@ -102,7 +102,7 @@ public class MapToServerInfoTest { .build()).build(); private static final MapToServerInfo MAP_TO_DRIVE = new MapToServerInfo(new MapToDevices(new DeviceToId()), - new MapToServerMetrics(new MapToDriveMetrics()), new MapToNICs()); + new MapToServerMetrics(new MapToDriveMetrics()), new MapToNICs("1.0")); public void testEmptyMapReturnsNull() { assertEquals(MAP_TO_DRIVE.apply(ImmutableMap. of()), null); @@ -158,4 +158,14 @@ public class MapToServerInfoTest { assertEquals(MAP_TO_DRIVE.apply(input), NEW); } + + + public void testNew2() throws IOException { + + Map input = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps().apply( + Strings2.toStringAndClose(MapToServerInfoTest.class.getResourceAsStream("/new_server2.txt"))).get(0); + + assertEquals(MAP_TO_DRIVE.apply(input), NEW); + + } } \ No newline at end of file diff --git a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ServerToMapTest.java b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ServerToMapTest.java index 24891766ee..940ea4e62f 100644 --- a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ServerToMapTest.java +++ b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/functions/ServerToMapTest.java @@ -1,20 +1,20 @@ /** + * 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 * - * Copyright (C) 2011 Cloud Conscious, LLC. + * http://www.apache.org/licenses/LICENSE-2.0 * - * ==================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== + * 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.elasticstack.functions; @@ -31,15 +31,16 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; /** - * + * * @author Adrian Cole */ @Test(groups = { "unit" }) public class ServerToMapTest { - private static final ServerToMap SERVER_TO_MAP = new ServerToMap(); + private static final ServerToMap SERVER_TO_MAP = new ServerToMap("1.0"); + private static final ServerToMap SERVER_TO_MAP_V2 = new ServerToMap("2.0"); - public void testBasics() { + public void testBasics() { assertEquals( SERVER_TO_MAP.apply(new Server.Builder() .name("TestServer") @@ -62,4 +63,27 @@ public class ServerToMapTest { "vnc:password", "XXXXXXXX")).build()); } + public void testBasicsV2() { + assertEquals( + SERVER_TO_MAP_V2.apply(new Server.Builder() + .name("TestServer") + .cpu(2000) + .mem(1024) + .devices( + ImmutableMap.of("ide:0:0", + new IDEDevice.Builder(0, 0).uuid("08c92dd5-70a0-4f51-83d2-835919d254df").build())) + .bootDeviceIds(ImmutableSet.of("ide:0:0")).nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000). + + build())).vnc(new VNC(null, "XXXXXXXX", false)).build()), + ImmutableMap + .builder() + .putAll(ImmutableMap.of("name", "TestServer", "cpu", "2000", "smp", "auto", "mem", "1024")) + .putAll( + ImmutableMap.of("persistent", "false", "boot", "ide:0:0", "ide:0:0", + "08c92dd5-70a0-4f51-83d2-835919d254df")) + .putAll( + ImmutableMap.of("ide:0:0:media", "disk", "nic:0:model", "e1000", "vnc", "auto", + "vnc:password", "XXXXXXXX")).build()); + } + } \ No newline at end of file diff --git a/apis/elasticstack/src/test/resources/new_server2.txt b/apis/elasticstack/src/test/resources/new_server2.txt new file mode 100644 index 0000000000..5f2aabdd87 --- /dev/null +++ b/apis/elasticstack/src/test/resources/new_server2.txt @@ -0,0 +1,25 @@ +ide:0:0:write:requests 0 +boot ide:0:0 +vnc:password XXXXXXXX +ide:0:0 403c9a86-0aab-4e47-aa95-e9768021c4c1 +ide:0:0:read:requests 0 +ide:0:0:read:bytes 0 +vnc auto +vnc:ip 83.222.249.221 +tx:packets 0 +tx 0 +rx 0 +smp 1 +mem 512 +nic:0:model e1000 +status active +started 1292695612 +rx:packets 0 +user 2f6244eb-50bc-4403-847e-f03cc3706a1f +ide:0:0:media disk +name adriancole.test +persistent true +nic:0:block tcp/43594 tcp/5902 udp/5060 tcp/5900 tcp/5901 tcp/21 tcp/22 tcp/23 tcp/25 tcp/110 tcp/143 tcp/43595 +server bd98615a-6f74-4d63-ad1e-b13338b9356a +ide:0:0:write:bytes 0 +cpu 1000 \ No newline at end of file diff --git a/apis/elasticstack/src/test/resources/server2.txt b/apis/elasticstack/src/test/resources/server2.txt new file mode 100644 index 0000000000..b3e91784f8 --- /dev/null +++ b/apis/elasticstack/src/test/resources/server2.txt @@ -0,0 +1,41 @@ +ide:0:0:write:requests 3698 +boot ide:0:0 +vnc:password HfHzVmLT +ide:0:0 4af85ed3-0caa-4736-8a26-a33d7de0a122 +ide:0:0:read:requests 11154 +ide:0:0:read:bytes 45686784 +vnc:ip 46.20.114.124 +tx:packets 31 +tx 2550 +rx 455530 +smp 1 +mem 1024 +nic:0:model e1000 +status active +started 1291493868 +rx:packets 7583 +user 2f6244eb-50bc-4403-847e-f03cc3706a1f +name jo +persistent true +nic:0:block tcp/43594 tcp/5902 udp/5060 tcp/5900 tcp/5901 tcp/21 tcp/22 tcp/23 tcp/25 tcp/110 tcp/143 tcp/43595 +server f8bee9cd-8e4b-4a05-8593-1314e3bfe49b +nic:0:dhcp auto +nic:0:dhcp:ip 46.20.114.124 +ide:0:0:write:bytes 15147008 +cpu 2000 + +status stopped +name Demo +mem 1024 +boot ide:0:0 +vnc:password HWbjvrg2 +persistent true +server 0f962616-2071-4173-be79-7dd084271edf +smp auto +nic:0:dhcp auto +user 2f6244eb-50bc-4403-847e-f03cc3706a1f +nic:0:model e1000 +vnc:ip auto +ide:0:0 853bb98a-4fff-4c2f-a265-97c363f19ea5 +cpu 2000 +ide:0:0:media cdrom diff --git a/providers/elastichosts-lon-b/src/main/java/org/jclouds/elastichosts/ElasticHostsBlueSquareLondonPropertiesBuilder.java b/providers/elastichosts-lon-b/src/main/java/org/jclouds/elastichosts/ElasticHostsBlueSquareLondonPropertiesBuilder.java index 15adc9b3fd..c19f991d5e 100644 --- a/providers/elastichosts-lon-b/src/main/java/org/jclouds/elastichosts/ElasticHostsBlueSquareLondonPropertiesBuilder.java +++ b/providers/elastichosts-lon-b/src/main/java/org/jclouds/elastichosts/ElasticHostsBlueSquareLondonPropertiesBuilder.java @@ -37,7 +37,7 @@ public class ElasticHostsBlueSquareLondonPropertiesBuilder extends ElasticStackP Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_ISO3166_CODES, "GB-LND"); properties.setProperty(PROPERTY_ENDPOINT, "https://api.lon-b.elastichosts.com"); - properties.setProperty(PROPERTY_API_VERSION, "1.0"); + properties.setProperty(PROPERTY_API_VERSION, "2.0"); return properties; } From fd1a5dd04c83573a2b09cdcba840e7eb76a7083d Mon Sep 17 00:00:00 2001 From: Mattias Holmqvist Date: Thu, 8 Sep 2011 16:16:33 +0200 Subject: [PATCH 2/2] Read "smp:cores" instead of "smp" --- .../elasticstack/functions/MapToServerInfo.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java index 7637f746d9..26affbe3a3 100644 --- a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java +++ b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/functions/MapToServerInfo.java @@ -36,20 +36,22 @@ import org.jclouds.elasticstack.domain.VNC; import com.google.common.base.Function; import com.google.common.base.Splitter; import com.google.common.collect.Maps; +import org.jclouds.rest.annotations.ApiVersion; /** - * * @author Adrian Cole */ @Singleton public class MapToServerInfo implements Function, ServerInfo> { + private String apiVersion; private final Function, Map> mapToDevices; private final Function, ServerMetrics> mapToMetrics; private final Function, List> mapToNICs; @Inject public MapToServerInfo(Function, Map> mapToDevices, - Function, ServerMetrics> mapToMetrics, Function, List> mapToNICs) { + Function, ServerMetrics> mapToMetrics, Function, List> mapToNICs) { + this.apiVersion = apiVersion; this.mapToDevices = mapToDevices; this.mapToMetrics = mapToMetrics; this.mapToNICs = mapToNICs; @@ -67,8 +69,12 @@ public class MapToServerInfo implements Function, ServerInfo if (from.containsKey("status")) builder.status(ServerStatus.fromValue(from.get("status"))); - if (from.containsKey("smp") && !"auto".equals(from.get("smp"))) - builder.smp(new Integer(from.get("smp"))); + + if (from.containsKey("smp:cores")) { + builder.smp(new Integer(from.get("smp:cores"))); + } else if (from.containsKey("smp") && !"auto".equals(from.get("smp"))) { + builder.smp(new Integer(from.get("smp"))); + } builder.cpu(Integer.parseInt(from.get("cpu"))); builder.mem(Integer.parseInt(from.get("mem")));