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);
TenantsRepresentation representation = identity.tenants().list();
List<Tenant> tenants = representation.getList();
for(Tenant tenant : tenants) {
System.out.println(tenant);
}
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());
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());
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());
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());
ComputeResource compute = new ComputeResource(client, "http://192.168.1.49:8774/v1.1"); TenantResource tenant = compute.tenant(tenants.get(0).getId());
ImagesRepresentation imagesRepresentation = tenant.images().list();
imagesRepresentation.fetchAll();
for(Image image : imagesRepresentation.getList()) {
System.out.println(image);
}
FlavorsRepresentation flavorsRepresentation = tenant.flavors().list();
flavorsRepresentation.fetchAll();
for(Flavor flavor : flavorsRepresentation.getList()) {
System.out.println(flavor);
}
ServersRepresentation serversRepresentation = tenant.servers().list(true);
serversRepresentation.fetchAll();
List<Server> servers = serversRepresentation.getList();
for(Server server : servers) {
System.out.println(server);
}
System.out.println(tenant.servers().server(servers.get(0).getId()).getConsoleOutput(20));
System.out.println(tenant.servers().server(servers.get(0).getId()).getVncConsole("novnc"));
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.