Giter VIP home page Giter VIP logo

openstack4j's Introduction

OpenStack4j

Build Status License Gitter

OpenStack4j is a fluent OpenStack client that allows provisioning and control of an OpenStack deployment. This includes support for Identity, Compute, Image, Network, Block Storage, Telemetry, Data Processing as well as many extensions (LBaaS, FWaaS, Quota-Sets, etc)

Documentation and Support

Bug Reports

Maven

Latest Release (Stable)

Maven Central

OpenStack4j version 2.0.0+ is now modular. One of the benefits to this is the ability to choose the connector that you would like to use in your environment.

Using OpenStack4j with the default Jersey2 Connector

<dependency>
    <groupId>org.pacesys</groupId>
    <artifactId>openstack4j</artifactId>
    <version>2.11</version>
</dependency>

Using OpenStack4j with one of our connector modules

To configure OpenStack4j to use one of our supported connectors (Jersey 2, Resteasy, Apache HttpClient, OKHttp) see the usage guide

Current (Master Branch)

See notes above about connectors (same rules apply) to development branches.

<dependency>
    <groupId>org.pacesys</groupId>
    <artifactId>openstack4j</artifactId>
    <version>2.20-SNAPSHOT</version>
</dependency>

A note about referencing Snapshots without Source

Snapshots are deploys to sonatype. You will need to add the repository to your POM or Settings file. Releases (above) are deployed to maven central and this step is not required.

Example POM based repository declaration to grab snapshots:

<repositories>
    <repository>
      <id>st-snapshots</id>
      <name>sonatype-snapshots</name>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
</repositories>

Contributing

If you would like to contribute please see our contributing guidelines

Top 15 Contributors

Rank Login Contributions
1 @gondor 527
2 @octupszhang 26
3 @gonzolino 18
4 @ekasitk 17
5 @magixyu 17
6 @maxrome 12
7 @isartcanyameres 9
8 @iviireczech 8
9 @n-r-anderson 7
10 @krishnabrucelee 6
11 @auhlig 6
12 @peter-nordquist 4
13 @RibeiroAna 4
14 @symcssn 4
15 @olivergondza 3

Throughput

Throughput Graph

Quick Usage Guide

Below are some examples of the API usage. Please visit www.OpenStack4j.com for the full manual and getting started guides.

Authenticating

Creating and authenticating against OpenStack is extremely simple. Below is an example of authenticating which will result with the authorized OSClient. OSClient allows you to invoke Compute, Identity, Neutron operations fluently.

// Identity V2 Authentication Example
OSClient os = OSFactory.builder()
                       .endpoint("http://127.0.0.1:5000/v2.0")
                       .credentials("admin","sample")
                       .tenantName("admin")
                       .authenticate();

Identity Operations (Keystone)

After successful authentication you can invoke any Identity (Keystone) directly from the OSClient.

Identity Services fully cover Tenants, Users, Roles, Services, Endpoints and Identity Extension listings. The examples below are only a small fraction of the existing API so please refer to the API documentation for more details.

Create a Tenant, User and associate a Role

// Create a Tenant (could also be created fluent within user create)
Tenant tenant = os.identity().tenants().create(Builders.tenant().name("MyNewTenant").build());

// Create a User associated to the new Tenant
User user = os.identity().users().create(Builders.user().name("jack").password("sample").tenant(tenant).build());

// Add a Tenant based Role to the User
os.identity().roles().addUserRole(tenant.getId(), user.getId(), os.identity().roles().getByName("Member").getId());

Compute Operations (Nova)

OpenStack4j covers most the major common compute based operations. With the simplistic API approach you can fully manage Servers, Flavors, Images, Quota-Sets, Diagnostics, Tenant Usage and more. As the API evolves additional providers and extensions will be covered and documented within the API.

Create a Flavor and Boot a Server/VM

// Create a Flavor for a special customer base
Flavor flavor = os.compute().flavors()
                  .create(Builders.flavor().name("Gold").vcpus(4).disk(80).ram(2048).build());
                  
// Create and Boot a new Server (minimal builder options shown in example)
Server server = os.compute().servers()
                  .boot(Builders.server().name("Ubuntu 2").flavor(flavor.getId()).image("imageId").build());

Create a new Server Snapshot

String imageId = os.compute().servers().createSnapshot(server.getId(), "Clean State Snapshot");

Server Diagnostics

Diagnostics are usage information about the server. Usage includes CPU, Memory and IO. Information is dependant on the hypervisor used by the OpenStack installation. As of right now there is no concrete diagnostic specification which is why the information is variable and in map form (key and value)

Map<String, ? extends Number> diagnostics = os.compute().servers().diagnostics("serverId");

Networks (Neutron)

Network Operations

// List the networks which the current authorized tenant has access to
List<? extends Network> networks = os.networking().network().list();

// Create a Network
Network network = os.networking().network()
                    .create(Builders.network().name("MyNewNet").tenantId(tenant.getId()).build());

Subnet Operations

// List all subnets which the current authorized tenant has access to
List<? extends Subnet> subnets = os.networking().subnet().list();

// Create a Subnet
Subnet subnet = os.networking().subnet().create(Builders.subnet()
                  .name("MySubnet")
                  .networkId("networkId")
                  .tenantId("tenantId")
                  .addPool("192.168.0.1", "192.168.0.254")
                  .ipVersion(IPVersionType.V4)
                  .cidr("192.168.0.0/24")
                  .build());

Router Operations

// List all Routers 
List<? extends Router> = os.networking().router().list();

// Create a Router
Router router = os.networking().router().create(Builders.router()
                  .name("ext_net").adminStateUp(true).externalGateway("networkId").build());
                  

Image Operations (Glance)

Basic Operations

// List all Images
List<? extends Image> images = os.images().list();

// Get an Image by ID
Image image = os.images().get("imageId");

// Delete a Image
os.images().delete("imageId");

// Update a Image
Image image = os.images().get("imageId");

os.images().update(image.toBuilder()
           .name("New VM Image Name").minDisk(1024).property("personal-distro", "true"));

Download the Image Data

InputStream is = os.images().getAsStream("imageId"); 

Create a Image

// (URL Payload in this example, File, InputStream are other payloads available)
Image image = os.images().create(Builders.image()
                .name("Cirros 0.3.0 x64")
				.isPublic(true)
				.containerFormat(ContainerFormat.BARE)
				.diskFormat(DiskFormat.QCOW2)
				.build()
				), Payloads.create(new URL("https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img")));

License

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

Copyright 2016 Jeremy Unruh and OpenStack4j

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.

openstack4j's People

Contributors

gondor avatar octupszhang avatar gonzolino avatar ekasitk avatar magixyu avatar maxrome avatar iviireczech avatar isartcanyameres avatar n-r-anderson avatar auhlig avatar krishnabrucelee avatar olivergondza avatar plnordquist avatar symcssn avatar ribeiroana avatar gschukin avatar petergardfjall avatar frsyuki avatar sachin-walia avatar nareshkumarciet avatar hyunsun avatar batdesso avatar mohammad-zimory avatar lianghuang avatar frank-zera avatar e3ky avatar dbantchovski avatar stansun avatar xyfigo avatar xianguang-zhou avatar

Watchers

James Cloos avatar jyzeng avatar

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.