Skip to content
This repository was archived by the owner on Nov 29, 2023. It is now read-only.

StackOps/openstack-java-sdk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenStack Java SDK

Example

Identity API (keystone)

Access

OpenStackClientFactory osf = new OpenStackClientFactory();
Client client = osf.create();
IdentityResource identity = new IdentityResource(client, "http://192.168.1.49:5000/v2.0");
Authentication authentication = new Authentication();
Authentication.PasswordCredentials passwordCredentials = new Authentication.PasswordCredentials();
passwordCredentials.setUsername("demo");
passwordCredentials.setPassword("woorea");
authentication.setPasswordCredentials(passwordCredentials);
Access access = identity.tokens().authenticate(authentication);

Tenants

TenantsRepresentation representation = identity.tenants().list();
List<Tenant> tenants = representation.getList();
for(Tenant tenant : tenants) {
	System.out.println(tenant);
}

Users

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

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

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

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

ComputeResource compute = new ComputeResource(client, "http://192.168.1.49:8774/v1.1");
TenantResource tenant = compute.tenant(tenants.get(0).getId());

Images

ImagesRepresentation imagesRepresentation = tenant.images().list();
imagesRepresentation.fetchAll();
for(Image image : imagesRepresentation.getList()) {
	System.out.println(image);
}

Flavors

FlavorsRepresentation flavorsRepresentation = tenant.flavors().list();
flavorsRepresentation.fetchAll();
for(Flavor flavor : flavorsRepresentation.getList()) {
	System.out.println(flavor);
}

Servers

ServersRepresentation serversRepresentation = tenant.servers().list(true);
serversRepresentation.fetchAll();
List<Server> servers = serversRepresentation.getList();
for(Server server : servers) {
	System.out.println(server);
}

Server Actions

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

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.

About

OpenStack Java SDK

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published