~gnuoy/charms/trusty/percona-cluster/bug-1389670

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/core/host.py

  • Committer: james.page at ubuntu
  • Date: 2014-06-23 09:47:35 UTC
  • Revision ID: james.page@ubuntu.com-20140623094735-qlvyu1yjvcx7wsl5
[trivial] Resync helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
from collections import OrderedDict
17
17
 
18
18
from hookenv import log
 
19
from fstab import Fstab
19
20
 
20
21
 
21
22
def service_start(service_name):
34
35
 
35
36
 
36
37
def service_reload(service_name, restart_on_failure=False):
37
 
    """Reload a system service, optionally falling back to restart if reload fails"""
 
38
    """Reload a system service, optionally falling back to restart if
 
39
    reload fails"""
38
40
    service_result = service('reload', service_name)
39
41
    if not service_result and restart_on_failure:
40
42
        service_result = service('restart', service_name)
143
145
        target.write(content)
144
146
 
145
147
 
146
 
def mount(device, mountpoint, options=None, persist=False):
 
148
def fstab_remove(mp):
 
149
    """Remove the given mountpoint entry from /etc/fstab
 
150
    """
 
151
    return Fstab.remove_by_mountpoint(mp)
 
152
 
 
153
 
 
154
def fstab_add(dev, mp, fs, options=None):
 
155
    """Adds the given device entry to the /etc/fstab file
 
156
    """
 
157
    return Fstab.add(dev, mp, fs, options=options)
 
158
 
 
159
 
 
160
def mount(device, mountpoint, options=None, persist=False, filesystem="ext3"):
147
161
    """Mount a filesystem at a particular mountpoint"""
148
162
    cmd_args = ['mount']
149
163
    if options is not None:
154
168
    except subprocess.CalledProcessError, e:
155
169
        log('Error mounting {} at {}\n{}'.format(device, mountpoint, e.output))
156
170
        return False
 
171
 
157
172
    if persist:
158
 
        # TODO: update fstab
159
 
        pass
 
173
        return fstab_add(device, mountpoint, filesystem, options=options)
160
174
    return True
161
175
 
162
176
 
168
182
    except subprocess.CalledProcessError, e:
169
183
        log('Error unmounting {}\n{}'.format(mountpoint, e.output))
170
184
        return False
 
185
 
171
186
    if persist:
172
 
        # TODO: update fstab
173
 
        pass
 
187
        return fstab_remove(mountpoint)
174
188
    return True
175
189
 
176
190
 
295
309
    if 'link/ether' in words:
296
310
        hwaddr = words[words.index('link/ether') + 1]
297
311
    return hwaddr
 
312
 
 
313
 
 
314
def cmp_pkgrevno(package, revno, pkgcache=None):
 
315
    '''Compare supplied revno with the revno of the installed package
 
316
       1 => Installed revno is greater than supplied arg
 
317
       0 => Installed revno is the same as supplied arg
 
318
      -1 => Installed revno is less than supplied arg
 
319
    '''
 
320
    import apt_pkg
 
321
    if not pkgcache:
 
322
        apt_pkg.init()
 
323
        pkgcache = apt_pkg.Cache()
 
324
    pkg = pkgcache[package]
 
325
    return apt_pkg.version_compare(pkg.current_ver.ver_str, revno)