jclouds / legacy-jclouds

Home Page:https://jclouds.apache.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

new Keystone user

Dorra01 opened this issue · comments

Hi, I'm working in a java project that let me to connect to my openstack using API. I used jclouds to create Server and to do other actions. But now my problem is that i can't create new user with jclouds (using my ptalform java). Is there any suggesstion plz?

Hi Dorra01,

What version of the Keystone API does your OpenStack environment support?
Can you please send a snippet of your code and what you are trying to do?

/jd

On Wed, Mar 20, 2013 at 8:58 AM, Dorra01 notifications@github.com wrote:

Hi, I'm working in a java project that let me to connect to my openstack
using API. I used jclouds to create Server and to do other actions. But now
my problem is that i can't create new user with jclouds (using my ptalform
java). Is there any suggesstion plz?


Reply to this email directly or view it on GitHubhttps://github.com/jclouds/jclouds/issues/1440
.

This is my code. it lets me just to have the list of my user in openstack. And i want to add a code to create new user keystone.

package org.jclouds.examples.rackspace.cloudfiles;

import java.io.Closeable;
import org.jclouds.ContextBuilder;
import org.jclouds.rest.RestContext;

import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.openstack.keystone.v2_0.domain.Access;
import org.jclouds.openstack.keystone.v2_0.domain.PasswordCredentials;
import org.jclouds.openstack.keystone.v2_0.domain.User;
import org.jclouds.openstack.keystone.v2_0.features.UserApi;
import org.jclouds.openstack.keystone.v2_0.AuthenticationApi;
import org.jclouds.openstack.keystone.v2_0.KeystoneApi;
import org.jclouds.openstack.keystone.v2_0.KeystoneAsyncApi;

import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;

public class list implements Closeable {
private RestContext<KeystoneApi, KeystoneAsyncApi> keystone;
//private RestContext<AuthenticationApi,AuthenticationAsyncApi> keystone;
public static void main(String[] args) {
list l=new list();

  try {
    l.init();
     l.close();
  }
  catch (Exception e) {
     e.printStackTrace();
  }
  finally {
     l.close();
  }

}

private void init() {

  String provider = "openstack-keystone";
  String identity = "openstackDemo:1"; // tenantName:userName
  String password = "azer"; // demo account uses ADMIN_PASSWORD too

  Iterable<Module> modules = ImmutableSet.<Module> of(
          new SLF4JLoggingModule());
  ContextBuilder contextBuilder =ContextBuilder.newBuilder(provider);

             keystone = contextBuilder
               .credentials(identity, password)
               .endpoint("http://192.168.1.3:5000/v2.0/")
               .modules(modules)
               .build();
             KeystoneApi keystoneApi =  keystone.getApi();

AuthenticationApi authenticationApi = keystone.utils().injector().getInstance(AuthenticationApi.class);
Access access = authenticationApi.authenticateWithTenantNameAndCredentials("openstackDemo", PasswordCredentials.createWithUsernameAndPassword("1", "azer"));
System.out.println(access);
Access.builder().user(User.builder().name("nova52").id("12548").build());

             UserApi uapi=keystone.getApi().getUserApi().get();
            System.out.println("user");
       //  User u1= uapi.get("b7a38e397be349a389e20c80be29e2c1");
        //System.out.println("  " + u1);

       //Set<Role> roles = u1.getRoles();
      //System.out.println(roles.toString());

}

public void close() {
//closeQuietly(keystone);
}
}