资源简介

用的是openstack4j库,java web,Maven工程。

资源截图

代码片段和文件信息


import java.util.List;
import java.util.Map;

import org.openstack4j.api.OSClient.OSClientV3;
import org.openstack4j.api.identity.EndpointURLResolver;
import org.openstack4j.api.types.Facing;
import org.openstack4j.core.transport.Config;
import org.openstack4j.model.common.Identifier;
import org.openstack4j.model.compute.Address;
import org.openstack4j.model.compute.Flavor;
import org.openstack4j.model.compute.FloatingIP;
import org.openstack4j.model.compute.HostAggregate;
import org.openstack4j.model.compute.Keypair;
import org.openstack4j.model.compute.QuotaSet;
import org.openstack4j.model.compute.SecGroupExtension;
import org.openstack4j.model.compute.Server;
import org.openstack4j.model.compute.ext.AvailabilityZone;
import org.openstack4j.model.compute.ext.AvailabilityZone.NovaService;
import org.openstack4j.model.compute.ext.DomainEntry;
import org.openstack4j.model.compute.ext.Hypervisor;
import org.openstack4j.model.compute.ext.HypervisorStatistics;
import org.openstack4j.model.compute.ext.Service;
import org.openstack4j.model.identity.URLResolverParams;
import org.openstack4j.model.identity.v3.Endpoint;
import org.openstack4j.model.identity.v3.Group;
import org.openstack4j.model.identity.v3.Project;
import org.openstack4j.model.identity.v3.Role;

import org.openstack4j.model.identity.v3.User;
import org.openstack4j.model.image.Image;
import org.openstack4j.model.network.Agent;
import org.openstack4j.model.network.IP;
import org.openstack4j.model.network.Network;
import org.openstack4j.model.network.Pool;
import org.openstack4j.model.network.Port;
import org.openstack4j.model.network.Router;
import org.openstack4j.model.network.Subnet;
import org.openstack4j.model.storage.block.Volume;
import org.openstack4j.openstack.OSFactory;

public class OpenStackConnection {
public static void main(String[] args) {
final EndpointURLResolver endpointUrlResolver = new EndpointURLResolver() {
@Override
public String findURLV2(URLResolverParams params) {
// TODO Auto-generated method stub
return null;
}

@Override
public String findURLV3(URLResolverParams params) {
switch (params.type.getServiceName()) {
case “keystone“:
return “http://xx.xx.xx.xx:5000/v3“;
case “glance“:
return “http://xx.xx.xx.xx:9292“;// 经openstack4j检验用的是v1版本
case “nova“:
return “http://xx.xx.xx.xx:8774/v2.1/d65c0ead45594d0d8fc3e2eace892ba7“;// compute计算相关
case “neutron“:
return “http://xx.xx.xx.xx:9696“;
case “cinder“:
return “http://xx.xx.xx.xx:8776/v1/d65c0ead45594d0d8fc3e2eace892ba7“;// 经openstack4j检验用的是v1版本
default:
return null;
}
}
};

// OSFactory.enableHttpLoggingFilter(true);//
Identifier domainIdentitier = Identifier.byName(“default“);
try {
// 不同域内的项目名和用户名有可能相同。
OSClientV3 os = OSFactory.builderV3()
.withConfig(Config.newConfig().withEndpointURLResolver(endpointUrlResolver))
.endpoint(

评论

共有 条评论