added libvirt specific context spec object

This commit is contained in:
Adrian Cole 2010-11-11 14:58:21 +01:00
parent 4f83c7dc1e
commit 08b8bb1f00
4 changed files with 88 additions and 49 deletions

View File

@ -1,3 +1,22 @@
/**
*
* 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.io.StringReader;

View File

@ -0,0 +1,43 @@
/**
*
* 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 org.jclouds.PropertiesBuilder;
import org.jclouds.compute.ComputeService;
import org.jclouds.rest.RestContextSpec;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
/**
* @author Adrian Cole
*/
public class LibvirtComputeServiceContextSpec extends RestContextSpec<ComputeService, ComputeService> {
@SuppressWarnings("unchecked")
public LibvirtComputeServiceContextSpec(String endpoint, String identity, String credential, Iterable<Module> modules) {
super("libvirt", endpoint, "1", identity, credential, ComputeService.class, ComputeService.class,
PropertiesBuilder.class, (Class) LibvirtComputeServiceContextBuilder.class, modules);
}
public LibvirtComputeServiceContextSpec(String endpoint, String identity, String credential) {
this(endpoint, identity, credential, ImmutableSet.<Module>of());
}
}

View File

@ -6,16 +6,8 @@ import java.util.Properties;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.StandaloneComputeServiceContextSpec;
import org.jclouds.libvirt.Datacenter;
import org.jclouds.libvirt.Image;
import org.jclouds.libvirt.compute.domain.LibvirtComputeServiceContextModule;
import org.libvirt.Domain;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
/**
*
* @author Adrian Cole
@ -32,11 +24,8 @@ public class LibvirtComputeServiceContextBuilderTest {
@Test
public void testCanBuildWithComputeService() {
ComputeServiceContext context = new ComputeServiceContextFactory()
.createContext(new StandaloneComputeServiceContextSpec<Domain, Domain, Image, Datacenter>("libvirt",
"test:///default", "1", "identity", "credential", new LibvirtComputeServiceContextModule(),
ImmutableSet.<Module> of()));
//System.err.println(context.getComputeService().
.createContext(new LibvirtComputeServiceContextSpec("test:///default", "identity", "credential"));
// System.err.println(context.getComputeService().
context.close();
}
}

View File

@ -25,19 +25,10 @@ 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.NodeMetadata;
import org.jclouds.libvirt.Datacenter;
import org.jclouds.libvirt.Image;
import org.jclouds.libvirt.compute.domain.LibvirtComputeServiceContextModule;
import org.libvirt.Domain;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
/**
*
* @author Adrian Cole
@ -62,35 +53,32 @@ public class LibvirtExperimentLiveTest {
public void testAndExperiment() {
ComputeServiceContext context = null;
try {
context = new ComputeServiceContextFactory()
.createContext(new StandaloneComputeServiceContextSpec<Domain, Domain, Image, Datacenter>("libvirt",
endpoint, apiversion, identity, credential, new LibvirtComputeServiceContextModule(), ImmutableSet
.<Module> of()));
context = new ComputeServiceContextFactory().createContext(new LibvirtComputeServiceContextSpec(
"test:///default", "identity", "credential"));
/*
/*
System.out.println("images " + context.getComputeService().listImages());
System.out.println("nodes " + context.getComputeService().listNodes());
System.out.println("hardware profiles " + context.getComputeService().listHardwareProfiles());
*
* /* 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();
* 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
* 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
*/
Set<? extends NodeMetadata> nodeMetadataSet = context.getComputeService().runNodesWithTag("tty", 1);
for (NodeMetadata nodeMetadata : nodeMetadataSet) {
/*
context.getComputeService().suspendNode(nodeMetadata.getId());
context.getComputeService().resumeNode(nodeMetadata.getId());
* context.getComputeService().suspendNode(nodeMetadata.getId());
* context.getComputeService().resumeNode(nodeMetadata.getId());
*/
context.getComputeService().destroyNode(nodeMetadata.getId());
}