summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/sources/DataSourceEc2.py20
-rw-r--r--cloudinit/stages.py20
-rw-r--r--cloudinit/util.py14
3 files changed, 35 insertions, 19 deletions
diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py
index cb460de1..cde73de3 100644
--- a/cloudinit/sources/DataSourceEc2.py
+++ b/cloudinit/sources/DataSourceEc2.py
@@ -87,6 +87,7 @@ class DataSourceEc2(sources.DataSource):
return self.get_mirror_from_availability_zone()
def get_mirror_from_availability_zone(self, availability_zone=None):
+ # Return type None indicates there is no cloud specific mirror
# Availability is like 'us-west-1b' or 'eu-west-1a'
if availability_zone is None:
availability_zone = self.get_availability_zone()
@@ -94,26 +95,27 @@ class DataSourceEc2(sources.DataSource):
if self.is_vpc():
return None
- # Use the distro to get the mirror
if not availability_zone:
return None
- mirror_tpl = self.distro.get_option('availability_zone_template')
- if not mirror_tpl:
+ mirror_tpl = self.distro.get_option('package_mirror_ec2_template',
+ None)
+
+ if mirror_tpl is None:
return None
+ # in EC2, the 'region' is 'us-east-1' if 'zone' is 'us-east-1a'
tpl_params = {
'zone': availability_zone.strip(),
+ 'region': availability_zone[:-1]
}
mirror_url = mirror_tpl % (tpl_params)
- (max_wait, timeout) = self._get_url_settings()
- worked = uhelp.wait_for_url([mirror_url], max_wait=max_wait,
- timeout=timeout, status_cb=LOG.warn)
- if not worked:
- return None
+ found = util.search_for_mirror([mirror_url])
+ if found is not None:
+ return mirror_url
- return mirror_url
+ return None
def _get_url_settings(self):
mcfg = self.ds_cfg
diff --git a/cloudinit/stages.py b/cloudinit/stages.py
index 8fd6aa5d..3beeb36e 100644
--- a/cloudinit/stages.py
+++ b/cloudinit/stages.py
@@ -133,12 +133,24 @@ class Init(object):
if log_file:
util.ensure_file(log_file)
if perms:
- (u, g) = perms.split(':', 1)
- if u == "-1" or u == "None":
+ perms_parted = perms.split(':', 1)
+ u = perms_parted[0]
+ if len(perms_parted) == 2:
+ g = perms_parted[1]
+ else:
+ g = ''
+ u = u.strip()
+ g = g.strip()
+ if u == "-1" or u.lower() == "none":
u = None
- if g == "-1" or g == "None":
+ if g == "-1" or g.lower() == "none":
g = None
- util.chownbyname(log_file, u, g)
+ try:
+ util.chownbyname(log_file, u, g)
+ except OSError:
+ util.logexc(LOG, ("Unable to change the ownership"
+ " of %s to user %s, group %s"),
+ log_file, u, g)
def read_cfg(self, extra_fns=None):
# None check so that we don't keep on re-loading if empty
diff --git a/cloudinit/util.py b/cloudinit/util.py
index d7dd20b5..e591e306 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -19,6 +19,8 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# pylint: disable=C0302
from StringIO import StringIO
@@ -805,7 +807,10 @@ def is_resolvable_url(url):
def search_for_mirror(candidates):
- """ Search through a list of mirror urls for one that works """
+ """
+ Search through a list of mirror urls for one that works
+ This needs to return quickly.
+ """
for cand in candidates:
try:
if is_resolvable_url(cand):
@@ -932,12 +937,9 @@ def chownbyname(fname, user=None, group=None):
uid = pwd.getpwnam(user).pw_uid
if group:
gid = grp.getgrnam(group).gr_gid
- except KeyError:
- logexc(LOG, ("Failed changing the ownership of %s using username %s and"
- " groupname %s (do they exist?)"), fname, user, group)
- return False
+ except KeyError as e:
+ raise OSError("Unknown user or group: %s" % (e))
chownbyid(fname, uid, gid)
- return True
# Always returns well formated values