Skip to content

Commit

Permalink
Dev: ui_resource: Add warning if detect maintenance-mode is true whil…
Browse files Browse the repository at this point in the history
…e start/stop/add RA
  • Loading branch information
liangxin1300 committed Aug 6, 2021
1 parent 18f9a8c commit 90a3b6b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions crmsh/ui_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ def _commit_meta_attrs(self, context, resources, name, value):
for rsc in resources:
if not utils.is_name_sane(rsc):
return False
if not xmlutil.RscState().is_managed(rsc):
context.warning("Resource {} is unmanaged".format(rsc))
commit = not cib_factory.has_cib_changed()
if not commit:
context.info("Currently editing the CIB, changes will not be committed")
Expand Down
23 changes: 22 additions & 1 deletion crmsh/xmlutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,15 @@ def is_managed(self, ident):
attr = get_attr_value(self.prop_elem, "maintenance-mode")
if attr and is_xs_boolean_true(attr):
return False
# then check the rsc is-managed meta attribute
# then check if all nodes in maintenance
if all([is_node_in_maintenance(node) for node in listnodes()]):
return False
rsc_meta_node = get_rsc_meta_node(rsc_node)
# then check the rsc maintenance meta attribute
attr = get_attr_value(rsc_meta_node, "maintenance")
if attr and is_xs_boolean_true(attr):
return False
# then check the rsc is-managed meta attribute
attr = get_attr_value(rsc_meta_node, "is-managed")
if attr:
return is_xs_boolean_true(attr)
Expand Down Expand Up @@ -293,6 +300,20 @@ def can_delete(self, ident):
return not (self.is_running(ident) and not self.is_group(ident) and self.is_managed(ident))


def is_node_in_maintenance(node_name):
"""
Detect if node is in maintenance
"""
if node_name not in listnodes():
common_err("Node {} not exist".format(node_name))
return
cib = cibdump2elem("configuration")
node_entry = cib.xpath(".//*[@uname=\"{}\"]".format(node_name))[0]
attr_entry = get_child_nvset_node(node_entry, attr_set="instance_attributes")
attr = get_attr_value(attr_entry, "maintenance")
return is_xs_boolean_true(attr) if attr else False


def resources_xml():
return cibdump2elem("resources")

Expand Down

0 comments on commit 90a3b6b

Please sign in to comment.