Skip to content

Commit 14a411f

Browse files
committed
Support configuration file
envvar based configuration will be dropped
1 parent b92b4b7 commit 14a411f

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

easy_deploy.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22
import argparse
3+
import ConfigParser
34
import getpass
45
from jinja2 import Template
56
import json
@@ -196,6 +197,27 @@ def parseArgs():
196197
return args
197198

198199

200+
def loadConfig():
201+
global mac_dict
202+
conf_file = os.path.join(os.environ.get('HOME'), '.easydeployrc')
203+
conf = ConfigParser.SafeConfigParser()
204+
conf.read(conf_file)
205+
if conf.has_section('mac'):
206+
mac_dict.update(dict(conf.items('mac')))
207+
if conf.has_section('alias'):
208+
alias_dict = dict(conf.items('alias'))
209+
for alias, name in alias_dict.items():
210+
if name in mac_dict:
211+
mac_dict[alias] = mac_dict[name]
212+
else:
213+
print ('Alias "%(alias)s" has no corresponding '
214+
'entry "%(name)s"') % locals()
215+
if conf.has_section('default'):
216+
if conf.has_option('default', 'public_bridge'):
217+
global PUBLIC_BRIDGE
218+
PUBLIC_BRIDGE = conf.get('default', 'public_bridge')
219+
220+
199221
def loadMacAddress():
200222
global mac_dict
201223
if os.path.exists(PUBLIC_MAC_FILE):
@@ -230,12 +252,12 @@ def randomMAC():
230252

231253
def getMacAddress(network, name):
232254
global mac_dict
233-
if (network == PUBLIC_BRIDGE and
234-
os.path.exists(PUBLIC_MAC_FILE) and name in mac_dict):
255+
if (network == PUBLIC_BRIDGE and name in mac_dict):
235256
mac = mac_dict[name]
236257
print 'Use %s for nic connected to %s' % (mac, network)
237258
else:
238259
mac = randomMAC()
260+
print 'Generate random MAC address %s for network %s' % (mac, network)
239261
return mac
240262

241263

@@ -293,6 +315,7 @@ def deleteLibvirtXML(libvirt_xml):
293315

294316

295317
def main():
318+
loadConfig()
296319
args = parseArgs()
297320

298321
#checkUser()

sample.easydeployrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[default]
2+
public_bridge = br0
3+
4+
[mac]
5+
dev01 = 52:54:00:1f:c6:57
6+
dev02 = 52:54:00:ee:7b:07
7+
dev03 = 52:54:00:f2:57:0e
8+
9+
[alias]
10+
cacheserver = dev02
11+
testserver = dev03

0 commit comments

Comments
 (0)