mirror of https://github.com/apache/cloudstack.git
List tenants
This commit is contained in:
parent
09afd261e8
commit
b3c89c62e9
|
|
@ -16,8 +16,10 @@
|
|||
// under the License.
|
||||
package org.apache.cloudstack.service;
|
||||
|
||||
import io.netris.ApiException;
|
||||
import io.netris.model.GetSiteBody;
|
||||
import io.netris.model.VPCListing;
|
||||
import io.netris.model.response.TenantResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -25,5 +27,5 @@ public interface NetrisApiClient {
|
|||
boolean isSessionAlive();
|
||||
List<GetSiteBody> listSites();
|
||||
List<VPCListing> listVPCs();
|
||||
|
||||
List<TenantResponse> listTenants() throws ApiException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import io.netris.ApiException;
|
|||
import io.netris.ApiResponse;
|
||||
import io.netris.api.v1.AuthenticationApi;
|
||||
import io.netris.api.v1.SitesApi;
|
||||
import io.netris.api.v1.TenantsApi;
|
||||
import io.netris.api.v2.VpcApi;
|
||||
import io.netris.model.AuthSchema;
|
||||
import io.netris.model.GetSiteBody;
|
||||
|
|
@ -29,6 +30,8 @@ import io.netris.model.SitesResponseOK;
|
|||
import io.netris.model.VPCListing;
|
||||
import io.netris.model.VPCResponseOK;
|
||||
import io.netris.model.response.AuthResponse;
|
||||
import io.netris.model.response.TenantResponse;
|
||||
import io.netris.model.response.TenantsResponse;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
|
@ -53,7 +56,6 @@ public class NetrisApiClientImpl implements NetrisApiClient {
|
|||
ApiResponse<AuthResponse> authResponse = authenticationApi.apiAuthPost(authSchema);
|
||||
if (authResponse.getStatusCode() == 200) {
|
||||
String cookie = authResponse.getHeaders().get("Set-Cookie").get(0).split(";")[0];
|
||||
apiClient.setApiKey(cookie);
|
||||
apiClient.addDefaultHeader("Cookie", cookie);
|
||||
} else {
|
||||
String msg = String.format("Authentication to the Netris Controller %s failed, please check the credentials provided", apiClient.getBasePath());
|
||||
|
|
@ -107,4 +109,11 @@ public class NetrisApiClientImpl implements NetrisApiClient {
|
|||
throw new CloudRuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TenantResponse> listTenants() throws ApiException {
|
||||
TenantsApi api = new TenantsApi(apiClient);
|
||||
ApiResponse<TenantsResponse> response = api.apiTenantsGet();
|
||||
return response.getData().getData();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,10 @@
|
|||
// under the License.
|
||||
package org.apache.cloudstack.service;
|
||||
|
||||
import io.netris.ApiException;
|
||||
import io.netris.model.GetSiteBody;
|
||||
import io.netris.model.VPCListing;
|
||||
import io.netris.model.response.TenantResponse;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -29,7 +31,7 @@ public class NetrisApiClientImplTest {
|
|||
private static final String username = "netris";
|
||||
private static final String password = "qHHa$CZ2oJv*@!7mwoSR";
|
||||
|
||||
private NetrisApiClientImpl client = new NetrisApiClientImpl(endpointUrl, username, password);
|
||||
private static final NetrisApiClientImpl client = new NetrisApiClientImpl(endpointUrl, username, password);
|
||||
|
||||
@Test
|
||||
public void testNetrisAuthStatus() {
|
||||
|
|
@ -47,4 +49,10 @@ public class NetrisApiClientImplTest {
|
|||
List<VPCListing> vpcs = client.listVPCs();
|
||||
Assert.assertTrue(vpcs.size() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListTenants() throws ApiException {
|
||||
List<TenantResponse> tenants = client.listTenants();
|
||||
Assert.assertTrue(tenants.size() > 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue