Ask Your Question

How can I create a new Role with openstack4j?

asked 2016-03-31 03:44:15 -0500

Fabio gravatar image

Hi all, I'm developing a project by exploiting openstack4j APIs (v. 2.0.9). I need to create a new role so I tried (after authentication) to use a Builder like Users creation:

public void role_create(String name) { 
org.openstack4j.model.identity.Role role = os.identity().roles().create(Builders.role().name(name).build());

When I noticed the error The method create(String) in the type RoleService is not applicable for the arguments (Role), I supposed I just had to pass the 'name' parameter to the create method:

public void role_create(String name) {
org.openstack4j.model.identity.Role role = os.identity().roles().create(name);

Anyway when I run the program on the server I get this error:

 Exception in thread "main" ServerResponseException{message=Internal Server Error, status=500, status-code=INTERNAL_SERVER_ERROR} 
at org.openstack4j.core.transport.HttpExceptionHandler.mapException( at org.openstack4j.core.transport.HttpExceptionHandler.mapException( at org.openstack4j.core.transport.HttpEntityHandler.handle( at org.openstack4j.connectors.okhttp.HttpResponseImpl.getEntity( at org.openstack4j.openstack.internal.BaseOpenStackService$Invocation.execute( at org.openstack4j.openstack.internal.BaseOpenStackService$Invocation.execute( at org.openstack4j.openstack.identity.internal.RoleServiceImpl.create( at openstack.Identity.role_create( at openstack.openstackTest.main(

I used V2 authentication:

public OSClient connect() {
        return OSFactory.builder()
                .credentials("myuser", "mypwd")

As I mentioned before I used Builders to create users:

public void user_create(String username, String password, String email, String tenant, Boolean enable) {
        try {
            User user = os.identity().users()
        } catch (ClientResponseException ex) {
            System.out.println("[CLIENT RESPONSE EXCEPTION] Cannot create user: duplicate name " + username);

Can anyone help me to solve this problem and create a new Role in openstack4j?

Best regards, Fabio

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-04-13 08:37:07 -0500

Fabio gravatar image

Solved! OpenStack V2 needs just the name of the role to crete it, but the version of Openstack4j I used automatically embedded in the request also the "enabled" parameter. That's why I got an exception, The bug was fixed in the latest version of the library (2.20)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools


Asked: 2016-03-31 03:44:15 -0500

Seen: 295 times

Last updated: Apr 13 '16