summaryrefslogtreecommitdiff
path: root/cloudinit/url_helper.py
AgeCommit message (Collapse)Author
2018-05-17read_file_or_url: move to url_helper, fix bug in its FileResponse.Scott Moser
The result of a read_file_or_url on a file and on a url would differ in behavior. str(UrlResponse) would return UrlResponse.contents.decode('utf-8') while str(FileResponse) would return str(FileResponse.contents) The difference being "b'foo'" versus "foo". As part of the general goal of cleaning util, move read_file_or_url into url_helper.
2018-04-19pylint: pay attention to unused variable warnings.Scott Moser
This enables warnings produced by pylint for unused variables (W0612), and fixes the existing errors.
2018-03-23Reduce AzurePreprovisioning HTTP timeouts.Douglas Jordan
Reducing timeout to 1 second as IMDS responds within a handful of milliseconds. Also get rid of max_retries to prevent exiting out of polling loop early due to IMDS outage / upgrade. Reduce Azure PreProvisioning HTTP timeouts during polling to avoid waiting an extra minute. LP: #1752977
2018-03-23Revert the logic of exception_cb in read_url.Kurt Garloff
In commit e9e8616, there was an inversion of the logic of the exception_cb return value meaning, breaking the (network) OpenStack DataSource, which implemented exception_cb as should_retry_cb, returning True when a retry should be done and False when the retry loop should be broken and the exception reraised again immediately. The OpenStack DS was the only user of this callback at the time and not touched by the commit (nor did the commit message mention an intended change), so this almost certainly happened by mistake. These days, we have a second user of the callback in DataSourceScaleway. It uses the new logic, so it needs change if we fix the meaning of the return value. This patch reverts the meaning of url_helper.read_url() execption_cb to the old semantics. It updates the comment and adjusts the Scaleway datasource. The patch has been tested on Open Telekom Cloud (which uses the OpenStack network Datasource) where previously a missing user_data and network_data.json would be retried 6 times each despite them not being present (they are optional!) and the server repsonding with a correct 404. After the patch, boot times are 10s faster, as we no longer pointlessly retry these files. LP: #1702160 LP: #1298921
2018-03-02Simplify some comparisions.Rémy Léone
Just replace a couple things like: if b > a and b < c: with: if a < b < c:
2018-01-24Azure VM Preprovisioning support.Douglas Jordan
This change will enable azure vms to report provisioning has completed twice, first to tell the fabric it has completed then a second time to enable customer settings. The datasource for the second provisioning is the Instance Metadata Service (IMDS),and the VM will poll indefinitely for the new ovf-env.xml from IMDS. This branch introduces EphemeralDHCPv4 which encapsulates common logic used by both DataSourceEc2 an DataSourceAzure for temporary DHCP interactions without side-effects. LP: #1734991
2017-08-30url_helper: dynamically import oauthlib import from inside oauth_headersChad Smith
oauth_headers is the only function which requires oauthlib, move the import and ImportError handling inside this function to only attempt loading at runtime if called. This will allow us to build on platforms that don't have python-oauthlib installed by default. Add simple unittests around the missing oauthlib dependencies to make sure the function performs as intended and raises and NotImplementedError if oauthlib can't be imported.
2017-08-29url_helper: fail gracefully if oauthlib is not availableLars Kellogg-Stedman
We are unable to ship python-oauthlib in RHEL. This commit allows imports of url_helper to succeed even when oauthlib is unavailable and OauthUrlHelper.oauth_headers to raise a NotImplementedException when called. LP: #1713760
2017-07-17Scaleway: add datasource with user and vendor data for Scaleway.Julien Castets
Here we add and enable by default a datasource for Scaleway cloud. The datasource quickly exits unless one of three things: a.) 'Scaleway' found as the system vendor b.) 'scaleway' found on the kernel command line. c.) the directory /var/run/scaleway exists (this is currently created by the scaleway initramfs module). One interesting bit of this particular datasource is that it requires the source port of the http request to be < 1024.
2017-04-21pylint: fix all logging warningsJoshua Powers
This will change all instances of LOG.warn to LOG.warning as warn is now a deprecated method. It will also make sure any logging uses lazy logging by passing string format arguments as function parameters.
2017-03-24test: add running of pylintJoshua Powers
Now tox will run pylint. The .pylintrc file sets pylint to only produce errors, and will ignore certain classes that are known problematic (six).
2016-12-22LICENSE: Allow dual licensing GPL-3 or Apache 2.0Jon Grimm
This has been a recurring ask and we had initially just made the change to the cloud-init 2.0 codebase. As the current thinking is we'll just continue to enhance the current codebase, its desirable to relicense to match what we'd intended as part of the 2.0 plan here. - put a brief description of license in LICENSE file - put full license versions in LICENSE-GPLv3 and LICENSE-Apache2.0 - simplify the per-file header to reference LICENSE - tox: ignore H102 (Apache License Header check) Add license header to files that ship. Reformat headers, make sure everything has vi: at end of file. Non-shipping files do not need the copyright header, but at the moment tests/ have it.
2016-05-12Fix up a ton of flake8 issuesJoshua Harlow
2016-03-03Update pep8 runner and fix pep8 issuesRyan Harper
2015-09-29MAAS: fix issues with url_helper and oauth moduleScott Moser
This would cause problems in the event that we actually had a bad clock. We add a retry in the main (for test) also, to ensure that the oauth timestamp fix gets in place. LP: #1499869
2015-08-31readurl: if headers are provided still provide base headersScott Moser
we want cloud-init user agent to be present even if the user provided some headers. In the event that they provided User-Agent, this will respect their wishes.
2015-08-25MAAS: fixes to data source and OauthUrlHelperScott Moser
the previous version was broken. The vital fixes here are: * adding parsedate and oauth1 imports to url_helper * fix skew_data usage intending to use self.skew_data Additionally: * reorder imports in url_helper * fixes to python3 -m cloudinit.sources.DataSourceMaas LP: #1488507
2015-08-07fix syntaxScott Moser
2015-08-07improvements on skewScott Moser
2015-08-07seems functional in testScott Moser
2015-08-06tests passScott Moser
2015-03-02url_helper.py: fix undefined variableScott Moser
python2 scoping is different and running wait_for_url in python3 results in a use of undeclared variable 'e'. $ python3 -c 'from cloudinit import url_helper; \ url_helper.wait_for_url("o", max_wait=3,timeout=1, exception_cb=print)' Traceback (most recent call last): File "<string>", line 1, in <module> File "cloudinit/url_helper.py", line 358, in wait_for_url exception_cb(msg=status_msg, exception=e)
2015-02-25move towards user-data being binaryScott Moser
UrlResponse: biggest change... make readurl return bytes, making user know what to do with it. util: add load_tfile_or_url for loading text file or url as read_file_or_url now returns bytes ec2_utils: all meta-data is text, remove non-obvious string translations DigitalOcean: adjust for ec2_utils DataSourceGCE, DataSourceMAAS: user-data is binary other fields are text. openstack.py: read paths without decoding to text. This is ok as paths other than user-data are json, and load_json will handle load_file still returns text, and that is what most things use.
2015-01-21Largely merge lp:~harlowja/cloud-init/py2-3 albeit manually because it seemedBarry Warsaw
to be behind trunk. `tox -e py27` passes full test suite. Now to work on replacing mocker.
2014-08-26further remove evidence of pylint.Scott Moser
This just removes comments '# pylint:' things and other code remnents of pylint.
2014-08-26fix(pep8): Fix various pep8 violations and version-lock pep8Jay Faulkner
Fixed all complaints from running "make pep8". Also version locked pep8 in test-requirements.txt to ensure that pep8 requirements don't change without an explicit commit.
2014-02-13wait less for the metadata service (by default)Scott Moser
Waiting around for a metadata service in a given datasource means that if its not there all the subsequent datasources have to wait, and boot is slowed down. As it is right now, EC2 is the only one that has the right to wait. In the past, we had to wait around for the EC2 metadata service. I really do not want to extend that courtesy to other cloud platforms. A network based metadata service should be up as soon as networking is up.
2014-02-08Spacing and comment cleanupJoshua Harlow
2014-02-08Update requests ssl not supported messageJoshua Harlow
2014-02-08Remove HEAD usage and other small adjustmentsJoshua Harlow
2014-02-07Remerged with trunkJoshua Harlow
2014-02-01Add a openstack specific datasourceJoshua Harlow
Openstack has a unique derivative datasource that is gaining usage. Previously the config drive datasource provided part of this functionality as well as the ec2 datasource, but since new functionality is being added to openstack is seems benefical to combine the used parts into one datasource just made for handling openstack deployments. This patch factors out the common logic shared between the config drive and the openstack metadata datasource and places that in a shared helper file and then creates a new openstack datasource that readers from the openstack metadata service and refactors the config drive datasource to use this common logic.
2014-01-24read_file_or_url: raise UrlError with 404 on ENOENTScott Moser
This makes it easier to call read_file_or_url and handle file or url errors. Now read_file_or_url will raise a UrlError in either case on errors.
2014-01-23Use the right exceptionJoshua Harlow
2014-01-23Skip retry and continued fetch of userdata when NOT_FOUNDJoshua Harlow
When a 404 http code comes back from the fetching of ec2 data, instead of retrying immediatly stop the fetching process and in the userdata fetching function handle this case as a special case of no userdata being fetched (an empty string in this case).
2013-05-03Fix a feature that doesn't yet exist on python 2.6Joshua Harlow
2013-04-25re-work maas datasource and headers call backsScott Moser
Couple of things here: * do not re-try on user-data (404 means 'not here') * re-generate headers on retry requests LP: #1172742
2013-03-19set 'allow_redirects' to True by defaultScott Moser
the previous implementation of url_helper.readurl() would default to allow_redirects being true. So, for backwards compat, we should keep that behavior.
2013-03-19do not bother retrying on ssl errorsScott Moser
if the error is an ssl error, its extremely unlikely that it would be fixed by waiting a few seconds and trying again.
2013-03-19appease pylint and pep8Scott Moser
* cloudinit/distros/parsers/resolv_conf.py added some pylint overrides with 'plXXXXX' syntax. example: # pl51222 pylint: disable=E0102 The pl51222 there means: http://www.logilab.org/ticket/51222 This specific issue is present in 12.04 pylint, but not 13.04. * pylint doesn't like the requests special handling we have. which makes sense as it is only checking versus one specific version. * general pep8 and pylint cleanups.
2013-03-13Fix how the http error doesn't always have the response attachedJoshua Harlow
in earlier versions of requests (pre 0.10.8).
2013-03-13Update to handle requests >= 1.0 which doesn't use the config dict.Joshua Harlow
2013-02-23Fix the maas callback mechanism now that requests is used.harlowja
2013-02-23Get tests working and further adjustments.harlowja
2013-02-19Continue working on integrating requests.harlowja
2012-10-22More cleanups for using the requests module.Joshua Harlow
1. Handle our own retries (so that we can sleep in between) 2. Cleanup the url so that partially invalid (no scheme) urls will continue working. 3. Allow redirects option now a param.
2012-10-21Fix the checking and capturing of exceptions.Joshua Harlow
2012-10-21Use the python requests lib instead of urllib3Joshua Harlow
since it provides the same support (and it uses that library). Urllib3 doesn't seem to exist as its own package (requests hides it) so solve that by using requests and handling its oddness ourself.
2012-10-19Remove the need for boto just for fetching the Joshua Harlow
userdata and metadata. Add in this crawling functionality to the ec2_utils module that will fully crawl (not lazily) the ec2 metadata and parse it in the same manner as boto. 1. Make the ec2 datasource + cloudstack now call into these. 2. Fix phone_home due to urllib3 change (TBD)
2012-10-18Start fixing how boto and our url fetching can notJoshua Harlow
use ssl correctly (they can not do validation due to the underlying usage of urllib/httplib). Adjust to use urllib3 which can in cloud-init url fetching. For now also take the metadata/userdata extraction code from boto (small amount) and fix it in a new local file called 'ec2_utils'.