cloudstack ids are unique across zones

This commit is contained in:
Adrian Cole 2011-11-11 19:48:16 +02:00
parent c08a7884bd
commit d4184786a0
7 changed files with 17 additions and 23 deletions

View File

@ -36,9 +36,7 @@ public class ServiceOfferingToHardware implements Function<ServiceOffering, Hard
@Override
public Hardware apply(ServiceOffering offering) {
return new HardwareBuilder()
.id(offering.getId() + "")
// TODO: can the id be ambigious? should we include the domain if available?
.providerId(offering.getId() + "")
.ids(offering.getId() + "")
.name(offering.getName())
.tags(offering.getTags())
.processors(ImmutableList.of(new Processor(offering.getCpuNumber(), offering.getCpuSpeed())))

View File

@ -56,9 +56,8 @@ public class TemplateToImage implements Function<Template, Image> {
OperatingSystem os = templateToOperatingSystem.apply(template);
ImageBuilder builder = new ImageBuilder().id(template.getZoneId() + "/" + template.getId())
.providerId(template.getId() + "").name(template.getName()).description(template.getDisplayText())
.operatingSystem(os);
ImageBuilder builder = new ImageBuilder().ids(template.getId() + "").name(template.getName())
.description(template.getDisplayText()).operatingSystem(os);
if (!template.isCrossZones())
builder.location(findLocationForTemplate.apply(template));

View File

@ -82,9 +82,7 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
public NodeMetadata apply(VirtualMachine from) {
// convert the result object to a jclouds NodeMetadata
NodeMetadataBuilder builder = new NodeMetadataBuilder();
String id = from.getZoneId() + "/" + from.getId();
builder.id(id);
builder.providerId(from.getId() + "");
builder.ids(from.getId() + "");
builder.name(from.getName());
builder.hostname(from.getHostname());
builder.location(findLocationForVirtualMachine.apply(from));
@ -110,7 +108,7 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
else
builder.publicAddresses(addresses);
}
builder.credentials(credentialStore.get("node#" + id));
builder.credentials(credentialStore.get("node#" + from.getId()));
return builder.build();
}

View File

@ -86,8 +86,8 @@ public class CloudStackComputeServiceAdapter implements
options.securityGroupIds(templateOptions.getSecurityGroupIds());
long zoneId = Long.parseLong(template.getLocation().getId());
long templateId = Long.parseLong(template.getImage().getProviderId());
long serviceOfferingId = Long.parseLong(template.getHardware().getProviderId());
long templateId = Long.parseLong(template.getImage().getId());
long serviceOfferingId = Long.parseLong(template.getHardware().getId());
System.out.printf("serviceOfferingId %d, templateId %d, zoneId %d, options %s%n", serviceOfferingId, templateId,
zoneId, options);

View File

@ -105,10 +105,9 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien
// TODO: check security groups vm.getSecurityGroups(),
// check other things, like cpu correct, mem correct, image/os is correct
// (as possible)
assert credentialStore.containsKey("node#" + vm.getZoneId() + "/" + vm.getId()) : "credentials to log into vm not found "
+ vm;
assert credentialStore.containsKey("node#" + vm.getId()) : "credentials to log into vm not found " + vm;
assert InetAddresses.isInetAddress(vm.getIPAddress()) : vm;
doConnectViaSsh(vm, credentialStore.get("node#" + vm.getZoneId() + "/" + vm.getId()));
doConnectViaSsh(vm, credentialStore.get("node#" + vm.getId()));
}
protected void doConnectViaSsh(VirtualMachine vm, Credentials creds) {

View File

@ -49,20 +49,20 @@ public class TemplateToImageTest {
TemplateToOperatingSystemTest.function);
// location free image
static Image one = new ImageBuilder().id("2/2").providerId("2").name("CentOS 5.3(64-bit) no GUI (XenServer)")
static Image one = new ImageBuilder().id("2").providerId("2").name("CentOS 5.3(64-bit) no GUI (XenServer)")
.operatingSystem(TemplateToOperatingSystemTest.one).description("CentOS 5.3(64-bit) no GUI (XenServer)")
.build();
// location free image
static Image two = new ImageBuilder().id("2/4").providerId("4").name("CentOS 5.5(64-bit) no GUI (KVM)")
static Image two = new ImageBuilder().id("4").providerId("4").name("CentOS 5.5(64-bit) no GUI (KVM)")
.operatingSystem(TemplateToOperatingSystemTest.two).description("CentOS 5.5(64-bit) no GUI (KVM)").build();
static Image three = new ImageBuilder().id("2/203").providerId("203").name("Windows 7 KVM")
static Image three = new ImageBuilder().id("203").providerId("203").name("Windows 7 KVM")
.operatingSystem(TemplateToOperatingSystemTest.three).description("Windows 7 KVM")
.location(ZoneToLocationTest.two).build();
// location free image
static Image four = new ImageBuilder().id("2/7").providerId("7").name("CentOS 5.3(64-bit) no GUI (vSphere)")
static Image four = new ImageBuilder().id("7").providerId("7").name("CentOS 5.3(64-bit) no GUI (vSphere)")
.operatingSystem(TemplateToOperatingSystemTest.four).description("CentOS 5.3(64-bit) no GUI (vSphere)")
.build();
static Image five = new ImageBuilder().id("2/241").providerId("241").name("kvmdev4")
static Image five = new ImageBuilder().id("241").providerId("241").name("kvmdev4")
.operatingSystem(TemplateToOperatingSystemTest.five).description("v5.6.28_Dev4")
.location(ZoneToLocationTest.two).build();

View File

@ -78,7 +78,7 @@ public class VirtualMachineToNodeMetadataTest {
assertEquals(
node.toString(),
new NodeMetadataBuilder().id("1/54").providerId("54").name("i-3-54-VM").location(ZoneToLocationTest.one)
new NodeMetadataBuilder().id("54").providerId("54").name("i-3-54-VM").location(ZoneToLocationTest.one)
.state(NodeState.PENDING).privateAddresses(ImmutableSet.of("10.1.1.18"))
.hardware(ServiceOfferingToHardwareTest.one).imageId(TemplateToImageTest.one.getId())
.operatingSystem(TemplateToImageTest.one.getOperatingSystem()).build().toString());
@ -90,7 +90,7 @@ public class VirtualMachineToNodeMetadataTest {
@Test
public void testApplyWhereVirtualMachineWithPassword() throws UnknownHostException {
Map<String, Credentials> credentialStore = ImmutableMap.<String, Credentials> of("node#1/54", new Credentials(
Map<String, Credentials> credentialStore = ImmutableMap.<String, Credentials> of("node#54", new Credentials(
"root", "password"));
Supplier<Set<? extends Location>> locationSupplier = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
@ -113,7 +113,7 @@ public class VirtualMachineToNodeMetadataTest {
assertEquals(
node.toString(),
new NodeMetadataBuilder().id("1/54").providerId("54").name("i-3-54-VM").location(ZoneToLocationTest.one)
new NodeMetadataBuilder().id("54").providerId("54").name("i-3-54-VM").location(ZoneToLocationTest.one)
.state(NodeState.PENDING).privateAddresses(ImmutableSet.of("10.1.1.18"))
.hardware(ServiceOfferingToHardwareTest.one).imageId(TemplateToImageTest.one.getId())
.credentials(new Credentials("root", "password"))