{"id":15043616,"url":"https://github.com/openstack4j/openstack4j","last_synced_at":"2025-04-04T20:10:12.151Z","repository":{"id":37405552,"uuid":"222457383","full_name":"openstack4j/openstack4j","owner":"openstack4j","description":"Fluent OpenStack SDK for Java","archived":false,"fork":false,"pushed_at":"2024-05-10T08:03:48.000Z","size":5600,"stargazers_count":119,"open_issues_count":80,"forks_count":95,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-28T19:07:44.304Z","etag":null,"topics":["cloud","hecktoberfest","java","openstack","sdk"],"latest_commit_sha":null,"homepage":"https://openstack4j.github.io/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openstack4j.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-18T13:36:41.000Z","updated_at":"2025-03-25T08:17:37.000Z","dependencies_parsed_at":"2023-12-22T12:40:22.384Z","dependency_job_id":"3d5e7798-d145-496d-8aae-4f875167a58a","html_url":"https://github.com/openstack4j/openstack4j","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openstack4j%2Fopenstack4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openstack4j%2Fopenstack4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openstack4j%2Fopenstack4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openstack4j%2Fopenstack4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openstack4j","download_url":"https://codeload.github.com/openstack4j/openstack4j/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247242678,"owners_count":20907134,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloud","hecktoberfest","java","openstack","sdk"],"created_at":"2024-09-24T20:49:20.800Z","updated_at":"2025-04-04T20:10:12.130Z","avatar_url":"https://github.com/openstack4j.png","language":"Java","readme":"OpenStack4j\n===========\n\n[![Build Status](https://github.com/openstack4j/openstack4j/actions/workflows/ci.yaml/badge.svg)](https://github.com/openstack4j/openstack4j/actions/workflows/ci.yaml)\n[![License](https://img.shields.io/badge/license-Apache%202-blue.svg)]()\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.openstack4j.core/openstack4j/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.openstack4j.core/openstack4j)\n[![javadoc](https://javadoc.io/badge2/com.github.openstack4j.core/openstack4j-core/javadoc.svg)](https://javadoc.io/doc/com.github.openstack4j.core/openstack4j-core)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=openstack4j_openstack4j\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=openstack4j_openstack4j)\n\nOpenStack4j 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)\n\n## Documentation and Support\n\n* Website: [openstack4j.github.io](https://openstack4j.github.io/)\n* Documentation/Tutorials: [openstack4j.github.io/learn/](https://openstack4j.github.io/learn/)\n* Questions - Use Google Groups: [groups.google.com/group/openstack4j](http://groups.google.com/group/openstack4j)\n* Questions - [StackOverflow](http://stackoverflow.com/search?q=openstack4j)\n* Changelog: [Changelog](https://github.com/openstack4j/openstack4j/releases)\n\n## Bug Reports\n\n* GitHub Issues: [Click Here](https://github.com/openstack4j/openstack4j/issues)\n\n## Java version support\n\n| ----                                | Java 8 | Java 11 | Java 17 | Java 21 |\n|-------------------------------------|--------|---------|---------|---------|\n| OpenStack4j                         | ?      | 🟢      | 🟢      | 🟢      |\n| HttpURL Connector                   | ?      | 🟢      | *       | *       |\n| HttpComponents-HttpClient Connector | ?      | 🟢      | 🟢      | 🟢      |\n| Jersey2 Connector                   | ?      | 🟢      | *       | *       |\n| OKHttp Connector                    | ?      | 🟢      | 🟢      | 🟢      |\n| RestEasy Connector                  | ?      | 🟢      | 🟢      | 🟢      |\n\n*) Starting with Java 16, it is not possible to use HttpUrlConnection to perform PATH requests.\nConnectors depending on native JDK http stack will not work after Java 16.\n\nMaven\n-----\n\n#### Latest Release (Stable)\n\nOpenStack4j 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.\n\n**Using OpenStack4j with the default Jersey2 Connector**\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.openstack4j.core\u003c/groupId\u003e\n    \u003cartifactId\u003eopenstack4j\u003c/artifactId\u003e\n    \u003cversion\u003e...\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n**Using OpenStack4j with one of our connector modules**\n\nTo configure OpenStack4j to use one of our supported connectors (Jersey 2, Resteasy, Apache HttpClient, OKHttp) [see the usage guide](https://github.com/openstack4j/openstack4j/tree/master/connectors)\n\n#### Current (Master Branch)\n\nSee notes above about connectors (same rules apply) to development branches.\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.openstack4j.core\u003c/groupId\u003e\n    \u003cartifactId\u003eopenstack4j\u003c/artifactId\u003e\n    \u003cversion\u003e...\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n**A note about referencing Snapshots without Source**\n\nSnapshots are deploys to sonatype.  We automatically deploy snapshots on every merge into the master branch.  Typically 5 - 10 snapshot releases before an official release.\n\nYou 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.\n\nExample POM based repository declaration to grab snapshots:\n```xml\n\u003crepositories\u003e\n    \u003crepository\u003e\n        \u003cid\u003est-snapshots\u003c/id\u003e\n        \u003cname\u003esonatype-snapshots\u003c/name\u003e\n        \u003curl\u003ehttps://oss.sonatype.org/content/repositories/snapshots\u003c/url\u003e\n    \u003c/repository\u003e\n\u003c/repositories\u003e\n```\n\nContributing\n------------\nIf you would like to contribute please see our contributing [guidelines](https://github.com/openstack4j/openstack4j/blob/master/CONTRIBUTING.md)\n\nThe OpenStack4j project is a work of Jeremy Unruh as the original project author and the [community of contributors](https://github.com/openstack4j/openstack4j/graphs/contributors).\n\nQuick Usage Guide\n-----------------\n\nBelow are some examples of the API usage.  Please visit [openstack4j.github.io](https://openstack4j.github.io/) for the full manual and getting started guides.\n\n\n### Authenticating\n\nOpenStack4j 3.0.0+ supports Identity (Keystone) V3 and V2.\n\nOpenStack4j 3.0.0 introduced some breaking changes.\nThe legacy Identity V2 API now uses the class ```OSClientV2``` in place of the class OSClient.\n\n##### Using Identity V2 authentication:\n```java\n// Identity V2 Authentication Example\nOSClientV2 os = OSFactory.builderV2()\n        .endpoint(\"http://127.0.0.1:5000/v2.0\")\n        .credentials(\"admin\",\"sample\")\n        .tenantName(\"admin\")\n        .authenticate();\n```\n\n##### Using Identity V3 authentication\n\nCreating and authenticating against OpenStack is extremely simple. Below is an example of authenticating which will\nresult with the authorized OSClient.  OSClient allows you to invoke Compute, Identity, Neutron operations fluently.\n\nYou can use either pass the users name or id and password in the following way\n```java\n.credentials(\"username\", \"secret\", Identifier.byId(\"domain id\"))\n```\nor\n```java\n.credentials(\"user id\", \"secret\")\n```\nto provide credentials in each of the following cases.\n\n\nUsing Identity V3 authentication you basically have 4 options:\n\n(1) authenticate with project-scope\n```java\nOSClientV3 os = OSFactory.builderV3()\n        .endpoint(\"http://\u003cfqdn\u003e:5000/v3\")\n        .credentials(\"admin\", \"secret\", Identifier.byId(\"user domain id\"))\n        .scopeToProject(Identifier.byId(\"project id\"))\n        .authenticate();\n```\n(2) authenticate with domain-scope\n```java\nOSClientV3 os = OSFactory.builderV3()\n        .endpoint(\"http://\u003cfqdn\u003e:5000/v3\")\n        .credentials(\"admin\", \"secret\", Identifier.byId(\"user domain id\"))\n        .scopeToDomain(Identifier.byId(\"domain id\"))\n        .authenticate();\n```\n\n(3) authenticate unscoped\n```java\nOSClientV3 os = OSFactory.builderV3()\n        .endpoint(\"http://\u003cfqdn\u003e:5000/v3\")\n        .credentials(\"user id\", \"secret\")\n        .authenticate();\n```\n\n(4) authenticate with a token\n```java\nOSClientV3 os = OSFactory.builderV3()\n        .endpoint(\"http://\u003cfqdn\u003e:5000/v3\")\n        .token(\"token id\")\n        .scopeToProject(Identifier.byId(\"project id\"))\n        .authenticate();\n```\n(5) authenticate using client certificate\n```bash\nopenssl pkcs12 -export -out client-certificate-keystore.p12  -inkey key.pem -in cert.pem -certfile ca.pem\nEnter Export Password:encrypt\nVerifying - Enter Export Password:encrypt\n```\n```java\nString encrypt =  \"encrypt\";\nKeyStore keyStore = KeyStore.getInstance(\"PKCS12\");\nkeyStore.load(new FileInputStream(new File(\"client-certificate-keystore.p12\")), encrypt.toCharArray());\nSSLContext sslContext = SSLContexts.custom()\n        //ignore server verify\n        .loadTrustMaterial(new TrustStrategy() {\n            @Override\n            public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {\n                return true;\n            }\n        })\n        .loadKeyMaterial(keyStore,encrypt.toCharArray())\n        .build();\nConfig config = Config.newConfig();\nconfig.withSSLContext(sslContext);\nOSClient.OSClientV3 osClient = OSFactory.builderV3()\n        .endpoint(\"https://\u003cfqdn\u003e:5000/v3\")\n        .withConfig(config)\n        .scopeToProject(Identifier.byId(\"project id\"))\n        //.scopeToDomain(Identifier.byId(\"domain id\"))\n        .authenticate();\n```\n\n#### Identity Operations (Keystone) V3\n\nAfter successful v3 - authentication you can invoke any Identity (Keystone) V3 directly from the OSClientV3.\n\nIdentity Services fully cover User, Role, Project, Domain, Group,.. service operations (in progess).\nThe examples below are only a small fraction of the existing API so please refer to the API documentation for more details.\n\n**NOTE**: The ```os``` used here is an instance of ```org.openstack4j.api.OSClient.OSClientV3```.\n\n**User operations**\n```java\n// Create a User associated to the new Project\nUser user = os.identity().users().create(Builders.user()\n\t      .domainId(\"domain id\")\n\t      .name(\"foobar\")\n\t      .password(\"secret\")\n\t      .email(\"foobar@example.com\")\n\t      .enabled(true)\n\t      .build());\n//or\nUser user = os.identity().users().create(\"domain id\", \"foobar\", \"secret\", \"foobar@example.org\", true);\n\n// Get detailed info on a user by id\nUser user = os.identity().users.get(\"user id\");\n//or by name and domain identifier\nUser user = os.identity().users.getByName(\"username\", \"domain id\");\n\n// Add a project based role to the user\nos.identity().roles().grantProjectUserRole(\"project id\",\"user id\", \"role id\");\n\n// Add a domain based role to the user\nos.identity().roles().grantDomainUserRole(\"domain id\",\"user id\", \"role id\");\n\n// Add a user to a group\nos.identity().users().addUserToGroup(\"user id\", \"group id\");\n```\n\n**Role operations**\n```java\n// Get a list of all roles\nos.identity().roles().list();\n\n// Get a role by name\nos.identity().roles().getByName(\"role name\");\n```\n\n**Project operations**\n\n```java\n// Create a project\nos.identity().project().create(\n    Builders.project().name(\"...\").description(\"...\").domainId(\"...\").enabled(true).build()\n);\n```\n\n#### Identity Operations (Keystone) V2\n\nAfter successful v2 - authentication you can invoke any Identity (Keystone) V2 directly from the OSClientV2.\n\nIdentity V2 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.\n\n**NOTE**: The ```os``` used here is an instance of ```org.openstack4j.api.OSClient.OSClientV2```.\n\n**Create a Tenant, User and associate a Role**\n```java\n// Create a Tenant (could also be created fluent within user create)\nTenant tenant = os.identity().tenants().create(\n    Builders.identityV2().tenant().name(\"MyNewTenant\").build()\n);\n\n// Create a User associated to the new Tenant\nUser user = os.identity().users().create(\n    Builders.identityV2().user().name(\"jack\").password(\"sample\").tenant(tenant).build()\n);\n\n// Add a Tenant based Role to the User\nos.identity().roles().addUserRole(\n    tenant.getId(),\n    user.getId(),\n    os.identity().roles().getByName(\"Member\").getId()\n);\n\n```\n\n### Compute Operations (Nova)\n\nOpenStack4j 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.\n\n**Create a Flavor and Boot a Server/VM**\n```java\n// Create a Flavor for a special customer base\nFlavor flavor = os.compute().flavors().create(\n    Builders.flavor().name(\"Gold\").vcpus(4).disk(80).ram(2048).build()\n);\n\n// Create and Boot a new Server (minimal builder options shown in example)\nServer server = os.compute().servers().boot(\n    Builders.server().name(\"Ubuntu 2\").flavor(flavor.getId()).image(\"imageId\").build()\n);\n```\n\n**Create a new Server Snapshot**\n```java\nString imageId = os.compute().servers().createSnapshot(server.getId(), \"Clean State Snapshot\");\n```\n\n**Server Diagnostics**\n\nDiagnostics are usage information about the server.  Usage includes CPU, Memory and IO.  Information is\ndependant on the hypervisor used by the OpenStack installation.  As of right now there is no concrete diagnostic\nspecification which is why the information is variable and in map form (key and value)\n```java\nMap\u003cString, ? extends Number\u003e diagnostics = os.compute().servers().diagnostics(\"serverId\");\n```\n\n\n### Networks (Neutron)\n\n**Network Operations**\n```java\n// List the networks which the current authorized tenant has access to\nList\u003c? extends Network\u003e networks = os.networking().network().list();\n\n// Create a Network\nNetwork network = os.networking().network().create(\n    Builders.network().name(\"MyNewNet\").tenantId(tenant.getId()).build()\n);\n```\n\n**Subnet Operations**\n```java\n// List all subnets which the current authorized tenant has access to\nList\u003c? extends Subnet\u003e subnets = os.networking().subnet().list();\n\n// Create a Subnet\nSubnet subnet = os.networking().subnet().create(Builders.subnet()\n        .name(\"MySubnet\")\n        .networkId(\"networkId\")\n        .tenantId(\"tenantId\")\n        .addPool(\"192.168.0.1\", \"192.168.0.254\")\n        .ipVersion(IPVersionType.V4)\n        .cidr(\"192.168.0.0/24\")\n        .build()\n);\n```\n\n**Router Operations**\n```java\n// List all Routers\nList\u003c? extends Router\u003e = os.networking().router().list();\n\n// Create a Router\nRouter router = os.networking().router().create(\n    Builders.router().name(\"ext_net\").adminStateUp(true).externalGateway(\"networkId\").build()\n);\n```\n\n### Image Operations (Glance)\n\n**Basic Operations**\n```java\n// List all Images\nList\u003c? extends Image\u003e images = os.images().list();\n\n// Get an Image by ID\nImage image = os.images().get(\"imageId\");\n\n// Delete a Image\nos.images().delete(\"imageId\");\n\n// Update a Image\nImage image = os.images().get(\"imageId\");\n\nos.images().update(\n   image.toBuilder().name(\"VM Image Name\").minDisk(1024).property(\"personal-distro\", \"true\")\n);\n```\n\n**Download the Image Data**\n```java\nInputStream is = os.images().getAsStream(\"imageId\");\n```\n\n**Create a Image**\n```java\n// (URL Payload in this example, File, InputStream are other payloads available)\nPayload\u003cURL\u003e create = Payloads.create(new URL(\"https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img\"))\nImage req = Builders.image().name(\"Cirros 0.3.0 x64\").isPublic(true).containerFormat(ContainerFormat.BARE).diskFormat(DiskFormat.QCOW2).build()\nImage image = c.images().create(req, create)\n```\n\nLicense\n-------\n```\nThis software is licensed under the Apache 2 license, quoted below.\n\nCopyright 2019 ContainX and OpenStack4j\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not\nuse this file except in compliance with the License. You may obtain a copy of\nthe License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\nWARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\nLicense for the specific language governing permissions and limitations under\nthe License.\n```\n","funding_links":[],"categories":["云计算"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenstack4j%2Fopenstack4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenstack4j%2Fopenstack4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenstack4j%2Fopenstack4j/lists"}