~corey.bryant/charms/trusty/neutron-api/db-stamp

« back to all changes in this revision

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

  • Committer: james.page at ubuntu
  • Date: 2014-10-01 21:05:24 UTC
  • mfrom: (39.3.25 ipv6)
  • Revision ID: james.page@ubuntu.com-20141001210524-z6uqyljzorphrhy6
[xianghui,dosaboy,r=james-page,t=gema] Add IPv6 support using prefer-ipv6 flag

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
from collections import OrderedDict
5
5
 
6
6
import subprocess
 
7
import json
7
8
import os
8
9
import socket
9
10
import sys
13
14
    log as juju_log,
14
15
    charm_dir,
15
16
    ERROR,
16
 
    INFO
 
17
    INFO,
 
18
    relation_ids,
 
19
    relation_set
17
20
)
18
21
 
19
22
from charmhelpers.contrib.storage.linux.lvm import (
22
25
    remove_lvm_physical_volume,
23
26
)
24
27
 
 
28
from charmhelpers.contrib.network.ip import (
 
29
    get_ipv6_addr
 
30
)
 
31
 
25
32
from charmhelpers.core.host import lsb_release, mounts, umount
26
 
from charmhelpers.fetch import apt_install
 
33
from charmhelpers.fetch import apt_install, apt_cache
27
34
from charmhelpers.contrib.storage.linux.utils import is_block_device, zap_disk
28
35
from charmhelpers.contrib.storage.linux.loopback import ensure_loopback_device
29
36
 
70
77
    ('1.13.0', 'icehouse'),
71
78
    ('1.12.0', 'icehouse'),
72
79
    ('1.11.0', 'icehouse'),
 
80
    ('2.0.0', 'juno'),
73
81
])
74
82
 
75
83
DEFAULT_LOOPBACK_SIZE = '5G'
134
142
def get_os_codename_package(package, fatal=True):
135
143
    '''Derive OpenStack release codename from an installed package.'''
136
144
    import apt_pkg as apt
137
 
    apt.init()
138
 
 
139
 
    # Tell apt to build an in-memory cache to prevent race conditions (if
140
 
    # another process is already building the cache).
141
 
    apt.config.set("Dir::Cache::pkgcache", "")
142
 
 
143
 
    cache = apt.Cache()
 
145
 
 
146
    cache = apt_cache()
144
147
 
145
148
    try:
146
149
        pkg = cache[package]
461
464
            return result
462
465
    else:
463
466
        return result.split('.')[0]
 
467
 
 
468
 
 
469
def sync_db_with_multi_ipv6_addresses(database, database_user,
 
470
                                      relation_prefix=None):
 
471
    hosts = get_ipv6_addr(dynamic_only=False)
 
472
 
 
473
    kwargs = {'database': database,
 
474
              'username': database_user,
 
475
              'hostname': json.dumps(hosts)}
 
476
 
 
477
    if relation_prefix:
 
478
        keys = kwargs.keys()
 
479
        for key in keys:
 
480
            kwargs["%s_%s" % (relation_prefix, key)] = kwargs[key]
 
481
            del kwargs[key]
 
482
 
 
483
    for rid in relation_ids('shared-db'):
 
484
        relation_set(relation_id=rid, **kwargs)