retr0h

be open minded, and always continue to learn

Public IP Address Discovery With Chef and Ohai

I am currently automating the deployment and configuration of a moderately complex service architecture. Ohai, currently has no way to discover a systems public (floating) ip address in an OpenStack environment. The ability to discover this information helps with additional automation (eg. Provisioning dns in DynECT).

This Ohai plugin is a semi-poor attempt at discovering a guest’s public ipaddress.

Update: Fri Nov 11 2011

Looks like Ohai already attempts to capture this information from the meta-data server. However, this fails due to MAC address not matching. Updated the previously discussed plugin to capture the floating IP from the meta-data server. Also, have it following the same API as the eucalyptus plugin.

https://github.com/opscode/ohai/blob/master/lib/ohai/plugins/eucalyptus.rb

Usage is as follows:

Zkpython and Homebrew

Ran into the following error on OSX, when trying to pip install a Homebrew installed version of ZooKeeper’s zkpython.

zookeeper.c:20:23: error: zookeeper.h: No such file or directory

Was able to install by providing the ‘C_INCLUDE_PATH’ to pip.

Using Netcat to Open Ports

I find it useful to easily open a port, to test access controls. Configuring a webserver or iptables to redirect to a known running port is cumbersome. The following has proved useful many times.

$ echo "open port" |nc -l 8080

Verification can be done with telnet or netcat.

$ telnet example.com 8080
Trying example.com...
Connected to example.com.
Escape character is '^]'.
open port
Connection closed by foreign host.

$ nc example.com 8080
open port

Nokogiri RVM Homebrew

Having problems getting Nokogiri to compile on OSX with Homebrew?

Openstack Image Uploader

My co-worker and best pal Kevin wrote a script to upload images into OpenStack’s Glance. He recently released the script as the ogler rubygem. It is a straight forward script, built on the ogle library. Our friends at Opscode contacted Kevin, and are planning to distribute it in some fashion.

Uploading directly into Glance allows the setting of metadata, it also avoids the unnecessary steps behind ‘euca-bundle-image’ (object store upload -> unbundle -> Glance upload).

Usage

Install the rubygem:

$ gem install ogler

To upload a x86_64 Ubuntu 11.04 ami and 2.6.35 aki:

$ ogler -i <ami> -k <aki> -a x86_64 -e 2.6.35 -d ubuntu -v 11.04 -h <Glance endpoint>

Attaching additional metadata is as simple as appending key/value pairs:

-c foo=bar,baz=qux

Glance uses decimal ids. Nova converts them to standard ami ids you’re used to, when queried through the EC2 API. To view the metadata we query Glance for the image id:

$ curl -i -X HEAD localhost:9292/v1.0/images/4
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Content-Length: 0
X-Image-Meta-Property-Distro: Ubuntu
X-Image-Meta-Id: 4
X-Image-Meta-Property-Arch: amd64
X-Image-Meta-Deleted: False
X-Image-Meta-Container_format: ami
X-Image-Meta-Property-Uploader: root@enc1b11
X-Image-Meta-Location: file:///var/lib/glance/images/4
X-Image-Meta-Deleted_at: 
X-Image-Meta-Created_at: 2011-05-11T15:48:02
X-Image-Meta-Size: 1476395008
X-Image-Meta-Status: active
X-Image-Meta-Property-Type: machine
X-Image-Meta-Property-Kernel_name: natty-server-uec-amd64-vmlinuz-virtual
X-Image-Meta-Is_public: True
X-Image-Meta-Property-Kernel_id: 3
X-Image-Meta-Updated_at: 2011-05-11T15:48:08
X-Image-Meta-Checksum: b6149317c554d2c335365e7bd43e9bf0
X-Image-Meta-Property-Version: 11.04
X-Image-Meta-Disk_format: ami
X-Image-Meta-Name: ubuntu_11.04-amd64
Location: http://localhost:9292/v1/images/4
Etag: b6149317c554d2c335365e7bd43e9bf0
Date: Sun, 14 Aug 2011 17:57:48 GMT