charm-cinder/actions/actions.py
Liam Young d21160a0d3 Add actions for renaming volume host attr
Add two new actions which are essentially wrappers around

cinder-manage volume update_host \
    --currenthost CURRENTHOST \
    --newhost NEWHOST

In previous versions of the charm if block-device is set or the
legacy ceph relation is used (as opposed to storage-backend relation)
then the configuration of those backends is done in the [DEFAULT]
section of the cinder.conf. As of Ocata that is no longer supported
and backends need to be listed in their own sections and referenced
via enable_backends parameter. This change in config results in a
change of host name and existing volumes need to have their metadata
updated to point at the new hostname.

Old Hostname: <unit-name>
New Hostname: <unit-name>@<backend section name>#<volume-backend-name>

New Action: volume-backend-name
Used for updating the host attribute of volumes to add the driver
name. This is needed after an upgrade to Ocata if there are existing
volumes which have been configured prior to multi-backends
being enabled.

New Action: rename-volume-host
Used for updating the host attribute of volumes. This action is
a lower level action then volume-host-add-driver and simply passes
the old and new hosts verbatim to cinder-manage.

Change-Id: I989074a3f41126aa57c514f7e18b887733bc18fe
Partial-Bug: #1665272
2017-02-22 09:48:08 +00:00

70 lines
1.8 KiB
Python
Executable File

#!/usr/bin/python
#
# Copyright 2016 Canonical Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
sys.path.append('hooks/')
from charmhelpers.core.hookenv import action_fail
from cinder_utils import (
pause_unit_helper,
resume_unit_helper,
register_configs,
)
import cinder_manage
def pause(args):
"""Pause the Ceilometer services.
@raises Exception should the service fail to stop.
"""
pause_unit_helper(register_configs())
def resume(args):
"""Resume the Ceilometer services.
@raises Exception should the service fail to start."""
resume_unit_helper(register_configs())
# A dictionary of all the defined actions to callables (which take
# parsed arguments).
ACTIONS = {
"pause": pause,
"resume": resume,
"remove-services": cinder_manage.remove_services,
"rename-volume-host": cinder_manage.rename_volume_host,
"volume-host-add-driver": cinder_manage.volume_host_add_driver,
}
def main(args):
action_name = os.path.basename(args[0])
try:
action = ACTIONS[action_name]
except KeyError:
return "Action %s undefined" % action_name
else:
try:
action(args)
except Exception as e:
action_fail(str(e))
if __name__ == "__main__":
sys.exit(main(sys.argv))