mirror of https://github.com/apache/jclouds.git
fix on jclouds-vsphere
This commit is contained in:
parent
b80fa45ebb
commit
f4afd8a53f
|
@ -28,10 +28,10 @@ import com.google.common.base.Objects;
|
||||||
*/
|
*/
|
||||||
public class Image {
|
public class Image {
|
||||||
|
|
||||||
public int id;
|
public String id;
|
||||||
public String name;
|
public String name;
|
||||||
|
|
||||||
public Image(int id, String name) {
|
public Image(String id, String name) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
package org.jclouds.vi.compute;
|
package org.jclouds.vi.compute;
|
||||||
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
@ -49,12 +48,10 @@ import org.jclouds.compute.strategy.SuspendNodeStrategy;
|
||||||
import org.jclouds.compute.util.ComputeUtils;
|
import org.jclouds.compute.util.ComputeUtils;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.jamesmurty.utils.XMLBuilder;
|
|
||||||
import com.vmware.vim25.mo.ServiceInstance;
|
import com.vmware.vim25.mo.ServiceInstance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
|
|
||||||
package org.jclouds.vi.compute;
|
package org.jclouds.vi.compute;
|
||||||
|
|
||||||
import static org.jclouds.vi.ViConstants.PROPERTY_LIBVIRT_DOMAIN_DIR;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@ -38,9 +36,6 @@ public class ViComputeServiceContextBuilder extends StandaloneComputeServiceCont
|
||||||
|
|
||||||
public ViComputeServiceContextBuilder(Properties props) {
|
public ViComputeServiceContextBuilder(Properties props) {
|
||||||
super(ServiceInstance.class, props);
|
super(ServiceInstance.class, props);
|
||||||
|
|
||||||
if (!properties.containsKey(PROPERTY_LIBVIRT_DOMAIN_DIR))
|
|
||||||
properties.setProperty(PROPERTY_LIBVIRT_DOMAIN_DIR, "/etc/libvirt/qemu");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class ViComputeServiceContextSpec extends RestContextSpec<ComputeService,
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public ViComputeServiceContextSpec(String endpoint, String identity, String credential, Iterable<Module> modules) {
|
public ViComputeServiceContextSpec(String endpoint, String identity, String credential, Iterable<Module> modules) {
|
||||||
super("vsphere", endpoint, "1", identity, credential, ComputeService.class, ComputeService.class,
|
super("vi", endpoint, "1", identity, credential, ComputeService.class, ComputeService.class,
|
||||||
PropertiesBuilder.class, (Class) ViComputeServiceContextBuilder.class, modules);
|
PropertiesBuilder.class, (Class) ViComputeServiceContextBuilder.class, modules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ import java.util.Properties;
|
||||||
import org.jclouds.PropertiesBuilder;
|
import org.jclouds.PropertiesBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds properties used in Libvirt Clients
|
* Builds properties used in vi Clients
|
||||||
*
|
*
|
||||||
* @author Andrea Turli
|
* @author Andrea Turli
|
||||||
*/
|
*/
|
||||||
|
@ -37,7 +37,7 @@ public class ViPropertiesBuilder extends PropertiesBuilder {
|
||||||
@Override
|
@Override
|
||||||
protected Properties defaultProperties() {
|
protected Properties defaultProperties() {
|
||||||
Properties properties = super.defaultProperties();
|
Properties properties = super.defaultProperties();
|
||||||
properties.setProperty(PROPERTY_LIBVIRT_DOMAIN_DIR, "/etc/libvirt/qemu");
|
// properties.setProperty(PROPERTY_LIBVIRT_DOMAIN_DIR, "/etc/libvirt/qemu");
|
||||||
|
|
||||||
properties.setProperty(PROPERTY_TIMEOUT_NODE_SUSPENDED, 120 * 1000 + "");
|
properties.setProperty(PROPERTY_TIMEOUT_NODE_SUSPENDED, 120 * 1000 + "");
|
||||||
// auth fail sometimes happens in EC2, as the rc.local script that injects the
|
// auth fail sometimes happens in EC2, as the rc.local script that injects the
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
|
|
||||||
package org.jclouds.vi.compute.config;
|
package org.jclouds.vi.compute.config;
|
||||||
|
|
||||||
import static org.jclouds.vi.ViConstants.PROPERTY_LIBVIRT_DOMAIN_DIR;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
@ -45,7 +43,6 @@ import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.suppliers.DefaultLocationSupplier;
|
import org.jclouds.compute.suppliers.DefaultLocationSupplier;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.rest.annotations.Provider;
|
import org.jclouds.rest.annotations.Provider;
|
||||||
import org.jclouds.vi.Datacenter;
|
|
||||||
import org.jclouds.vi.Image;
|
import org.jclouds.vi.Image;
|
||||||
import org.jclouds.vi.compute.functions.DatacenterToLocation;
|
import org.jclouds.vi.compute.functions.DatacenterToLocation;
|
||||||
import org.jclouds.vi.compute.functions.ViImageToImage;
|
import org.jclouds.vi.compute.functions.ViImageToImage;
|
||||||
|
@ -61,11 +58,10 @@ import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
import com.google.inject.name.Names;
|
|
||||||
import com.jamesmurty.utils.XMLBuilder;
|
import com.jamesmurty.utils.XMLBuilder;
|
||||||
|
import com.vmware.vim25.mo.Datacenter;
|
||||||
import com.vmware.vim25.mo.ServiceInstance;
|
import com.vmware.vim25.mo.ServiceInstance;
|
||||||
import com.vmware.vim25.mo.VirtualMachine;
|
import com.vmware.vim25.mo.VirtualMachine;
|
||||||
|
|
||||||
|
@ -97,16 +93,14 @@ public class ViComputeServiceContextModule extends
|
||||||
protected ServiceInstance createConnection(@Provider URI endpoint,
|
protected ServiceInstance createConnection(@Provider URI endpoint,
|
||||||
@Named(Constants.PROPERTY_IDENTITY) String identity, @Named(Constants.PROPERTY_CREDENTIAL) String credential)
|
@Named(Constants.PROPERTY_IDENTITY) String identity, @Named(Constants.PROPERTY_CREDENTIAL) String credential)
|
||||||
throws RemoteException, MalformedURLException {
|
throws RemoteException, MalformedURLException {
|
||||||
System.out.println(endpoint);
|
|
||||||
System.out.println(identity);
|
|
||||||
System.out.println(credential);
|
|
||||||
return new ServiceInstance(endpoint.toURL(), identity, credential, true);
|
return new ServiceInstance(endpoint.toURL(), identity, credential, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
|
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
|
||||||
String domainDir = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_LIBVIRT_DOMAIN_DIR)));
|
//String domainDir = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_LIBVIRT_DOMAIN_DIR)));
|
||||||
String hardwareId = searchForHardwareIdInDomainDir(domainDir);
|
String domainDir = "";
|
||||||
|
String hardwareId = searchForHardwareIdInDomainDir(domainDir);
|
||||||
String image = searchForImageIdInDomainDir(domainDir);
|
String image = searchForImageIdInDomainDir(domainDir);
|
||||||
return template.hardwareId(hardwareId).imageId(image);
|
return template.hardwareId(hardwareId).imageId(image);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,9 @@ import javax.inject.Singleton;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
import org.jclouds.domain.internal.LocationImpl;
|
import org.jclouds.domain.internal.LocationImpl;
|
||||||
import org.jclouds.vi.Datacenter;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.vmware.vim25.mo.Datacenter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -36,7 +36,7 @@ public class DatacenterToLocation implements Function<Datacenter, Location> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Location apply(Datacenter from) {
|
public Location apply(Datacenter from) {
|
||||||
return new LocationImpl(LocationScope.ZONE, from.id + "", from.name, null);
|
return new LocationImpl(LocationScope.ZONE, from.getName() + "", from.getName(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* 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.vi.compute.functions;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.domain.Location;
|
|
||||||
import org.jclouds.domain.LocationScope;
|
|
||||||
import org.jclouds.domain.internal.LocationImpl;
|
|
||||||
import org.jclouds.vi.Datacenter;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class LibvirtNodeToLocation implements Function<Datacenter, Location> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Location apply(Datacenter from) {
|
|
||||||
return new LocationImpl(LocationScope.ZONE, from.id + "", from.name, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -51,6 +51,7 @@ public class ViImageToImage implements Function<org.jclouds.vi.Image, Image> {
|
||||||
|
|
||||||
OsFamily family = null;
|
OsFamily family = null;
|
||||||
try {
|
try {
|
||||||
|
// TODO
|
||||||
family = OsFamily.fromValue(from.name);
|
family = OsFamily.fromValue(from.name);
|
||||||
builder.operatingSystem(new OperatingSystemBuilder().name(from.name).family(family).description(from.name).build());
|
builder.operatingSystem(new OperatingSystemBuilder().name(from.name).family(family).description(from.name).build());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
|
|
@ -19,31 +19,23 @@
|
||||||
|
|
||||||
package org.jclouds.vi.compute.functions;
|
package org.jclouds.vi.compute.functions;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
import javax.xml.xpath.XPathConstants;
|
|
||||||
import javax.xml.xpath.XPathExpression;
|
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
|
||||||
import javax.xml.xpath.XPathFactory;
|
|
||||||
|
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.HardwareBuilder;
|
import org.jclouds.compute.domain.HardwareBuilder;
|
||||||
import org.jclouds.compute.domain.Processor;
|
import org.jclouds.compute.domain.Processor;
|
||||||
import org.jclouds.compute.domain.Volume;
|
import org.jclouds.compute.domain.Volume;
|
||||||
import org.jclouds.compute.domain.internal.VolumeImpl;
|
import org.jclouds.compute.domain.internal.VolumeImpl;
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.jamesmurty.utils.XMLBuilder;
|
import com.vmware.vim25.VirtualDevice;
|
||||||
|
import com.vmware.vim25.VirtualDeviceBackingInfo;
|
||||||
|
import com.vmware.vim25.VirtualDisk;
|
||||||
|
import com.vmware.vim25.VirtualDiskFlatVer2BackingInfo;
|
||||||
import com.vmware.vim25.mo.VirtualMachine;
|
import com.vmware.vim25.mo.VirtualMachine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,26 +59,21 @@ public class VirtualMachineToHardware implements Function<VirtualMachine, Hardwa
|
||||||
|
|
||||||
builder.ram((int) from.getConfig().getHardware().getMemoryMB());
|
builder.ram((int) from.getConfig().getHardware().getMemoryMB());
|
||||||
List<Volume> volumes = Lists.newArrayList();
|
List<Volume> volumes = Lists.newArrayList();
|
||||||
|
// look for volumes
|
||||||
/*
|
VirtualDevice[] devices = from.getConfig().getHardware().getDevice();
|
||||||
XMLBuilder xmlBuilder = XMLBuilder.parse(new InputSource(new StringReader(from.getXMLDesc(0))));
|
for (VirtualDevice virtualDevice : devices) {
|
||||||
Document doc = xmlBuilder.getDocument();
|
if(virtualDevice.getDeviceInfo().getLabel().contains("Hard disk")) {
|
||||||
XPathExpression expr = XPathFactory.newInstance().newXPath().compile("//devices/disk[@device='disk']/source/@file");
|
if(virtualDevice instanceof VirtualDisk) {
|
||||||
NodeList nodes = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
|
VirtualDisk disk = (VirtualDisk) virtualDevice;
|
||||||
String diskFileName = nodes.item(0).getNodeValue();
|
VirtualDeviceBackingInfo backingInfo = disk.getBacking();
|
||||||
for (int i = 0; i < nodes.getLength(); i++) {
|
if(backingInfo instanceof VirtualDiskFlatVer2BackingInfo) {
|
||||||
StorageVol storageVol = from.getConnect().storageVolLookupByPath(diskFileName);
|
VirtualDiskFlatVer2BackingInfo diskFlatVer2BackingInfo = (VirtualDiskFlatVer2BackingInfo) backingInfo;
|
||||||
String id = storageVol.getKey();
|
volumes.add(new VolumeImpl(diskFlatVer2BackingInfo.getUuid(), Volume.Type.LOCAL, new Float(disk.getCapacityInKB() + ""), diskFlatVer2BackingInfo.getFileName(), true, false));
|
||||||
float size = new Long(storageVol.getInfo().capacity).floatValue();
|
}
|
||||||
volumes.add(new VolumeImpl(id, Volume.Type.LOCAL, size, null, true, false));
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
builder.volumes((List<Volume>) volumes);
|
builder.volumes((List<Volume>) volumes);
|
||||||
Float size = new Float(21345);
|
|
||||||
String id = "dglffdbdflmb";
|
|
||||||
volumes.add(new VolumeImpl(id, Volume.Type.LOCAL, size, null, true, false));
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,18 +59,18 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
|
||||||
.put(VirtualMachinePowerState.poweredOff, NodeState.TERMINATED)//
|
.put(VirtualMachinePowerState.poweredOff, NodeState.TERMINATED)//
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
private final Function<VirtualMachine, Hardware> findHardwareForDomain;
|
private final Function<VirtualMachine, Hardware> findHardwareForVirtualMachine;
|
||||||
private final FindLocationForDomain findLocationForDomain;
|
private final FindLocationForVirtualMachine findLocationForVirtualMachine;
|
||||||
private final FindImageForDomain findImageForDomain;
|
private final FindImageForVirtualMachine findImageForVirtualMachine;
|
||||||
private final Map<String, Credentials> credentialStore;
|
private final Map<String, Credentials> credentialStore;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
VirtualMachineToNodeMetadata(Map<String, Credentials> credentialStore, Function<VirtualMachine, Hardware> findHardwareForDomain,
|
VirtualMachineToNodeMetadata(Map<String, Credentials> credentialStore, Function<VirtualMachine, Hardware> findHardwareForVirtualMachine,
|
||||||
FindLocationForDomain findLocationForDomain, FindImageForDomain findImageForDomain) {
|
FindLocationForVirtualMachine findLocationForVirtualMachine, FindImageForVirtualMachine findImageForVirtualMachine) {
|
||||||
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
||||||
this.findHardwareForDomain = checkNotNull(findHardwareForDomain, "findHardwareForDomain");
|
this.findHardwareForVirtualMachine = checkNotNull(findHardwareForVirtualMachine, "findHardwareForVirtualMachine");
|
||||||
this.findLocationForDomain = checkNotNull(findLocationForDomain, "findLocationForDomain");
|
this.findLocationForVirtualMachine = checkNotNull(findLocationForVirtualMachine, "findLocationForVirtualMachine");
|
||||||
this.findImageForDomain = checkNotNull(findImageForDomain, "findImageForDomain");
|
this.findImageForVirtualMachine = checkNotNull(findImageForVirtualMachine, "findImageForVirtualMachine");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -79,19 +79,23 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
|
||||||
// convert the result object to a jclouds NodeMetadata
|
// convert the result object to a jclouds NodeMetadata
|
||||||
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
||||||
try {
|
try {
|
||||||
builder.id(from.getMOR().get_value() + "");
|
builder.id(from.getConfig().getInstanceUuid());
|
||||||
builder.providerId(from.getConfig().getLocationId() + "");
|
builder.providerId(from.getConfig().getLocationId() + "");
|
||||||
builder.name(from.getName());
|
builder.name(from.getName());
|
||||||
builder.location(findLocationForDomain.apply(from));
|
builder.location(findLocationForVirtualMachine.apply(from));
|
||||||
builder.tag(parseTagFromName(from.getName()));
|
builder.tag(parseTagFromName(from.getName()));
|
||||||
|
|
||||||
builder.operatingSystem(new OperatingSystemBuilder().description(from.getConfig().getGuestFullName()).build());
|
builder.operatingSystem(new OperatingSystemBuilder()
|
||||||
builder.hardware(findHardwareForDomain.apply(from));
|
.name(from.getConfig().getGuestFullName())
|
||||||
|
.description(from.getConfig().getGuestFullName())
|
||||||
|
.is64Bit(from.getConfig().getGuestId().contains("64"))
|
||||||
|
.build());
|
||||||
|
builder.hardware(findHardwareForVirtualMachine.apply(from));
|
||||||
|
|
||||||
builder.state(domainStateToNodeState.get(from.getRuntime().getPowerState()));
|
builder.state(domainStateToNodeState.get(from.getRuntime().getPowerState()));
|
||||||
// builder.publicAddresses(ImmutableSet.<String> of(from.publicAddress));
|
// builder.publicAddresses(ImmutableSet.<String> of(from.publicAddress));
|
||||||
// builder.privateAddresses(ImmutableSet.<String> of(from.privateAddress));
|
// builder.privateAddresses(ImmutableSet.<String> of(from.privateAddress));
|
||||||
builder.credentials(credentialStore.get("node#" + from.getMOR().get_value()));
|
builder.credentials(credentialStore.get("node#" + from.getName()));
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
|
@ -101,10 +105,10 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public static class FindImageForDomain extends FindResourceInSet<VirtualMachine, Image> {
|
public static class FindImageForVirtualMachine extends FindResourceInSet<VirtualMachine, Image> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public FindImageForDomain(@Memoized Supplier<Set<? extends Image>> hardware) {
|
public FindImageForVirtualMachine(@Memoized Supplier<Set<? extends Image>> hardware) {
|
||||||
super(hardware);
|
super(hardware);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,10 +121,10 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public static class FindLocationForDomain extends FindResourceInSet<VirtualMachine, Location> {
|
public static class FindLocationForVirtualMachine extends FindResourceInSet<VirtualMachine, Location> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public FindLocationForDomain(@Memoized Supplier<Set<? extends Location>> hardware) {
|
public FindLocationForVirtualMachine(@Memoized Supplier<Set<? extends Location>> hardware) {
|
||||||
super(hardware);
|
super(hardware);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
package org.jclouds.vi.compute.strategy;
|
package org.jclouds.vi.compute.strategy;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static org.jclouds.vi.ViConstants.PROPERTY_LIBVIRT_DOMAIN_DIR;
|
|
||||||
|
|
||||||
import java.rmi.RemoteException;
|
import java.rmi.RemoteException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -33,14 +32,14 @@ import org.jclouds.compute.ComputeService;
|
||||||
import org.jclouds.compute.ComputeServiceAdapter;
|
import org.jclouds.compute.ComputeServiceAdapter;
|
||||||
import org.jclouds.compute.domain.Template;
|
import org.jclouds.compute.domain.Template;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.vi.Datacenter;
|
|
||||||
import org.jclouds.vi.Image;
|
import org.jclouds.vi.Image;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.inject.name.Named;
|
|
||||||
import com.vmware.vim25.InvalidProperty;
|
import com.vmware.vim25.InvalidProperty;
|
||||||
import com.vmware.vim25.RuntimeFault;
|
import com.vmware.vim25.RuntimeFault;
|
||||||
|
import com.vmware.vim25.mo.Datacenter;
|
||||||
|
import com.vmware.vim25.mo.Folder;
|
||||||
import com.vmware.vim25.mo.InventoryNavigator;
|
import com.vmware.vim25.mo.InventoryNavigator;
|
||||||
import com.vmware.vim25.mo.ManagedEntity;
|
import com.vmware.vim25.mo.ManagedEntity;
|
||||||
import com.vmware.vim25.mo.ServiceInstance;
|
import com.vmware.vim25.mo.ServiceInstance;
|
||||||
|
@ -116,25 +115,25 @@ public class ViComputeServiceAdapter implements ComputeServiceAdapter<VirtualMac
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<VirtualMachine> listHardwareProfiles() {
|
public Iterable<VirtualMachine> listHardwareProfiles() {
|
||||||
return listNodes();
|
// TODO
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<Image> listImages() {
|
public Iterable<Image> listImages() {
|
||||||
/*
|
List<Image> images = Lists.newArrayList();
|
||||||
int i = 1;
|
|
||||||
try {
|
try {
|
||||||
String[] domains = client.listDefinedDomains();
|
|
||||||
List<Image> images = Lists.newArrayList();
|
ManagedEntity[] entities = new InventoryNavigator(
|
||||||
for (String domainName : domains) {
|
client.getRootFolder()).searchManagedEntities("VirtualMachine");
|
||||||
images.add(new Image(i++, domainName));
|
for (ManagedEntity entity : entities) {
|
||||||
|
VirtualMachine vm = (VirtualMachine) entity;
|
||||||
|
images.add(new Image(vm.getConfig().getGuestId(), vm.getConfig().getGuestFullName()));
|
||||||
}
|
}
|
||||||
return images;
|
return images;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return propogate(e);
|
return propogate(e);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -143,8 +142,8 @@ public class ViComputeServiceAdapter implements ComputeServiceAdapter<VirtualMac
|
||||||
ManagedEntity[] vmEntities = new InventoryNavigator(client.getRootFolder()).searchManagedEntities("VirtualMachine");
|
ManagedEntity[] vmEntities = new InventoryNavigator(client.getRootFolder()).searchManagedEntities("VirtualMachine");
|
||||||
List<VirtualMachine> vms = Lists.newArrayList();
|
List<VirtualMachine> vms = Lists.newArrayList();
|
||||||
for (ManagedEntity entity : vmEntities) {
|
for (ManagedEntity entity : vmEntities) {
|
||||||
System.out.println(entity.getName());
|
VirtualMachine vm = (VirtualMachine) entity;
|
||||||
vms.add((VirtualMachine) entity);
|
vms.add(vm);
|
||||||
}
|
}
|
||||||
return vms;
|
return vms;
|
||||||
} catch (InvalidProperty e) {
|
} catch (InvalidProperty e) {
|
||||||
|
@ -164,7 +163,7 @@ public class ViComputeServiceAdapter implements ComputeServiceAdapter<VirtualMac
|
||||||
datacenterEntities = new InventoryNavigator(client.getRootFolder()).searchManagedEntities("Datacenter");
|
datacenterEntities = new InventoryNavigator(client.getRootFolder()).searchManagedEntities("Datacenter");
|
||||||
List<Datacenter> datacenters = Lists.newArrayList();
|
List<Datacenter> datacenters = Lists.newArrayList();
|
||||||
for (int i = 0; i< datacenterEntities.length; i++) {
|
for (int i = 0; i< datacenterEntities.length; i++) {
|
||||||
datacenters.add(new Datacenter(i, datacenterEntities[i].getName()));
|
datacenters.add((Datacenter) datacenterEntities[i]);
|
||||||
}
|
}
|
||||||
return datacenters;
|
return datacenters;
|
||||||
} catch (InvalidProperty e) {
|
} catch (InvalidProperty e) {
|
||||||
|
@ -178,18 +177,20 @@ public class ViComputeServiceAdapter implements ComputeServiceAdapter<VirtualMac
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VirtualMachine getNode(String id) {
|
public VirtualMachine getNode(String vmName) {
|
||||||
VirtualMachine vm = null;
|
|
||||||
/*
|
Folder rootFolder = client.getRootFolder();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
d = client.domainLookupByUUIDString(id);
|
return (VirtualMachine) new InventoryNavigator(
|
||||||
} catch (LibvirtException e) {
|
rootFolder).searchManagedEntity("VirtualMachine", vmName);
|
||||||
if (e.getMessage().indexOf("Domain not found: no domain with matching uuid") != -1)
|
} catch (InvalidProperty e) {
|
||||||
return null;
|
return propogate(e);
|
||||||
propogate(e);
|
} catch (RuntimeFault e) {
|
||||||
|
return propogate(e);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
return propogate(e);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
return vm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -33,11 +33,10 @@ public class ViComputeServiceContextBuilderTest {
|
||||||
Properties restProperties = new Properties();
|
Properties restProperties = new Properties();
|
||||||
restProperties.setProperty("vi.contextbuilder", ViComputeServiceContextBuilder.class.getName());
|
restProperties.setProperty("vi.contextbuilder", ViComputeServiceContextBuilder.class.getName());
|
||||||
restProperties.setProperty("vi.propertiesbuilder", ViPropertiesBuilder.class.getName());
|
restProperties.setProperty("vi.propertiesbuilder", ViPropertiesBuilder.class.getName());
|
||||||
restProperties.setProperty("vi.endpoint", "https://localhost/sdk");
|
restProperties.setProperty("vi.endpoint", "https://localhost/sdk");
|
||||||
|
|
||||||
ComputeServiceContext context = new ComputeServiceContextFactory(restProperties).createContext("vi",
|
ComputeServiceContext context = new ComputeServiceContextFactory(restProperties).createContext("vi",
|
||||||
"identity", "credential");
|
"identity", "credential");
|
||||||
|
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ import com.vmware.vim25.mo.ServiceInstance;
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live", enabled = true, sequential = true, testName = "vi.ViComputeServiceLiveTest")
|
@Test(groups = "live", enabled = true, sequential = true, testName = "vi.ViComputeServiceLiveTest")
|
||||||
public class ViComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
public class ViComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
||||||
|
|
||||||
public ViComputeServiceLiveTest() {
|
public ViComputeServiceLiveTest() {
|
||||||
provider = "vi";
|
provider = "vi";
|
||||||
}
|
}
|
||||||
|
@ -50,7 +51,7 @@ public class ViComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
||||||
|
|
||||||
public void testAssignability() throws Exception {
|
public void testAssignability() throws Exception {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
RestContext<ServiceInstance, ServiceInstance> goGridContext = new ComputeServiceContextFactory().createContext(
|
RestContext<ServiceInstance, ServiceInstance> viContext = new ComputeServiceContextFactory().createContext(
|
||||||
provider, identity, credential).getProviderSpecificContext();
|
provider, identity, credential).getProviderSpecificContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,11 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||||
|
import org.jclouds.compute.domain.ComputeMetadata;
|
||||||
|
import org.jclouds.compute.domain.Hardware;
|
||||||
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.domain.Template;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.vi.compute.ViComputeServiceContextSpec;
|
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -57,37 +59,38 @@ public class ViExperimentLiveTest {
|
||||||
try {
|
try {
|
||||||
context = new ComputeServiceContextFactory().createContext(new ViComputeServiceContextSpec(
|
context = new ComputeServiceContextFactory().createContext(new ViComputeServiceContextSpec(
|
||||||
endpoint, identity, credential));
|
endpoint, identity, credential));
|
||||||
context.getComputeService().listNodes();
|
|
||||||
|
|
||||||
|
// Set<? extends Location> locations = context.getComputeService().listAssignableLocations();
|
||||||
/*
|
//
|
||||||
* /* System.out.println("images " + context.getComputeService().listImages());
|
// Set<? extends ComputeMetadata> nodes = context.getComputeService().listNodes();
|
||||||
* System.out.println("nodes " + context.getComputeService().listNodes());
|
|
||||||
* System.out.println("hardware profiles " +
|
|
||||||
* context.getComputeService().listHardwareProfiles());
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
// TODO
|
||||||
/* Template defaultTemplate = context.getComputeService().templateBuilder()
|
// Set<? extends Hardware> hardwares = context.getComputeService().listHardwareProfiles();
|
||||||
.hardwareId("d106ae67-5a1b-8f91-b311-83c93bcb0a1f").imageId("1") //.locationId("")
|
//
|
||||||
.build();*/
|
// Set<? extends Image> images = context.getComputeService().listImages();
|
||||||
|
|
||||||
|
NodeMetadata node = context.getComputeService().getNodeMetadata("provaVM");
|
||||||
|
System.out.println(node);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We will probably make a default template out of properties at some point You can control
|
* 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
|
* the default template via overriding a method in standalonecomputeservicexontextmodule
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Set<? extends NodeMetadata> nodeMetadataSet = context.getComputeService().runNodesWithTag("tty", 1);
|
/* Template defaultTemplate = context.getComputeService().templateBuilder()
|
||||||
|
.hardwareId("d106ae67-5a1b-8f91-b311-83c93bcb0a1f").imageId("1") //.locationId("")
|
||||||
|
.build();
|
||||||
|
Set<? extends NodeMetadata> nodeMetadataSet = context.getComputeService().runNodesWithTag("MyServer", 1);
|
||||||
for (NodeMetadata nodeMetadata : nodeMetadataSet) {
|
for (NodeMetadata nodeMetadata : nodeMetadataSet) {
|
||||||
/*
|
|
||||||
* context.getComputeService().suspendNode(nodeMetadata.getId());
|
// context.getComputeService().suspendNode(nodeMetadata.getId());
|
||||||
* context.getComputeService().resumeNode(nodeMetadata.getId());
|
// context.getComputeService().resumeNode(nodeMetadata.getId());
|
||||||
*/
|
|
||||||
context.getComputeService().destroyNode(nodeMetadata.getId());
|
context.getComputeService().destroyNode(nodeMetadata.getId());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
*/
|
||||||
} finally {
|
} finally {
|
||||||
if (context != null)
|
if (context != null)
|
||||||
context.close();
|
context.close();
|
||||||
|
|
Loading…
Reference in New Issue