def resource_manage(argv, set_managed): if len(argv) == 0: usage.resource() sys.exit(1) for resource in argv: if not utils.does_exist("//primitive[@id='"+resource+"']"): print "Error: %s doesn't exist." % resource sys.exit(1) exists = utils.does_exist("//primitive[@id='"+resource+"']/meta_attributes/nvpair[@name='is-managed']") if set_managed and not exists: print "Error: %s is already managed" % resource sys.exit(1) elif not set_managed and exists: print "Error: %s is already unmanaged" % resource sys.exit(1) for resource in argv: if not set_managed: (output, retval) = utils.set_unmanaged(resource) if retval != 0: print "Error attempting to unmanage resource: %s" % output sys.exit(1) else: xpath = "//primitive[@id='"+resource+"']/meta_attributes/nvpair[@name='is-managed']" my_xml = utils.get_cib_xpath(xpath) utils.remove_from_cib(my_xml)
def resource_remove(resource_id, output = True): group = utils.get_cib_xpath('//resources/group/primitive[@id="'+resource_id+'"]/..') num_resources_in_group = 0 master = utils.get_cib_xpath('//resources/master/primitive[@id="'+resource_id+'"]/..') clone = utils.get_cib_xpath('//resources/clone/primitive[@id="'+resource_id+'"]/..') if not utils.does_exist('//resources/descendant::primitive[@id="'+resource_id+'"]'): if utils.does_exist('//resources/master[@id="'+resource_id+'"]'): return resource_master_remove([resource_id]) print "Error: Resource does not exist." sys.exit(1) if (group != ""): num_resources_in_group = len(parseString(group).documentElement.getElementsByTagName("primitive")) if (group == "" or num_resources_in_group > 1): if clone != "": args = ["cibadmin", "-o", "resources", "-D", "--xml-text", clone] elif master != "": args = ["cibadmin", "-o", "resources", "-D", "--xml-text", master] else: args = ["cibadmin", "-o", "resources", "-D", "--xpath", "//primitive[@id='"+resource_id+"']"] constraints = constraint.find_constraints_containing(resource_id) for c in constraints: if output == True: print "Removing Constraint - " + c constraint.constraint_rm([c]) if output == True: print "Deleting Resource - " + resource_id output,retVal = utils.run(args) if retVal != 0: print "Unable to remove resource: %s, it may still be referenced in constraints." % resource_id sys.exit(1) return False else: args = ["cibadmin", "-o", "resources", "-D", "--xml-text", group] if output == True: print "Deleting Resource (and group) - " + resource_id cmdoutput,retVal = utils.run(args) if retVal != 0: if output == True: print "ERROR: Unable to remove resource '%s' (do constraints exist?)" % (resource_id) return False # Only clean up resource if we're *not* using a file (otherwise we get a 60s timeout) if (not utils.usefile): args = ["crm_resource","-C","-r",resource_id] cmdoutput, retVal = utils.run(args) # We don't currently check output because the resource may have already been # properly cleaned up return True
def resource_remove(resource_id, output = True): group = utils.get_cib_xpath('//resources/group/primitive[@id="'+resource_id+'"]/..') num_resources_in_group = 0 if not utils.does_exist('//resources/descendant::primitive[@id="'+resource_id+'"]'): print "Error: Resource does not exist." sys.exit(1) if (group != ""): num_resources_in_group = len(parseString(group).documentElement.getElementsByTagName("primitive")) if (group == "" or num_resources_in_group > 1): args = ["cibadmin", "-o", "resources", "-D", "--xpath", "//primitive[@id='"+resource_id+"']"] if output == True: print "Deleting Resource - " + resource_id, output,retVal = utils.run(args) if retVal != 0: return False else: args = ["cibadmin", "-o", "resources", "-D", "--xml-text", group] if output == True: print "Deleting Resource (and group) - " + resource_id cmdoutput,retVal = utils.run(args) if retVal != 0: if output == True: print "ERROR: Unable to remove resource '%s' (do constraints exist?)" % (resource_id) return False args = ["crm_resource","-C","-r",resource_id] cmdoutput, retVal = utils.run(args) # We don't currently check output because the resource may have already been # properly cleaned up return True
def install(self, force=False): if does_exist(self.filepath) and not force: print(f"{self.filepath} exists") return False print(f"=====> running {self.command}") code = sub.call(self.command.split()) if code != 0: return False return True