溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

OpenStack4j中怎么實(shí)現(xiàn)一個(gè)對外接口

發(fā)布時(shí)間:2021-08-12 17:01:13 來源:億速云 閱讀:155 作者:Leah 欄目:云計(jì)算

OpenStack4j中怎么實(shí)現(xiàn)一個(gè)對外接口 ,相信很多沒有經(jīng)驗(yàn)的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。

在項(xiàng)目中增加maven依賴包

<dependency>
  <groupId>org.pacesys</groupId>
  <artifactId>openstack4j</artifactId>
  <version>3.0.3</version>
  <classifier>withdeps</classifier></dependency>

通過權(quán)限認(rèn)證

import org.openstack4j.api.OSClient.OSClientV3;import org.openstack4j.openstack.OSFactory;import org.openstack4j.model.common.Identifier;

# use Identifier.byId("domainId") or Identifier.byName("example-domain")
Identifier domainIdentifier = Identifier.byId("domainId");

# unscoped authentication
# as the username is not unique across domains you need to provide the domainIdentifier
OSClientV3 os = OSFactory.builderV3()
                       .endpoint("http://127.0.0.1:5000/v3")
                       .credentials("admin","sample", domainIdentifier)
                       .authenticate();

# project scoped authentication
OSClientV3 os = OSFactory.builderV3()
                    .endpoint("http://127.0.0.1:5000/v3")
                    .credentials("admin", "secret", Identifier.byName("example-domain"))
                    .scopeToProject(Identifier.byId(projectIdentifier))
                    .authenticate();

# domain scoped authentication
# using the unique userId does not require a domainIdentifier
OSClientV3 os = OSFactory.builderV3()
                    .endpoint("http://127.0.0.1:5000/v3")
                    .credentials("userId", "secret")
                    .scopeToDomain(Identifier.byId(domainIdentifier))
                    .authenticate();

# Scoping to a project just by name isn't possible as the project name is only unique within a domain. # You can either use this as the id of the project is unique across domains OSClientV3 os = OSFactory.builderV3() .endpoint("http://127.0.0.1:5000/v3") .credentials("userId", "secret") .scopeToProject(Identifier.byName(projectName), Identifier.byName(domainName)) .authenticate(); # Or alternatively OSClientV3 os = OSFactory.builderV3() .endpoint("http://127.0.0.1:5000/v3") .credentials("userId", "secret") .scopeToDomain(Identifier.byName(domainName)) .authenticate();

常用模塊調(diào)用

// Find all UsersList<? extends User> users = os.identity().users().list();// List all TenantsList<? extends Tenant> tenants = os.identity().tenants().list();// Find all Compute FlavorsList<? extends Flavor> flavors = os.compute().flavors().list();// Find all running ServersList<? extends Server> servers = os.compute().servers().list();// Suspend a Serveros.compute().servers().action("serverId", Action.SUSPEND);// List all NetworksList<? extends Network> networks = os.networking().network().list();// List all SubnetsList<? extends Subnet> subnets = os.networking().subnet().list();// List all RoutersList<? extends Router> routers = os.networking().router().list();// List all Images (Glance)List<? extends Image> images = os.images().list();// Download the Image DataInputStream is = os.images().getAsStream("imageId");

看完上述內(nèi)容,你們掌握OpenStack4j中怎么實(shí)現(xiàn)一個(gè)對外接口 的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI