added new createNodeTest

This commit is contained in:
andreaturli 2010-10-26 08:03:39 +02:00
parent e5315d3348
commit 5711495cb0
4 changed files with 72 additions and 6 deletions

View File

@ -46,7 +46,29 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
// Integer.parseInt(template.getHardware().getProviderId()));
// store the credentials so that later functions can use them
// credentialStore.put(from.id + "", new Credentials(from.loginUser, from.password));
return null;
String xmlDesc ="<domain type='kvm'>" + "<name>test</name>" + "<uuid>abcf2039-a9f1-a659-7f91-e0f82f59d52e</uuid>" +
"<memory>524288</memory>" +
"<currentMemory>524288</currentMemory>" +
"<vcpu>1</vcpu>" +
"<os><type arch='i686' machine='pc-0.12'>hvm</type><boot dev='hd'/></os>" +
"<features><acpi/> <apic/> <pae/> </features>" +
"<clock offset='utc'/>" +
"<on_poweroff>destroy</on_poweroff>"+
"<on_reboot>restart</on_reboot>"+
"<on_crash>restart</on_crash>"+
"<devices><emulator>/usr/bin/kvm</emulator><disk type='file' device='disk'><driver name='qemu' type='raw'/><source file='/var/lib/libvirt/images/test.img'/> <target dev='vda' bus='virtio'/> </disk> <disk type='block' device='cdrom'> <driver name='qemu' type='raw'/> <target dev='hdc' bus='ide'/><readonly/></disk> <interface type='network'> <mac address='52:54:00:05:cf:92'/> <source network='default'/> <model type='virtio'/> </interface> <console type='pty'> <target port='0'/> </console> <console type='pty'> <target port='0'/> </console> <input type='mouse' bus='ps2'/> <graphics type='vnc' port='-1' autoport='yes'/> <video> <model type='cirrus' vram='9216' heads='1'/> </video> </devices>"+
"</domain>";
Domain domain = null;
try {
client.domainDefineXML(xmlDesc);
domain = client.domainCreateXML(xmlDesc, 1);
} catch (LibvirtException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return domain;
}
@Override
@ -74,6 +96,19 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
}
}
// @Override
// public Iterable<Domain> listNodes() {
// try {
// List<Domain> domains = Lists.newArrayList();
// for (String domain : client.listDefinedDomains()) {
// domains.add(client.domainLookupByName(domain));
// }
// return domains;
// } catch (LibvirtException e) {
// return propogate(e);
// }
// }
protected <T> T propogate(LibvirtException e) {
Throwables.propagate(e);
assert false;
@ -111,4 +146,14 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
propogate(e);
}
}
public void createDomain() throws LibvirtException {
Domain domain = client.domainDefineXML("<domain type='test' id='2'>" + " <name>deftest</name>"
+ " <uuid>004b96e1-2d78-c30f-5aa5-f03c87d21e70</uuid>" + " <memory>8388608</memory>"
+ " <vcpu>2</vcpu>" + " <os><type arch='i686'>hvm</type></os>" + " <on_reboot>restart</on_reboot>"
+ " <on_poweroff>destroy</on_poweroff>" + " <on_crash>restart</on_crash>" + "</domain>");
}
}

View File

@ -35,7 +35,7 @@ public class LibvirtComputeServiceContextBuilderTest {
.createContext(new StandaloneComputeServiceContextSpec<Domain, Domain, Image, Datacenter>("libvirt",
"test:///default", "1", "identity", "credential", new LibvirtComputeServiceContextModule(),
ImmutableSet.<Module> of()));
System.err.println(context.getComputeService().listNodes());
//System.err.println(context.getComputeService().
context.close();
}

View File

@ -23,7 +23,11 @@ import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.StandaloneComputeServiceContextSpec;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.libvirt.Datacenter;
import org.jclouds.libvirt.Image;
import org.jclouds.libvirt.compute.domain.LibvirtComputeServiceContextModule;
@ -63,9 +67,26 @@ public class LibvirtExperimentLiveTest {
endpoint, apiversion, identity, credential, new LibvirtComputeServiceContextModule(), ImmutableSet
.<Module> of()));
context.getComputeService().listNodes();
System.out.println("images " + context.getComputeService().listImages());
System.out.println("hardware profiles " + context.getComputeService().listHardwareProfiles());
} finally {
Template defaultTemplate = context.getComputeService().templateBuilder()
//.hardwareId("").locationId("").imageId("")
.build();
/*
* We will probably make a default template out of properties at some point
* You can control the default template via overriding a method in standalonecomputeservicexontextmodule
*/
// context.getComputeService().templateOptions().;
context.getComputeService().runNodesWithTag("test", 1);
System.out.println(context.getComputeService().listNodes());
} catch (RunNodesException e) {
e.printStackTrace();
} finally {
if (context != null)
context.close();
}

View File

@ -130,7 +130,7 @@
<!-- ======================= -->
<root>
<priority value="WARN" />
<priority value="DEBUG" />
</root>
</log4j:configuration>