summaryrefslogtreecommitdiff
path: root/cloudinit/sources
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-06-15 21:33:55 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-06-15 21:33:55 -0700
commit450261a1fcf1f8929a2f7a25c2c278ba40689289 (patch)
tree83430d74ea63c5a11df3fb774e281d0f8efce8f3 /cloudinit/sources
parent784edb7689d60b81a4334d5171603841cc83da98 (diff)
downloadvyos-cloud-init-450261a1fcf1f8929a2f7a25c2c278ba40689289.tar.gz
vyos-cloud-init-450261a1fcf1f8929a2f7a25c2c278ba40689289.zip
Fixups to ensure that pylint does not find anything major wrong.
Diffstat (limited to 'cloudinit/sources')
-rw-r--r--cloudinit/sources/DataSourceCloudStack.py2
-rw-r--r--cloudinit/sources/DataSourceConfigDrive.py4
-rw-r--r--cloudinit/sources/DataSourceMAAS.py14
-rw-r--r--cloudinit/sources/DataSourceNoCloud.py3
-rw-r--r--cloudinit/sources/DataSourceOVF.py12
-rw-r--r--cloudinit/sources/__init__.py23
6 files changed, 32 insertions, 26 deletions
diff --git a/cloudinit/sources/DataSourceCloudStack.py b/cloudinit/sources/DataSourceCloudStack.py
index 791df68f..27217e65 100644
--- a/cloudinit/sources/DataSourceCloudStack.py
+++ b/cloudinit/sources/DataSourceCloudStack.py
@@ -79,7 +79,7 @@ class DataSourceCloudStack(sources.DataSource):
tot_time = (time.time() - start)
LOG.debug("Crawl of metadata service took %s", int(tot_time))
return True
- except Exception as e:
+ except Exception:
util.logexc(LOG, ('Failed fetching from metadata '
'service %s'), self.metadata_address)
return False
diff --git a/cloudinit/sources/DataSourceConfigDrive.py b/cloudinit/sources/DataSourceConfigDrive.py
index 176b62b0..7450572f 100644
--- a/cloudinit/sources/DataSourceConfigDrive.py
+++ b/cloudinit/sources/DataSourceConfigDrive.py
@@ -51,8 +51,8 @@ class DataSourceConfigDrive(sources.DataSource):
self.seed_dir = os.path.join(paths.seed_dir, 'config_drive')
def __str__(self):
- mstr = "%s[%s]" % (util.obj_name(self), self.dsmode)
- mstr += " [seed=%s]" % (self.seed)
+ mstr = "%s [%s]" % (util.obj_name(self), self.dsmode)
+ mstr += "[seed=%s]" % (self.seed)
return mstr
def get_data(self):
diff --git a/cloudinit/sources/DataSourceMAAS.py b/cloudinit/sources/DataSourceMAAS.py
index 27196265..9e639649 100644
--- a/cloudinit/sources/DataSourceMAAS.py
+++ b/cloudinit/sources/DataSourceMAAS.py
@@ -18,9 +18,9 @@
# 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 os
import errno
import oauth.oauth as oauth
+import os
import time
import urllib2
@@ -48,7 +48,7 @@ class DataSourceMAAS(sources.DataSource):
self.seed_dir = os.path.join(paths.seed_dir, 'maas')
def __str__(self):
- return "%s[%s]" % (util.obj_name(self), self.base_url)
+ return "%s [%s]" % (util.obj_name(self), self.base_url)
def get_data(self):
mcfg = self.ds_cfg
@@ -122,9 +122,10 @@ class DataSourceMAAS(sources.DataSource):
starttime = time.time()
check_url = "%s/%s/meta-data/instance-id" % (url, MD_VERSION)
- url = util.wait_for_url(urls=[check_url], max_wait=max_wait,
- timeout=timeout, status_cb=LOG.warn,
- headers_cb=self.md_headers)
+ urls = [check_url]
+ url = uhelp.wait_for_url(urls=urls, max_wait=max_wait,
+ timeout=timeout, status_cb=LOG.warn,
+ headers_cb=self.md_headers)
if url:
LOG.info("Using metadata source: '%s'", url)
@@ -185,7 +186,8 @@ def read_maas_seed_url(seed_url, header_cb=None, timeout=None,
headers = {}
try:
(resp, sc) = uhelp.readurl(url, headers=headers, timeout=timeout)
- md[name] = resp
+ if uhelp.ok_http_code(sc):
+ md[name] = resp
except urllib2.HTTPError as e:
if e.code != 404:
raise
diff --git a/cloudinit/sources/DataSourceNoCloud.py b/cloudinit/sources/DataSourceNoCloud.py
index 84d0f99d..2b016d1c 100644
--- a/cloudinit/sources/DataSourceNoCloud.py
+++ b/cloudinit/sources/DataSourceNoCloud.py
@@ -106,7 +106,8 @@ class DataSourceNoCloud(sources.DataSource):
if e.errno != errno.ENOENT:
raise
except util.MountFailedError:
- util.logexc(LOG, "Failed to mount %s when looking for seed", dev)
+ util.logexc(LOG, ("Failed to mount %s"
+ " when looking for data"), dev)
# There was no indication on kernel cmdline or data
# in the seeddir suggesting this handler should be used.
diff --git a/cloudinit/sources/DataSourceOVF.py b/cloudinit/sources/DataSourceOVF.py
index bb0f46c2..258d8d03 100644
--- a/cloudinit/sources/DataSourceOVF.py
+++ b/cloudinit/sources/DataSourceOVF.py
@@ -21,10 +21,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from xml.dom import minidom
+
import base64
import os
import re
-import tempfile
from cloudinit import log as logging
from cloudinit import sources
@@ -51,7 +51,7 @@ class DataSourceOVF(sources.DataSource):
ud = ""
defaults = {
- "instance-id": "iid-dsovf"
+ "instance-id": "iid-dsovf",
}
(seedfile, contents) = get_ovf_env(self.paths.seed_dir)
@@ -198,7 +198,7 @@ def transport_iso9660(require_iso=True):
for dev in devs:
fullp = os.path.join("/dev/", dev)
- if (fullp in mounted or
+ if (fullp in mounts or
not cdmatch.match(dev) or os.path.isdir(fullp)):
continue
@@ -210,7 +210,8 @@ def transport_iso9660(require_iso=True):
continue
try:
- (fname, contents) = utils.mount_cb(fullp, get_ovf_env, mtype="iso9660")
+ (fname, contents) = util.mount_cb(fullp,
+ get_ovf_env, mtype="iso9660")
except util.MountFailedError:
util.logexc(LOG, "Failed mounting %s", fullp)
continue
@@ -265,7 +266,8 @@ def get_properties(contents):
raise XmlError("No 'PropertySection's")
props = {}
- propElems = find_child(propSections[0], lambda n: n.localName == "Property")
+ propElems = find_child(propSections[0],
+ (lambda n: n.localName == "Property"))
for elem in propElems:
key = elem.attributes.getNamedItemNS(envNsURI, "key").value
diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py
index 08669f5d..beb0f3d7 100644
--- a/cloudinit/sources/__init__.py
+++ b/cloudinit/sources/__init__.py
@@ -22,10 +22,9 @@
from cloudinit import importer
from cloudinit import log as logging
+from cloudinit import user_data as ud
from cloudinit import util
-from cloudinit.user_data import processor as ud_proc
-
DEP_FILESYSTEM = "FILESYSTEM"
DEP_NETWORK = "NETWORK"
DS_PREFIX = 'DataSource'
@@ -42,7 +41,6 @@ class DataSource(object):
self.sys_cfg = sys_cfg
self.distro = distro
self.paths = paths
- self.userdata_proc = ud_proc.UserDataProcessor(paths)
self.userdata = None
self.metadata = None
self.userdata_raw = None
@@ -55,7 +53,7 @@ class DataSource(object):
def get_userdata(self):
if self.userdata is None:
raw_data = self.get_userdata_raw()
- self.userdata = self.userdata_proc.process(raw_data)
+ self.userdata = ud.UserDataProcessor(self.paths).process(raw_data)
return self.userdata
def get_userdata_raw(self):
@@ -73,7 +71,7 @@ class DataSource(object):
if not self.metadata or 'public-keys' not in self.metadata:
return keys
- if isinstance(self.metadata['public-keys'], (str)):
+ if isinstance(self.metadata['public-keys'], (basestring, str)):
return str(self.metadata['public-keys']).splitlines()
if isinstance(self.metadata['public-keys'], (list, set)):
@@ -84,11 +82,12 @@ class DataSource(object):
# lp:506332 uec metadata service responds with
# data that makes boto populate a string for 'klist' rather
# than a list.
- if isinstance(klist, (str)):
+ if isinstance(klist, (str, basestring)):
klist = [klist]
if isinstance(klist, (list, set)):
for pkey in klist:
- # there is an empty string at the end of the keylist, trim it
+ # There is an empty string at
+ # the end of the keylist, trim it
if pkey:
keys.append(pkey)
@@ -159,13 +158,14 @@ def find_source(sys_cfg, distro, paths, ds_deps, cfg_list, pkg_list):
ds_list = list_sources(cfg_list, ds_deps, pkg_list)
ds_names = [util.obj_name(f) for f in ds_list]
LOG.info("Searching for data source in: %s", ds_names)
+
for cls in ds_list:
ds = util.obj_name(cls)
try:
s = cls(distro, sys_cfg, paths)
if s.get_data():
return (s, ds)
- except Exception as e:
+ except Exception:
util.logexc(LOG, "Getting data from %s failed", ds)
msg = "Did not find any data source, searched classes: %s" % (ds_names)
@@ -178,7 +178,8 @@ def find_source(sys_cfg, distro, paths, ds_deps, cfg_list, pkg_list):
# return an ordered list of classes that match
def list_sources(cfg_list, depends, pkg_list):
src_list = []
- LOG.info("Looking for for data source in: %s, %s that match %s", cfg_list, pkg_list, depends)
+ LOG.info(("Looking for for data source in: %s,"
+ " %s that matches %s"), cfg_list, pkg_list, depends)
for ds_coll in cfg_list:
ds_name = str(ds_coll)
if not ds_name.startswith(DS_PREFIX):
@@ -201,8 +202,8 @@ def list_sources(cfg_list, depends, pkg_list):
if not cls_matches:
continue
src_list.extend(cls_matches)
- LOG.debug("Found a match for data source %s in %s with matches %s",
- ds_name, mod, cls_matches)
+ LOG.debug(("Found a match for data source %s"
+ " in %s with matches %s"), ds_name, mod, cls_matches)
break
return src_list