How to convert VMWare virtual machines to Virtual Box

Where I started from

This is my situation: I’m on a Windows7 x86 host, and I have an old Ubuntu 10.04 virtual machine with VMWare Tools installed on it.

My need is to turn it into an OVF appliance, so that I can run it on Virtual Box, no matter where what architecture it will be run on.

Steps

This is what I’ve done:

  • I made sure (e.g: using VMWare Player or Workstation) that the virtual appliance is powered off;
  • Opened a Command Prompt, moved to the VMWare Player/Workstation installation dir and executed the OVF conversion tool. Be aware that this conversion may take some time, depending on how big is your VMX appliance. I did it as follows (replace the paths as needed):
cd "C:\Program Files\VMware\VMware Workstation\OVFTool"
ovftool.exe "C:\Users\claudio\Documents\Virtual Machines\ubuntu1004\ubuntu1004.vmx" "C:\Users\claudio\Documents\Virtual Machines\converted-to-virtualbox\ubuntu1004.ovf"
  • When the conversion process was over, I imported the “ubuntu1004.ovf” appliance into Virtual Box by using the “File” > “Import virtual appliance ..” menu element  and leaving all the defaults;
  • Then I booted up the “ubuntu1004.ovf” appliance and performed VMWare Tools uninstallation by opening up an SSH shell and executing:
sudo /usr/bin/vmware-uninstall-tools.pl
  • Then I finished the whole process by executing the “Device” > “Install Guest Additions” menu item: a virtual CD is then mounted and I launched the installation process from a shell
cd /media/VBOXADDITIONS_4.2.12_84980
sudo bash VBoxLinuxAdditions.run

 

Not as difficult as it may seem…. Hope this helps!

Advertisements

How to deploy Flask applications to Apache webserver

This is a simple guide explaining how I managed to configure Apache 2.2 httpd server on a Windows platform so that it can serve a Python webapplication I wrote using the Flask micro-framework. The guide is valid, with a very little modification, also on Linux environments (you geeks know how to do)

Why I needed to to this

I developed this application at work and ‘ve been serving it from the beginning via the Flask’s built-in minimal webserver: unfortunately this  is not enough for production stage as I need a more robust server with SSL capabilities, which Flask’s has not. This was my first time in deploying a Python webapp…So, after googling a bit and reading the Flask deployment notes, I came up with the answer: what I needed was a WSGI-compliant server running on my target platform, a Windows 2012 server. The natural choice to me was to enable the WSGI module on the “good ole” Apache webserver, which I’m experienced with.

Steps

Flask app

We choose a folder in which we place the Python code. For instance,

D:\webapps\test

In this folder we create the real Flask webapplication that we want to deploy (file “test.py”):

from flask import Flask, request
app = Flask(__name__)

@app.route('/hello')
def hello_world():
    name = request.args.get('name','')
    return 'Hello ' + name + '!'
if __name__ == '__main__':
    app.run()

The Apache server won’t be aware of “test.py” at all. What you need to do now is to write in the same folder a Python file named “test.wsgi” that we will link into the webserver’s configuration: the code in this file will import the main Flask application object (built in our case as a singleton) and will be actually executed by the WSGI module of Apache. In the code, it is vital that you DON’T change the name of the “application” variable, as it is exactly what the server expects to find. Also please note that we are extending the Python classes path to include our own webapplication’s folder. This is “test.wsgi”:

import sys

#Expand Python classes path with your app's path
sys.path.insert(0, "d:/webapps/test")

from test import app

#Put logging code (and imports) here ...

#Initialize WSGI app object
application = app

As an additional remark, if you want to put any logging code (e.g: file/e-mail/console loggers) into your Flask app, you must put it before the if __name__ == ‘__main__’ block, otherwise it won’t log anything! Add your loggers to the app object.

Apache setup

Ok, what’s next? Now it’s all about installing and properly configuring Apache.

First: install Apache webserver. I downloaded and executed the .msi installer. Apache was installed at

"C:\Program Files (x86)\Apache Software Foundation\Apache2.2"

Second: install the WSGI Apache module. Pay attention to download the module compiled for your specific combination of platform and Python and Apache versions: I downloaded this module. Once downloaded, rename the .so file into “mod_wsgi.so” and put it under the “modules” subfolder of your Apache installation folder. Then you have to tell Apache to use it: open in a text editor the “httpd.config” file which is under the “conf” subfolder and add the following line at the bottom:

LoadModule wsgi_module modules/mod_wsgi.so

Third: restart Apache.

Now Apache is ready to serve WSGI webapplications. What is left is to tell about where our application is and match it to a URL alias. It’s child’s play: open in a text editor the “httpd.config” file we used before and add these lines to the bottom:

<Directory d:/webapps/test>
    Order allow,deny
    Allow from all
</Directory>
WSGIScriptAlias /flasktest d:/webapps/test/test.wsgi

(nevertheless, I prefer to place the per-virtual-host or per-alias configurations’ stuff into separate files and then use an Include directive into the main “httpd.conf”)

Now restart Apache again and if you open a browser and point it to:

http://localhost/flasktest/hello?name=claudio

and you should see the webapp’s greetings!

Further references

  • This guide helped me a lot in understanding how to setup Apache WSGI.
  • I also found this tutorial which is far more comprehensive than mine and covers Flask deployment on Apache on Debian/Ubuntu environments

How to install MongoDB on Windows as a service

I’m showing you a quick procedure to install MongoDB as a service on Windows platforms (I simply gathered the hints explained in the official documentation page and adapted the whole stuff to my specific case).

In my example, I’m installing MongoDB version 2.2.0 on a Windows Server 2003 R2 machine and my goal is to have it available as a service.

The procedure is pretty straightforward: all you need is to setup the path in which MongoDB will physically store the data collections, to provide a logfile for the service we’re going to create and finally to tell the mongod daemon to run as a service.

Here we go (be sure to enclose all the paths in double quotes if they contain spaces):


:: 1. Download the installation package (a .zip archive) and decompress it into folder C:\mongodb-2.2.0\

:: 2. Create the data path folders (in my example, C:\mongodb-2.2.0\data\db):
md C:\mongodb-2.2.0\data
md C:\mongodb-2.2.0\data\db
set datapath = C:\mongodb-2.2.0\data\db

:: 3. Setup mongod configuration file path (my file is C:\mongodb-2.2.0\mongod.cfg):
set configpath = C:\mongodb-2.2.0\mongod.cfg

:: 4. Create the folder that will host the service's log file (my folder is C:\mongodb-2.2.0\log) and write its path into the config file:
md C:\mongodb-2.2.0\log
echo logpath = C:\mongodb-2.2.0\log\mongod.log > C:\mongodb-2.2.0\mongod.cfg

:: 5. install mongod as a service:
C:\mongodb-2.2.0\bin\mongod.exe --config %configpath% --dbpath %dbpath% --install

Now you can start/stop/remove the MongoDB service via the services administration graphical interface, or via the command line using the following commands:


:: Start service
net start MongoDB

:: Stop service
net stop MongoDB

:: Uninstall the service
C:\mongodb-2.2.0\bin\mongod.exe --remove

Wanna test out your installation? Just call the MongoDB Javascript shell:


C:\mongodb-2.2.0\bin\mongo.exe

and if no error message appears – have fun!