Skip to content

Instantly share code, notes, and snippets.

@hashimotor
Last active August 29, 2015 13:56
Show Gist options
  • Save hashimotor/8828689 to your computer and use it in GitHub Desktop.
Save hashimotor/8828689 to your computer and use it in GitHub Desktop.
Find IP addresses on Swift rings.
#!/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
require 'spec_helper'
describe command('verify_existence_ipaddr.py') do
it { should return_exit_status 0 }
end
#!/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