Skip to content

Commit 52a7c49

Browse files
authored
Merge pull request #55 from timvaillancourt/issue54_config_replset
Issue 54: Remove 'replset/' prefix from config server hostnames
2 parents 4c7acf0 + 85ab665 commit 52a7c49

File tree

6 files changed

+21
-4
lines changed

6 files changed

+21
-4
lines changed

MongoBackup/Backup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from time import time
1010

1111
from Archiver import Archiver
12-
from Common import DB, Lock
12+
from Common import DB, Lock, validate_hostname
1313
from Methods import Dumper
1414
from Notify import NotifyNSCA
1515
from Oplog import OplogTailer, OplogResolver
@@ -144,6 +144,7 @@ def __init__(self, options):
144144
#TODO should this be in init or a sub-function?
145145
# Get a DB connection
146146
try:
147+
validate_hostname(self.host)
147148
self.db = DB(self.host, self.port, self.user, self.password, self.authdb)
148149
self.connection = self.db.connection()
149150
self.is_sharded = self.connection.is_mongos

MongoBackup/Common/Util.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import socket
2+
3+
4+
def validate_hostname(hostname):
5+
try:
6+
if ":" in hostname:
7+
hostname, port = hostname.split(":")
8+
socket.gethostbyname(hostname)
9+
except socket.error, e:
10+
raise Exception, "Could not resolve host '%s', error: %s" % (hostname, e), None

MongoBackup/Common/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from DB import DB
22
from LocalCommand import LocalCommand
33
from Lock import Lock
4+
from Util import validate_hostname

MongoBackup/Replset.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from math import ceil
44

5-
from Common import DB
5+
from Common import DB, validate_hostname
66

77

88
class Replset:
@@ -66,6 +66,7 @@ def find_primary(self, force=False, quiet=False):
6666
'host': member['name'],
6767
'optime': optime_ts
6868
}
69+
validate_hostname(self.primary['host'])
6970
logging.info("Found PRIMARY: %s/%s with optime %s" % (
7071
rs_name,
7172
member['name'],
@@ -115,6 +116,7 @@ def find_secondary(self, force=False, quiet=False):
115116
'optime': optime_ts,
116117
'score': score
117118
}
119+
validate_hostname(self.secondary['host'])
118120
log_msg = "Found SECONDARY %s/%s" % (rs_name, member['name'])
119121
else:
120122
log_msg = "Found SECONDARY %s/%s with too-high replication lag! Skipping" % (rs_name, member['name'])

MongoBackup/Sharding.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from time import sleep
44

5-
from Common import DB
5+
from Common import DB, validate_hostname
66
from Replset import Replset
77

88

@@ -112,6 +112,8 @@ def get_configdb_hosts(self):
112112
if config_string:
113113
# noinspection PyBroadException
114114
try:
115+
if "/" in config_string:
116+
config_replset, config_string = config_string.split("/")
115117
return config_string.split(',')
116118
except Exception:
117119
return [config_string]
@@ -126,6 +128,7 @@ def get_config_server(self, force=False):
126128
configdb_hosts = self.get_configdb_hosts()
127129
try:
128130
config_host, config_port = configdb_hosts[0].split(":")
131+
validate_hostname(config_host)
129132
logging.info("Found sharding config server: %s:%s" % (config_host, config_port))
130133

131134
self.config_db = DB(config_host, config_port, self.user, self.password, self.authdb)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.1
1+
0.3.2

0 commit comments

Comments
 (0)