~smoser/cloud-init/trunk.new-ds

« back to all changes in this revision

Viewing changes to cloudinit/stages.py

  • Committer: Scott Moser
  • Date: 2015-02-11 01:53:20 UTC
  • mfrom: (1052.1.45 py2-3.smoser)
  • Revision ID: smoser@ubuntu.com-20150211015320-049dv6n1mk2in7l1
python3 support.

This gives us functional python3 support.  There are likely
still bugs, but instance boot on openstack is functional now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#    You should have received a copy of the GNU General Public License
21
21
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
22
 
23
 
import cPickle as pickle
24
 
 
25
23
import copy
26
24
import os
27
25
import sys
28
26
 
 
27
import six
 
28
from six.moves import cPickle as pickle
 
29
 
29
30
from cloudinit.settings import (PER_INSTANCE, FREQUENCIES, CLOUD_CONFIG)
30
31
 
31
32
from cloudinit import handlers
202
203
            util.logexc(LOG, "Failed pickling datasource %s", self.datasource)
203
204
            return False
204
205
        try:
205
 
            util.write_file(pickled_fn, pk_contents, mode=0400)
 
206
            util.write_file(pickled_fn, pk_contents, mode=0o400)
206
207
        except Exception:
207
208
            util.logexc(LOG, "Failed pickling datasource to %s", pickled_fn)
208
209
            return False
324
325
 
325
326
    def _store_userdata(self):
326
327
        raw_ud = "%s" % (self.datasource.get_userdata_raw())
327
 
        util.write_file(self._get_ipath('userdata_raw'), raw_ud, 0600)
 
328
        util.write_file(self._get_ipath('userdata_raw'), raw_ud, 0o600)
328
329
        processed_ud = "%s" % (self.datasource.get_userdata())
329
 
        util.write_file(self._get_ipath('userdata'), processed_ud, 0600)
 
330
        util.write_file(self._get_ipath('userdata'), processed_ud, 0o600)
330
331
 
331
332
    def _store_vendordata(self):
332
333
        raw_vd = "%s" % (self.datasource.get_vendordata_raw())
333
 
        util.write_file(self._get_ipath('vendordata_raw'), raw_vd, 0600)
 
334
        util.write_file(self._get_ipath('vendordata_raw'), raw_vd, 0o600)
334
335
        processed_vd = "%s" % (self.datasource.get_vendordata())
335
 
        util.write_file(self._get_ipath('vendordata'), processed_vd, 0600)
 
336
        util.write_file(self._get_ipath('vendordata'), processed_vd, 0o600)
336
337
 
337
338
    def _default_handlers(self, opts=None):
338
339
        if opts is None:
384
385
            if not path or not os.path.isdir(path):
385
386
                return
386
387
            potential_handlers = util.find_modules(path)
387
 
            for (fname, mod_name) in potential_handlers.iteritems():
 
388
            for (fname, mod_name) in potential_handlers.items():
388
389
                try:
389
390
                    mod_locs, looked_locs = importer.find_module(
390
391
                        mod_name, [''], ['list_types', 'handle_part'])
422
423
 
423
424
        def init_handlers():
424
425
            # Init the handlers first
425
 
            for (_ctype, mod) in c_handlers.iteritems():
 
426
            for (_ctype, mod) in c_handlers.items():
426
427
                if mod in c_handlers.initialized:
427
428
                    # Avoid initing the same module twice (if said module
428
429
                    # is registered to more than one content-type).
449
450
 
450
451
        def finalize_handlers():
451
452
            # Give callbacks opportunity to finalize
452
 
            for (_ctype, mod) in c_handlers.iteritems():
 
453
            for (_ctype, mod) in c_handlers.items():
453
454
                if mod not in c_handlers.initialized:
454
455
                    # Said module was never inited in the first place, so lets
455
456
                    # not attempt to finalize those that never got called.
574
575
        for item in cfg_mods:
575
576
            if not item:
576
577
                continue
577
 
            if isinstance(item, (str, basestring)):
 
578
            if isinstance(item, six.string_types):
578
579
                module_list.append({
579
580
                    'mod': item.strip(),
580
581
                })