|
1 | 1 | #!/usr/bin/env python
|
2 | 2 | import argparse
|
| 3 | +import ConfigParser |
3 | 4 | import getpass
|
4 | 5 | from jinja2 import Template
|
5 | 6 | import json
|
@@ -196,6 +197,27 @@ def parseArgs():
|
196 | 197 | return args
|
197 | 198 |
|
198 | 199 |
|
| 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 | + |
199 | 221 | def loadMacAddress():
|
200 | 222 | global mac_dict
|
201 | 223 | if os.path.exists(PUBLIC_MAC_FILE):
|
@@ -230,12 +252,12 @@ def randomMAC():
|
230 | 252 |
|
231 | 253 | def getMacAddress(network, name):
|
232 | 254 | 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): |
235 | 256 | mac = mac_dict[name]
|
236 | 257 | print 'Use %s for nic connected to %s' % (mac, network)
|
237 | 258 | else:
|
238 | 259 | mac = randomMAC()
|
| 260 | + print 'Generate random MAC address %s for network %s' % (mac, network) |
239 | 261 | return mac
|
240 | 262 |
|
241 | 263 |
|
@@ -293,6 +315,7 @@ def deleteLibvirtXML(libvirt_xml):
|
293 | 315 |
|
294 | 316 |
|
295 | 317 | def main():
|
| 318 | + loadConfig() |
296 | 319 | args = parseArgs()
|
297 | 320 |
|
298 | 321 | #checkUser()
|
|
0 commit comments