diff options
-rw-r--r-- | cloudinit/sources/DataSourceMAAS.py | 25 | ||||
-rw-r--r-- | cloudinit/url_helper.py | 14 |
2 files changed, 20 insertions, 19 deletions
diff --git a/cloudinit/sources/DataSourceMAAS.py b/cloudinit/sources/DataSourceMAAS.py index 2f36bbe2..6c95c218 100644 --- a/cloudinit/sources/DataSourceMAAS.py +++ b/cloudinit/sources/DataSourceMAAS.py @@ -20,14 +20,10 @@ from __future__ import print_function -from email.utils import parsedate import errno -import oauthlib.oauth1 as oauth1 import os import time -from six.moves.urllib_request import Request, urlopen - from cloudinit import log as logging from cloudinit import sources from cloudinit import url_helper @@ -62,7 +58,7 @@ class DataSourceMAAS(sources.DataSource): if required not in mcfg: return url_helper.OauthUrlHelper() - return url_helper.OauthHelper( + return url_helper.OauthUrlHelper( consumer_key=mcfg['consumer_key'], token_key=mcfg['token_key'], token_secret=mcfg['token_secret'], consumer_secret=mcfg.get('consumer_secret')) @@ -98,7 +94,7 @@ class DataSourceMAAS(sources.DataSource): self.base_url = url (userdata, metadata) = read_maas_seed_url( - self.base_url, self.oauth_helper.md_headers, + self.base_url, read_file_or_url=self.oauth_helper.readurl, paths=self.paths) self.userdata_raw = userdata self.metadata = metadata @@ -312,25 +308,30 @@ if __name__ == "__main__": def geturl(url): return oauth_helper.readurl(url).contents - def printurl(url, headers_cb): - print("== %s ==\n%s\n" % (url, geturl(url))) + def printurl(url): + print("== %s ==\n%s\n" % (url, geturl(url).decode())) def crawl(url): if url.endswith("/"): - for line in geturl(url).splitlines(): + for line in geturl(url).decode().splitlines(): if line.endswith("/"): crawl("%s%s" % (url, line)) + elif line == "meta-data": + # meta-data is a dir, it *should* end in a / + crawl("%s%s" % (url, "meta-data/")) else: printurl("%s%s" % (url, line)) else: printurl(url) if args.subcmd == "check-seed": + readurl = oauth_helper.readurl + if args.url[0] == "/" or args.url.startswith("file://"): + readurl = None (userdata, metadata) = read_maas_seed_url( - args.url, read_file_or_url=oauth_helper.read_file_or_url, - version=args.apiver) + args.url, version=args.apiver, read_file_or_url=readurl) print("=== userdata ===") - print(userdata) + print(userdata.decode()) print("=== metadata ===") pprint.pprint(metadata) diff --git a/cloudinit/url_helper.py b/cloudinit/url_helper.py index dca4cc85..ce6b5444 100644 --- a/cloudinit/url_helper.py +++ b/cloudinit/url_helper.py @@ -20,16 +20,16 @@ # 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 time - +import json +import os +import requests import six +import time -import requests -import oauthlib.oauth1 as oauth1 -import os -import json +from email.utils import parsedate from functools import partial from requests import exceptions +import oauthlib.oauth1 as oauth1 from six.moves.urllib.parse import ( urlparse, urlunparse, @@ -434,7 +434,7 @@ class OauthUrlHelper(object): if abs(old_skew - skew) > self.skew_change_limit: self.update_skew_file(host, skew) LOG.warn("Setting oauth clockskew for %s to %d", host, skew) - skew_data[host] = skew + self.skew_data[host] = skew return |