~mikemc/glance-simplestreams-sync-charm/add-nclxd-default-imagetype

« back to all changes in this revision

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

  • Committer: Michael McCracken
  • Date: 2014-06-18 17:52:49 UTC
  • mfrom: (44.2.1)
  • Revision ID: git-v1:2c173d6816bed098d7134cb012528b7676b16d70
Merge pull request #10 from mikemccracken/sync-new-charmhelpers

auto-sync of charmhelpers to lp:charm-helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
import string
13
13
import subprocess
14
14
import hashlib
15
 
import apt_pkg
16
15
 
17
16
from collections import OrderedDict
18
17
 
19
18
from hookenv import log
 
19
from fstab import Fstab
20
20
 
21
21
 
22
22
def service_start(service_name):
35
35
 
36
36
 
37
37
def service_reload(service_name, restart_on_failure=False):
38
 
    """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"""
39
40
    service_result = service('reload', service_name)
40
41
    if not service_result and restart_on_failure:
41
42
        service_result = service('restart', service_name)
144
145
        target.write(content)
145
146
 
146
147
 
147
 
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"):
148
161
    """Mount a filesystem at a particular mountpoint"""
149
162
    cmd_args = ['mount']
150
163
    if options is not None:
155
168
    except subprocess.CalledProcessError, e:
156
169
        log('Error mounting {} at {}\n{}'.format(device, mountpoint, e.output))
157
170
        return False
 
171
 
158
172
    if persist:
159
 
        # TODO: update fstab
160
 
        pass
 
173
        return fstab_add(device, mountpoint, filesystem, options=options)
161
174
    return True
162
175
 
163
176
 
169
182
    except subprocess.CalledProcessError, e:
170
183
        log('Error unmounting {}\n{}'.format(mountpoint, e.output))
171
184
        return False
 
185
 
172
186
    if persist:
173
 
        # TODO: update fstab
174
 
        pass
 
187
        return fstab_remove(mountpoint)
175
188
    return True
176
189
 
177
190
 
304
317
       0 => Installed revno is the same as supplied arg
305
318
      -1 => Installed revno is less than supplied arg
306
319
    '''
 
320
    import apt_pkg
307
321
    if not pkgcache:
308
322
        apt_pkg.init()
309
323
        pkgcache = apt_pkg.Cache()