Fix VirtualBox VM launching

Don't reconfigure a VM if it already exists to avoid trashing user
configured VMs.  Enable error checking for VM creation to make it more
robust.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Set vbox memory size

Default memeory size is 64MB. It is too small to start a OSv image=default
image.

Signed-off-by: Asias He <asias@cloudius-systems.com>
Merge pull request #14 from asias/master

Set vbox memory size
run: Add memory size command line option

Add a "-m" command line option to "capstan run" that specifies VM memory
size.

Unify default memory size to 1 GB for both QEMU and VirtualBox.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vbox: Launch freshly created VMs

Create the VirtualBox VM on the fly to make sure "capstan run" command
line options such as "-m" are always respected.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
run: Add CPU count command line option

Add a "-c" command line option to "capstan run" to specify number of
CPUs in the VM.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Move build logic to cmd/build.go

Image building is not specific to QEMU although it's currently the only
supported hypervisor for building images.

Move the code to cmd/build.go in preparation for making the code more
generic.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Fix UploadFiles and UploadRPM error handling

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Clean up imports in capstan.go

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Refactor NBD client code

The NBD code looks like it was written by a Go newbie.  Clean it up.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Fix NBD error handling

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Fix QEMU hypervisor name

It's not KVM, it's QEMU.  This is needed for sane per-hypervisor image
naming convention.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
test: push test case

Add a test case for 'capstan push'.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Per-hypervisor images

Start using per-hypervisor images in the Capstan repository.  This is
needed for vbox image build support.  Please note that QEMU is still
used for the actual image building but the generated image is in VDI
format for vbox.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Fix "rmi" command from not removing everything

Commit 8e37354 ("Per-hypervisor images") broke "capstan rmi" to
accidentally remove all images from the local repository.  Fix it up.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Add test case for rmi command

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
build: Print stdout and stderr on error

Currently, if the "build" command specified in Capstanfile fails,
there's no way to see the error.  Fix that up by printing out stdout and
stderr on failures.

Example output looks as follows:

  [penberg@localhost http-server]$ capstan build
  Building http-server...
  cc -o http-server.so -std=gnu99 -fPIC -shared -levent http-server.c
  cc -o http-server -std=gnu99 -fPIC -levent http-server.c
  http-server.c:28:26: fatal error: event2/event.h: No such file or directory
   #include <event2/event.h>
                          ^
  http-server.c:28:26: fatal error: event2/event.h: No such file or directory
   #include <event2/event.h>
                          ^
  compilation terminated.
  compilation terminated.
  make: *** [http-server.so] Error 1
  make: *** Waiting for unfinished jobs....
  make: *** [http-server] Error 1

  exit status 2

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
run: Fix broken image detection logic

I tried running Don's HTTP server example but it 'capstan run' fails:

[penberg@localhost http-server]$ capstan run
http-server: image format not recognized, unable to run it.

The problem is that there's an ELF executable with the same
'http-server' name in the directory:

  [penberg@localhost http-server]$ file http-server
  http-server: ELF 64-bit LSB executable, x86-64, version 1 (SYSV),
  dynamically linked (uses shared libs), for GNU/Linux 2.6.32,
  BuildID[sha1]=0xa72de03d76d08142358c11686250d12202ac4c37, not stripped

which the run command attempts to run.  Fix the problem by looking up
the default image from local repository, not from the current directory.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
run: Fix running local repository images by name

Commit 79e6d55 ("run: Fix broken image detection logic") was overly
eager and broke Asias' workflow of running images from local repository
by name.

Fix it up.

Reported-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Port forwarding support for QEMU

This adds a "-f" command line option to "capstan run" for specifying
port forwarding rules. The syntax of a port forward rule is:

  <host-port>:<guest-port>

For example, running Don's HTTP server example with:

  [penberg@localhost http-server]$ capstan run -f 9090:8080

makes the guest 8080 port available at localhost:9090.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>