Merge branch 'master' of github.com:jclouds/jclouds

This commit is contained in:
Lili Nader 2010-11-05 15:53:04 -07:00
commit 40aa8aa591
11 changed files with 219 additions and 99 deletions

View File

@ -1,2 +1,73 @@
The libvirt library is used to interface with different virtualization technologies (http://libvirt.org/)
libvirt supports:
The Xen hypervisor on Linux and Solaris hosts.
The QEMU emulator
The KVM Linux hypervisor
The LXC Linux container system
The OpenVZ Linux container system
The User Mode Linux paravirtualized kernel
The VirtualBox hypervisor
The VMware ESX and GSX hypervisors
Storage on IDE/SCSI/USB disks, FibreChannel, LVM, iSCSI, NFS and filesystems
Getting Started Guide for jclouds-libvirt
install libvirt on your os
* if os/x, see http://github.com/justinclift/libvirt
* if you are using Linux, let's suppose you want to use KVM:
- install libvirt and KVM (http://www.linux-kvm.org/page/Main_Page).
Remember to run
egrep '(vmx|svm)' /proc/cpuinfo
If nothing is printed, it means that your cpu does not support hardware virtualization.
Verify Installation
$ virsh -c qemu:///system list
Id Name State
----------------------------------
(for Ubuntu users: look also at this good turorial https://help.ubuntu.com/community/KVM)
Create your first guest
- download, for example, an ubuntu 10.04 LTS ISO
- create a libvirt domain by using:
virt-manager: a GUI tool at http://virt-manager.et.redhat.com/
virt-install, a python script developed by Red Hat (sudo apt-get install python-virtinst)
ubuntu-vm-builder, developed by Canonical. (sudo apt-get install ubuntu-vm-builder)
NB: use Javascript tool that generates the parameters for ubuntu-vm-builder: http://people.ubuntu.com/~kirkland/ubuntu-vm-builder.html
Now that you have a libvirt domain, your workstation is ready to use jclouds-libvirt.
You can now download jclouds-libvirt and give a try by running
ComputeServiceContext context = null;
try {
context = new ComputeServiceContextFactory()
.createContext(new StandaloneComputeServiceContextSpec<Domain, Domain, Image, Datacenter>("libvirt",
endpoint, apiversion, identity, credential, new LibvirtComputeServiceContextModule(), ImmutableSet
.<Module> of()));
Template defaultTemplate = context.getComputeService().templateBuilder()
.hardwareId("c7ff2039-a9f1-a659-7f91-e0f82f59d52e").imageId("1").build();
context.getComputeService().runNodesWithTag(domainName, 1, defaultTemplate);
} catch (RunNodesException e) {
e.printStackTrace();
} finally {
if (context != null)
context.close();
}
where identity=your_name, endpoint=qemu:///system
and domainName equals to the name chosen during the creation of libvirt domain
NB: apiversion, credential can be null

View File

@ -29,6 +29,7 @@ import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.config.StandaloneComputeServiceContextModule;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.suppliers.DefaultLocationSupplier;
import org.jclouds.domain.Location;
import org.jclouds.libvirt.Datacenter;
@ -45,37 +46,58 @@ import org.libvirt.LibvirtException;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
/**
*
* @author Adrian Cole
*/
public class LibvirtComputeServiceContextModule extends
StandaloneComputeServiceContextModule<Domain, Domain, Image, Datacenter> {
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<ComputeServiceAdapter<Domain, Domain, Image, Datacenter>>() {
}).to(LibvirtComputeServiceAdapter.class);
bind(new TypeLiteral<Supplier<Location>>() {
}).to(DefaultLocationSupplier.class);
bind(new TypeLiteral<Function<Domain, NodeMetadata>>() {
}).to(DomainToNodeMetadata.class);
bind(new TypeLiteral<Function<Image, org.jclouds.compute.domain.Image>>() {
}).to(LibvirtImageToImage.class);
bind(new TypeLiteral<Function<Domain, Hardware>>() {
}).to(DomainToHardware.class);
bind(new TypeLiteral<Function<Datacenter, Location>>() {
}).to(DatacenterToLocation.class);
}
StandaloneComputeServiceContextModule<Domain, Domain, Image, Datacenter> {
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<ComputeServiceAdapter<Domain, Domain, Image, Datacenter>>() {
}).to(LibvirtComputeServiceAdapter.class);
bind(new TypeLiteral<Supplier<Location>>() {
}).to(DefaultLocationSupplier.class);
bind(new TypeLiteral<Function<Domain, NodeMetadata>>() {
}).to(DomainToNodeMetadata.class);
bind(new TypeLiteral<Function<Image, org.jclouds.compute.domain.Image>>() {
}).to(LibvirtImageToImage.class);
bind(new TypeLiteral<Function<Domain, Hardware>>() {
}).to(DomainToHardware.class);
bind(new TypeLiteral<Function<Datacenter, Location>>() {
}).to(DatacenterToLocation.class);
}
@Provides
@Singleton
protected Connect createConnection(@Provider URI endpoint, @Named(Constants.PROPERTY_IDENTITY) String identity,
@Named(Constants.PROPERTY_CREDENTIAL) String credential) throws LibvirtException {
// ConnectAuth connectAuth = null;
return new Connect(endpoint.toASCIIString());
}
@Provides
@Singleton
protected Connect createConnection(@Provider URI endpoint, @Named(Constants.PROPERTY_IDENTITY) String identity,
@Named(Constants.PROPERTY_CREDENTIAL) String credential) throws LibvirtException {
// ConnectAuth connectAuth = null;
return new Connect(endpoint.toASCIIString());
}
@Override
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
String domainDir = injector.getInstance(Key.get(String.class, Names.named("jclouds.libvirt.domain-dir")));
String hardwareId = searchForHardwareIdInDomainDir(domainDir);
String image = searchForImageIdInDomainDir(domainDir);
return template.hardwareId(hardwareId).imageId(image) ;
}
private String searchForImageIdInDomainDir(String domainDir) {
// TODO
return "1";
}
private String searchForHardwareIdInDomainDir(String domainDir) {
// TODO
return "c7ff2039-a9f1-a659-7f91-e0f82f59d52e";
}
}

View File

@ -77,6 +77,7 @@ public class DomainToHardware implements Function<Domain, Hardware> {
NodeList nodes = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
String diskFileName = nodes.item(0).getNodeValue();
for (int i = 0; i < nodes.getLength(); i++) {
System.out.println("disk " + diskFileName);
StorageVol storageVol = from.getConnect().storageVolLookupByPath(diskFileName);
String id = storageVol.getKey();
float size = new Long(storageVol.getInfo().capacity).floatValue();

View File

@ -52,7 +52,7 @@ public class LibvirtImageToImage implements Function<org.jclouds.libvirt.Image,
OsFamily family = null;
try {
family = OsFamily.fromValue(from.name);
builder.operatingSystem(new OperatingSystemBuilder().name(from.name).family(family).description("ubuntu").build());
builder.operatingSystem(new OperatingSystemBuilder().name(from.name).family(family).description(from.name).build());
} catch (IllegalArgumentException e) {
logger.debug("<< didn't match os(%s)", from);
}

View File

@ -83,47 +83,47 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
// Domain from = client.createDomainInDC(template.getLocation().getId(), name,
// Integer.parseInt(template.getImage().getProviderId()),
// Integer.parseInt(template.getHardware().getProviderId()));
// store the credentials so that later functions can use them
// store the credentials so that later functions can use them
// credentialStore.put(from.id + "", new Credentials(from.loginUser, from.password));
String[] domains;
//String[] domains;
try {
domains = client.listDefinedDomains();
//domains = client.listDefinedDomains();
String xmlDesc = "";
Domain domain = null;
String xmlDesc = "";
for (String domainName : domains) {
domain = client.domainLookupByName(domainName);
if (domainName.equals("ttylinux")) {
domain = client.domainLookupByName(domainName);
xmlDesc = domain.getXMLDesc(0);
System.out.println("domain: " + domain.getUUIDString());
XMLBuilder builder = XMLBuilder.parse(new InputSource(new StringReader(xmlDesc)));
Document doc = builder.getDocument();
XPathExpression expr = null;
//for (String domainName : domains) {
// domain = client.domainLookupByName(domainName);
// if (domainName.equals(tag)) {
String domainName = tag;
domain = client.domainLookupByName(domainName);
System.out.println("domain name " + domain.getName());
XMLBuilder builder = XMLBuilder.parse(new InputSource(new StringReader(domain.getXMLDesc(0))));
Document doc = builder.getDocument();
XPathExpression expr = null;
NodeList nodes = null;
String xpathString = "//devices/disk[@device='disk']/source/@file"; // +
expr = XPathFactory.newInstance().newXPath().compile(xpathString);
nodes = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
String diskFileName = nodes.item(0).getNodeValue();
System.out.println("\n *** diskFileName " + diskFileName);
StorageVol storageVol = client.storageVolLookupByPath(diskFileName);
System.out.println(storageVol.getXMLDesc(0));
// cloning volume
String poolName = "default";
StoragePool storagePool = client.storagePoolLookupByName(poolName);
StorageVol clonedVol = cloneVolume(storagePool, storageVol);
// System.out.println(generateClonedDomainXML(xmlDesc));
domain = client.domainDefineXML(generateClonedDomainXML(xmlDesc));
}
}
System.out.println(clonedVol.getXMLDesc(0));
// define Domain
String xmlFinal = generateClonedDomainXML(domain.getXMLDesc(0));
domain = client.domainDefineXML(xmlFinal);
domain.create();
// store the credentials so that later functions can use them
credentialStore.put(domain.getUUIDString() + "", new Credentials("identity", "credential"));
//}
//}
return domain;
} catch (LibvirtException e) {
return propogate(e);
@ -142,26 +142,19 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
// return ImmutableSet.of();
// TODO
// return client.listImages();
List<Image> images = Lists.newArrayList();
images.add(new Image(1, "ubuntu"));
return images;
int i = 1;
try {
String[] domains = client.listDefinedDomains();
List<Image> images = Lists.newArrayList();
for (String domainName : domains) {
images.add(new Image(i++, domainName));
}
return images;
} catch (Exception e) {
return propogate(e);
}
}
// @Override
// public Iterable<Domain> listNodes() {
// try {
// List<Domain> domains = Lists.newArrayList();
// for (int domain : client.listDomains()) {
// domains.add(client.domainLookupByID(domain));
// }
// return domains;
// } catch (LibvirtException e) {
// return propogate(e);
// }
// }
@Override
public Iterable<Domain> listNodes() {
try {
@ -219,20 +212,10 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
}
}
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>");
}
private static StorageVol cloneVolume(StoragePool storagePool, StorageVol from) throws LibvirtException,
XPathExpressionException, ParserConfigurationException, SAXException, IOException, TransformerException {
String fromXML = from.getXMLDesc(0);
String clonedXML = generateClonedVolumeXML(fromXML);
System.out.println(clonedXML);
// return null;
return storagePool.storageVolCreateXMLFrom(clonedXML, from, 0);
}

View File

@ -65,24 +65,28 @@ public class LibvirtExperimentLiveTest {
endpoint, apiversion, identity, credential, new LibvirtComputeServiceContextModule(), ImmutableSet
.<Module> of()));
/*
System.out.println("images " + context.getComputeService().listImages());
System.out.println("nodes " + context.getComputeService().listNodes());
System.out.println("hardware profiles " + context.getComputeService().listHardwareProfiles());
*/
/*
Template defaultTemplate = context.getComputeService().templateBuilder()
.hardwareId("c7ff2039-a9f1-a659-7f91-e0f82f59d52e").imageId("1") //.locationId("")
.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().runNodesWithTag("ttylinux", 1/*, defaultTemplate*/);
// context.getComputeService().templateOptions().;
context.getComputeService().runNodesWithTag("ttylinux", 1, defaultTemplate);
} catch (RunNodesException e) {
} catch (RunNodesException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (context != null)

View File

@ -33,9 +33,10 @@
<properties>
<!-- when instances are hung, open a ticket and add here -->
<jclouds.compute.blacklist.nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist.nodes>
<test.servermanager-compute.endpoint>https://servermanager-compute.com</test.servermanager-compute.endpoint>
<test.servermanager-compute.apiversion>1.0</test.servermanager-compute.apiversion>
<test.servermanager-compute.identity>FIXME</test.servermanager-compute.identity>
<test.servermanager.identity>FIXME</test.servermanager.identity>
<test.servermanager.endpoint>https://servermanager.com</test.servermanager.endpoint>
<test.servermanager.apiversion>1.0</test.servermanager.apiversion>
<test.servermanager.identity>FIXME</test.servermanager.identity>
</properties>
<dependencies>
<dependency>
@ -95,16 +96,16 @@
<configuration>
<systemProperties>
<property>
<name>test.servermanager-compute.endpoint</name>
<value>${test.servermanager-compute.endpoint}</value>
<name>test.servermanager.endpoint</name>
<value>${test.servermanager.endpoint}</value>
</property>
<property>
<name>test.servermanager-compute.apiversion</name>
<value>${test.servermanager-compute.apiversion}</value>
<name>test.servermanager.apiversion</name>
<value>${test.servermanager.apiversion}</value>
</property>
<property>
<name>test.servermanager-compute.identity</name>
<value>${test.servermanager-compute.identity}</value>
<name>test.servermanager.identity</name>
<value>${test.servermanager.identity}</value>
</property>
<property>
<name>jclouds.compute.blacklist.nodes</name>

View File

@ -25,7 +25,7 @@ import java.util.Properties;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.vcloud.VCloudExpressContextBuilder;
import org.jclouds.vcloud.terremark.compute.config.TerremarkVCloudComputeServiceContextModule;
import org.jclouds.vcloud.terremark.compute.config.TerremarkECloudComputeServiceContextModule;
import org.jclouds.vcloud.terremark.config.TerremarkECloudRestClientModule;
import com.google.inject.Injector;
@ -52,7 +52,7 @@ public class TerremarkECloudContextBuilder extends VCloudExpressContextBuilder {
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new TerremarkVCloudComputeServiceContextModule());
modules.add(new TerremarkECloudComputeServiceContextModule());
}
@Override

View File

@ -21,6 +21,7 @@ package org.jclouds.vcloud.terremark;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
import static org.jclouds.vcloud.terremark.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NAME;
import static org.jclouds.vcloud.terremark.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_VERSION;
@ -39,6 +40,8 @@ public class TerremarkECloudPropertiesBuilder extends TerremarkVCloudPropertiesB
properties.setProperty(PROPERTY_ENDPOINT, "https://services.enterprisecloud.terremark.com/api");
properties.setProperty(PROPERTY_TERREMARK_EXTENSION_NAME, "eCloudExtensions");
properties.setProperty(PROPERTY_TERREMARK_EXTENSION_VERSION, "2.5");
// for some reason the centos template is very slow to deploy
properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 720l * 1000l + "");
return properties;
}

View File

@ -0,0 +1,35 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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.
* ====================================================================
*/
package org.jclouds.vcloud.terremark.compute.config;
import static org.jclouds.compute.domain.OsFamily.CENTOS;
import org.jclouds.compute.domain.TemplateBuilder;
import com.google.inject.Injector;
/**
* @author Adrian Cole
*/
public class TerremarkECloudComputeServiceContextModule extends TerremarkVCloudComputeServiceContextModule {
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
return template.osFamily(CENTOS);
}
}

View File

@ -44,9 +44,9 @@ import org.testng.annotations.Test;
*
* @author Adrian Cole
*/
@Test(groups = "live", enabled = false, sequential = true, testName = "terremark.TerremarkVCloudComputeServiceLiveTest")
public class TerremarkECloudComputeServiceLiveTestDisabled extends BaseComputeServiceLiveTest {
public TerremarkECloudComputeServiceLiveTestDisabled() {
@Test(groups = "live", enabled = true, sequential = true, testName = "terremark.TerremarkVCloudComputeServiceLiveTest")
public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiveTest {
public TerremarkECloudComputeServiceLiveTest() {
provider = "trmk-ecloud";
}