diff options
author | Scott Moser <smoser@ubuntu.com> | 2012-01-17 14:41:29 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2012-01-17 14:41:29 -0500 |
commit | 15e3241ba725a21604e0f3570e755a91b5edba00 (patch) | |
tree | d84be61c3a56ddc03eb927d5de5433afacadf64b /cloudinit/DataSourceEc2.py | |
parent | 2f7227c7092ad873757167f62c2a82fb4ee69472 (diff) | |
download | vyos-cloud-init-15e3241ba725a21604e0f3570e755a91b5edba00.tar.gz vyos-cloud-init-15e3241ba725a21604e0f3570e755a91b5edba00.zip |
[PATCH] PEP8 coding style fixes.
From: Juerg Haefliger <juerg.haefliger@hp.com>
This pulls in the named patch for LP: #914739 with a few other changes.
Diffstat (limited to 'cloudinit/DataSourceEc2.py')
-rw-r--r-- | cloudinit/DataSourceEc2.py | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/cloudinit/DataSourceEc2.py b/cloudinit/DataSourceEc2.py index 14484bdd..37dfcb5d 100644 --- a/cloudinit/DataSourceEc2.py +++ b/cloudinit/DataSourceEc2.py @@ -16,9 +16,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -import DataSource +import cloudinit.DataSource as DataSource -from cloudinit import seeddir, log # pylint: disable=W0611 +from cloudinit import seeddir as base_seeddir +from cloudinit import log import cloudinit.util as util import socket import urllib2 @@ -26,22 +27,23 @@ import time import boto.utils as boto_utils import os.path + class DataSourceEc2(DataSource.DataSource): - api_ver = '2009-04-04' - seeddir = seeddir + '/ec2' + api_ver = '2009-04-04' + seeddir = base_seeddir + '/ec2' metadata_address = "http://169.254.169.254" def __str__(self): return("DataSourceEc2") def get_data(self): - seedret = { } - if util.read_optional_seed(seedret, base=self.seeddir+"/"): + seedret = {} + if util.read_optional_seed(seedret, base=self.seeddir + "/"): self.userdata_raw = seedret['user-data'] self.metadata = seedret['meta-data'] log.debug("using seeded ec2 data in %s" % self.seeddir) return True - + try: if not self.wait_for_metadata_service(): return False @@ -66,7 +68,7 @@ class DataSourceEc2(DataSource.DataSource): def get_local_mirror(self): return(self.get_mirror_from_availability_zone()) - def get_mirror_from_availability_zone(self, availability_zone = None): + def get_mirror_from_availability_zone(self, availability_zone=None): # availability is like 'us-west-1b' or 'eu-west-1a' if availability_zone == None: availability_zone = self.get_availability_zone() @@ -87,7 +89,7 @@ class DataSourceEc2(DataSource.DataSource): mcfg = self.ds_cfg if not hasattr(mcfg, "get"): - mcfg = {} + mcfg = {} max_wait = 120 try: @@ -122,8 +124,8 @@ class DataSourceEc2(DataSource.DataSource): log.warn("Empty metadata url list! using default list") mdurls = def_mdurls - urls = [ ] - url2base = { False: False } + urls = [] + url2base = {False: False} for url in mdurls: cur = "%s/%s/meta-data/instance-id" % (url, self.api_ver) urls.append(cur) @@ -137,7 +139,7 @@ class DataSourceEc2(DataSource.DataSource): log.debug("Using metadata source: '%s'" % url2base[url]) else: log.critical("giving up on md after %i seconds\n" % - int(time.time()-starttime)) + int(time.time() - starttime)) self.metadata_address = url2base[url] return (bool(url)) @@ -146,7 +148,7 @@ class DataSourceEc2(DataSource.DataSource): # consult metadata service, that has # ephemeral0: sdb # and return 'sdb' for input 'ephemeral0' - if not self.metadata.has_key('block-device-mapping'): + if 'block-device-mapping' not in self.metadata: return(None) found = None @@ -166,10 +168,10 @@ class DataSourceEc2(DataSource.DataSource): # when the kernel named them 'vda' or 'xvda' # we want to return the correct value for what will actually # exist in this instance - mappings = { "sd": ("vd", "xvd") } + mappings = {"sd": ("vd", "xvd")} ofound = found short = os.path.basename(found) - + if not found.startswith("/"): found = "/dev/%s" % found @@ -213,7 +215,7 @@ def wait_for_metadata_service(urls, max_wait=None, timeout=None, be tried once and given the timeout provided. timeout: the timeout provided to urllib2.urlopen status_cb: call method with string message when a url is not available - + the idea of this routine is to wait for the EC2 metdata service to come up. On both Eucalyptus and EC2 we have seen the case where the instance hit the MD before the MD service was up. EC2 seems @@ -233,16 +235,19 @@ def wait_for_metadata_service(urls, max_wait=None, timeout=None, sleeptime = 1 + def nullstatus_cb(msg): + return + if status_cb == None: - def status_cb(msg): return + status_cb = nullstatus_cb def timeup(max_wait, starttime): return((max_wait <= 0 or max_wait == None) or - (time.time()-starttime > max_wait)) + (time.time() - starttime > max_wait)) loop_n = 0 while True: - sleeptime = int(loop_n/5)+1 + sleeptime = int(loop_n / 5) + 1 for url in urls: now = time.time() if loop_n != 0: @@ -270,7 +275,8 @@ def wait_for_metadata_service(urls, max_wait=None, timeout=None, if log: status_cb("'%s' failed [%s/%ss]: %s" % - (url, int(time.time()-starttime), max_wait, reason)) + (url, int(time.time() - starttime), max_wait, + reason)) if timeup(max_wait, starttime): break @@ -281,10 +287,11 @@ def wait_for_metadata_service(urls, max_wait=None, timeout=None, return False -datasources = [ - ( DataSourceEc2, ( DataSource.DEP_FILESYSTEM , DataSource.DEP_NETWORK ) ), +datasources = [ + (DataSourceEc2, (DataSource.DEP_FILESYSTEM, DataSource.DEP_NETWORK)), ] + # return a list of data sources that match this set of dependencies def get_datasource_list(depends): return(DataSource.list_from_depends(depends, datasources)) |