Last active
May 19, 2019 11:42
-
-
Save iKalin/360f8a7eb941a1b43e0f8f77758b4905 to your computer and use it in GitHub Desktop.
This file contains 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
import urllib | |
# read in redis configuration file to parse ip addresses and ports | |
def readIn(confFile): | |
slotsPortArray = [] | |
portRegex = re.compile("(?<=:)[0-9]*") # regex to match port in file | |
slotsRegex = re.compile("[0-9]+-[0-9]+") # regex to match hash-slot in file | |
addr = getIp() # ip address of machine | |
for line in confFile: | |
portMatch = re.search(portRegex, line) # match port to find dump file | |
slotsMatch = re.search(slotsRegex, line) # match hash-slots, only masters have hash-slots declared in conf file | |
if portMatch and slotsMatch: # if we detect ports and ip addresses in the | |
if addr in line: # if we find the ip address of the machine we provided | |
print('Found:',addr, portMatch.group(), slotsMatch.group()) | |
slotsPortArray.append({'HashSlot': slotsMatch.group(), 'Port': portMatch.group() }) # create an array of dicts that have hash slot and port | |
return slotsPortArray | |
def getIp(): | |
request = urllib.request.urlopen('http://111.111.111.254/latest/meta-data/local-ipv4' ) | |
machineIp = request.read().decode('utf-8') | |
return machineIp | |
def example() | |
with open('nodes_6379.conf', 'r') as file: | |
params = readIn(file) | |
# now do things with params according to spec; Eg. upload to s3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment