~oddbloke/cloud-init/fix-gce-az

« back to all changes in this revision

Viewing changes to cloudinit/distros/__init__.py

  • Committer: Daniel Watkins
  • Date: 2015-07-22 12:06:34 UTC
  • Revision ID: daniel.watkins@canonical.com-20150722120634-wsg8rwzcaanhc2pn
Make full data source available to code that handles mirror selection.

Show diffs side-by-side

added added

removed removed

Lines of Context:
117
117
            arch = self.get_primary_arch()
118
118
        return _get_arch_package_mirror_info(mirror_info, arch)
119
119
 
120
 
    def get_package_mirror_info(self, arch=None,
121
 
                                availability_zone=None):
 
120
    def get_package_mirror_info(self, arch=None, data_source=None):
122
121
        # This resolves the package_mirrors config option
123
122
        # down to a single dict of {mirror_name: mirror_url}
124
123
        arch_info = self._get_arch_package_mirror_info(arch)
125
 
        return _get_package_mirror_info(availability_zone=availability_zone,
 
124
        return _get_package_mirror_info(data_source=data_source,
126
125
                                        mirror_info=arch_info)
127
126
 
128
127
    def apply_network(self, settings, bring_up=True):
556
555
                LOG.info("Added user '%s' to group '%s'" % (member, name))
557
556
 
558
557
 
559
 
def _get_package_mirror_info(mirror_info, availability_zone=None,
 
558
def _get_package_mirror_info(mirror_info, data_source=None,
560
559
                             mirror_filter=util.search_for_mirror):
561
560
    # given a arch specific 'mirror_info' entry (from package_mirrors)
562
561
    # search through the 'search' entries, and fallback appropriately
572
571
    ec2_az_re = ("^[a-z][a-z]-(%s)-[1-9][0-9]*[a-z]$" % directions_re)
573
572
 
574
573
    subst = {}
575
 
    if availability_zone:
576
 
        subst['availability_zone'] = availability_zone
 
574
    if data_source and data_source.availability_zone:
 
575
        subst['availability_zone'] = data_source.availability_zone
577
576
 
578
 
    if availability_zone and re.match(ec2_az_re, availability_zone):
579
 
        subst['ec2_region'] = "%s" % availability_zone[0:-1]
 
577
        if re.match(ec2_az_re, data_source.availability_zone):
 
578
            subst['ec2_region'] = "%s" % data_source.availability_zone[0:-1]
580
579
 
581
580
    results = {}
582
581
    for (name, mirror) in mirror_info.get('failsafe', {}).items():