Issue 382 started libvirt

This commit is contained in:
Adrian Cole 2010-10-24 11:02:18 -05:00
parent 61c9583136
commit 78e39c688a
13 changed files with 1022 additions and 0 deletions

128
sandbox/libvirt/pom.xml Normal file
View File

@ -0,0 +1,128 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
====================================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../project/pom.xml</relativePath>
</parent>
<artifactId>jclouds-libvirt</artifactId>
<name>jclouds example components for a libvirt provider</name>
<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.libvirt.endpoint>https://libvirt.com</test.libvirt.endpoint>
<test.libvirt.apiversion>1.0</test.libvirt.apiversion>
<test.libvirt.identity>FIXME</test.libvirt.identity>
</properties>
<dependencies>
<dependency>
<groupId>org.libvirt</groupId>
<artifactId>libvirt</artifactId>
<version>0.4.1</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-jsch</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemProperties>
<property>
<name>test.libvirt.endpoint</name>
<value>${test.libvirt.endpoint}</value>
</property>
<property>
<name>test.libvirt.apiversion</name>
<value>${test.libvirt.apiversion}</value>
</property>
<property>
<name>test.libvirt.identity</name>
<value>${test.libvirt.identity}</value>
</property>
<property>
<name>jclouds.compute.blacklist.nodes</name>
<value>${jclouds.compute.blacklist.nodes}</value>
</property>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -0,0 +1,56 @@
/**
*
* 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.libvirt;
import com.google.common.base.Objects;
/**
* This would be replaced with the real java object related to the underlying data center
*
* @author Adrian Cole
*/
public class Datacenter {
public int id;
public String name;
public Datacenter(int id, String name) {
this.id = id;
this.name = name;
}
@Override
public int hashCode() {
return Objects.hashCode(id, name);
}
@Override
public boolean equals(Object that) {
if (that == null)
return false;
return Objects.equal(this.toString(), that.toString());
}
@Override
public String toString() {
return Objects.toStringHelper(this).add("id", id).add("name", name).toString();
}
}

View File

@ -0,0 +1,63 @@
/**
*
* 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.libvirt;
import com.google.common.base.Objects;
/**
* This would be replaced with the real java object related to the underlying hardware
*
* @author Adrian Cole
*/
public class Hardware {
public int id;
public String name;
public int cores;
public int ram;
public float disk;
public Hardware(int id, String name, int cores, int ram, float disk) {
this.id = id;
this.name = name;
this.cores = cores;
this.ram = ram;
this.disk = disk;
}
@Override
public int hashCode() {
return Objects.hashCode(id, name, cores, ram, disk);
}
@Override
public boolean equals(Object that) {
if (that == null)
return false;
return Objects.equal(this.toString(), that.toString());
}
@Override
public String toString() {
return Objects.toStringHelper(this).add("id", id).add("name", name).add("cores", cores).add("ram", ram)
.add("disk", disk).toString();
}
}

View File

@ -0,0 +1,56 @@
/**
*
* 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.libvirt;
import com.google.common.base.Objects;
/**
* This would be replaced with the real java object related to the underlying image
*
* @author Adrian Cole
*/
public class Image {
public int id;
public String name;
public Image(int id, String name) {
this.id = id;
this.name = name;
}
@Override
public int hashCode() {
return Objects.hashCode(id, name);
}
@Override
public boolean equals(Object that) {
if (that == null)
return false;
return Objects.equal(this.toString(), that.toString());
}
@Override
public String toString() {
return Objects.toStringHelper(this).add("id", id).add("name", name).toString();
}
}

View File

@ -0,0 +1,54 @@
/**
*
* 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.libvirt.compute;
import java.util.List;
import java.util.Properties;
import org.jclouds.compute.StandaloneComputeServiceContextBuilder;
import org.jclouds.compute.config.StandaloneComputeServiceContextModule;
import org.jclouds.libvirt.Datacenter;
import org.jclouds.libvirt.Hardware;
import org.jclouds.libvirt.Image;
import org.jclouds.libvirt.compute.domain.LibvirtComputeServiceContextModule;
import org.libvirt.Domain;
import com.google.inject.Module;
/**
*
* @author Adrian Cole
*/
public class LibvirtComputeServiceContextBuilder extends StandaloneComputeServiceContextBuilder {
public LibvirtComputeServiceContextBuilder(Properties props) {
super(props);
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(createContextModule());
}
public StandaloneComputeServiceContextModule<Domain, Hardware, Image, Datacenter> createContextModule() {
return new LibvirtComputeServiceContextModule();
}
}

View File

@ -0,0 +1,81 @@
/**
*
* 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.libvirt.compute.domain;
import java.net.URI;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.config.StandaloneComputeServiceContextModule;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.suppliers.DefaultLocationSupplier;
import org.jclouds.domain.Location;
import org.jclouds.libvirt.Datacenter;
import org.jclouds.libvirt.Hardware;
import org.jclouds.libvirt.Image;
import org.jclouds.libvirt.compute.functions.DatacenterToLocation;
import org.jclouds.libvirt.compute.functions.DomainToNodeMetadata;
import org.jclouds.libvirt.compute.functions.LibvirtHardwareToHardware;
import org.jclouds.libvirt.compute.functions.LibvirtImageToImage;
import org.jclouds.libvirt.compute.strategy.LibvirtComputeServiceAdapter;
import org.jclouds.rest.annotations.Provider;
import org.libvirt.Connect;
import org.libvirt.Domain;
import org.libvirt.LibvirtException;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
/**
*
* @author Adrian Cole
*/
public class LibvirtComputeServiceContextModule extends
StandaloneComputeServiceContextModule<Domain, Hardware, Image, Datacenter> {
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<ComputeServiceAdapter<Domain, Hardware, 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<Hardware, org.jclouds.compute.domain.Hardware>>() {
}).to(LibvirtHardwareToHardware.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());
}
}

View File

@ -0,0 +1,42 @@
/**
*
* 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.libvirt.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.libvirt.Datacenter;
import com.google.common.base.Function;
/**
* @author Adrian Cole
*/
@Singleton
public class DatacenterToLocation implements Function<Datacenter, Location> {
@Override
public Location apply(Datacenter from) {
return new LocationImpl(LocationScope.ZONE, from.id + "", from.name, null);
}
}

View File

@ -0,0 +1,141 @@
/**
*
* 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.libvirt.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.collect.FindResourceInSet;
import org.jclouds.collect.Memoized;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.libvirt.Domain;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
/**
* @author Adrian Cole
*/
@Singleton
public class DomainToNodeMetadata implements Function<Domain, NodeMetadata> {
// public static final Map<Domain.Status, NodeState> serverStatusToNodeState = ImmutableMap
// .<Domain.Status, NodeState> builder().put(Domain.Status.ACTIVE, NodeState.RUNNING)//
// .put(Domain.Status.BUILD, NodeState.PENDING)//
// .put(Domain.Status.TERMINATED, NodeState.TERMINATED)//
// .put(Domain.Status.UNRECOGNIZED, NodeState.UNRECOGNIZED)//
// .build();
private final FindHardwareForDomain findHardwareForDomain;
private final FindLocationForDomain findLocationForDomain;
private final FindImageForDomain findImageForDomain;
private final Map<String, Credentials> credentialStore;
@Inject
DomainToNodeMetadata(Map<String, Credentials> credentialStore, FindHardwareForDomain findHardwareForDomain,
FindLocationForDomain findLocationForDomain, FindImageForDomain findImageForDomain) {
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
this.findHardwareForDomain = checkNotNull(findHardwareForDomain, "findHardwareForDomain");
this.findLocationForDomain = checkNotNull(findLocationForDomain, "findLocationForDomain");
this.findImageForDomain = checkNotNull(findImageForDomain, "findImageForDomain");
}
@Override
public NodeMetadata apply(Domain from) {
// convert the result object to a jclouds NodeMetadata
NodeMetadataBuilder builder = new NodeMetadataBuilder();
// builder.ids(from.id + "");
// builder.name(from.name);
// builder.location(findLocationForDomain.apply(from));
// builder.tag(parseTagFromName(from.name));
// builder.imageId(from.imageId + "");
// Image image = findImageForDomain.apply(from);
// if (image != null)
// builder.operatingSystem(image.getOperatingSystem());
// builder.hardware(findHardwareForDomain.apply(from));
// builder.state(serverStatusToNodeState.get(from.status));
// builder.publicAddresses(ImmutableSet.<String> of(from.publicAddress));
// builder.privateAddresses(ImmutableSet.<String> of(from.privateAddress));
// builder.credentials(credentialStore.get(from.id + ""));
return builder.build();
}
@Singleton
public static class FindHardwareForDomain extends FindResourceInSet<Domain, Hardware> {
@Inject
public FindHardwareForDomain(@Memoized Supplier<Set<? extends Hardware>> hardware) {
super(hardware);
}
@Override
public boolean matches(Domain from, Hardware input) {
// TODO
// return input.getProviderId().equals(from.hardwareId + "");
return true;
}
}
@Singleton
public static class FindImageForDomain extends FindResourceInSet<Domain, Image> {
@Inject
public FindImageForDomain(@Memoized Supplier<Set<? extends Image>> hardware) {
super(hardware);
}
@Override
public boolean matches(Domain from, Image input) {
// TODO
// return input.getProviderId().equals(from.imageId + "");
return true;
}
}
@Singleton
public static class FindLocationForDomain extends FindResourceInSet<Domain, Location> {
@Inject
public FindLocationForDomain(@Memoized Supplier<Set<? extends Location>> hardware) {
super(hardware);
}
@Override
public boolean matches(Domain from, Location input) {
// TODO
// return input.getId().equals(from.datacenter + "");
return true;
}
}
}

View File

@ -0,0 +1,50 @@
/**
*
* 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.libvirt.compute.functions;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.internal.VolumeImpl;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
/**
* @author Adrian Cole
*/
@Singleton
public class LibvirtHardwareToHardware implements Function<org.jclouds.libvirt.Hardware, Hardware> {
@Override
public Hardware apply(org.jclouds.libvirt.Hardware from) {
HardwareBuilder builder = new HardwareBuilder();
builder.ids(from.id + "");
builder.name(from.name);
builder.processors(ImmutableList.of(new Processor(from.cores, 1.0)));
builder.ram(from.ram);
builder.volumes(ImmutableList.<Volume> of(new VolumeImpl(from.disk, true, false)));
return builder.build();
}
}

View File

@ -0,0 +1,62 @@
/**
*
* 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.libvirt.compute.functions;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import com.google.common.base.Function;
/**
* @author Adrian Cole
*/
@Singleton
public class LibvirtImageToImage implements Function<org.jclouds.libvirt.Image, Image> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
@Override
public Image apply(org.jclouds.libvirt.Image from) {
ImageBuilder builder = new ImageBuilder();
builder.ids(from.id + "");
builder.name(from.name);
builder.description(from.name);
OsFamily family = null;
try {
family = OsFamily.fromValue(from.name);
builder.operatingSystem(new OperatingSystemBuilder().name(from.name).family(family).build());
} catch (IllegalArgumentException e) {
logger.debug("<< didn't match os(%s)", from);
}
return builder.build();
}
}

View File

@ -0,0 +1,90 @@
package org.jclouds.libvirt.compute.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.domain.Template;
import org.jclouds.domain.Credentials;
import org.jclouds.libvirt.Datacenter;
import org.jclouds.libvirt.Hardware;
import org.jclouds.libvirt.Image;
import org.libvirt.Domain;
import org.libvirt.jna.Libvirt;
import com.google.common.collect.ImmutableSet;
/**
* defines the connection between the {@link Libvirt} implementation and the jclouds
* {@link ComputeService}
*
*/
@Singleton
public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domain, Hardware, Image, Datacenter> {
private final Libvirt client;
@Inject
public LibvirtComputeServiceAdapter(Libvirt client) {
this.client = checkNotNull(client, "client");
}
@Override
public Domain createNodeAndStoreCredentials(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));
return null;
}
@Override
public Iterable<Hardware> listHardware() {
return ImmutableSet.of();
// TODO
// return client.listHardware();
}
@Override
public Iterable<Image> listImages() {
return ImmutableSet.of();
// TODO
// return client.listImages();
}
@Override
public Iterable<Domain> listNodes() {
return ImmutableSet.of();
// TODO
// return client.listDomains();
}
@Override
public Iterable<Datacenter> listLocations() {
return ImmutableSet.of(new Datacenter(1, "SFO"));
}
@Override
public Domain getNode(String id) {
// int serverId = Integer.parseInt(id);
// return client.getDomain(serverId);
return null;
}
@Override
public void destroyNode(String id) {
// client.destroyDomain(Integer.parseInt(id));
}
@Override
public void rebootNode(String id) {
// client.rebootDomain(Integer.parseInt(id));
}
}

View File

@ -0,0 +1,63 @@
package org.jclouds.libvirt.compute;
import static org.testng.Assert.assertNotNull;
import java.net.URI;
import java.util.Properties;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.config.StandaloneComputeServiceContextModule;
import org.jclouds.libvirt.Datacenter;
import org.jclouds.libvirt.Hardware;
import org.jclouds.libvirt.Image;
import org.jclouds.libvirt.compute.domain.LibvirtComputeServiceContextModule;
import org.libvirt.Connect;
import org.libvirt.Domain;
import org.libvirt.LibvirtException;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*
*/
@Test(groups = "unit")
public class LibvirtComputeServiceContextBuilderTest {
//
// @Test
// public void testCreateContextModule() {
// assertNotNull(new LibvirtComputeServiceContextBuilder(new Properties()).createContextModule());
// }
//
// @Test
// public void testCanBuildDirectly() {
// ComputeServiceContext context = new LibvirtComputeServiceContextBuilder(new Properties()) {
//
// @Override
// public StandaloneComputeServiceContextModule<Domain, Hardware, Image, Datacenter> createContextModule() {
// return new StubLibvirtComputeServiceContextModule();
// }
//
// }.buildComputeServiceContext();
// context.close();
// }
//
// @Test
// public void testCanBuildWithComputeService() {
// ComputeServiceContext context = ComputeServiceContextFactory
// .createStandaloneContext(new StubLibvirtComputeServiceContextModule());
// context.close();
//
// }
private static class StubLibvirtComputeServiceContextModule extends LibvirtComputeServiceContextModule {
@Override
protected Connect createConnection(URI endpoint, String identity, String credential) throws LibvirtException {
// TODO replace with mock
return null;
}
}
}

View File

@ -0,0 +1,136 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2009 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.
====================================================================
-->
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--
For more configuration infromation and examples see the Apache
Log4j website: http://logging.apache.org/log4j/
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
<!-- A time/date based rolling appender -->
<appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-wire.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="COMPUTEFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-compute.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<appender name="ASYNCCOMPUTE" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="COMPUTEFILE" />
</appender>
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
<appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="WIREFILE" />
</appender>
<!-- ================ -->
<!-- Limit categories -->
<!-- ================ -->
<category name="org.jclouds">
<priority value="DEBUG" />
<appender-ref ref="ASYNC" />
</category>
<category name="jclouds.headers">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<category name="jclouds.wire">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<category name="jclouds.compute">
<priority value="TRACE" />
<appender-ref ref="ASYNCCOMPUTE" />
</category>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root>
<priority value="WARN" />
</root>
</log4j:configuration>