Hi,
I am fairly new to jclouds and trying basic examples.
I can successfully access openstack setup for our organization through curl
commands but getting 401 authorization exception while accessing through
java code.
*Example code that I am trying*
public class JCloudsOpenStack {
private ComputeService compute;
private RestContext<NovaApi, NovaAsyncApi> nova;
private Set<String> zones;
public static void main(String[] args) {
JCloudsOpenStack jCloudsOpenStack = new JCloudsOpenStack();
jCloudsOpenStack.init();
jCloudsOpenStack.listImages();
jCloudsOpenStack.close();
}
private void init(){
Thread.setDefaultUncaughtExceptionHandler(new
UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
if (compute != null) close();
e.printStackTrace();
System.exit(1);
}
});
Iterable<Module> modules = ImmutableSet.<Module> of(
new SLF4JLoggingModule());
String provider = "openstack-nova";
String identity = "shital.patil"; // tenantName:userName
String password = "shital123";
ComputeServiceContext context = ContextBuilder.newBuilder(provider)
.credentials(identity, password)
.endpoint("http://10.43.2.3:9696/v2.0/")
.modules(modules)
.buildView(ComputeServiceContext.class);
compute = context.getComputeService();
//System.out.println(compute.listHardwareProfiles());
nova = context.unwrap();
System.out.println(nova.getProviderMetadata());
zones = nova.getApi().getConfiguredZones();
}
private void listImages() {
for (String zone: zones) {
ImageApi imageApi = nova.getApi().getImageApiForZone(zone);
System.out.println("Calling listImages for " + zone + ":");
FluentIterable<? extends Image> images =
imageApi.listInDetail().concat();
for (Image image: images) {
System.out.println("\t" + image);
}
}
//System.out.println(compute.listAssignableLocations());
}
private void close() {
compute.getContext().close();
}
}
*Description of tenants from curl is *
"tenant": {"description": "", "enabled": true, "id":
"8c8b7bed01954c40a9dc35e82fe81b10", "name": "Shital Patil"}},
"serviceCatalog": [{"endpoints": [{"adminURL": "
http://10.43.2.3:8774/v2/8c8b7bed01954c40a9dc35e82fe81b10", "region":
"RegionOne", "internalURL": "
http://10.43.2.3:8774/v2/8c8b7bed01954c40a9dc35e82fe81b10", "id":
"6149c25bc2954b41b1766fcd1117eb3f", "publicURL": "
http://10.43.2.3:8774/v2/8c8b7bed01954c40a9dc35e82fe81b10"}],
"endpoints_links": [], "type": "compute", "name": "nova"}, {"endpoints":
[{"adminURL": "http://10.43.2.3:9696/", "region": "RegionOne",
"internalURL": "http://10.43.2.3:9696/", "id":
"1e050ea2e99c4e24a763a22481002add", "publicURL": "http://10.43.2.3:9696/"}],
"endpoints_links": [], "type": "network", "name": "quantum"}, {"endpoints":
[{"adminURL": "http://10.43.2.15:9292/v2", "region": "RegionOne",
"internalURL": "http://10.43.2.15:9292/v2", "id":
"c90930778fdb4084a7c142491484fb07", "publicURL": "http://10.43.2.15:9292/v2"}],
"endpoints_links": [], "type": "image", "name": "glance"}, {"endpoints":
[{"adminURL": "http://10.43.2.3:8776/v1/8c8b7bed01954c40a9dc35e82fe81b10",
"region": "RegionOne", "internalURL": "
http://10.43.2.3:8776/v1/8c8b7bed01954c40a9dc35e82fe81b10", "id":
"1312aca71aab4a5ab2f1f9014c006289", "publicURL": "
http://10.43.2.3:8776/v1/8c8b7bed01954c40a9dc35e82fe81b10"}],
"endpoints_links": [], "type": "volume", "name": "cinder"}, {"endpoints":*
Connection #0 to host 10.43.2.3 left intact
* Closing connection #0
[{"adminURL": "http://10.43.2.3:8773/services/Admin", "region":
"RegionOne", "internalURL": "http://10.43.2.3:8773/services/Cloud", "id":
"10bd0d9efea549a7a6c36ad039745a14", "publicURL": "
http://10.43.2.3:8773/services/Cloud"}], "endpoints_links": [], "type":
"ec2", "name": "ec2"}, {"endpoints": [{"adminURL": "
http://10.43.2.3:35357/v2.0", "region": "RegionOne", "internalURL": "
http://10.43.2.3:5000/v2.0", "id": "0f0f3cd5070046b3a26f3be5361878e0",
"publicURL": "http://10.43.2.3:5000/v2.0"}], "endpoints_links": [], "type":
"identity", "name": "keystone"}], "user": {"username": "shital.patil",
"roles_links": [], "id": "8b953f04ca3f40248f16497a8685b695", "roles":
[{"name": "_member_"}, {"name": "Member"}], "name": "shital.patil"},
"metadata": {"is_admin": 0, "roles": ["9fe2ff9ee4384b1894a90878d3e92bab",
"293ac6c460064389af2063ab46691c71"]}}}
I read few posts
https://groups.google.com/forum/#!topic/jclouds/vH9S2jRjoHQ
https://groups.google.com/forum/#!topic/jclouds/vH9S2jRjoHQ
but could not resolve it
kindly help me to gain access and try some basic commands through java code.
Thank you