Syntax Highlighter

Tuesday, October 5, 2010

How do I clone thee? Let me count the ways...

Dynamically provisioning stateful VMs with Copper is fast and easy. It occurred to me that we don't often show how fast and easy it is in ways other than using the shell (because it's simple and accessible). Not everyone's workflow is bash-based, so I thought I would show a few examples of our API used with different language bindings.

Our API is powerful and fully featured, allowing for synchronization, resource reservations, and the equivalent of process control for VMs. For the purpose of these examples, I've created four different extremely simple "VM fork" programs below. Each one duplicates the running VM machine (which takes seconds with Copper) and prints the VM's id ala fork().

C/C++


/* Must be linked with -lgridcentric */
#include <gridcentric/gc-guest.h>

int main(int argc, char** argv);
    gc_uuid_t ticket;
    int vmid;
    gc_request_ticket(1, 1, 1, 1000, &ticket);
    vmid = gc_clone(ticket);
    printf("%d\n", vmid);
}

bash


#!/bin/bash
ticket=`gc rt 1 1 1 1000 | awk '{print $2;}'`
gc clone $ticket # Could have pulled the vmid from here.
vmid=`gc vmid`   # But this is much simpler.
echo $vmid

python


#!/usr/bin/env python
import gridcentric.guest

ticket = gridcentric.guest.request_ticket(1,1,1,1000)
vmid = gridcentric.guest.clone(ticket)
print vmid

java


// Be sure to include '/usr/share/gridcentric/gridcentric.jar'
// in the classpath when running this program.
import ca.gridcentric.guest.API;

class VMFork {
    public static void main(String[] args) {
        API api = new API(); 
        API.Uuid ticket = api.requestTicket(1,1,1,1000);
        int vmid = api.clone(ticket);
        System.out.println("" + vmid);
    }
}

Got it? These programs all implement fork() for VMs.

The result of running any of these programs is the same: two nearly-identical VMs, printing our two different vmid values. The operation takes seconds, and can easily be incorporated into complex workflows. It's pretty nuts. Of course, you need not limit yourself to fork with Copper. Say hello to endless possibilities for distributed and scalable applications!

0 comments:

Post a Comment