Kaydet (Commit) afba52dc authored tarafından shin-'s avatar shin-

Added utils.ping and used to expand registry URL (http VS https)

üst addecd49
...@@ -18,6 +18,8 @@ import os ...@@ -18,6 +18,8 @@ import os
import six import six
import utils
INDEX_URL = 'https://index.docker.io/v1/' INDEX_URL = 'https://index.docker.io/v1/'
def swap_protocol(url): def swap_protocol(url):
...@@ -33,7 +35,8 @@ def expand_registry_url(hostname): ...@@ -33,7 +35,8 @@ def expand_registry_url(hostname):
if '/' not in hostname[9:]: if '/' not in hostname[9:]:
hostname = hostname + '/v1/' hostname = hostname + '/v1/'
return hostname return hostname
#FIXME: ping https then fallback to http if utils.ping('https://' + hostname + '_ping'):
return 'https://' + hostname + '/v1/'
return 'http://' + hostname + '/v1/' return 'http://' + hostname + '/v1/'
......
...@@ -12,10 +12,12 @@ ...@@ -12,10 +12,12 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import six
import tarfile import tarfile
import tempfile import tempfile
import requests
import six
if six.PY3: if six.PY3:
from io import StringIO from io import StringIO
else: else:
...@@ -44,5 +46,14 @@ def tar(self, path): ...@@ -44,5 +46,14 @@ def tar(self, path):
f.seek(0) f.seek(0)
return f return f
def compare_version(v1, v2): def compare_version(v1, v2):
return float(v2) - float(v1) return float(v2) - float(v1)
\ No newline at end of file
def ping(url):
try:
res = requests.get(url)
return res.status >= 400
except Exception:
return False
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment