~hglkrijger/cloud-init/pep8-fixes

« back to all changes in this revision

Viewing changes to cloudinit/sources/DataSourceNoCloud.py

  • Committer: Scott Moser
  • Date: 2016-06-16 03:20:22 UTC
  • mfrom: (1234.1.5 trunk.1592505)
  • Revision ID: smoser@ubuntu.com-20160616032022-379n7u2a60y118zc
DataSourceNoCloud: fix stack trace on reboot, default to dsmode=net

On reboot (loading module from obj.pkl) we would hit a AttributeError
when trying to access cmdline_id.
Addtionally, dsmode was inadvertantly defaulting to local for
DataSourceNoCloud.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import os
25
25
 
26
26
from cloudinit import log as logging
27
 
from cloudinit import net
 
27
from cloudinit.net import eni
28
28
from cloudinit import sources
29
29
from cloudinit import util
30
30
 
34
34
class DataSourceNoCloud(sources.DataSource):
35
35
    def __init__(self, sys_cfg, distro, paths):
36
36
        sources.DataSource.__init__(self, sys_cfg, distro, paths)
37
 
        self.dsmode = 'local'
38
37
        self.seed = None
39
38
        self.seed_dirs = [os.path.join(paths.seed_dir, 'nocloud'),
40
39
                          os.path.join(paths.seed_dir, 'nocloud-net')]
194
193
        # LP: #1568150 need getattr in the case that an old class object
195
194
        # has been loaded from a pickled file and now executing new source.
196
195
        dirs = getattr(self, 'seed_dirs', [self.seed_dir])
197
 
        quick_id = _quick_read_instance_id(cmdline_id=self.cmdline_id,
198
 
                                           dirs=dirs)
 
196
        quick_id = _quick_read_instance_id(dirs=dirs)
199
197
        if not quick_id:
200
198
            return None
201
199
        return quick_id == current
203
201
    @property
204
202
    def network_config(self):
205
203
        if self._network_config is None:
206
 
            if self.network_eni is not None:
207
 
                self._network_config = net.convert_eni_data(self.network_eni)
 
204
            if self._network_eni is not None:
 
205
                self._network_config = eni.convert_eni_data(self._network_eni)
208
206
        return self._network_config
209
207
 
210
208
 
211
 
def _quick_read_instance_id(cmdline_id, dirs=None):
 
209
def _quick_read_instance_id(dirs=None):
212
210
    if dirs is None:
213
211
        dirs = []
214
212
 
215
213
    iid_key = 'instance-id'
216
 
    if cmdline_id is None:
217
 
        fill = {}
218
 
        if parse_cmdline_data(cmdline_id, fill) and iid_key in fill:
219
 
            return fill[iid_key]
 
214
    fill = {}
 
215
    if load_cmdline_data(fill) and iid_key in fill:
 
216
        return fill[iid_key]
220
217
 
221
218
    for d in dirs:
222
219
        if d is None: