diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalAccountAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalAccountAsyncClient.java index 87485a93c7..88f0746f69 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalAccountAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalAccountAsyncClient.java @@ -22,6 +22,7 @@ import com.google.common.util.concurrent.ListenableFuture; import org.jclouds.cloudstack.domain.Account; import org.jclouds.cloudstack.filters.QuerySigner; import org.jclouds.cloudstack.options.CreateAccountOptions; +import org.jclouds.cloudstack.options.UpdateAccountOptions; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; @@ -60,6 +61,17 @@ public interface GlobalAccountAsyncClient extends DomainAccountAsyncClient { @QueryParam("firstname") String firstName, @QueryParam("lastname") String lastName, @QueryParam("password") String hashedPassword, CreateAccountOptions... options); + /** + * @see GlobalAccountClient#updateAccount + */ + @GET + @QueryParams(keys = "command", values = "updateAccount") + @SelectJson("account") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture updateAccount(@QueryParam("account") String accountName, + @QueryParam("domainid") long domainId, @QueryParam("newname") String newName, UpdateAccountOptions... options); + /** * @see GlobalAccountClient#deleteAccount */ diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalAccountClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalAccountClient.java index d7c09c8d5f..76d72cc0ec 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalAccountClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalAccountClient.java @@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.cloudstack.domain.Account; import org.jclouds.cloudstack.options.CreateAccountOptions; +import org.jclouds.cloudstack.options.UpdateAccountOptions; import org.jclouds.concurrent.Timeout; /** @@ -54,6 +55,17 @@ public interface GlobalAccountClient extends DomainAccountClient { Account createAccount(String userName, Account.Type accountType, String email, String firstName, String lastName, String hashedPassword, CreateAccountOptions... options); + /** + * Update an existing account + * + * @param accountName the current account name + * @param domainId the ID of the domain were the account exists + * @param newName new name for the account + * @param options optional arguments + * @return + */ + Account updateAccount(String accountName, long domainId, String newName, UpdateAccountOptions... options); + /** * Delete an account with the specified ID * diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/UpdateAccountOptions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/UpdateAccountOptions.java new file mode 100644 index 0000000000..cde893b9b4 --- /dev/null +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/UpdateAccountOptions.java @@ -0,0 +1,56 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.cloudstack.options; + +import com.google.common.collect.ImmutableSet; +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Optional arguments for updating an Account + * + * @see + * @author Andrei Savu + */ +public class UpdateAccountOptions extends BaseHttpRequestOptions { + + public static final UpdateAccountOptions NONE = new UpdateAccountOptions(); + + /** + * @param networkDomain + * network domain for the account's networks + */ + public UpdateAccountOptions networkDomain(String networkDomain) { + this.queryParameters.replaceValues("networkdomain", ImmutableSet.of(networkDomain)); + return this; + } + + public static class Builder { + + /** + * @see UpdateAccountOptions#networkDomain + */ + public static UpdateAccountOptions networkDomain(String networkDomain) { + UpdateAccountOptions options = new UpdateAccountOptions(); + return options.networkDomain(networkDomain); + } + } + +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalAccountClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalAccountClientLiveTest.java index bfa2d00c5d..3f3431b14d 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalAccountClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalAccountClientLiveTest.java @@ -19,7 +19,6 @@ package org.jclouds.cloudstack.features; import org.jclouds.cloudstack.domain.Account; -import org.jclouds.logging.Logger; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; @@ -45,6 +44,12 @@ public class GlobalAccountClientLiveTest extends BaseCloudStackClientLiveTest { assertEquals(account.getName(), prefix + "-account"); assertEquals(account.getType(), Account.Type.USER); + Account updated = globalAdminClient.getAccountClient().updateAccount( + account.getName(), account.getDomainId(), prefix + "-account-2"); + + assertNotNull(updated); + assertEquals(updated.getName(), prefix + "-account-2"); + } finally { if (account != null) { globalAdminClient.getAccountClient().deleteAccount(account.getId());