Last active
August 29, 2015 13:56
-
-
Save hashimotor/8828689 to your computer and use it in GitHub Desktop.
Find IP addresses on Swift rings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# assume swift library, python-pip, rubygems, rspec, rake and serverspec is installed. | |
# assume PATH contains /usr/local/bin | |
cp swift_ring_spec.rb /usr/local/bin | |
chmod +x /usr/local/bin/swift_ring_spec.rb | |
sudo pip install netifaces |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe command('verify_existence_ipaddr.py') do | |
it { should return_exit_status 0 } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
from netifaces import ifaddresses, interfaces | |
from swift.common.ring import Ring | |
def all_ipaddresses(): | |
""" Returns all IP addresses on this server """ | |
return [ifaddresses(x)[2][0]['addr'] for x in interfaces()] | |
def devices_on_node(): | |
""" Returns all devices on this server in the rings """ | |
ifaddrs = all_ipaddresses() | |
devs = [] | |
for i in ['account', 'container', 'object']: | |
ring = Ring('/etc/swift/%s.ring.gz' % i) | |
devs.append([dev for dev in ring.devs if dev['ip'] in ifaddrs]) | |
return devs | |
if __name__ == '__main__': | |
devs = devices_on_node() | |
if devs.__len__() > 0: exit(0) | |
else: exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment