Resynced helpers

This commit is contained in:
James Page 2014-03-20 13:47:54 +00:00
parent 0cfc682bc8
commit bee3a38230
7 changed files with 71 additions and 5 deletions

17
.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>swift-storage</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>

9
.pydevproject Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/swift-storage/hooks</path>
<path>/swift-storage/unit_tests</path>
</pydev_pathproperty>
</pydev_project>

View File

@ -29,6 +29,7 @@ from charmhelpers.contrib.hahelpers.cluster import (
determine_apache_port, determine_apache_port,
determine_api_port, determine_api_port,
https, https,
is_clustered
) )
from charmhelpers.contrib.hahelpers.apache import ( from charmhelpers.contrib.hahelpers.apache import (
@ -240,10 +241,13 @@ class CephContext(OSContextGenerator):
'''This generates context for /etc/ceph/ceph.conf templates''' '''This generates context for /etc/ceph/ceph.conf templates'''
if not relation_ids('ceph'): if not relation_ids('ceph'):
return {} return {}
log('Generating template context for ceph') log('Generating template context for ceph')
mon_hosts = [] mon_hosts = []
auth = None auth = None
key = None key = None
use_syslog = str(config('use-syslog')).lower()
for rid in relation_ids('ceph'): for rid in relation_ids('ceph'):
for unit in related_units(rid): for unit in related_units(rid):
mon_hosts.append(relation_get('private-address', rid=rid, mon_hosts.append(relation_get('private-address', rid=rid,
@ -255,7 +259,7 @@ class CephContext(OSContextGenerator):
'mon_hosts': ' '.join(mon_hosts), 'mon_hosts': ' '.join(mon_hosts),
'auth': auth, 'auth': auth,
'key': key, 'key': key,
'use_syslog': str(config('use-syslog')).lower() 'use_syslog': use_syslog
} }
if not os.path.isdir('/etc/ceph'): if not os.path.isdir('/etc/ceph'):
@ -392,7 +396,7 @@ class ApacheSSLContext(OSContextGenerator):
return ctxt return ctxt
class NeutronContext(object): class NeutronContext(OSContextGenerator):
interfaces = [] interfaces = []
@property @property
@ -453,6 +457,22 @@ class NeutronContext(object):
return nvp_ctxt return nvp_ctxt
def neutron_ctxt(self):
if https():
proto = 'https'
else:
proto = 'http'
if is_clustered():
host = config('vip')
else:
host = unit_get('private-address')
url = '%s://%s:%s' % (proto, host, '9696')
ctxt = {
'network_manager': self.network_manager,
'neutron_url': url,
}
return ctxt
def __call__(self): def __call__(self):
self._ensure_packages() self._ensure_packages()
@ -462,7 +482,7 @@ class NeutronContext(object):
if not self.plugin: if not self.plugin:
return {} return {}
ctxt = {'network_manager': self.network_manager} ctxt = self.neutron_ctxt()
if self.plugin == 'ovs': if self.plugin == 'ovs':
ctxt.update(self.ovs_ctxt()) ctxt.update(self.ovs_ctxt())

View File

@ -20,7 +20,7 @@ def headers_package():
def kernel_version(): def kernel_version():
""" Retrieve the current major kernel version as a tuple e.g. (3, 13) """ """ Retrieve the current major kernel version as a tuple e.g. (3, 13) """
kver = check_output(['uname' , '-r']).strip() kver = check_output(['uname', '-r']).strip()
kver = kver.split('.') kver = kver.split('.')
return (int(kver[0]), int(kver[1])) return (int(kver[0]), int(kver[1]))

View File

@ -22,4 +22,5 @@ def zap_disk(block_device):
:param block_device: str: Full path of block device to clean. :param block_device: str: Full path of block device to clean.
''' '''
check_call(['sgdisk', '--zap-all', '--mbrtogpt', block_device]) check_call(['sgdisk', '--zap-all', '--clear',
'--mbrtogpt', block_device])

View File

@ -158,6 +158,10 @@ def apt_hold(packages, fatal=False):
def add_source(source, key=None): def add_source(source, key=None):
if source is None:
log('Source is not present. Skipping')
return
if (source.startswith('ppa:') or if (source.startswith('ppa:') or
source.startswith('http') or source.startswith('http') or
source.startswith('deb ') or source.startswith('deb ') or

View File

@ -1,5 +1,7 @@
import os import os
import urllib2 import urllib2
import urlparse
from charmhelpers.fetch import ( from charmhelpers.fetch import (
BaseFetchHandler, BaseFetchHandler,
UnhandledSource UnhandledSource
@ -24,6 +26,19 @@ class ArchiveUrlFetchHandler(BaseFetchHandler):
def download(self, source, dest): def download(self, source, dest):
# propogate all exceptions # propogate all exceptions
# URLError, OSError, etc # URLError, OSError, etc
proto, netloc, path, params, query, fragment = urlparse.urlparse(source)
if proto in ('http', 'https'):
auth, barehost = urllib2.splituser(netloc)
if auth is not None:
source = urlparse.urlunparse((proto, barehost, path, params, query, fragment))
username, password = urllib2.splitpasswd(auth)
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
# Realm is set to None in add_password to force the username and password
# to be used whatever the realm
passman.add_password(None, source, username, password)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
response = urllib2.urlopen(source) response = urllib2.urlopen(source)
try: try:
with open(dest, 'w') as dest_file: with open(dest, 'w') as dest_file: