~ibm-charms/charms/trusty/nova-compute-power/trunk

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/fetch/archiveurl.py

  • Committer: Edward Hope-Morley
  • Date: 2014-03-26 18:08:46 UTC
  • mfrom: (55.1.1 nova-compute.lp1273067)
  • Revision ID: edward.hope-morley@canonical.com-20140326180846-o2mo693uow2urlpj
[hopem] Added support for ceph-client logging to syslog

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import os
2
2
import urllib2
 
3
import urlparse
 
4
 
3
5
from charmhelpers.fetch import (
4
6
    BaseFetchHandler,
5
7
    UnhandledSource
24
26
    def download(self, source, dest):
25
27
        # propogate all exceptions
26
28
        # URLError, OSError, etc
 
29
        proto, netloc, path, params, query, fragment = urlparse.urlparse(source)
 
30
        if proto in ('http', 'https'):
 
31
            auth, barehost = urllib2.splituser(netloc)
 
32
            if auth is not None:
 
33
                source = urlparse.urlunparse((proto, barehost, path, params, query, fragment))
 
34
                username, password = urllib2.splitpasswd(auth)
 
35
                passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
 
36
                # Realm is set to None in add_password to force the username and password
 
37
                # to be used whatever the realm
 
38
                passman.add_password(None, source, username, password)
 
39
                authhandler = urllib2.HTTPBasicAuthHandler(passman)
 
40
                opener = urllib2.build_opener(authhandler)
 
41
                urllib2.install_opener(opener)
27
42
        response = urllib2.urlopen(source)
28
43
        try:
29
44
            with open(dest, 'w') as dest_file: