GithubHelp home page GithubHelp logo

platformlayer / openstack-java Goto Github PK

View Code? Open in Web Editor NEW

This project forked from woorea/openstack-java-sdk

1.0 3.0 2.0 2.29 MB

Openstack Bindings for Java

JavaScript 0.66% Shell 0.56% Java 95.38% C 3.40%

openstack-java's Introduction

OpenStack Java SDK

Example

Identity API (keystone)

Access

// X-Auth-Token (no tenant selected)
OpenstackSession session = new OpenstackSession().with(Feature.VERBOSE);
OpenstackCredentials credentials = new OpenstackCredentials("admin", "woorea");
session.authenticate("http://192.168.1.49:5000/v2.0", credentials);

Tenants

// Let' show our available tenants
IdentityResource identity = session.getAuthenticationClient().root();
Iterable<Tenant> tenants = identity.tenants().list();
for (Tenant tenant : tenants) {
	System.out.println(tenant);
}

// Ok, I will choose the first available tenant (
for (Tenant tenant : tenants) {
	credentials.setTenant(tenant.getName());
	session.authenticate("http://192.168.1.49:5000/v2.0", credentials);
	break;
}

Users (this is from previous revision)

UsersResource usersResource = identity.users();
UsersRepresentation usersRepresentation = usersResource.list();
List<User> users = usersRepresentation.getList();
for(User user : users) {
	System.out.println(user);
}

UserResource userResource = usersResource.user(users.get(0).getId());
System.out.println(userResource.show());

Roles (this is from previous revision)

RolesResource rolesResource = identity.roles();
RolesRepresentation rolesRepresentation = rolesResource.list();
List<Role> roles = rolesRepresentation.getList();
for(Role role : roles) {
	System.out.println(role);
}

RoleResource roleResource = rolesResource.role(roles.get(0).getId());
System.out.println(roleResource.show());

Services (this is from previous revision)

ServicesResource servicesResource = identity.services();
ServicesRepresentation servicesRepresentation = servicesResource.list();
List<Service> services = servicesRepresentation.getList();
for(Service service : services) {
	System.out.println(service);
}

ServiceResource serviceResource = servicesResource.service(services.get(0).getId());
System.out.println(serviceResource.show());

EndpointTemplates (this is from previous revision)

EndpointTemplatesResource endpointTemplatesResource = identity.endpointTemplates();
EndpointTemplatesRepresentation endpointTemplatesRepresentation = identity.endpointTemplates().list();
List<EndpointTemplate> endpointTemplates = endpointTemplatesRepresentation.getList();
for(EndpointTemplate endEndpointTemplate : endpointTemplates) {
	System.out.println(endEndpointTemplate);
}

EndpointTemplateResource endpointTemplateResource = endpointTemplatesResource.endpointTemplate(services.get(0).getId());
System.out.println(endpointTemplateResource.show());

Compute API (nova)

Select a Tenant

// Give me access to compute API on the selected tenant
TenantResource compute = session.getComputeClient().root();
for (Server s : compute.servers().list()) {
	System.out.println(s);
}

Images

// List the available images
Iterable<Image> images = compute.images().list();
Image image = null;
for (Image i : images) {
	System.out.println(i);

	//If it's the devstack default image, then i go to select it
	if (i.getName().equals("cirros-0.3.0-x86_64-blank")) {
		image = i;
		break;
	}
}

// Show me the image details
System.out.println(image);

Flavors

// List the available flavors
Iterable<Flavor> flavors = compute.flavors().list();
for (Flavor f : flavors) {
	System.out.println(f);
}

Servers

// List the servers
Iterable<Server> servers = compute.servers().list();
for (Server s : servers) {
	ServerResource sr = new ServerResource(session, s);
	System.out.println(sr.get(true).show());
}

Server Actions

System.out.println(compute.servers().server(servers.get(0).getId()).getConsoleOutput(20));
System.out.println(compute.servers().server(servers.get(0).getId()).getVncConsole("novnc"));

Maven

We use maven to build the project. Some helpful maven commands:

mvn eclipse:eclipse Create the eclipse projects
mvn install Builds everything, runs unit & integration tests, installs into your maven repo
mvn install -Dmaven.test.skip=true As above, but without running tests
mvn test Runs unit tests
mvn verify Runs integration tests

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

License

This software is licensed under the Apache 2 license, quoted below.

Copyright 2012 Luis Gervaso and OpenStack Java SDK
Copyright 2012 Justin Santa Barbara

Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.

openstack-java's People

Contributors

justinsb avatar woorea avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

pnirmalrajan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.