~harlowja/cloud-init/cloud-init-tag-distros

« back to all changes in this revision

Viewing changes to cloudinit/helpers.py

improve network configuration

This branch accomplishes several things:
 - centrally handle 'dsmode' to be 'local' or 'net.
   This allows local data sources to run before networking
   but still have user-data read by default when networking is available.

 - support networking information being read on dreamcompute
   dreamcompute's openstack declares networking via the
   /etc/network/interfaces style 'network_config' format.
 
 - support reading and applying networking information on SmartOS

 - improve reading networking from openstack network_data.json (LP: #1577982)
   add support for mtu and routes and many miscellaneous fixes.

 - support for renaming devices in a container (LP: #1579130).
   Also rename network devices as instructed by the host on
   every boot where cloud-init networking is enabled.  This is required
   because a.) containers do not get systemd.link files applied
   as they do not have udev. b.) if the initramfs is out of date
   then we need to apply them.

 - remove blocking of udev rules (LP: #1577844, LP: #1571761)

Show diffs side-by-side

added added

removed removed

Lines of Context:
328
328
        self.cfgs = path_cfgs
329
329
        # Populate all the initial paths
330
330
        self.cloud_dir = path_cfgs.get('cloud_dir', '/var/lib/cloud')
 
331
        self.run_dir = path_cfgs.get('run_dir', '/run/cloud-init')
331
332
        self.instance_link = os.path.join(self.cloud_dir, 'instance')
332
333
        self.boot_finished = os.path.join(self.instance_link, "boot-finished")
333
334
        self.upstart_conf_d = path_cfgs.get('upstart_dir')
349
350
            "data": "data",
350
351
            "vendordata_raw": "vendor-data.txt",
351
352
            "vendordata": "vendor-data.txt.i",
 
353
            "instance_id": ".instance-id",
352
354
        }
353
355
        # Set when a datasource becomes active
354
356
        self.datasource = ds
355
357
 
356
358
    # get_ipath_cur: get the current instance path for an item
357
359
    def get_ipath_cur(self, name=None):
358
 
        ipath = self.instance_link
359
 
        add_on = self.lookups.get(name)
360
 
        if add_on:
361
 
            ipath = os.path.join(ipath, add_on)
362
 
        return ipath
 
360
        return self._get_path(self.instance_link, name)
363
361
 
364
362
    # get_cpath : get the "clouddir" (/var/lib/cloud/<name>)
365
363
    # for a name in dirmap
366
364
    def get_cpath(self, name=None):
367
 
        cpath = self.cloud_dir
368
 
        add_on = self.lookups.get(name)
369
 
        if add_on:
370
 
            cpath = os.path.join(cpath, add_on)
371
 
        return cpath
 
365
        return self._get_path(self.cloud_dir, name)
372
366
 
373
367
    # _get_ipath : get the instance path for a name in pathmap
374
368
    # (/var/lib/cloud/instances/<instance>/<name>)
397
391
        else:
398
392
            return ipath
399
393
 
 
394
    def _get_path(self, base, name=None):
 
395
        if name is None:
 
396
            return base
 
397
        return os.path.join(base, self.lookups[name])
 
398
 
 
399
    def get_runpath(self, name=None):
 
400
        return self._get_path(self.run_dir, name)
 
401
 
400
402
 
401
403
# This config parser will not throw when sections don't exist
402
404
# and you are setting values on those sections which is useful