~lazypower/charms/trusty/keystone/fix_proof

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/openstack/alternatives.py

  • Committer: Ante Karamatic
  • Date: 2014-02-25 11:34:13 UTC
  • Revision ID: ivoks@ubuntu.com-20140225113413-tlm02x1ibc6xb10d
Rewrite charm to get it more in line with other OpenStack charms.

Added support for contexts and templating. Makes use of charm-helpers
instead of relaying on its own tools (probably could use some additional work).

HA is currently non-functional. ETA for fixing: less than 2 days.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
''' Helper for managing alternatives for file conflict resolution '''
 
2
 
 
3
import subprocess
 
4
import shutil
 
5
import os
 
6
 
 
7
 
 
8
def install_alternative(name, target, source, priority=50):
 
9
    ''' Install alternative configuration '''
 
10
    if (os.path.exists(target) and not os.path.islink(target)):
 
11
        # Move existing file/directory away before installing
 
12
        shutil.move(target, '{}.bak'.format(target))
 
13
    cmd = [
 
14
        'update-alternatives', '--force', '--install',
 
15
        target, name, source, str(priority)
 
16
    ]
 
17
    subprocess.check_call(cmd)