summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorDaniel Watkins <daniel.watkins@canonical.com>2015-07-22 13:06:34 +0100
committerDaniel Watkins <daniel.watkins@canonical.com>2015-07-22 13:06:34 +0100
commitbc7d57a0ae827978c87919c833bb5e8d2d5143c6 (patch)
tree4a3e97d4f0760f00682b9e84888c4b3f001c3777 /cloudinit
parent73c5bbfa31b922a0ba403216c0fc1f63b22a9262 (diff)
downloadvyos-cloud-init-bc7d57a0ae827978c87919c833bb5e8d2d5143c6.tar.gz
vyos-cloud-init-bc7d57a0ae827978c87919c833bb5e8d2d5143c6.zip
Add DataSource.region and use it in mirror selection.
Also implement DataSource.region for EC2 and GCE data sources.
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/distros/__init__.py3
-rw-r--r--cloudinit/sources/DataSourceEc2.py7
-rw-r--r--cloudinit/sources/DataSourceGCE.py4
-rw-r--r--cloudinit/sources/__init__.py4
4 files changed, 18 insertions, 0 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index 47b76c68..71884b32 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -577,6 +577,9 @@ def _get_package_mirror_info(mirror_info, data_source=None,
if re.match(ec2_az_re, data_source.availability_zone):
subst['ec2_region'] = "%s" % data_source.availability_zone[0:-1]
+ if data_source and data_source.region:
+ subst['region'] = data_source.region
+
results = {}
for (name, mirror) in mirror_info.get('failsafe', {}).items():
results[name] = mirror
diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py
index 798869b7..0032d06c 100644
--- a/cloudinit/sources/DataSourceEc2.py
+++ b/cloudinit/sources/DataSourceEc2.py
@@ -197,6 +197,13 @@ class DataSourceEc2(sources.DataSource):
except KeyError:
return None
+ @property
+ def region(self):
+ az = self.availability_zone
+ if az is not None:
+ return az[:-1]
+ return None
+
# Used to match classes to dependencies
datasources = [
(DataSourceEc2, (sources.DEP_FILESYSTEM, sources.DEP_NETWORK)),
diff --git a/cloudinit/sources/DataSourceGCE.py b/cloudinit/sources/DataSourceGCE.py
index 1b28a68c..7e7fc033 100644
--- a/cloudinit/sources/DataSourceGCE.py
+++ b/cloudinit/sources/DataSourceGCE.py
@@ -152,6 +152,10 @@ class DataSourceGCE(sources.DataSource):
def availability_zone(self):
return self.metadata['availability-zone']
+ @property
+ def region(self):
+ return self.availability_zone.rsplit('-', 1)[0]
+
# Used to match classes to dependencies
datasources = [
(DataSourceGCE, (sources.DEP_FILESYSTEM, sources.DEP_NETWORK)),
diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py
index 1a036638..a21c08c2 100644
--- a/cloudinit/sources/__init__.py
+++ b/cloudinit/sources/__init__.py
@@ -157,6 +157,10 @@ class DataSource(object):
return self.metadata.get('availability-zone',
self.metadata.get('availability_zone'))
+ @property
+ def region(self):
+ return self.metadata.get('region')
+
def get_instance_id(self):
if not self.metadata or 'instance-id' not in self.metadata:
# Return a magic not really instance id string