1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-31 12:49:46 +00:00

bitbake: toaster: Support environments which have proxies set

In an environment with a proxy which requires authentication, e.g. with
$http_proxy = 'http://user:password@ip:port', the following error
occurs when running Toaster:

  EE: Using proxy http://user:password@ip:port
  EE: could not connect to 'url', skipping update: 'error message'

This prevents Toaster from fetching layer, recipe and machine information
from remote repositories.

This patch allows Toaster to use the proxy settings from the
environment for HTTP/HTTPS requests.

(Bitbake rev: e7a85031fd05a46ef60b380883da4cc372acf89b)

Signed-off-by: Bian Naimeng <biannm@cn.fujitsu.com>
Signed-off-by: Elliot Smith <elliot.smith@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Bian Naimeng
2015-08-28 16:37:38 +01:00
committed by Richard Purdie
parent ce2a827086
commit 8e1f080c04
+6 -28
View File
@@ -817,42 +817,20 @@ class LayerIndexLayerSource(LayerSource):
assert self.apiurl is not None assert self.apiurl is not None
from django.db import transaction, connection from django.db import transaction, connection
import httplib, urlparse, json import urllib2, urlparse, json
import os import os
proxy_settings = os.environ.get("http_proxy", None) proxy_settings = os.environ.get("http_proxy", None)
def _get_json_response(apiurl = self.apiurl): def _get_json_response(apiurl = self.apiurl):
conn = None
_parsedurl = urlparse.urlparse(apiurl) _parsedurl = urlparse.urlparse(apiurl)
path = _parsedurl.path path = _parsedurl.path
query = _parsedurl.query
def parse_url(url):
parsedurl = urlparse.urlparse(url)
try:
(host, port) = parsedurl.netloc.split(":")
except ValueError:
host = parsedurl.netloc
port = None
if port is None: try:
port = 80 res = urllib2.urlopen(apiurl)
else: except urllib2.URLError as e:
port = int(port) raise Exception("Failed to read %s: %s" % (path, e.reason))
return (host, port)
if proxy_settings is None: return json.loads(res.read())
host, port = parse_url(apiurl)
conn = httplib.HTTPConnection(host, port)
conn.request("GET", path + "?" + query)
else:
host, port = parse_url(proxy_settings)
conn = httplib.HTTPConnection(host, port)
conn.request("GET", apiurl)
r = conn.getresponse()
if r.status != 200:
raise Exception("Failed to read " + path + ": %d %s" % (r.status, r.reason))
return json.loads(r.read())
# verify we can get the basic api # verify we can get the basic api
try: try: