Crushmap Update Action
This action takes a json definition of a crushmap and applies it. Change-Id: Icaabc89016be22aa16d2f813a746842fd30fd989
This commit is contained in:
parent
79e7fccf08
commit
4829591648
12
actions.yaml
12
actions.yaml
|
@ -214,3 +214,15 @@ pool-get:
|
|||
description: Any valid Ceph key from http://docs.ceph.com/docs/master/rados/operations/pools/#get-pool-values
|
||||
required: [key, pool-name]
|
||||
additionalProperties: false
|
||||
crushmap-update:
|
||||
description: |
|
||||
Apply a json crushmap definition. This will throw away the existing
|
||||
ceph crushmap and apply the new definition. Use with extreme caution.
|
||||
WARNING - This function is extremely dangerous if misused. It can very
|
||||
easily break your cluster in unexpected ways.
|
||||
params:
|
||||
map:
|
||||
type: string
|
||||
description: The json crushmap blob
|
||||
required: [map]
|
||||
additionalProperties: false
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
crushmap-update.py
|
|
@ -0,0 +1,46 @@
|
|||
#!/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 base64
|
||||
from charmhelpers.core.hookenv import action_get, action_fail
|
||||
from subprocess import check_output, CalledProcessError, PIPE, Popen
|
||||
|
||||
|
||||
def update_crushmap():
|
||||
try:
|
||||
encoded_text = action_get("map")
|
||||
json_map = base64.b64decode(encoded_text)
|
||||
try:
|
||||
# This needs json_map passed to it from stdin
|
||||
crushtool = Popen(
|
||||
["crushtool", "-o", "compiled_crushmap", "-m", "compile"],
|
||||
stdin=PIPE)
|
||||
crushtool_stdout, crushtool_stderr = crushtool.communicate(
|
||||
input=json_map)
|
||||
if crushtool_stderr is not None:
|
||||
action_fail(
|
||||
"Failed to compile json: {}".format(crushtool_stderr))
|
||||
check_output(
|
||||
["ceph", "osd", "setcrushmap", "-i", "compiled_crushmap"])
|
||||
except (CalledProcessError, OSError) as err2:
|
||||
action_fail("Crush compile or load failed with error: {}".format(
|
||||
err2.output))
|
||||
except TypeError as err:
|
||||
action_fail(
|
||||
"Unable to base64 decode: {}. Error: {}".format(encoded_text, err))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
update_crushmap()
|
Loading…
Reference in New Issue