~harlowja/cloud-init/cloud-init-fix-configobj-bound

« back to all changes in this revision

Viewing changes to cloudinit/net/cmdline.py

  • Committer: Joshua Harlow
  • Date: 2016-05-11 21:18:02 UTC
  • mto: (1218.2.1 cloud-init)
  • mto: This revision was merged to the branch mainline in revision 1232.
  • Revision ID: harlowja@gmail.com-20160511211802-84sdqyim4z2dem4f
Fix py26 for rhel (and older versions of python)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import glob
21
21
import gzip
22
22
import io
23
 
import shlex
24
23
 
25
24
from cloudinit.net import get_devicelist
26
25
from cloudinit.net import sys_netdev_info
34
33
       then add entries in to the returned dictionary for 'VAR='
35
34
       variables.  Set their value to empty_val."""
36
35
    data = {}
37
 
    for line in shlex.split(content):
38
 
        key, value = line.split("=", 1)
39
 
        if not value:
40
 
            value = empty_val
41
 
        if add_empty or value:
42
 
            data[key] = value
43
 
 
 
36
    for line in util.shlex_split(content):
 
37
        try:
 
38
            key, value = line.split("=", 1)
 
39
        except ValueError:
 
40
            # Unsplittable line, skip it...
 
41
            pass
 
42
        else:
 
43
            if not value:
 
44
                value = empty_val
 
45
            if add_empty or value:
 
46
                data[key] = value
44
47
    return data
45
48
 
46
49
 
60
63
    if mac_addrs is None:
61
64
        mac_addrs = {}
62
65
 
 
66
    print("Reading content")
 
67
    print(content)
 
68
 
63
69
    data = _load_shell_content(content)
64
70
    try:
65
71
        name = data['DEVICE']
185
191
        return None
186
192
 
187
193
    if mac_addrs is None:
188
 
        mac_addrs = {k: sys_netdev_info(k, 'address')
189
 
                     for k in get_devicelist()}
 
194
        mac_addrs = dict((k, sys_netdev_info(k, 'address'))
 
195
                         for k in get_devicelist())
190
196
 
191
197
    return config_from_klibc_net_cfg(files=files, mac_addrs=mac_addrs)