From 3c0cffc54f3be0850bb5e243364d4e9a83e91f49 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 20 Feb 2011 08:41:15 -0800 Subject: [PATCH] in cloudstack operations that affect resources, account and domainid must be paired --- .../options/AssociateIPAddressOptions.java | 33 +++++-------------- .../options/DeployVirtualMachineOptions.java | 22 ++----------- .../AssociateIPAddressOptionsTest.java | 23 ++++--------- 3 files changed, 19 insertions(+), 59 deletions(-) diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/AssociateIPAddressOptions.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/AssociateIPAddressOptions.java index 647c3b270e..45a9a54f2c 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/AssociateIPAddressOptions.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/AssociateIPAddressOptions.java @@ -34,21 +34,15 @@ public class AssociateIPAddressOptions extends BaseHttpRequestOptions { public static final AssociateIPAddressOptions NONE = new AssociateIPAddressOptions(); /** - * @param domainId - * the ID of the domain to associate with this IP address - */ - public AssociateIPAddressOptions domainId(long domainId) { - this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId + "")); - return this; - - } - - /** + * * @param account - * the account to associate with this IP address + * an optional account for the ip address + * @param domain + * domain id */ - public AssociateIPAddressOptions account(String account) { + public AssociateIPAddressOptions accountInDomain(String account, long domain) { this.queryParameters.replaceValues("account", ImmutableSet.of(account)); + this.queryParameters.replaceValues("domainid", ImmutableSet.of(domain + "")); return this; } @@ -63,21 +57,12 @@ public class AssociateIPAddressOptions extends BaseHttpRequestOptions { } public static class Builder { - /** - * @see AssociateIPAddressOptions#account + * @see AssociateIPAddressOptions#accountInDomain */ - public static AssociateIPAddressOptions account(String account) { + public static AssociateIPAddressOptions accountInDomain(String account, long domain) { AssociateIPAddressOptions options = new AssociateIPAddressOptions(); - return options.account(account); - } - - /** - * @see AssociateIPAddressOptions#domainId - */ - public static AssociateIPAddressOptions domainId(long id) { - AssociateIPAddressOptions options = new AssociateIPAddressOptions(); - return options.domainId(id); + return options.accountInDomain(account, domain); } /** diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/DeployVirtualMachineOptions.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/DeployVirtualMachineOptions.java index fa2c75b4ef..8e4f1e8902 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/DeployVirtualMachineOptions.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/DeployVirtualMachineOptions.java @@ -46,8 +46,9 @@ public class DeployVirtualMachineOptions extends BaseHttpRequestOptions { * domain id */ public DeployVirtualMachineOptions accountInDomain(String account, long domain) { - this.queryParameters.replaceValues("account", ImmutableSet.of(account + "")); - return domainId(domain); + this.queryParameters.replaceValues("account", ImmutableSet.of(account)); + this.queryParameters.replaceValues("domain", ImmutableSet.of(domain + "")); + return this; } /** @@ -75,15 +76,6 @@ public class DeployVirtualMachineOptions extends BaseHttpRequestOptions { return this; } - /** - * @param domainId - * an optional domainId for the virtual machine - */ - public DeployVirtualMachineOptions domainId(long domainId) { - this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId + "")); - return this; - } - /** * @param group * an optional group for the virtual machine @@ -208,14 +200,6 @@ public class DeployVirtualMachineOptions extends BaseHttpRequestOptions { return options.displayName(displayName); } - /** - * @see DeployVirtualMachineOptions#domainId - */ - public static DeployVirtualMachineOptions domainId(long id) { - DeployVirtualMachineOptions options = new DeployVirtualMachineOptions(); - return options.domainId(id); - } - /** * @see DeployVirtualMachineOptions#group */ diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/AssociateIPAddressOptionsTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/AssociateIPAddressOptionsTest.java index 0458b4b858..97d0a0e71f 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/AssociateIPAddressOptionsTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/AssociateIPAddressOptionsTest.java @@ -19,8 +19,7 @@ package org.jclouds.cloudstack.options; -import static org.jclouds.cloudstack.options.AssociateIPAddressOptions.Builder.account; -import static org.jclouds.cloudstack.options.AssociateIPAddressOptions.Builder.domainId; +import static org.jclouds.cloudstack.options.AssociateIPAddressOptions.Builder.accountInDomain; import static org.jclouds.cloudstack.options.AssociateIPAddressOptions.Builder.networkId; import static org.testng.Assert.assertEquals; @@ -36,23 +35,15 @@ import com.google.common.collect.ImmutableList; @Test(groups = "unit") public class AssociateIPAddressOptionsTest { - public void testAccount() { - AssociateIPAddressOptions options = new AssociateIPAddressOptions().account("account"); - assertEquals(ImmutableList.of("account"), options.buildQueryParameters().get("account")); - } - - public void testAccountStatic() { - AssociateIPAddressOptions options = account("account"); - assertEquals(ImmutableList.of("account"), options.buildQueryParameters().get("account")); - } - - public void testDomainId() { - AssociateIPAddressOptions options = new AssociateIPAddressOptions().domainId(6); + public void testAccountInDomainId() { + AssociateIPAddressOptions options = new AssociateIPAddressOptions().accountInDomain("adrian", 6); + assertEquals(ImmutableList.of("adrian"), options.buildQueryParameters().get("account")); assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid")); } - public void testDomainIdStatic() { - AssociateIPAddressOptions options = domainId(6); + public void testAccountInDomainIdStatic() { + AssociateIPAddressOptions options = accountInDomain("adrian", 6); + assertEquals(ImmutableList.of("adrian"), options.buildQueryParameters().get("account")); assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid")); }