diff --git a/cts/haresources2cib.py.in b/cts/haresources2cib.py.in index 2dd5cbfdbc..29aa1f6bb4 100755 --- a/cts/haresources2cib.py.in +++ b/cts/haresources2cib.py.in @@ -1,186 +1,174 @@ #!@PYTHON@ '''haresources2cib.py.in, convert the haresources file of heartbeat 1.x to cib.xml for heartbeat 2.x ''' __copyright__=''' Author: Huang Zhen Copyright (C) 2005 International Business Machines ''' # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import sys,string import xml.dom.minidom def create_cib() : doc = xml.dom.minidom.Document() cib = doc.createElement("cib") doc.appendChild(cib) configuration = doc.createElement("configuration") cib.appendChild(configuration) crm_config = doc.createElement("crm_config") configuration.appendChild(crm_config) nvpair = doc.createElement("nvpair") crm_config.appendChild(nvpair) nvpair.setAttribute("id","transition_timeout") nvpair.setAttribute("name","transition_timeout") nvpair.setAttribute("value","120s") - nvpair = doc.createElement("nvpair") - crm_config.appendChild(nvpair) - nvpair.setAttribute("id","require_quorum") - nvpair.setAttribute("name","require_quorum") - nvpair.setAttribute("value","true") - nvpair = doc.createElement("nvpair") crm_config.appendChild(nvpair) nvpair.setAttribute("id","symmetric_cluster") nvpair.setAttribute("name","symmetric_cluster") nvpair.setAttribute("value","true") - - nvpair = doc.createElement("nvpair") - crm_config.appendChild(nvpair) - nvpair.setAttribute("id","suppress_cib_writes") - nvpair.setAttribute("name","suppress_cib_writes") - nvpair.setAttribute("value","true") nvpair = doc.createElement("nvpair") crm_config.appendChild(nvpair) nvpair.setAttribute("id","no_quorum_policy") nvpair.setAttribute("name","no_quorum_policy") nvpair.setAttribute("value","stop") configuration.appendChild(doc.createElement("nodes")) resources = doc.createElement("resources") configuration.appendChild(resources) constraints = doc.createElement("constraints") configuration.appendChild(constraints) status = doc.createElement("status") cib.appendChild(status) return doc, resources, constraints def cib_resource(doc,index, rsc): id, type, params = None, None, None if len(string.split(rsc,'.')) == 4 : - id = "IPaddr"+"_"+str(index) + id = "IPaddr_"+str(index) type = "IPaddr" params = [rsc] else : fields = string.split(rsc,"::") id = fields[0]+"_"+str(index) type = fields[0] params = fields[1:] resource = doc.createElement("resource") resource.setAttribute("id",id) resource.setAttribute("type",type) resource.setAttribute("class","heartbeat") resource.setAttribute("provider","heartbeat") if len(params) != 0: instance_attributes = doc.createElement("instance_attributes") resource.appendChild(instance_attributes) attributes = doc.createElement("attributes") instance_attributes.appendChild(attributes) index = 1 for param in params : nvpair = doc.createElement("nvpair") nvpair.setAttribute("name",str(index)) nvpair.setAttribute("value",str(param)) attributes.appendChild(nvpair) index += 1 return id, resource def cib_rsc_location(doc, id, node): rsc_location = doc.createElement("rsc_location") - rsc_location.setAttribute("id","run_"+id) + rsc_location.setAttribute("id","rsc_location_"+id) rsc_location.setAttribute("rsc",id) rule = doc.createElement("rule") - rule.setAttribute("id","pre_run_"+id) + rule.setAttribute("id","prefered_location_"+id) rule.setAttribute("score","100") rsc_location.appendChild(rule) expression = doc.createElement("expression") expression.setAttribute("attribute","#uname") expression.setAttribute("operation","eq") expression.setAttribute("value", node) rule.appendChild(expression) return rsc_location def cib_resource_group(doc, id): resource_group = doc.createElement("resource_group") resource_group.setAttribute("id",id) return resource_group def add_resource(cib,index,node,rsc): id,resource = cib_resource(cib[0],index,rsc) cib[1].appendChild(resource) rsc_location = cib_rsc_location(cib[0],id,node) cib[2].appendChild(rsc_location) def add_resource_group(cib,index,node,rscs): - groupid = "group"+str(index) + groupid = "group_"+str(index) resource_group = cib_resource_group(cib[0],groupid) cib[1].appendChild(resource_group) for rsc in rscs : rid,resource = cib_resource(cib[0],index,rsc) resource_group.appendChild(resource) index += 1 rsc_location = cib_rsc_location(cib[0],groupid,node) cib[2].appendChild(rsc_location) if __name__=="__main__" : cib = create_cib() resource_file = None if len(sys.argv) == 1 : resource_file = "/etc/ha.d/haresources" elif len(sys.argv) == 2 : resource_file = sys.argv[1] else : print "Usage: %s or %s resourcefile"%(sys.argv[0],sys.argv[0]) sys.exit(1) file = open(resource_file, "r") pre_line = "" id_index = 1 for line in file.readlines() : line = string.strip(line) if len (line) == 0 or line[0] == '#' : continue if line[-1] == '\\' : pre_line += line[:-1] + " " continue else : line = pre_line + line pre_line = "" fields = string.split(line) if len(fields) == 2 : add_resource(cib, id_index, fields[0], fields[1]) id_index += 1 elif len(fields) > 2 : add_resource_group(cib, id_index, fields[0], fields[1:]) id_index += len(fields) else : print "can not parse this line:"+line print cib[0].toprettyxml()