mirror of https://github.com/apache/jclouds.git
Implemented create / deleteAccount global admin APIs
This commit is contained in:
parent
842c7b8e01
commit
d2eb9866c5
|
@ -273,7 +273,7 @@ public class Account extends ForwardingSet<User> implements Comparable<Account>
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name();
|
||||
return "" + code;
|
||||
}
|
||||
|
||||
public static Type fromValue(String type) {
|
||||
|
|
|
@ -18,15 +18,27 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
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.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to CloudStack Account features available to Global
|
||||
* Admin users.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @author Adrian Cole, Andrei Savu
|
||||
* @see <a href=
|
||||
* "http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_Global_Admin.html"
|
||||
* />
|
||||
|
@ -35,4 +47,25 @@ import org.jclouds.rest.annotations.RequestFilters;
|
|||
@QueryParams(keys = "response", values = "json")
|
||||
public interface GlobalAccountAsyncClient extends DomainAccountAsyncClient {
|
||||
|
||||
/**
|
||||
* @see GlobalAccountClient#createAccount
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "createAccount")
|
||||
@SelectJson("account")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Account> createAccount(@QueryParam("username") String userName,
|
||||
@QueryParam("accounttype") Account.Type accountType, @QueryParam("email") String email,
|
||||
@QueryParam("firstname") String firstName, @QueryParam("lastname") String lastName,
|
||||
@QueryParam("password") String hashedPassword, CreateAccountOptions... options);
|
||||
|
||||
/**
|
||||
* @see GlobalAccountClient#deleteAccount
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "deleteAccount")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> deleteAccount(@QueryParam("id") long id);
|
||||
}
|
||||
|
|
|
@ -20,13 +20,15 @@ package org.jclouds.cloudstack.features;
|
|||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.cloudstack.domain.Account;
|
||||
import org.jclouds.cloudstack.options.CreateAccountOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to CloudStack Account features available to Global
|
||||
* Admin users.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @author Adrian Cole, Andrei Savu
|
||||
* @see <a href=
|
||||
* "http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_Global_Admin.html"
|
||||
* />
|
||||
|
@ -34,5 +36,30 @@ import org.jclouds.concurrent.Timeout;
|
|||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public interface GlobalAccountClient extends DomainAccountClient {
|
||||
|
||||
/**
|
||||
* Create a new Cloudstack account
|
||||
*
|
||||
* @param userName unique username.
|
||||
* @param accountType type of account
|
||||
* @param email
|
||||
* @param firstName
|
||||
* @param lastName
|
||||
* @param hashedPassword
|
||||
* Hashed password (Default is MD5). If you wish to use any other
|
||||
* hashing algorithm, you would need to write a custom authentication adapter See Docs section.
|
||||
* @param options
|
||||
* optional parameters
|
||||
* @return
|
||||
*/
|
||||
Account createAccount(String userName, Account.Type accountType, String email,
|
||||
String firstName, String lastName, String hashedPassword, CreateAccountOptions... options);
|
||||
|
||||
/**
|
||||
* Delete an account with the specified ID
|
||||
*
|
||||
* @param accountId
|
||||
* @return
|
||||
*/
|
||||
Void deleteAccount(long accountId);
|
||||
|
||||
}
|
||||
|
|
|
@ -34,5 +34,4 @@ import org.jclouds.concurrent.Timeout;
|
|||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public interface GlobalUserClient extends DomainUserClient {
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
* 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 fields for account creation
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see <a
|
||||
* href="http://download.cloud.com/releases/2.2.0/api_2.2.12/global_admin/createAccount.html"
|
||||
* />
|
||||
*/
|
||||
public class CreateAccountOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public static final CreateAccountOptions NONE = new CreateAccountOptions();
|
||||
|
||||
/**
|
||||
* @param networkDomain network domain
|
||||
*/
|
||||
public CreateAccountOptions networkDomain(String networkDomain) {
|
||||
this.queryParameters.replaceValues("networkdomain", ImmutableSet.of(networkDomain));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param account an optional account for the resource
|
||||
*/
|
||||
public CreateAccountOptions account(String account) {
|
||||
this.queryParameters.replaceValues("account", ImmutableSet.of(account));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param domainId The domain for the resource
|
||||
*/
|
||||
public CreateAccountOptions domainId(long domainId) {
|
||||
this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId + ""));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see CreateAccountOptions#networkDomain
|
||||
*/
|
||||
public static CreateAccountOptions networkDomain(String networkDomain) {
|
||||
CreateAccountOptions options = new CreateAccountOptions();
|
||||
return options.networkDomain(networkDomain);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CreateAccountOptions#account
|
||||
*/
|
||||
public static CreateAccountOptions account(String account) {
|
||||
CreateAccountOptions options = new CreateAccountOptions();
|
||||
return options.account(account);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CreateAccountOptions#domainId
|
||||
*/
|
||||
public static CreateAccountOptions domainId(long domainId) {
|
||||
CreateAccountOptions options = new CreateAccountOptions();
|
||||
return options.domainId(domainId);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,10 +21,10 @@ package org.jclouds.cloudstack.options;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Options used to control what networks information is returned
|
||||
* Optional fields for network creation
|
||||
*
|
||||
* @see <a
|
||||
* href="http://download.cloud.com/releases/2.2.0/api/user/listNetworks.html"
|
||||
* href="http://download.cloud.com/releases/2.2.0/api_2.2.12/user/createNetwork.html"
|
||||
* />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
|
|
|
@ -18,14 +18,39 @@
|
|||
*/
|
||||
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;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code GlobalAccountClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @author Adrian Cole, Andrei Savu
|
||||
*/
|
||||
@Test(groups = "live", singleThreaded = true, testName = "GlobalAccountClientLiveTest")
|
||||
public class GlobalAccountClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
@Test
|
||||
public void testCreateAndRemoveAccount() {
|
||||
Account account = null;
|
||||
try {
|
||||
account = globalAdminClient.getAccountClient().createAccount(
|
||||
prefix + "-account", Account.Type.USER, "dummy@example.com",
|
||||
"First", "Last", "hashed-password");
|
||||
|
||||
assertNotNull(account);
|
||||
assertEquals(account.getName(), prefix + "-account");
|
||||
assertEquals(account.getType(), Account.Type.USER);
|
||||
|
||||
} finally {
|
||||
if (account != null) {
|
||||
globalAdminClient.getAccountClient().deleteAccount(account.getId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue