Example #1
0
# examples/01-ringinfo.py
#
# show some base functions of the ringtools module.

import sys

try:
    from ringtools import ring
except ImportError:
    # ringtools probaly isn't installed yet
    sys.path.append("..")
    from ringtools import ring


# number of nodes in the ring
print "unique nodes: %d" % len(ring.get_ring_nodes())

# number of active nodes in the ring
print "active nodes: %d" % len(ring.get_ring_nodes(active_only=True))

# number of unique networks in the ring
print "unique networks: %d" % len(ring.get_ring_networks())

# number of unique countries in the ring
print "unique countries: %d" % len(ring.get_ring_countries())

# determine if a name is a node
print "bit01 is a ringnode: %s" % ring.is_ring_node("bit01")
print "bit02 is a ringnode: %s" % ring.is_ring_node("bit02")

# check legacy IPv4 support ;-)
Example #2
0
# examples/03-single-node.py
#
# run a command on a single ringnode. Verify if the SSH connection was ok
# and if so if the command excuted properly. Print the result if it did,
# print the stderr output if it didn't.

import sys

try:
    from ringtools import ring
    from ringtools.node import RingNode
except ImportError:
    # ringtools probaly isn't installed yet
    sys.path.append('..')
    from ringtools import ring
    from ringtools.node import RingNode

hosts = ring.get_ring_nodes()
result = ring.run_command('uptime', hosts)
print "succesful results:"
for res in result.get_successful_results().get_results():
    print "  %25s: %s" % (res.get_hostname(), '\n'.join(res.get_stdout()))
print "command failed:"
for res in result.get_failed_results(False).get_results():
    print "  %25s: %s" % (res.get_hostname(), '\n'.join(res.get_stderr()))

print "connection problems:"
for res in result.get_failed_results(True, True).get_results():
    print "  %25s: %s" % (res.get_hostname(), repr(res.get_ssh_errormsg()))