Ask Your Question
0

How can I create a new Role with openstack4j?

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

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(HttpExceptionHandler.java:40) at org.openstack4j.core.transport.HttpExceptionHandler.mapException(HttpExceptionHandler.java:23) at org.openstack4j.core.transport.HttpEntityHandler.handle(HttpEntityHandler.java:50) at org.openstack4j.connectors.okhttp.HttpResponseImpl.getEntity(HttpResponseImpl.java:69) at org.openstack4j.openstack.internal.BaseOpenStackService$Invocation.execute(BaseOpenStackService.java:189) at org.openstack4j.openstack.internal.BaseOpenStackService$Invocation.execute(BaseOpenStackService.java:183) at org.openstack4j.openstack.identity.internal.RoleServiceImpl.create(RoleServiceImpl.java:121) at openstack.Identity.role_create(Identity.java:75) at openstack.openstackTest.main(openstackTest.java:21)

I used V2 authentication:

public OSClient connect() {
        return OSFactory.builder()
                .endpoint("http://127.0.0.1:5000/v2.0")
                .credentials("myuser", "mypwd")
                .tenantName("myTenant")
                .perspective(Facing.ADMIN)
                .authenticate();
    }

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()
                    .create(Builders.user()
                            .name(username)
                            .password(password)
                            .email(email)
                            .tenantId(tenant)
                            .enabled(enable).build());
            System.out.println(user.toString());
        } 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
0

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

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

Stats

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

Seen: 234 times

Last updated: Apr 13 '16