Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Friday, August 12, 2016

GUI for Zookeeper

I created tool in python 2.7. It is self hosted web application and it allows you to view, add and delete node, and you can modify node data.
Tool and instruction how to install it can be found at
github.com/mijalko/zookeeper_browser

Wednesday, February 12, 2014

Tuesday, September 04, 2012

Python script for deleting VM using Nova API

This is sample python script that delete virtual machines, keys and security groups where security group has a same name as keypair



import os, sys, time
from pprint import pprint
from novaclient.v1_1 import client

nt = client.Client("username", "pwd", "test", "http://192.168.0.155:1111/v1.1/", service_type="compute")
a = nt.servers.list()
for s in a:
        print s.name + " | "  + s.key_name  + " | " + str(s.addresses)
        varDelete = raw_input("Delete machine, keys and groups (y/n): ")
        if varDelete == "y":

                print "deleting"
                print
                print "checking if there is an IP for release"

                for nets in s.addresses:
                        pprint (s.addresses[nets])
                        for a in s.addresses[nets]:
                                address = str(a["addr"])
                                print "checking address " + address
                                existInFloating=[checked for checked in nt.floating_ips.list() if checked.ip == address]
                                if len(existInFloating) > 0:
                                        print "exist"
                                        s.remove_floating_ip(address)
                                        existInFloating[0].delete()
                                        print "ip address released"
                                else:
                                        print "not exist"

                nt.servers.delete(s)

                keyname = s.key_name
                if keyname != "":
                        print "deleting keyname and group: " + keyname
                        selectedKeyPairs = [k for k in nt.keypairs.list() if k.name == keyname]
                        if len(selectedKeyPairs) > 0:
                                selectedKeyPairs[0].delete()

                        selectedGroups = [k for k in nt.security_groups.list() if k.name == keyname]
                        if len(selectedGroups) > 0:
                                time.sleep(5)
                                selectedGroups[0].delete()

                print "deleted"
        else:
                print "skipping"



Print all object attributes in python

In case of lack of documentation for some API you may need, for example, list of attributes for some object. You can do that using:


from pprint import pprint
pprint (vars(myobject))


or...



pprint (dir(obj))


or....


import inspect
inspect.getmembers(obj, predicate=inspect.ismethod)