mirror of https://github.com/apache/jclouds.git
cosmetic fixes
This commit is contained in:
parent
3e30910b86
commit
b0a9263486
|
@ -44,6 +44,7 @@ import org.xml.sax.InputSource;
|
|||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
@ -69,7 +70,6 @@ public class DomainToHardware implements Function<Domain, Hardware> {
|
|||
builder.processors(processors);
|
||||
|
||||
builder.ram((int) from.getInfo().maxMem);
|
||||
// TODO volumes
|
||||
List<Volume> volumes = Lists.newArrayList();
|
||||
XMLBuilder xmlBuilder = XMLBuilder.parse(new InputSource(new StringReader(from.getXMLDesc(0))));
|
||||
Document doc = xmlBuilder.getDocument();
|
||||
|
@ -85,22 +85,22 @@ public class DomainToHardware implements Function<Domain, Hardware> {
|
|||
}
|
||||
builder.volumes((List<Volume>) volumes);
|
||||
} catch (LibvirtException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
propagate(e);
|
||||
} catch (XPathExpressionException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
propagate(e);
|
||||
} catch (ParserConfigurationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
propagate(e);
|
||||
} catch (SAXException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
propagate(e);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
propagate(e);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
protected <T> T propagate(Exception e) {
|
||||
Throwables.propagate(e);
|
||||
assert false;
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -26,6 +26,7 @@ import java.io.StringReader;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -79,24 +80,11 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
|
|||
@Override
|
||||
public Domain runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template,
|
||||
Map<String, Credentials> credentialStore) {
|
||||
// create the backend object using parameters from the template.
|
||||
// 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
|
||||
// credentialStore.put(from.id + "", new Credentials(from.loginUser, from.password));
|
||||
|
||||
//String[] domains;
|
||||
try {
|
||||
//domains = client.listDefinedDomains();
|
||||
String xmlDesc = "";
|
||||
Domain domain = 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;
|
||||
|
@ -112,18 +100,13 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
|
|||
StoragePool storagePool = client.storagePoolLookupByName(poolName);
|
||||
StorageVol clonedVol = cloneVolume(storagePool, storageVol);
|
||||
|
||||
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);
|
||||
|
@ -139,9 +122,6 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
|
|||
|
||||
@Override
|
||||
public Iterable<Image> listImages() {
|
||||
// return ImmutableSet.of();
|
||||
// TODO
|
||||
// return client.listImages();
|
||||
int i = 1;
|
||||
try {
|
||||
String[] domains = client.listDefinedDomains();
|
||||
|
@ -168,18 +148,6 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
|
|||
}
|
||||
}
|
||||
|
||||
protected <T> T propogate(LibvirtException e) {
|
||||
Throwables.propagate(e);
|
||||
assert false;
|
||||
return null;
|
||||
}
|
||||
|
||||
protected <T> T propogate(Exception e) {
|
||||
Throwables.propagate(e);
|
||||
assert false;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Datacenter> listLocations() {
|
||||
return ImmutableSet.of(new Datacenter(1, "SFO"));
|
||||
|
@ -197,9 +165,23 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
|
|||
@Override
|
||||
public void destroyNode(String id) {
|
||||
try {
|
||||
client.domainLookupByUUIDString(id).destroy();
|
||||
client.domainLookupByUUIDString(id).finalize();
|
||||
|
||||
/* TODO
|
||||
XMLBuilder builder = XMLBuilder.parse(new InputSource(new StringReader(
|
||||
client.domainLookupByUUIDString(id).getXMLDesc(0)
|
||||
)));
|
||||
String diskFileName = builder.xpathFind("//devices/disk[@device='disk']/source").getElement().getAttribute("file");
|
||||
System.out.println(" :P " +diskFileName);
|
||||
StorageVol storageVol = client.storageVolLookupByPath(diskFileName);
|
||||
storageVol.delete(0);
|
||||
|
||||
client.domainLookupByUUIDString(id).undefine();
|
||||
*/
|
||||
} catch (LibvirtException e) {
|
||||
propogate(e);
|
||||
} catch (Exception e) {
|
||||
propogate(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -212,6 +194,18 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
|
|||
}
|
||||
}
|
||||
|
||||
protected <T> T propogate(LibvirtException e) {
|
||||
Throwables.propagate(e);
|
||||
assert false;
|
||||
return null;
|
||||
}
|
||||
|
||||
protected <T> T propogate(Exception e) {
|
||||
Throwables.propagate(e);
|
||||
assert false;
|
||||
return null;
|
||||
}
|
||||
|
||||
private static StorageVol cloneVolume(StoragePool storagePool, StorageVol from) throws LibvirtException,
|
||||
XPathExpressionException, ParserConfigurationException, SAXException, IOException, TransformerException {
|
||||
String fromXML = from.getXMLDesc(0);
|
||||
|
@ -254,7 +248,6 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
|
|||
XMLBuilder builder = XMLBuilder.parse(new InputSource(new StringReader(fromXML)));
|
||||
|
||||
String cloneAppend = "-clone";
|
||||
|
||||
builder.xpathFind("//domain/name").t(cloneAppend);
|
||||
// change uuid domain
|
||||
Element oldChild = builder.xpathFind("//domain/uuid").getElement();
|
||||
|
@ -262,8 +255,11 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domai
|
|||
newNode.getFirstChild().setNodeValue(UUID.randomUUID().toString());
|
||||
builder.getDocument().getDocumentElement().replaceChild(newNode, oldChild);
|
||||
|
||||
builder.xpathFind("//domain/devices/disk/source").a("file", "/var/lib/libvirt/images/ttylinux.img-clone");
|
||||
String fromVolPath = builder.xpathFind("//domain/devices/disk/source").getElement().getAttribute("file");
|
||||
builder.xpathFind("//domain/devices/disk/source").a("file", fromVolPath + cloneAppend);
|
||||
// TODO generate valid MAC address
|
||||
String fromMACaddress = builder.xpathFind("//domain/devices/interface/mac").getElement().getAttribute("address");
|
||||
|
||||
builder.xpathFind("//domain/devices/interface/mac").a("address", "52:54:00:5c:dd:eb");
|
||||
return builder.asString(outputProperties);
|
||||
}
|
||||
|
|
|
@ -21,11 +21,13 @@ package org.jclouds.libvirt.compute;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
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.NodeMetadata;
|
||||
import org.jclouds.libvirt.Datacenter;
|
||||
import org.jclouds.libvirt.Image;
|
||||
import org.jclouds.libvirt.compute.domain.LibvirtComputeServiceContextModule;
|
||||
|
@ -65,6 +67,7 @@ public class LibvirtExperimentLiveTest {
|
|||
endpoint, apiversion, identity, credential, new LibvirtComputeServiceContextModule(), ImmutableSet
|
||||
.<Module> of()));
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
System.out.println("images " + context.getComputeService().listImages());
|
||||
|
@ -83,9 +86,16 @@ public class LibvirtExperimentLiveTest {
|
|||
* You can control the default template via overriding a method in standalonecomputeservicexontextmodule
|
||||
*/
|
||||
|
||||
context.getComputeService().runNodesWithTag("ttylinux", 1/*, defaultTemplate*/);
|
||||
Set<? extends NodeMetadata> nodeMetadataSet = context.getComputeService().runNodesWithTag("ttylinux", 1);
|
||||
|
||||
} catch (RunNodesException e) {
|
||||
for (NodeMetadata nodeMetadata : nodeMetadataSet) {
|
||||
context.getComputeService().suspendNode(nodeMetadata.getId());
|
||||
Thread.sleep(2000);
|
||||
context.getComputeService().resumeNode(nodeMetadata.getId());
|
||||
// TODO seems that destroy is intended to be a force shutoff, not a delete VM ...
|
||||
//context.getComputeService().destroyNode(nodeMetadata.getId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
|
|
Loading…
Reference in New Issue