Get Monitor Helper Function

Copied a helper function from the ceph-osd charm into
this shared library.  This function is useful and
is getting copied into several other ceph
related repos.

Change-Id: Idf9c673f2d44b1f000947fb90b864eedad3f4ece
This commit is contained in:
Chris Holcombe 2016-11-30 11:29:57 -08:00
parent 9c51547707
commit f11843671b
1 changed files with 29 additions and 4 deletions

View File

@ -25,6 +25,7 @@
import errno
import hashlib
import math
from charmhelpers.contrib.network.ip import format_ipv6_addr
import six
import os
@ -56,7 +57,8 @@ from charmhelpers.core.host import (mount,
from charmhelpers.fetch import (apt_install, )
from charmhelpers.core.kernel import modprobe
from charmhelpers.contrib.openstack.utils import config_flags_parser
from charmhelpers.contrib.openstack.utils import config_flags_parser, \
get_host_ip
KEYRING = '/etc/ceph/ceph.client.{}.keyring'
KEYFILE = '/etc/ceph/ceph.client.{}.key'
@ -411,7 +413,7 @@ class Pool(object):
# highest value is used. To do this, find the nearest power of 2 such
# that 2^n <= num_pg, check to see if its within the 25% tolerance.
exponent = math.floor(math.log(num_pg, 2))
nearest = 2**exponent
nearest = 2 ** exponent
if (num_pg - nearest) > (num_pg * 0.25):
# Choose the next highest power of 2 since the nearest is more
# than 25% below the original value.
@ -421,7 +423,6 @@ class Pool(object):
class ReplicatedPool(Pool):
def __init__(self,
service,
name,
@ -455,7 +456,6 @@ class ReplicatedPool(Pool):
# Default jerasure erasure coded pool
class ErasurePool(Pool):
def __init__(self,
service,
name,
@ -1179,6 +1179,30 @@ def ensure_ceph_keyring(service, user=None, group=None, relation='ceph'):
return True
def get_mon_hosts():
"""
Helper function to gather up the ceph monitor host public addresses
:return: list. Returns a list of ip_address:port
"""
hosts = []
for relid in relation_ids('mon'):
for unit in related_units(relid):
addr = \
relation_get('ceph-public-address',
unit,
relid) or get_host_ip(
relation_get(
'private-address',
unit,
relid))
if addr:
hosts.append('{}:6789'.format(format_ipv6_addr(addr) or addr))
hosts.sort()
return hosts
def ceph_version():
"""Retrieve the local version of ceph."""
if os.path.exists('/usr/bin/ceph'):
@ -1293,6 +1317,7 @@ class CephBrokerRsp(object):
def exit_msg(self):
return self.rsp.get('stderr')
# Ceph Broker Conversation:
# If a charm needs an action to be taken by ceph it can create a CephBrokerRq
# and send that request to ceph via the ceph relation. The CephBrokerRq has a