Friday, July 22, 2011

Aeolus todo

RHEL is to Fedora as CloudForms is to Aeolus. So rather than wait to be approved for the CloudForms beta we're looking into trying Aeolus now.

Wednesday, July 13, 2011

Pwn Plug Wireless

A friend shared this link to a commercial-grade wireless pentesting drop box with me.

Tuesday, July 12, 2011

python configparser

I'm writing a Python program and as it grows I realize that it would be best to have certain variables in a configuration file. Python ConfigParser to the rescue! It's nice that this is a built-in. I just followed the examples and I was up and running quickly.

Sunday, July 10, 2011

php:include "bar.php" 2 python:?

PHP programmers are used to having code in one file they can use in another file simply by calling include. Python's module system supports more than just including files, but if you want to just include a file the following code provides an example:

> ls 
foo.py mod/
> ls mod/
bar.py
> 
> cat mod/bar.py 
def f():
    print("I am bar")
> 
> cat foo.py 
print("I am foo")
import sys
sys.path.append("mod/")
import bar
bar.f()
> 
> python foo.py 
I am foo
I am bar
> 

Thursday, July 7, 2011

Simple python inheritance example

Python's Classes documentation has a bag class. Since I'm writing a program in which I want to do inheritance but haven't done it in a while and need a refresh, I thought I'd extend bag into a wet paper bag; which looses things you put in it nearly half the time. I came up with this:

class Bag(object):
    def __init__(self):
        self.data = []
    def add(self, x):
        self.data.append(x)
    def addtwice(self, x):
        self.add(x)
        self.add(x)

class WetPaper(Bag):
    def __init__(self):
        super(WetPaper, self).__init__()
    def add(self, x):
        from random import randint
        if (randint(1,10) > 4):
            super(WetPaper, self).add(x)

if __name__ == '__main__':
    bag = Bag()
    bag.addtwice(1)
    print "Bag:", bag.data
    wet = WetPaper()
    wet.addtwice(1)
    print "WetPaper:", wet.data
Since I'm extending Bag, defining the constructor was simplified and I didn't have to worry about how add() was implemented; I could just flip a coin with rand to see if the inherited add() should be called. I also didn't have to define addtwice() and it inherited the unreliable aspect of WetPaper's add().

When writing the above, the first thing I had to do was update the original Bag definition to a new style class descended from object. Until I did this I got a "TypeError: must be type, not classobj" error when I used super and I had to directly use the parent class name instead:

    def __init__(self):
        Bag.__init__(self)
While working on this I found Python's Super is nifty, but you can't use it. I also found out that in Python 3 self will become implicit in super calls so instead of:
  super(WetPaper, self).__init__()
I will just be able to do:
  super().__init__()

Cloud Computing Definition

I read an article in the FSF Bulletin about Merlin. It contained a good definition of Cloud Computing, which I think is worth posting since there is a lot of confusion about what Cloud Computing is.

"Cloud Computing is about (a) aggregating server, network, and storage resources into a seemingly contiguous system ("the cloud"), (b) providing some kind of interface for the user to request or release these resources, and (c) making these resources network or location agnostic, so that the resources are accessible from anywhere, even in the face of system or network failures." -- Justin Baugh

Monday, July 4, 2011

Python Logging

I read Doug Hellmann's blogpost on logging with Python.