- Notifications
You must be signed in to change notification settings - Fork 191
Getting Started
woorea edited this page Feb 22, 2012
·
2 revisions
// X-Auth-Token (no tenant selected)OpenstackSessionsession = newOpenstackSession().with(Feature.VERBOSE);
OpenstackCredentialscredentials = newOpenstackCredentials("admin", "woorea");
session.authenticate("http://192.168.1.49:5000/v2.0", credentials);// Let' show our available tenantsIdentityResourceidentity = session.getAuthenticationClient().root();
Iterable<Tenant> tenants = identity.tenants().list();
for (Tenanttenant : tenants) {
System.out.println(tenant);
}
// Ok, I will choose the first available tenant (for (Tenanttenant : tenants) {
credentials.setTenant(tenant.getName());
session.authenticate("http://192.168.1.49:5000/v2.0", credentials);
break;
}UsersResourceusersResource = identity.users();
UsersRepresentationusersRepresentation = usersResource.list();
List<User> users = usersRepresentation.getList();
for(Useruser : users) {
System.out.println(user);
}
UserResourceuserResource = usersResource.user(users.get(0).getId());
System.out.println(userResource.show());RolesResourcerolesResource = identity.roles();
RolesRepresentationrolesRepresentation = rolesResource.list();
List<Role> roles = rolesRepresentation.getList();
for(Rolerole : roles) {
System.out.println(role);
}
RoleResourceroleResource = rolesResource.role(roles.get(0).getId());
System.out.println(roleResource.show());ServicesResourceservicesResource = identity.services();
ServicesRepresentationservicesRepresentation = servicesResource.list();
List<Service> services = servicesRepresentation.getList();
for(Serviceservice : services) {
System.out.println(service);
}
ServiceResourceserviceResource = servicesResource.service(services.get(0).getId());
System.out.println(serviceResource.show());EndpointTemplatesResourceendpointTemplatesResource = identity.endpointTemplates();
EndpointTemplatesRepresentationendpointTemplatesRepresentation = identity.endpointTemplates().list();
List<EndpointTemplate> endpointTemplates = endpointTemplatesRepresentation.getList();
for(EndpointTemplateendEndpointTemplate : endpointTemplates) {
System.out.println(endEndpointTemplate);
}
EndpointTemplateResourceendpointTemplateResource = endpointTemplatesResource.endpointTemplate(services.get(0).getId());
System.out.println(endpointTemplateResource.show());// Give me access to compute API on the selected tenantTenantResourcecompute = session.getComputeClient().root();
for (Servers : compute.servers().list()) {
System.out.println(s);
}// List the available imagesIterable<Image> images = compute.images().list();
Imageimage = null;
for (Imagei : images) {
System.out.println(i);
//If it's the devstack default image, then i go to select itif (i.getName().equals("cirros-0.3.0-x86_64-blank")) {
image = i;
break;
}
}
// Show me the image detailsSystem.out.println(image);// List the available flavorsIterable<Flavor> flavors = compute.flavors().list();
for (Flavorf : flavors) {
System.out.println(f);
}// List the serversIterable<Server> servers = compute.servers().list();
for (Servers : servers) {
ServerResourcesr = newServerResource(session, s);
System.out.println(sr.get(true).show());
}System.out.println(compute.servers().server(servers.get(0).getId()).getConsoleOutput(20));
System.out.println(compute.servers().server(servers.get(0).getId()).getVncConsole("novnc"));We use maven to build the project. Some helpful maven commands:
mvn eclipse:eclipseCreate the eclipse projectsmvn installBuilds everything, runs unit & integration tests, installs into your maven repomvn install -Dmaven.test.skip=trueAs above, but without running testsmvn testRuns unit testsmvn verifyRuns integration tests
The integration tests run against an OpenStack installation.
It takes its configuration from the system properties.
Useful properties:
| Property | Default | Explanation |
| openstack.debug | false | Set to true for lots of debug output |
| openstack.auth.url | http://127.0.0.1:5000/v2.0 | Location of Keystone service |
| openstack.auth.user | demo | Authentication info: username |
| openstack.auth.secret | supersecret | Authentication info: password |
| openstack.auth.tenant | demo | Authentication info: tenant |
The defaults should work with a local devstack installation. Otherwise do something like this:
mvn verify -Dopenstack.auth.url=http://192.168.71.1:5000/v2.0