~corey.bryant/charms/trusty/glance/drop-symlinks

« back to all changes in this revision

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

  • Committer: Billy Olsen
  • Date: 2015-06-22 17:03:00 UTC
  • mfrom: (119.1.1 glance)
  • Revision ID: billy.olsen@canonical.com-20150622170300-iqeusmtudt8v20bz
[corey.bryant,r=billy-olsen] Fix global requirements for git-deploy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import os
25
25
import re
26
26
import pwd
 
27
import glob
27
28
import grp
28
29
import random
29
30
import string
269
270
        return None
270
271
 
271
272
 
 
273
def path_hash(path):
 
274
    """
 
275
    Generate a hash checksum of all files matching 'path'. Standard wildcards
 
276
    like '*' and '?' are supported, see documentation for the 'glob' module for
 
277
    more information.
 
278
 
 
279
    :return: dict: A { filename: hash } dictionary for all matched files.
 
280
                   Empty if none found.
 
281
    """
 
282
    return {
 
283
        filename: file_hash(filename)
 
284
        for filename in glob.iglob(path)
 
285
    }
 
286
 
 
287
 
272
288
def check_hash(path, checksum, hash_type='md5'):
273
289
    """
274
290
    Validate a file using a cryptographic checksum.
296
312
 
297
313
        @restart_on_change({
298
314
            '/etc/ceph/ceph.conf': [ 'cinder-api', 'cinder-volume' ]
 
315
            '/etc/apache/sites-enabled/*': [ 'apache2' ]
299
316
            })
300
 
        def ceph_client_changed():
 
317
        def config_changed():
301
318
            pass  # your code here
302
319
 
303
320
    In this example, the cinder-api and cinder-volume services
304
321
    would be restarted if /etc/ceph/ceph.conf is changed by the
305
 
    ceph_client_changed function.
 
322
    ceph_client_changed function. The apache2 service would be
 
323
    restarted if any file matching the pattern got changed, created
 
324
    or removed. Standard wildcards are supported, see documentation
 
325
    for the 'glob' module for more information.
306
326
    """
307
327
    def wrap(f):
308
328
        def wrapped_f(*args, **kwargs):
309
 
            checksums = {}
310
 
            for path in restart_map:
311
 
                checksums[path] = file_hash(path)
 
329
            checksums = {path: path_hash(path) for path in restart_map}
312
330
            f(*args, **kwargs)
313
331
            restarts = []
314
332
            for path in restart_map:
315
 
                if checksums[path] != file_hash(path):
 
333
                if path_hash(path) != checksums[path]:
316
334
                    restarts += restart_map[path]
317
335
            services_list = list(OrderedDict.fromkeys(restarts))
318
336
            if not stopstart: