Introduction of two Openstack-api (Java edition)--jcoulds && openstack4j
Jclouds1. Introduction
Jclouds-This API provides a portable abstraction layer for cloud computing environments and cloud specification features that support cloud computing platforms such as Amazon, VMWare, Azure, and OpenStack, which are currently supported for OpenStack, Nova, Cinder, API interfaces such as glance, Neutron, Keystone, and Swift, but Ceilometer API interfaces are not supported.
2. Use with the JAR package
Official documents-Highly recommended
http://jclouds.apache.org/guides/openstack/
Jcloudsjar package use maven install download management can;
3. For example
Importcom. Google. Common. Collect. Immutableset;Importcom. Google. Common. IO. Closeables;Importcom. Google. Inject. Module;import org. Jclouds. Contextbuilder;import org. Jclouds. Logging. SLF4j. config. SLF4JLoggingModule;import org. Jclouds. OpenStack. Nova. V2_0. Novaapi;import org. Jclouds. OpenStack. Nova. V2_0. Domain. Server;import org. Jclouds. OpenStack. Nova. V2_0. Features. Serverapi;Import Java. IO. Closeable;Import Java. IO. IOException;Import Java. Util. Set;public class Jcloudsnova implements closeable {private final Novaapi Novaapi;Private finalSet<String> regions;public static void Main (string[] args) throws IOException {Jcloudsnova Jcloudsnova = new Jcloudsnova ();try {Jcloudsnova. Listservers();Jcloudsnova. Close();} catch (Exception e) {E. Printstacktrace();} finally {Jcloudsnova. Close();}} public Jcloudsnova () {iterable<module> modules = immutableset.<module>of (new Slf4jloggingmod Ule ());String Provider ="Openstack-nova";String identity ="Demo:demo";//Project Administrators and usersString credential ="Devstack";//user PasswordNovaapi = Contextbuilder. Newbuilder(provider). Endpoint("http://xxx.xxx.xxx.xxx:5000/v2.0/")//api Address. Credentials(Identity, credential). Modules(modules). Buildapi(Novaapi. Class);Regions = Novaapi. Getconfiguredregions();private void Listservers () {for (String region:regions) {Serverapi Serverapi = Novaapi. Getserverapi(region);System. out. println("Servers in"+ region);for (Server Server:serverapi. Listindetail(). Concat()) {System. out. println(" "+ server);}}} public void Close () throws IOException {Closeables. Close(Novaapi, True);}}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21st
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
4. Test results:
More stable, and API documentation is full, teach good understanding;
Openstack4j1. Introduction
Web-api for OpenStack, including Keystone, Nova, Neutron, Glance, Cinder
, Swift, Ceilometer, Heat API support, update fast, there is a problem need to contact GitHub in a timely manner can be resolved.
2. Use with the JAR package
Official Document--http://www.openstack4j.com/learn/
http://www.openstack4j.com/javadoc/
Openstack4j-jar package using the provided Openstack4j-2.0.1-withdeps-sources.jar can be, note that the use of the best JDK is more than 1.7, jdk1.7 best. Java EE 5 or Java EE 6 are available. (with MyEclipse, the JDK version is 1.6, which makes it easy to report version 51 errors.) )
3. For example:
List<string> openstacknetworklist=new arraylist<string> ();Openstacknetworklist. Add("Df6effa2-a1b5-400a-8ab1-457673591aa1");String Openstackimageid =""String openstackflavorid="";String Openstackservername ="";String Openstackzone ="Nova:compute2";Servercreate sc = Builders. Server(). Name(Openstackservername). Flavor(Openstackflavorid). Image(Openstackimageid). Networks(openstacknetworklist). Availabilityzone(Openstackzone). Build();Boot the Server osclient os = osfactory. Builder(). Endpoint("http://x.x.x.x:5000/v2.0/"). Credentials("XXX","XXX"). Tenantname("XXX"). Authenticate();Server server = OS. Compute(). Servers(). Boot(SC);
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21st
- 22
- 23
4. Use effect
API is easy to use, and supports ceilometer and heat, recommended.
OPENSTACK-API Development