Created
October 7, 2013 14:55
-
-
Save vksuktha/6869347 to your computer and use it in GitHub Desktop.
example to show ResourceNotFound erroe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.vijayks.jclouds; | |
import org.jclouds.ContextBuilder; | |
import org.jclouds.compute.ComputeServiceContext; | |
import org.jclouds.compute.ComputeService; | |
import org.jclouds.domain.Credentials; | |
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; | |
import org.jclouds.openstack.keystone.v2_0.domain.Access; | |
import org.jclouds.openstack.nova.v2_0.config.NovaParserModule; | |
import org.jclouds.openstack.nova.v2_0.NovaApi; | |
import org.jclouds.openstack.nova.v2_0.NovaAsyncApi; | |
import org.jclouds.openstack.nova.v2_0.domain.Server; | |
import org.jclouds.openstack.nova.v2_0.features.ServerApi; | |
import org.jclouds.rest.RestContext; | |
import java.util.Set; | |
import com.google.common.base.Function; | |
import com.google.inject.Module; | |
import com.google.common.collect.ImmutableSet; | |
import com.google.inject.Key; | |
import com.google.inject.TypeLiteral; | |
@SuppressWarnings("deprecation") | |
public class openstackListservers { | |
private static ComputeService compute; | |
private static RestContext<NovaApi,NovaAsyncApi> nova; | |
private static Set<String> zones; | |
public static void main(String[] args){ | |
openstackListservers listserver = new openstackListservers(); | |
try { | |
System.out.println("In Init"); | |
openstackListservers.init(); | |
openstackListservers.Listserver(); | |
System.out.println("calling Listservers"); | |
openstackListservers.close(); | |
}catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
private static void init(){ | |
Iterable<Module> modules = ImmutableSet.<Module> of (new SLF4JLoggingModule()); | |
String provider = "openstack-nova"; | |
String username = "tenant:username"; | |
String password = "password"; | |
String endpoint = "http://10.0.2.15:5000/V2.0"; | |
ComputeServiceContext context = ContextBuilder.newBuilder(provider) | |
.credentials(username,password) | |
.endpoint(endpoint) | |
.buildView(ComputeServiceContext.class); | |
System.out.println("trying to complete the contxt"); | |
compute = context.getComputeService(); | |
nova = context.unwrap(); | |
System.out.println("trying to get zones"); | |
// zones = nova.getApi().getConfiguredZones(); | |
//zones = "Regionone"; | |
System.out.println("Init completed"); | |
}; | |
private static void Listserver(){ | |
//for (String zone : zones){ | |
ServerApi serverApi = nova.getApi().getServerApiForZone("nova"); | |
// System.out.println("Servers in " +zone); | |
for (Server server: serverApi.listInDetail().concat()){ | |
System.out.println(" " +server); | |
} | |
//} | |
} | |
private static void close(){ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment