From 08b8bb1f001025b65e6eadc93c2bb770dd877922 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 11 Nov 2010 14:58:21 +0100 Subject: [PATCH] added libvirt specific context spec object --- .../compute/LibvirtComputeService.java | 19 ++++++ .../LibvirtComputeServiceContextSpec.java | 43 +++++++++++++ ...bvirtComputeServiceContextBuilderTest.java | 15 +---- .../compute/LibvirtExperimentLiveTest.java | 60 ++++++++----------- 4 files changed, 88 insertions(+), 49 deletions(-) create mode 100644 sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/LibvirtComputeServiceContextSpec.java diff --git a/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/LibvirtComputeService.java b/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/LibvirtComputeService.java index 468d062753..676f4bfacd 100644 --- a/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/LibvirtComputeService.java +++ b/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/LibvirtComputeService.java @@ -1,3 +1,22 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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; diff --git a/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/LibvirtComputeServiceContextSpec.java b/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/LibvirtComputeServiceContextSpec.java new file mode 100644 index 0000000000..82c39c15d8 --- /dev/null +++ b/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/LibvirtComputeServiceContextSpec.java @@ -0,0 +1,43 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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 { + + @SuppressWarnings("unchecked") + public LibvirtComputeServiceContextSpec(String endpoint, String identity, String credential, Iterable 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.of()); + } +} \ No newline at end of file diff --git a/sandbox/libvirt/src/test/java/org/jclouds/libvirt/compute/LibvirtComputeServiceContextBuilderTest.java b/sandbox/libvirt/src/test/java/org/jclouds/libvirt/compute/LibvirtComputeServiceContextBuilderTest.java index 5297bce4f6..60e094a5fc 100644 --- a/sandbox/libvirt/src/test/java/org/jclouds/libvirt/compute/LibvirtComputeServiceContextBuilderTest.java +++ b/sandbox/libvirt/src/test/java/org/jclouds/libvirt/compute/LibvirtComputeServiceContextBuilderTest.java @@ -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("libvirt", - "test:///default", "1", "identity", "credential", new LibvirtComputeServiceContextModule(), - ImmutableSet. of())); - //System.err.println(context.getComputeService(). + .createContext(new LibvirtComputeServiceContextSpec("test:///default", "identity", "credential")); + // System.err.println(context.getComputeService(). context.close(); } - } diff --git a/sandbox/libvirt/src/test/java/org/jclouds/libvirt/compute/LibvirtExperimentLiveTest.java b/sandbox/libvirt/src/test/java/org/jclouds/libvirt/compute/LibvirtExperimentLiveTest.java index 3183840028..ebfac1e2f5 100644 --- a/sandbox/libvirt/src/test/java/org/jclouds/libvirt/compute/LibvirtExperimentLiveTest.java +++ b/sandbox/libvirt/src/test/java/org/jclouds/libvirt/compute/LibvirtExperimentLiveTest.java @@ -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,41 +53,38 @@ public class LibvirtExperimentLiveTest { public void testAndExperiment() { ComputeServiceContext context = null; try { - context = new ComputeServiceContextFactory() - .createContext(new StandaloneComputeServiceContextSpec("libvirt", - endpoint, apiversion, identity, credential, new LibvirtComputeServiceContextModule(), ImmutableSet - . 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()); + */ /* + * Template defaultTemplate = context.getComputeService().templateBuilder() + * .hardwareId("c7ff2039-a9f1-a659-7f91-e0f82f59d52e").imageId("1") //.locationId("") + * .build(); + */ /* - 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 - */ + * 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 nodeMetadataSet = context.getComputeService().runNodesWithTag("tty", 1); for (NodeMetadata nodeMetadata : nodeMetadataSet) { - /* - context.getComputeService().suspendNode(nodeMetadata.getId()); - context.getComputeService().resumeNode(nodeMetadata.getId()); - */ - context.getComputeService().destroyNode(nodeMetadata.getId()); + /* + * context.getComputeService().suspendNode(nodeMetadata.getId()); + * context.getComputeService().resumeNode(nodeMetadata.getId()); + */ + context.getComputeService().destroyNode(nodeMetadata.getId()); } - } catch (Exception e) { - e.printStackTrace(); - } finally { + } catch (Exception e) { + e.printStackTrace(); + } finally { if (context != null) context.close(); }