Open hudy1987 opened 9 years ago
@hudy1987 Which OpenStack version are you using? Also.. you probably need to change the perspective into "ADMIN". Example from your above snippet:
OSClient os = OSFactory.builder()
.endpoint("http://control.openstack.test:5000/v2.0")
.credentials("admin", "admin")
.tenantName("admin")
.perspective(Facing.ADMIN) // Add this line
.authenticate();
// now try Tenant creation
@gondor I did like your guidance, but in eclepse alert : The method tenantName(String) is undefined for the type IOSClientBuilder.V3 here my code :
os = OSFactory.builderV3().endpoint("http://10.60.0.220:5000/v3") .credentials("xxxxxxxxxx", "xxxxxxxxx", Identifier.byName("default")) .tenantName("admin") .scopeToProject(Identifier.byName("admin"), Identifier.byName("default")).perspective(Facing.ADMIN) .authenticate();
and cant not get tenantName, or project , the all return null when i call :
List<? extends Tenant> tenants = os.identity().tenants().list();
Find a specific Tenant
// Find by ID Tenant tenant = os.identity().tenants().get("tenantId");
// Find by Name tenant = os.identity().tenants().getByName("ABC Corp");
@huytt1992 do not use tenantName() it is for V2 and not for V3.
thank @vinodborole I deleted tenantName() but os = OSFactory.builderV3().endpoint("http://10.60.0.220:5000/v3") .credentials("xxxxxxxxxx", "xxxxxxxxx", Identifier.byName("default")) .scopeToProject(Identifier.byName("admin"), Identifier.byName("default")).perspective(Facing.ADMIN) .authenticate(); when i query List<? extends Tenant> tenants = os.identity().tenants().list(); tenants .size() = 0, Tenant tenant = os.identity().tenants().get("tenantId"); tenant = null
below is my code that works for me
private static OSClient buildOSClient(OpenstackModel ospModel) {
OSClient os=null;
if(ospModel.getDomain()!=null && !ospModel.getDomain().isEmpty())
os = OSFactory.builderV3().useNonStrictSSLClient(ospModel.isSsl()).scopeToProject(Identifier.byId(ospModel.getTenantId()), Identifier.byName(ospModel.getDomain()))
.credentials(ospModel.getUsername(), ospModel.getPassword(), Identifier.byName(ospModel.getDomain())).endpoint(ospModel.getAuthURL())
.perspective(ospModel.getApiType()).authenticate();
else
os = OSFactory.builder().endpoint(ospModel.getAuthURL()).credentials(ospModel.getUsername(), ospModel.getPassword()).tenantId(ospModel.getTenantId()).useNonStrictSSLClient(ospModel.isSsl()).perspective(ospModel.getApiType()).authenticate();
return os;
}
private static void listTenants(OSClient client) {
List<? extends Tenant> tenants=client.identity().tenants().list();
if(tenants!=null && !tenants.isEmpty()){
for(Tenant tenant : tenants){
System.out.println(tenant.getName());
}
}
}
thank @vinodborole i am using Version 3 Authentication, and i running Mitaka. Lib : version .2.11 here my code folow your useguide. os = OSFactory.builderV3().useNonStrictSSLClient(true).scopeToProject(Identifier.byId("5fe442be936440c2bba57df3f8c71230"), Identifier.byName("default")) .credentials("xxx", "xxxxx", Identifier.byName("default")).endpoint("http://10.60.0.220:5000/v3") .perspective(Facing.ADMIN).authenticate();
List<? extends Tenant> tenants= os.identity().tenants().list();
if(tenants!=null && !tenants.isEmpty()){
for(Tenant tenant : tenants){
System.out.println(tenant.getName());
}
}
but resull is null. if i call to server others using Version 2 Authentication. it is good, result right.
Is this still an issue? if not please close
hello,I have a question have bothers me lang time,I use openstack4j v2.0.3 to create a tenant but it always return null: OSClient os = OSFactory.builder() .endpoint("http://control.openstack.test:5000/v2.0") .credentials("admin", "admin") .tenantName("admin") .authenticate(); Tenant tenant = os.identity().tenants() .create(Builders.tenant().name("ABC Corp").description("ABC Corporation Tenant").build()); tenant is null. please help me, thank you!