public T fromAccount(Account in) { return this .id(in.getId()) .type(in.getType()) .networkDomain(in.getNetworkDomain()) .domain(in.getDomain()) .domainId(in.getDomainId()) .IPsAvailable(in.getIPsAvailable()) .IPLimit(in.getIPLimit()) .IPs(in.getIPs()) .cleanupRequired(in.isCleanupRequired()) .name(in.getName()) .receivedBytes(in.getReceivedBytes()) .sentBytes(in.getSentBytes()) .snapshotsAvailable(in.getSnapshotsAvailable()) .snapshotLimit(in.getSnapshotLimit()) .snapshots(in.getSnapshots()) .state(in.getState()) .templatesAvailable(in.getTemplatesAvailable()) .templateLimit(in.getTemplateLimit()) .templates(in.getTemplates()) .VMsAvailable(in.getVMsAvailable()) .VMLimit(in.getVMLimit()) .VMsRunning(in.getVMsRunning()) .VMsStopped(in.getVMsStopped()) .VMs(in.getVMs()) .volumesAvailable(in.getVolumesAvailable()) .volumeLimit(in.getVolumeLimit()) .volumes(in.getVolumes()) .users(in.getUsers());
@Test public void testCreateAndRemoveAccount() { skipIfNotGlobalAdmin(); Account account = null; try { account = createTestAccount(globalAdminClient, prefix); assertNotNull(account); 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()); } } }
@Test public void testEnableDisableAccount() { skipIfNotGlobalAdmin(); Account testAccount = null; try { testAccount = createTestAccount(globalAdminClient, prefix); AsyncCreateResponse response = domainAdminClient.getAccountClient() .disableAccount(testAccount.getName(), testAccount.getDomainId(), false); assertNotNull(response); assertTrue(jobComplete.apply(response.getJobId())); AsyncJob<Account> job = domainAdminClient.getAsyncJobClient().getAsyncJob(response.getJobId()); assertEquals(job.getResult().getState(), Account.State.DISABLED); Account updated = domainAdminClient.getAccountClient() .enableAccount(testAccount.getName(), testAccount.getDomainId()); assertNotNull(updated); assertEquals(updated.getState(), Account.State.ENABLED); } finally { if (testAccount != null) { globalAdminClient.getAccountClient().deleteAccount(testAccount.getId()); } } }
@Test public void testCreateContextUsingUserAndPasswordAuthentication() { skipIfNotGlobalAdmin(); Account testAccount = null; User testUser = null; String prefix = this.prefix + "-session"; try { testAccount = createTestAccount(globalAdminClient, prefix); testUser = createTestUser(globalAdminClient, testAccount, prefix); String expectedUsername = prefix + "-user"; assertEquals(testUser.getName(), expectedUsername); checkLoginAsTheNewUser(expectedUsername); ApiKeyPair expected = globalAdminClient.getUserClient().registerUserKeys(testUser.getId()); ApiKeyPair actual = ApiKeyPairs.loginToEndpointAsUsernameInDomainWithPasswordAndReturnApiKeyPair( URI.create(endpoint), prefix + "-user", "password", ""); assertEquals(actual, expected); } finally { if (testUser != null) globalAdminClient.getUserClient().deleteUser(testUser.getId()); if (testAccount != null) globalAdminClient.getAccountClient().deleteAccount(testAccount.getId()); } }
public String findDomainIdForAccount(String accountName) { Set<Account> accounts = client.getAccountClient().listAccounts(ListAccountsOptions.Builder.name(accountName)); Account account = Iterables.getOnlyElement(accounts, null); if (account == null) { throw new IllegalStateException("No account found in "+loc+"} with name "+accountName); } return account.getDomainId(); }
public static User createTestUser(CloudStackGlobalClient client, Account account, String prefix) { return client.getUserClient().createUser(prefix + "-user", account.getName(), "dummy2@example.com", base16().lowerCase().encode(md5().hashString("password", UTF_8).asBytes()), "First", "Last"); }
@Test public void testCreateAndRemoveAccount() { skipIfNotGlobalAdmin(); Account account = null; try { account = createTestAccount(globalAdminClient, prefix); assertNotNull(account); assertEquals(account.getName(), prefix + "-account"); assertEquals(account.getType(), Account.Type.USER); Account updated = globalAdminClient.getAccountApi().updateAccount( account.getName(), account.getDomainId(), prefix + "-account-2"); assertNotNull(updated); assertEquals(updated.getName(), prefix + "-account-2"); } finally { if (account != null) { globalAdminClient.getAccountApi().deleteAccount(account.getId()); } } }
@Test public void testEnableDisableAccount() { skipIfNotGlobalAdmin(); Account testAccount = null; try { testAccount = createTestAccount(globalAdminClient, prefix); AsyncCreateResponse response = domainAdminClient.getAccountApi() .disableAccount(testAccount.getName(), testAccount.getDomainId(), false); assertNotNull(response); assertTrue(adminJobComplete.apply(response.getJobId())); AsyncJob<Account> job = domainAdminClient.getAsyncJobApi().getAsyncJob(response.getJobId()); assertEquals(job.getResult().getState(), Account.State.DISABLED); Account updated = domainAdminClient.getAccountApi() .enableAccount(testAccount.getName(), testAccount.getDomainId()); assertNotNull(updated); assertEquals(updated.getState(), Account.State.ENABLED); } finally { if (testAccount != null) { globalAdminClient.getAccountApi().deleteAccount(testAccount.getId()); } } }
@Test public void testCreateUser() { skipIfNotGlobalAdmin(); Account testAccount = createTestAccount(globalAdminClient, prefix); User testUser = null; try { testUser = createTestUser(globalAdminClient, testAccount, prefix); assertNotNull(testUser); assertEquals(testUser.getName(), prefix + "-user"); assertEquals(testUser.getAccount(), prefix + "-account"); User updatedUser = globalAdminClient.getUserClient() .updateUser(testUser.getId(), userName(prefix + "-user-2")); assertNotNull(updatedUser); assertEquals(updatedUser.getName(), prefix + "-user-2"); ApiKeyPair apiKeys = globalAdminClient.getUserClient() .registerUserKeys(updatedUser.getId()); assertNotNull(apiKeys.getApiKey()); assertNotNull(apiKeys.getSecretKey()); checkAuthAsUser(apiKeys); } finally { if (testUser != null) { globalAdminClient.getUserClient().deleteUser(testUser.getId()); } globalAdminClient.getAccountClient().deleteAccount(testAccount.getId()); } }
public static User createTestUser(CloudStackGlobalApi client, Account account, String prefix) { return client.getUserClient().createUser(prefix + "-user", account.getName(), "dummy2@example.com", base16().lowerCase().encode(md5().hashString("password", UTF_8).asBytes()), "First", "Last"); }
public T fromAccount(Account in) { return this .id(in.getId()) .type(in.getType()) .networkDomain(in.getNetworkDomain()) .domain(in.getDomain()) .domainId(in.getDomainId()) .IPsAvailable(in.getIPsAvailable()) .IPLimit(in.getIPLimit()) .IPs(in.getIPs()) .cleanupRequired(in.isCleanupRequired()) .name(in.getName()) .receivedBytes(in.getReceivedBytes()) .sentBytes(in.getSentBytes()) .snapshotsAvailable(in.getSnapshotsAvailable()) .snapshotLimit(in.getSnapshotLimit()) .snapshots(in.getSnapshots()) .state(in.getState()) .templatesAvailable(in.getTemplatesAvailable()) .templateLimit(in.getTemplateLimit()) .templates(in.getTemplates()) .VMsAvailable(in.getVMsAvailable()) .VMLimit(in.getVMLimit()) .VMsRunning(in.getVMsRunning()) .VMsStopped(in.getVMsStopped()) .VMs(in.getVMs()) .volumesAvailable(in.getVolumesAvailable()) .volumeLimit(in.getVolumeLimit()) .volumes(in.getVolumes()) .users(in.getUsers());
globalAdminClient.getAccountClient().deleteAccount(testAccount.getId());
public T fromAccount(Account in) { return this .id(in.getId()) .type(in.getType()) .networkDomain(in.getNetworkDomain()) .domain(in.getDomain()) .domainId(in.getDomainId()) .IPsAvailable(in.getIPsAvailable()) .IPLimit(in.getIPLimit()) .IPs(in.getIPs()) .cleanupRequired(in.isCleanupRequired()) .name(in.getName()) .receivedBytes(in.getReceivedBytes()) .sentBytes(in.getSentBytes()) .snapshotsAvailable(in.getSnapshotsAvailable()) .snapshotLimit(in.getSnapshotLimit()) .snapshots(in.getSnapshots()) .state(in.getState()) .templatesAvailable(in.getTemplatesAvailable()) .templateLimit(in.getTemplateLimit()) .templates(in.getTemplates()) .VMsAvailable(in.getVMsAvailable()) .VMLimit(in.getVMLimit()) .VMsRunning(in.getVMsRunning()) .VMsStopped(in.getVMsStopped()) .VMs(in.getVMs()) .volumesAvailable(in.getVolumesAvailable()) .volumeLimit(in.getVolumeLimit()) .volumes(in.getVolumes()) .users(in.getUsers());
@Test public void testCreateContextUsingUserAndPasswordAuthentication() { skipIfNotGlobalAdmin(); Account testAccount = null; User testUser = null; String prefix = this.prefix + "-session"; try { testAccount = createTestAccount(globalAdminClient, prefix); testUser = createTestUser(globalAdminClient, testAccount, prefix); String expectedUsername = prefix + "-user"; assertEquals(testUser.getName(), expectedUsername); checkLoginAsTheNewUser(expectedUsername); ApiKeyPair expected = globalAdminClient.getUserClient().registerUserKeys(testUser.getId()); ApiKeyPair actual = ApiKeyPairs.loginToEndpointAsUsernameInDomainWithPasswordAndReturnApiKeyPair( URI.create(endpoint), prefix + "-user", "password", ""); assertEquals(actual, expected); } finally { if (testUser != null) globalAdminClient.getUserClient().deleteUser(testUser.getId()); if (testAccount != null) globalAdminClient.getAccountApi().deleteAccount(testAccount.getId()); } }
protected void checkAccount(Account account) { assert account.getId() != null : account; assertEquals(account.toString(), client.getAccountClient().getAccount(account.getId()).toString()); assert account.getName() != null : account; assert account.getType() != null && account.getType() != Account.Type.UNRECOGNIZED : account; assert account.getDomain() != null : account; assert account.getDomainId() != null : account; assert account.getUsers() != null : account; for (User user : account.getUsers()) { assert user.getName() != null : user; assert user.getAccountType().equals(account.getType()) : user; assert user.getDomain().equals(account.getDomain()) : user; assert user.getDomainId().equals(account.getDomainId()) : user; assert user.getCreated() != null : user; assert user.getEmail() != null : user; assert account.getIPsAvailable() == null || account.getIPsAvailable() >= 0 : account; assert account.getIPLimit() == null || account.getIPLimit() >= 0 : account; assert account.getIPs() >= 0 : account; assert account.getReceivedBytes() >= 0 : account; assert account.getSentBytes() >= 0 : account; assert account.getSnapshotsAvailable() == null || account.getSnapshotsAvailable() >= 0 : account; assert account.getSnapshotLimit() == null || account.getSnapshotLimit() >= 0 : account; assert account.getSnapshots() >= 0 : account; assert account.getState() != null && account.getState() != Account.State.UNRECOGNIZED : account; assert account.getTemplatesAvailable() == null || account.getTemplatesAvailable() >= 0 : account; assert account.getTemplateLimit() == null || account.getTemplateLimit() >= 0 : account; assert account.getTemplates() >= 0 : account; assert account.getVMsAvailable() == null || account.getVMsAvailable() >= 0 : account; assert account.getVMLimit() == null || account.getVMLimit() >= 0 : account;
@Test public void testCreateUser() { skipIfNotGlobalAdmin(); Account testAccount = createTestAccount(globalAdminClient, prefix); User testUser = null; try { testUser = createTestUser(globalAdminClient, testAccount, prefix); assertNotNull(testUser); assertEquals(testUser.getName(), prefix + "-user"); assertEquals(testUser.getAccount(), prefix + "-account"); User updatedUser = globalAdminClient.getUserClient() .updateUser(testUser.getId(), userName(prefix + "-user-2")); assertNotNull(updatedUser); assertEquals(updatedUser.getName(), prefix + "-user-2"); ApiKeyPair apiKeys = globalAdminClient.getUserClient() .registerUserKeys(updatedUser.getId()); assertNotNull(apiKeys.getApiKey()); assertNotNull(apiKeys.getSecretKey()); checkAuthAsUser(apiKeys); } finally { if (testUser != null) { globalAdminClient.getUserClient().deleteUser(testUser.getId()); } globalAdminClient.getAccountApi().deleteAccount(testAccount.getId()); } }
protected void checkAccount(Account account) { assert account.getId() != null : account; assertEquals(account.toString(), client.getAccountApi().getAccount(account.getId()).toString()); assert account.getName() != null : account; assert account.getType() != null && account.getType() != Account.Type.UNRECOGNIZED : account; assert account.getDomain() != null : account; assert account.getDomainId() != null : account; assert account.getUsers() != null : account; for (User user : account.getUsers()) { assert user.getName() != null : user; assert user.getAccountType().equals(account.getType()) : user; assert user.getDomain().equals(account.getDomain()) : user; assert user.getDomainId().equals(account.getDomainId()) : user; assert user.getCreated() != null : user; assert user.getEmail() != null : user; assert account.getIPsAvailable() == null || account.getIPsAvailable() >= 0 : account; assert account.getIPLimit() == null || account.getIPLimit() >= 0 : account; assert account.getIPs() >= 0 : account; assert account.getReceivedBytes() >= 0 : account; assert account.getSentBytes() >= 0 : account; assert account.getSnapshotsAvailable() == null || account.getSnapshotsAvailable() >= 0 : account; assert account.getSnapshotLimit() == null || account.getSnapshotLimit() >= 0 : account; assert account.getSnapshots() >= 0 : account; assert account.getState() != null && account.getState() != Account.State.UNRECOGNIZED : account; assert account.getTemplatesAvailable() == null || account.getTemplatesAvailable() >= 0 : account; assert account.getTemplateLimit() == null || account.getTemplateLimit() >= 0 : account; assert account.getTemplates() >= 0 : account; assert account.getVMsAvailable() == null || account.getVMsAvailable() >= 0 : account; assert account.getVMLimit() == null || account.getVMLimit() >= 0 : account;
globalAdminClient.getAccountApi().deleteAccount(testAccount.getId());