Add metadata to nova compute service

This commit is contained in:
Matt Stephenson 2012-03-13 14:50:46 -07:00
parent 0f0209e3c4
commit 4054eaee4f
2 changed files with 9 additions and 0 deletions

View File

@ -26,6 +26,7 @@ import org.jclouds.openstack.nova.v1_1.domain.Address;
import org.jclouds.openstack.nova.v1_1.domain.Server; import org.jclouds.openstack.nova.v1_1.domain.Server;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
/** /**
@ -47,6 +48,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata>
.publicAddresses(Iterables.transform(server.getPublicAddresses(), new AddressToStringTransformationFunction())) .publicAddresses(Iterables.transform(server.getPublicAddresses(), new AddressToStringTransformationFunction()))
.privateAddresses(Iterables.transform(server.getPrivateAddresses(), new AddressToStringTransformationFunction())) .privateAddresses(Iterables.transform(server.getPrivateAddresses(), new AddressToStringTransformationFunction()))
.state(server.getStatus().getNodeState()) .state(server.getStatus().getNodeState())
.userMetadata(ImmutableMap.copyOf(server.getMetadata()))
.build(); .build();
} }

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.openstack.nova.v1_1.compute.functions; package org.jclouds.openstack.nova.v1_1.compute.functions;
import com.google.common.collect.ImmutableMap;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
@ -47,6 +49,7 @@ public class ServerToNodeMetadataTest
.privateAddresses(Address.createV4("10.0.0.1")) .privateAddresses(Address.createV4("10.0.0.1"))
.publicAddresses(Address.createV4("1.0.1.1")) .publicAddresses(Address.createV4("1.0.1.1"))
.status(ServerStatus.ACTIVE) .status(ServerStatus.ACTIVE)
.metadata(ImmutableMap.of("test", "testing"))
.build(); .build();
ServerToNodeMetadata converter = new ServerToNodeMetadata(); ServerToNodeMetadata converter = new ServerToNodeMetadata();
@ -65,5 +68,9 @@ public class ServerToNodeMetadataTest
assertNotNull(convertedNodeMetadata.getPublicAddresses()); assertNotNull(convertedNodeMetadata.getPublicAddresses());
assertEquals(convertedNodeMetadata.getPublicAddresses().size(), 1); assertEquals(convertedNodeMetadata.getPublicAddresses().size(), 1);
assertEquals(convertedNodeMetadata.getPublicAddresses().iterator().next(), "1.0.1.1"); assertEquals(convertedNodeMetadata.getPublicAddresses().iterator().next(), "1.0.1.1");
assertNotNull(convertedNodeMetadata.getUserMetadata());
assertEquals(convertedNodeMetadata.getUserMetadata().size(), 1);
assertEquals(convertedNodeMetadata.getUserMetadata().get("test"),"testing");
} }
} }