Resync charmhelpers for py3 fixes.
Change-Id: I2bc5711c73c39b47400a7be923bc5bebc0a3307e
This commit is contained in:
parent
209341a601
commit
7459560a8a
@ -30,6 +30,7 @@ import yaml
|
|||||||
|
|
||||||
from charmhelpers.core.hookenv import (
|
from charmhelpers.core.hookenv import (
|
||||||
config,
|
config,
|
||||||
|
hook_name,
|
||||||
local_unit,
|
local_unit,
|
||||||
log,
|
log,
|
||||||
relation_ids,
|
relation_ids,
|
||||||
@ -302,7 +303,12 @@ class NRPE(object):
|
|||||||
"command": nrpecheck.command,
|
"command": nrpecheck.command,
|
||||||
}
|
}
|
||||||
|
|
||||||
service('restart', 'nagios-nrpe-server')
|
# update-status hooks are configured to firing every 5 minutes by
|
||||||
|
# default. When nagios-nrpe-server is restarted, the nagios server
|
||||||
|
# reports checks failing causing unneccessary alerts. Let's not restart
|
||||||
|
# on update-status hooks.
|
||||||
|
if not hook_name() == 'update-status':
|
||||||
|
service('restart', 'nagios-nrpe-server')
|
||||||
|
|
||||||
monitor_ids = relation_ids("local-monitors") + \
|
monitor_ids = relation_ids("local-monitors") + \
|
||||||
relation_ids("nrpe-external-master")
|
relation_ids("nrpe-external-master")
|
||||||
|
@ -628,6 +628,18 @@ class OpenStackAmuletUtils(AmuletUtils):
|
|||||||
_keypair = nova.keypairs.create(name=keypair_name)
|
_keypair = nova.keypairs.create(name=keypair_name)
|
||||||
return _keypair
|
return _keypair
|
||||||
|
|
||||||
|
def _get_cinder_obj_name(self, cinder_object):
|
||||||
|
"""Retrieve name of cinder object.
|
||||||
|
|
||||||
|
:param cinder_object: cinder snapshot or volume object
|
||||||
|
:returns: str cinder object name
|
||||||
|
"""
|
||||||
|
# v1 objects store name in 'display_name' attr but v2+ use 'name'
|
||||||
|
try:
|
||||||
|
return cinder_object.display_name
|
||||||
|
except AttributeError:
|
||||||
|
return cinder_object.name
|
||||||
|
|
||||||
def create_cinder_volume(self, cinder, vol_name="demo-vol", vol_size=1,
|
def create_cinder_volume(self, cinder, vol_name="demo-vol", vol_size=1,
|
||||||
img_id=None, src_vol_id=None, snap_id=None):
|
img_id=None, src_vol_id=None, snap_id=None):
|
||||||
"""Create cinder volume, optionally from a glance image, OR
|
"""Create cinder volume, optionally from a glance image, OR
|
||||||
@ -678,6 +690,13 @@ class OpenStackAmuletUtils(AmuletUtils):
|
|||||||
source_volid=src_vol_id,
|
source_volid=src_vol_id,
|
||||||
snapshot_id=snap_id)
|
snapshot_id=snap_id)
|
||||||
vol_id = vol_new.id
|
vol_id = vol_new.id
|
||||||
|
except TypeError:
|
||||||
|
vol_new = cinder.volumes.create(name=vol_name,
|
||||||
|
imageRef=img_id,
|
||||||
|
size=vol_size,
|
||||||
|
source_volid=src_vol_id,
|
||||||
|
snapshot_id=snap_id)
|
||||||
|
vol_id = vol_new.id
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = 'Failed to create volume: {}'.format(e)
|
msg = 'Failed to create volume: {}'.format(e)
|
||||||
amulet.raise_status(amulet.FAIL, msg=msg)
|
amulet.raise_status(amulet.FAIL, msg=msg)
|
||||||
@ -692,7 +711,7 @@ class OpenStackAmuletUtils(AmuletUtils):
|
|||||||
|
|
||||||
# Re-validate new volume
|
# Re-validate new volume
|
||||||
self.log.debug('Validating volume attributes...')
|
self.log.debug('Validating volume attributes...')
|
||||||
val_vol_name = cinder.volumes.get(vol_id).display_name
|
val_vol_name = self._get_cinder_obj_name(cinder.volumes.get(vol_id))
|
||||||
val_vol_boot = cinder.volumes.get(vol_id).bootable
|
val_vol_boot = cinder.volumes.get(vol_id).bootable
|
||||||
val_vol_stat = cinder.volumes.get(vol_id).status
|
val_vol_stat = cinder.volumes.get(vol_id).status
|
||||||
val_vol_size = cinder.volumes.get(vol_id).size
|
val_vol_size = cinder.volumes.get(vol_id).size
|
||||||
|
@ -853,15 +853,6 @@ class NeutronContext(OSContextGenerator):
|
|||||||
for pkgs in self.packages:
|
for pkgs in self.packages:
|
||||||
ensure_packages(pkgs)
|
ensure_packages(pkgs)
|
||||||
|
|
||||||
def _save_flag_file(self):
|
|
||||||
if self.network_manager == 'quantum':
|
|
||||||
_file = '/etc/nova/quantum_plugin.conf'
|
|
||||||
else:
|
|
||||||
_file = '/etc/nova/neutron_plugin.conf'
|
|
||||||
|
|
||||||
with open(_file, 'wb') as out:
|
|
||||||
out.write(self.plugin + '\n')
|
|
||||||
|
|
||||||
def ovs_ctxt(self):
|
def ovs_ctxt(self):
|
||||||
driver = neutron_plugin_attribute(self.plugin, 'driver',
|
driver = neutron_plugin_attribute(self.plugin, 'driver',
|
||||||
self.network_manager)
|
self.network_manager)
|
||||||
@ -1006,7 +997,6 @@ class NeutronContext(OSContextGenerator):
|
|||||||
flags = config_flags_parser(alchemy_flags)
|
flags = config_flags_parser(alchemy_flags)
|
||||||
ctxt['neutron_alchemy_flags'] = flags
|
ctxt['neutron_alchemy_flags'] = flags
|
||||||
|
|
||||||
self._save_flag_file()
|
|
||||||
return ctxt
|
return ctxt
|
||||||
|
|
||||||
|
|
||||||
|
@ -618,7 +618,7 @@ def save_script_rc(script_path="scripts/scriptrc", **env_vars):
|
|||||||
juju_rc_path = "%s/%s" % (charm_dir(), script_path)
|
juju_rc_path = "%s/%s" % (charm_dir(), script_path)
|
||||||
if not os.path.exists(os.path.dirname(juju_rc_path)):
|
if not os.path.exists(os.path.dirname(juju_rc_path)):
|
||||||
os.mkdir(os.path.dirname(juju_rc_path))
|
os.mkdir(os.path.dirname(juju_rc_path))
|
||||||
with open(juju_rc_path, 'wb') as rc_script:
|
with open(juju_rc_path, 'wt') as rc_script:
|
||||||
rc_script.write(
|
rc_script.write(
|
||||||
"#!/bin/bash\n")
|
"#!/bin/bash\n")
|
||||||
[rc_script.write('export %s=%s\n' % (u, p))
|
[rc_script.write('export %s=%s\n' % (u, p))
|
||||||
|
@ -22,6 +22,7 @@ from __future__ import print_function
|
|||||||
import copy
|
import copy
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
from collections import namedtuple
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
@ -1164,3 +1165,42 @@ def meter_info():
|
|||||||
"""Get the meter status information, if running in the meter-status-changed
|
"""Get the meter status information, if running in the meter-status-changed
|
||||||
hook."""
|
hook."""
|
||||||
return os.environ.get('JUJU_METER_INFO')
|
return os.environ.get('JUJU_METER_INFO')
|
||||||
|
|
||||||
|
|
||||||
|
def iter_units_for_relation_name(relation_name):
|
||||||
|
"""Iterate through all units in a relation
|
||||||
|
|
||||||
|
Generator that iterates through all the units in a relation and yields
|
||||||
|
a named tuple with rid and unit field names.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
data = [(u.rid, u.unit)
|
||||||
|
for u in iter_units_for_relation_name(relation_name)]
|
||||||
|
|
||||||
|
:param relation_name: string relation name
|
||||||
|
:yield: Named Tuple with rid and unit field names
|
||||||
|
"""
|
||||||
|
RelatedUnit = namedtuple('RelatedUnit', 'rid, unit')
|
||||||
|
for rid in relation_ids(relation_name):
|
||||||
|
for unit in related_units(rid):
|
||||||
|
yield RelatedUnit(rid, unit)
|
||||||
|
|
||||||
|
|
||||||
|
def ingress_address(rid=None, unit=None):
|
||||||
|
"""
|
||||||
|
Retrieve the ingress-address from a relation when available. Otherwise,
|
||||||
|
return the private-address. This function is to be used on the consuming
|
||||||
|
side of the relation.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
addresses = [ingress_address(rid=u.rid, unit=u.unit)
|
||||||
|
for u in iter_units_for_relation_name(relation_name)]
|
||||||
|
|
||||||
|
:param rid: string relation id
|
||||||
|
:param unit: string unit name
|
||||||
|
:side effect: calls relation_get
|
||||||
|
:return: string IP address
|
||||||
|
"""
|
||||||
|
settings = relation_get(rid=rid, unit=unit)
|
||||||
|
return (settings.get('ingress-address') or
|
||||||
|
settings.get('private-address'))
|
||||||
|
@ -628,6 +628,18 @@ class OpenStackAmuletUtils(AmuletUtils):
|
|||||||
_keypair = nova.keypairs.create(name=keypair_name)
|
_keypair = nova.keypairs.create(name=keypair_name)
|
||||||
return _keypair
|
return _keypair
|
||||||
|
|
||||||
|
def _get_cinder_obj_name(self, cinder_object):
|
||||||
|
"""Retrieve name of cinder object.
|
||||||
|
|
||||||
|
:param cinder_object: cinder snapshot or volume object
|
||||||
|
:returns: str cinder object name
|
||||||
|
"""
|
||||||
|
# v1 objects store name in 'display_name' attr but v2+ use 'name'
|
||||||
|
try:
|
||||||
|
return cinder_object.display_name
|
||||||
|
except AttributeError:
|
||||||
|
return cinder_object.name
|
||||||
|
|
||||||
def create_cinder_volume(self, cinder, vol_name="demo-vol", vol_size=1,
|
def create_cinder_volume(self, cinder, vol_name="demo-vol", vol_size=1,
|
||||||
img_id=None, src_vol_id=None, snap_id=None):
|
img_id=None, src_vol_id=None, snap_id=None):
|
||||||
"""Create cinder volume, optionally from a glance image, OR
|
"""Create cinder volume, optionally from a glance image, OR
|
||||||
@ -678,6 +690,13 @@ class OpenStackAmuletUtils(AmuletUtils):
|
|||||||
source_volid=src_vol_id,
|
source_volid=src_vol_id,
|
||||||
snapshot_id=snap_id)
|
snapshot_id=snap_id)
|
||||||
vol_id = vol_new.id
|
vol_id = vol_new.id
|
||||||
|
except TypeError:
|
||||||
|
vol_new = cinder.volumes.create(name=vol_name,
|
||||||
|
imageRef=img_id,
|
||||||
|
size=vol_size,
|
||||||
|
source_volid=src_vol_id,
|
||||||
|
snapshot_id=snap_id)
|
||||||
|
vol_id = vol_new.id
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = 'Failed to create volume: {}'.format(e)
|
msg = 'Failed to create volume: {}'.format(e)
|
||||||
amulet.raise_status(amulet.FAIL, msg=msg)
|
amulet.raise_status(amulet.FAIL, msg=msg)
|
||||||
@ -692,7 +711,7 @@ class OpenStackAmuletUtils(AmuletUtils):
|
|||||||
|
|
||||||
# Re-validate new volume
|
# Re-validate new volume
|
||||||
self.log.debug('Validating volume attributes...')
|
self.log.debug('Validating volume attributes...')
|
||||||
val_vol_name = cinder.volumes.get(vol_id).display_name
|
val_vol_name = self._get_cinder_obj_name(cinder.volumes.get(vol_id))
|
||||||
val_vol_boot = cinder.volumes.get(vol_id).bootable
|
val_vol_boot = cinder.volumes.get(vol_id).bootable
|
||||||
val_vol_stat = cinder.volumes.get(vol_id).status
|
val_vol_stat = cinder.volumes.get(vol_id).status
|
||||||
val_vol_size = cinder.volumes.get(vol_id).size
|
val_vol_size = cinder.volumes.get(vol_id).size
|
||||||
|
@ -22,6 +22,7 @@ from __future__ import print_function
|
|||||||
import copy
|
import copy
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
from collections import namedtuple
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
@ -1164,3 +1165,42 @@ def meter_info():
|
|||||||
"""Get the meter status information, if running in the meter-status-changed
|
"""Get the meter status information, if running in the meter-status-changed
|
||||||
hook."""
|
hook."""
|
||||||
return os.environ.get('JUJU_METER_INFO')
|
return os.environ.get('JUJU_METER_INFO')
|
||||||
|
|
||||||
|
|
||||||
|
def iter_units_for_relation_name(relation_name):
|
||||||
|
"""Iterate through all units in a relation
|
||||||
|
|
||||||
|
Generator that iterates through all the units in a relation and yields
|
||||||
|
a named tuple with rid and unit field names.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
data = [(u.rid, u.unit)
|
||||||
|
for u in iter_units_for_relation_name(relation_name)]
|
||||||
|
|
||||||
|
:param relation_name: string relation name
|
||||||
|
:yield: Named Tuple with rid and unit field names
|
||||||
|
"""
|
||||||
|
RelatedUnit = namedtuple('RelatedUnit', 'rid, unit')
|
||||||
|
for rid in relation_ids(relation_name):
|
||||||
|
for unit in related_units(rid):
|
||||||
|
yield RelatedUnit(rid, unit)
|
||||||
|
|
||||||
|
|
||||||
|
def ingress_address(rid=None, unit=None):
|
||||||
|
"""
|
||||||
|
Retrieve the ingress-address from a relation when available. Otherwise,
|
||||||
|
return the private-address. This function is to be used on the consuming
|
||||||
|
side of the relation.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
addresses = [ingress_address(rid=u.rid, unit=u.unit)
|
||||||
|
for u in iter_units_for_relation_name(relation_name)]
|
||||||
|
|
||||||
|
:param rid: string relation id
|
||||||
|
:param unit: string unit name
|
||||||
|
:side effect: calls relation_get
|
||||||
|
:return: string IP address
|
||||||
|
"""
|
||||||
|
settings = relation_get(rid=rid, unit=unit)
|
||||||
|
return (settings.get('ingress-address') or
|
||||||
|
settings.get('private-address'))
|
||||||
|
Loading…
Reference in New Issue
Block a user