lunedì 12 maggio 2014

JClouds APIs - HOW TO DEPLOY A VM ON OPENSTACK USING JCLOUDS

Today I want to wirte a short, but I hope clear, tutorial on how to use jclouds with Openstack.
I’m pretty sure this will be the first article of a series, explaining every time a new feauture. All these posts will be gather together at the end for an awesome article. 

Apache jclouds is an open source multi-cloud toolkit for the Java platform that gives you the freedom to create applications that are portable across clouds while giving you full control to use cloud-specific features (http://jclouds.apache.org/).

 This tutorial is focused on the Compute Service and on how to deploy a VM on openstack using jclouds. Before I deepen the specific argument , if you are asking if there any other APIs that can do the same operation the answer is YES! If you go to openstack page, you will find what you are looking for.

Let’s start with the tutorial: Requirements:

  •  Java Programming Skill 
  • A working openstack with credential and endpoints
  • An Imagae stored in glance

If you are planning to have a maven project (and that is a good thing) you can just add the jcloud dependency:
 <dependency>  
    <groupid>org.jclouds.driver</groupid>  
    <artifactid>jclouds-log4j</artifactid>  
    <version>1.6.0</version>  
   </dependency>  
   <dependency>  
    <groupid>org.apache.jclouds</groupid>  
    <artifactid>jclouds-core</artifactid>  
    <version>1.6.1-incubating</version>  
   </dependency>  
   <dependency>  
    <groupid>org.jclouds.driver</groupid>  
    <artifactid>jclouds-slf4j</artifactid>  
    <version>1.6.0</version>  
   </dependency>  
   <dependency>  
    <groupid>org.jclouds.api</groupid>  
    <artifactid>openstack-nova</artifactid>  
    <version>1.6.0</version>  
   </dependency>  
I used two classes to show how to deploy a VM on openstack using jclouds:

  • Deployer
  • Configuration
Deployer contains all the code to deploy the VM, instead Configuration all the information about the openstack connection.


Let's take a look to Configuration.java:
 public class Configuration {  
      public static final String KEYSTONE_AUTH_URL = "http://172.25.27.16:35357/v2.0";  
      public static final String KEYSTONE_USERNAME = "admin";  
      public static final String KEYSTONE_PASSWORD = "password";  
      public static final String KEYSTONE_ENDPOINT = "http://172.25.27.16:35357/v2.0";  
      public static final String TENANT_NAME = "admin";  
      public static final String NOVA_ENDPOINT = "http://172.25.27.16:5000/v2";  
      public static final String CEILOMETER_ENDPOINT = "";  
 }  


You have to change the value with your configuration.


Once the configuration is done you have to connect to openstack:

 ComputeServiceContext context = ContextBuilder.newBuilder("openstack-nova")
                  .endpoint(Configuration.NOVA_ENDPOINT)
                   .credentials(identity, credential)
            .modules(modules)
            .overrides(overrides)
         .buildView(ComputeServiceContext.class);


overrides is an empty Property Object, identity and password are string containing the openstack creadentials (tenant:admin and password). The builder specifies to create a ContextBuilder for openstack-nova!


Now you can get the ComputeService:
 ComputeService computeService = context.getComputeService();  

To instantiate a VM in openstack we have to create its template.
Jclouds provides a template builder to map the given template with all the different specifics of the supported clouds.

In the example, I deployed a VM with at least 512Mb of Ram and using the specific Image "RegionOne/f72885a5-e681-4219-b931-bb062d74c591". All the Images have to be specified using the approach <openstackZone>/<imageID>.

 TemplateBuilder tb = computeService.templateBuilder();  
        tb.minRam(Integer.parseInt("512"));  
        tb.imageId("RegionOne/f72885a5-e681-4219-b931-bb062d74c591");  
        NodeMetadata node1=null;  
           try {  
                node1 = getOnlyElement(computeService.createNodesInGroup(groupName, 1, tb.build()));  
           } catch (RunNodesException e) {  
                e.printStackTrace();  
           }  
        System.out.printf("<< node %s: %s%n", node1.getId(),  
         concat(node1.getPrivateAddresses(), node1.getPublicAddresses()));  

We should get the information about the VM if everything run well.

The Complete example is hosted at FilippoGaudenzi github. Inside Deloyer there are other operations that may help you to understand how to interact with the ComputeService interface.

Enjoy


lunedì 29 ottobre 2012

SET UP PROXY - SHELL

SET UP PROXY - SHELL


to set up the proxy from the shell you have to exectue

$export http_proxy="<proxyadress>"

example:
 $export http_proxy="http:192.168.122.4:3128"

Rember that this variable is temporary and it is bound only to the user who executed the line. If you want to use as sudo user you have to execute the same command as sudoer (sudo export...).

Ubuntu 12.04 and contextualization over OpenNebula

Ubuntu 12.04 and contextualization over OpenNebula

There are two possibilities:


  1. download the Deb package from: here. Then just execute: 
    $sudo dpkg -i one-context_1.0.1_all.deb



  2. copy the vmcontext.sh script inside the image and set up the init. If you decide to use this approach, pay attention to the Ubuntu init process. It doesn't use the normal init that is composed by sequential steps, but it uses upstart that lunches parallel init threads