您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
OpenStack4j中怎么实现一个对外接口 ,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
<dependency> <groupId>org.pacesys</groupId> <artifactId>openstack4j</artifactId> <version>3.0.3</version> <classifier>withdeps</classifier></dependency>
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();
// 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");
看完上述内容,你们掌握OpenStack4j中怎么实现一个对外接口 的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。