+def set_node_options(gen, node, options):
+ if options.router:
+ node.setAttribute('router', '1')
+ if options.timeout:
+ gen.addElement(node, "timeout", get_option(options, 'timeout'))
+ if options.upcall:
+ default_upcall = get_option(options, 'upcall')
+ else:
+ default_upcall = ''
+ if default_upcall or options.lustre_upcall:
+ if options.lustre_upcall:
+ gen.addElement(node, 'lustreUpcall', options.lustre_upcall)
+ else:
+ gen.addElement(node, 'lustreUpcall', default_upcall)
+ if default_upcall or options.portals_upcall:
+ if options.portals_upcall:
+ gen.addElement(node, 'portalsUpcall', options.portals_upcall)
+ else:
+ gen.addElement(node, 'portalsUpcall', default_upcall)
+ if options.ptldebug:
+ gen.addElement(node, "ptldebug", get_option(options, 'ptldebug'))
+ if options.subsystem:
+ gen.addElement(node, "subsystem", get_option(options, 'subsystem'))
+ return node
+
+def do_add_node(gen, lustre, options, node_name):
+ uuid = new_uuid(node_name)
+ prof_name = new_name("PROFILE_" + node_name)
+ prof_uuid = new_uuid(prof_name)
+ profile = gen.profile(prof_name, prof_uuid)
+ node = gen.node(node_name, uuid, prof_uuid)
+ lustre.appendChild(node)
+ lustre.appendChild(profile)
+
+ node_add_profile(gen, node, 'ldlm', ldlm_uuid)
+ set_node_options(gen, node, options)
+
+ return node
+
+
+def add_node(gen, lustre, options):
+ """ create a node with a network config """
+
+ node_name = get_option(options, 'node')
+ ret = findByName(lustre, node_name, "node")
+ if ret:
+ print "Node:", node_name, "exists."
+ return
+ do_add_node(gen, lustre, options, node_name)
+
+
+def add_net(gen, lustre, options):
+ """ create a node with a network config """
+
+ node_name = get_option(options, 'node')
+ nid = get_option(options, 'nid')
+ cluster_id = get_option(options, 'cluster_id')
+ hostaddr = get_option(options, 'hostaddr')
+ net_type = get_option(options, 'nettype')
+
+ if net_type in ('tcp',):
+ port = get_option_int(options, 'port')
+ tcpbuf = get_option_int(options, 'tcpbuf')
+ irq_aff = get_option_int(options, 'irq_affinity')
+ elif net_type in ('elan', 'gm'):
+ port = 0
+ tcpbuf = 0
+ irq_aff = 0
+ else:
+ print "Unknown net_type: ", net_type
+ sys.exit(2)
+
+ ret = findByName(lustre, node_name, "node")
+ if not ret:
+ node = do_add_node(gen, lustre, options, node_name)
+ else:
+ node = ret
+ set_node_options(gen, node, options)
+
+ net_name = new_name('NET_'+ node_name +'_'+ net_type)
+ net_uuid = new_uuid(net_name)
+ node.appendChild(gen.network(net_name, net_uuid, nid, cluster_id, net_type,
+ hostaddr, port, tcpbuf, irq_aff))
+ node_add_profile(gen, node, "network", net_uuid)
+
+
+def add_route(gen, lustre, options):
+ """ create a node with a network config """
+
+ node_name = get_option(options, 'node')
+ gw_net_type = get_option(options, 'nettype')
+ gw = get_option(options, 'gw')
+ gw_cluster_id = get_option(options, 'gateway_cluster_id')
+ tgt_cluster_id = get_option(options, 'target_cluster_id')
+ lo = get_option(options, 'lo')
+ hi = get_option(options, 'hi')
+ if not hi:
+ hi = lo
+
+ node = findByName(lustre, node_name, "node")
+ if not node:
+ error (node_name, " not found.")
+
+ rlist = node.getElementsByTagName('routetbl')
+ if len(rlist) > 0:
+ rtbl = rlist[0]
+ else:
+ rtbl_name = new_name("RTBL_" + node_name)
+ rtbl_uuid = new_uuid(rtbl_name)
+ rtbl = gen.routetbl(rtbl_name, rtbl_uuid)
+ node.appendChild(rtbl)
+ node_add_profile(gen, node, "routetbl", rtbl_uuid)
+ rtbl.appendChild(gen.route(gw_net_type, gw, gw_cluster_id, tgt_cluster_id,
+ lo, hi))
+
+
+def add_mds(gen, lustre, options):
+ node_name = get_option(options, 'node')
+ mds_name = get_option(options, 'mds')
+ lmv_name = get_option(options, 'lmv')
+ mdd_name = new_name("MDD_" + mds_name +"_" + node_name)
+ mdd_uuid = new_uuid(mdd_name)
+
+ lmv_uuid = ""
+ if lmv_name:
+ lmv = findByName(lustre, lmv_name, "lmv")
+ if not lmv:
+ error('add_mds:', '"' + lmv_name + '"', "lmv element not found.")
+ lmv_uuid = name2uuid(lustre, lmv_name, fatal=0)
+
+ mds_uuid = name2uuid(lustre, mds_name, 'mds', fatal=0)
+ if not mds_uuid:
+ mds_uuid = new_uuid(mds_name)
+ mds = gen.mds(mds_name, mds_uuid, mdd_uuid, options.group)
+ lustre.appendChild(mds)
+ if lmv_name:
+ lmv_add_obd(gen, lmv, mds_uuid)
+ else:
+ mds = lookup(lustre, mds_uuid)
+
+ if options.failover:
+ mds.setAttribute('failover', "1")
+
+ devname = get_option(options, 'dev')
+ backdevname = get_option(options, 'backdev')
+ size = get_option(options, 'size')
+ fstype = get_option(options, 'fstype')
+ backfstype = get_option(options, 'backfstype')
+ journal_size = get_option(options, 'journal_size')
+ inode_size = get_option(options, 'inode_size')
+ nspath = get_option(options, 'nspath')
+ mkfsoptions = get_option(options, 'mkfsoptions')
+ mountfsoptions = get_option(options, 'mountfsoptions')
+
+ node_uuid = name2uuid(lustre, node_name, 'node')
+
+ node = findByName(lustre, node_name, "node")
+ node_add_profile(gen, node, "mdsdev", mdd_uuid)
+ net_uuid = get_net_uuid(lustre, node_name)
+ if not net_uuid:
+ error("NODE: ", node_name, "not found")
+
+ if lmv_name:
+ mds.appendChild(gen.ref("lmv", lmv_uuid))
+
+ mdd = gen.mdsdev(mdd_name, mdd_uuid, fstype, devname,
+ get_format_flag(options), node_uuid, mds_uuid,
+ size, journal_size, inode_size, nspath, mkfsoptions,
+ mountfsoptions, backfstype, backdevname, lmv_uuid)
+ lustre.appendChild(mdd)
+
+
+def add_mgmt(gen, lustre, options):
+ node_name = get_option(options, 'node')
+ node_uuid = name2uuid(lustre, node_name, 'node')
+ mgmt_name = get_option(options, 'mgmt')
+ if not mgmt_name:
+ mgmt_name = new_name('MGMT_' + node_name)
+ mgmt_uuid = name2uuid(lustre, mgmt_name, 'mgmt', fatal=0)
+ if not mgmt_uuid:
+ mgmt_uuid = new_uuid(mgmt_name)
+ mgmt = gen.mgmt(mgmt_name, mgmt_uuid, node_uuid)
+ lustre.appendChild(mgmt)
+ else:
+ mgmt = lookup(lustre, mgmt_uuid)
+
+ node = findByName(lustre, node_name, "node")
+ node_add_profile(gen, node, 'mgmt', mgmt_uuid)
+
+def add_ost(gen, lustre, options):
+ node_name = get_option(options, 'node')
+ lovname = get_option(options, 'lov')
+ osdtype = get_option(options, 'osdtype')
+
+ node_uuid = name2uuid(lustre, node_name, 'node')
+
+ if osdtype == 'obdecho':
+ fstype = ''
+ backfstype = ''
+ devname = ''
+ backdevname = ''
+ size = 0
+ journal_size = ''
+ inode_size = ''
+ mkfsoptions = ''
+ mountfsoptions = ''
+ else:
+ devname = get_option(options, 'dev') # can be unset for bluearcs
+ backdevname = get_option(options, 'backdev')
+ size = get_option(options, 'size')
+ fstype = get_option(options, 'fstype')
+ backfstype = get_option(options, 'backfstype')
+ journal_size = get_option(options, 'journal_size')
+ inode_size = get_option(options, 'inode_size')
+ mkfsoptions = get_option(options, 'mkfsoptions')
+ mountfsoptions = get_option(options, 'mountfsoptions')
+
+ nspath = get_option(options, 'nspath')
+
+ ostname = get_option(options, 'ost')
+ if not ostname:
+ ostname = new_name('OST_'+ node_name)
+
+ osdname = new_name("OSD_" + ostname + "_" + node_name)
+ osd_uuid = new_uuid(osdname)
+
+ ost_uuid = name2uuid(lustre, ostname, 'ost', fatal=0)
+ if not ost_uuid:
+ ost_uuid = get_option(options, 'ostuuid')
+ if ost_uuid:
+ if lookup(lustre, ost_uuid):
+ error("Duplicate OST UUID:", ost_uuid)
+ else:
+ ost_uuid = new_uuid(ostname)
+
+ ost = gen.ost(ostname, ost_uuid, osd_uuid, options.group)
+ lustre.appendChild(ost)
+ else:
+ ost = lookup(lustre, ost_uuid)
+
+ if lovname:
+ lov = findByName(lustre, lovname, "lov")
+ if not lov:
+ error('add_ost:', '"'+lovname+'"', "lov element not found.")
+ lov_add_obd(gen, lustre, lov, ost_uuid, options)
+
+ if options.failover:
+ ost.setAttribute('failover', "1")
+
+
+ osd = gen.osd(osdname, osd_uuid, fstype, osdtype, devname,
+ get_format_flag(options), ost_uuid, node_uuid, size,
+ journal_size, inode_size, nspath, mkfsoptions,
+ mountfsoptions, backfstype, backdevname)
+
+ node = findByName(lustre, node_name, "node")
+
+## if node_add_profile(gen, node, 'oss', oss_uuid):
+## ossname = 'OSS'
+## oss_uuid = new_uuid(ossname)
+## oss = gen.oss(ossname, oss_uuid)
+## lustre.appendChild(oss)
+
+ node_add_profile(gen, node, 'osd', osd_uuid)
+ lustre.appendChild(osd)
+
+def del_ost(gen, lustre, options):
+ ostname = get_option(options, 'ost')
+ if not ostname:
+ raise OptionError("del_ost: --ost requires a <ost name>")
+ ost = findByName(lustre, ostname, "ost")
+ if not ost:
+ error('del_ost: ', 'Unable to find ', ostname)
+ ost_uuid = name2uuid(lustre, ostname, fatal=0)
+ if not ost_uuid:
+ error('del_ost: ', 'Unable to find uuid for ', ostname)
+ lovname = get_option(options, 'lov')
+ if lovname:
+ lov = findByName(lustre, lovname, "lov")
+ if not lov:
+ error('del_ost:', '"'+lovname+'"', "lov element not found.")
+ lov_del_obd(gen, lustre, lov, ost_uuid, options)
+ # if the user specified a speficic LOV don't delete the OST itself
+ return
+
+ # remove OSD references from all LOVs
+ for n in lustre.getElementsByTagName('lov'):
+ lov_del_obd(gen, lustre, n, ost_uuid, options)
+ if not options.migrate:
+ return
+ # delete the OSDs
+ for osd in lustre.getElementsByTagName('osd'):
+ if ref_exists(osd, ost_uuid):
+ osd_uuid = osd.getAttribute('uuid')
+ # delete all profile references to this OSD
+ for profile in lustre.getElementsByTagName('profile'):
+ for osd_ref in profile.getElementsByTagName('osd_ref'):
+ if osd_uuid == osd_ref.getAttribute('uuidref'):
+ profile.removeChild(osd_ref)
+ lustre.removeChild(osd)
+
+ # delete the OST
+ lustre.removeChild(ost)
+
+def add_cmobd(gen, lustre, options):
+ node_name = get_option(options, 'node')
+ name = get_option(options, 'cmobd')
+ uuid = new_uuid(name)
+
+ real_name = get_option(options, 'master_dev')
+ cache_name = get_option(options, 'cache_dev')
+
+ node = findByName(lustre, node_name, "node")
+ node_add_profile(gen, node, "cmobd", uuid)
+ real_uuid = node_found_target_by_dev(gen, lustre, node, real_name)
+ cache_uuid = node_found_target_by_dev(gen, lustre, node, cache_name)
+ if not real_uuid:
+ panic("add_cmobd", "can not find real_uuid")
+ if not cache_uuid:
+ panic("add_cmobd", "can not find cache_uuid")
+ cmobd = gen.cmobd(name, uuid, real_uuid, cache_uuid)
+ lustre.appendChild(cmobd)
+
+def add_cobd(gen, lustre, options):
+ node_name = get_option(options, 'node')
+ name = get_option(options, 'cobd')
+ uuid = new_uuid(name)
+
+ real_name = get_option(options, 'real_obd')
+ cache_name = get_option(options, 'cache_obd')
+
+ real_uuid = name2uuid(lustre, real_name, tag='lov', fatal=0)
+ cache_uuid = name2uuid(lustre, cache_name, tag='lov', fatal=0)
+
+ if real_uuid:
+ node = lookup(lustre, real_uuid)
+ rets = node.getElementsByTagName('lov_tgt')
+ for ret in rets:
+ ost_uuid = ret.getAttribute('uuidref')
+ ost_node = lookup(lustre, ost_uuid)
+ ret = ost_node.getElementsByTagName('active_ref')
+ if ret:
+ osd_uuid = ret[0].getAttribute('uuidref')
+ osd_node = lookup(lustre, osd_uuid)
+ gen.addElement(osd_node, 'cachetype', 'master')
+
+ if cache_uuid:
+ node = lookup(lustre, cache_uuid)
+ rets = node.getElementsByTagName('lov_tgt')
+ for ret in rets:
+ ost_uuid = ret.getAttribute('uuidref')
+ ost_node = lookup(lustre, ost_uuid)
+ ret = ost_node.getElementsByTagName('active_ref')
+ if ret:
+ osd_uuid = ret[0].getAttribute('uuidref')
+ osd_node = lookup(lustre, osd_uuid)
+ gen.addElement(osd_node, 'cachetype', 'cache')
+
+ if not real_uuid or not cache_uuid:
+ real_uuid = name2uuid(lustre,real_name, tag='mds')
+ cache_uuid = name2uuid(lustre,cache_name, tag='mds')
+ if real_uuid:
+ mds_node = lookup(lustre, real_uuid)
+ ret = mds_node.getElementsByTagName('active_ref')
+ if ret:
+ mdsdev_uuid = ret[0].getAttribute('uuidref')
+ mdsdev_node = lookup(lustre, mdsdev_uuid)
+ gen.addElement(mdsdev_node, 'cachetype', 'master')
+ if cache_uuid:
+ mds_node = lookup(lustre, cache_uuid)
+ ret = mds_node.getElementsByTagName('active_ref')
+ if ret:
+ mdsdev_uuid = ret[0].getAttribute('uuidref')
+ mdsdev_node = lookup(lustre, mdsdev_uuid)
+ gen.addElement(mdsdev_node, 'cachetype', 'cache')
+
+ node = findByName(lustre, node_name, "node")
+ cobd = gen.cobd(name, uuid, real_uuid, cache_uuid)
+ lustre.appendChild(cobd)
+
+
+def add_echo_client(gen, lustre, options):
+ """ add an echo client to the profile for this node. """
+ node_name = get_option(options, 'node')
+ lov_name = get_option(options, 'ost')
+
+ node = findByName(lustre, node_name, 'node')
+
+ echoname = new_name('ECHO_'+ node_name)
+ echo_uuid = new_uuid(echoname)
+ node_add_profile(gen, node, 'echoclient', echo_uuid)
+
+ lov_uuid = name2uuid(lustre, lov_name, tag='lov', fatal=0)
+ if not lov_uuid:
+ lov_uuid = name2uuid(lustre, lov_name, tag='ost', fatal=1)
+
+ echo = gen.echo_client(echoname, echo_uuid, lov_uuid)
+ lustre.appendChild(echo)
+
+
+def add_lov(gen, lustre, options):
+ """ create a lov """
+
+ lmv_name = get_option(options, 'lmv')
+ lov_orig = get_option(options, 'lov')
+ name = new_name(lov_orig)
+ if name != lov_orig:
+ warning("name:", lov_orig, "already used. using:", name)
+
+ mds_name = get_option(options, 'mds')
+ if not mds_name:
+ if not lmv_name:
+ error("LOV: MDS or LMV must be specified.");
+
+ stripe_sz = get_option_int(options, 'stripe_sz')
+ stripe_cnt = get_option_int(options, 'stripe_cnt')
+ pattern = get_option_int(options, 'stripe_pattern')
+ uuid = new_uuid(name)
+
+ ret = findByName(lustre, name, "lov")
+ if ret:
+ error("LOV: ", name, " already exists.")
+
+ if not mds_name:
+ mds_uuid = name2uuid(lustre, lmv_name, 'lmv')
+ else:
+ mds_uuid = name2uuid(lustre, mds_name, 'mds')
+
+ lov = gen.lov(name, uuid, mds_uuid, stripe_sz, stripe_cnt, pattern)
+ lustre.appendChild(lov)
+
+ # add an lovconfig entry to the active mdsdev profile
+ lovconfig_name = new_name('LVCFG_' + name)
+ lovconfig_uuid = new_uuid(lovconfig_name)
+ if mds_name:
+ mds = findByName(lustre, mds_name, "mds")
+ mds.appendChild(gen.ref("lovconfig", lovconfig_uuid))
+ if lmv_name:
+ lmv = findByName(lustre, lmv_name, "lmv")
+ lmv.appendChild(gen.ref("lovconfig", lovconfig_uuid))
+ lovconfig = gen.lovconfig(lovconfig_name, lovconfig_uuid, uuid)
+ lustre.appendChild(lovconfig)
+
+def add_default_lov(gen, lustre, mds_name, lov_name):
+ """ create a default lov """
+
+ stripe_sz = DEFAULT_STRIPE_SZ
+ stripe_cnt = DEFAULT_STRIPE_CNT
+ pattern = DEFAULT_STRIPE_PATTERN
+ uuid = new_uuid(lov_name)
+
+ ret = findByName(lustre, lov_name, "lov")
+ if ret:
+ error("LOV: ", lov_name, " already exists.")
+
+ mds_uuid = name2uuid(lustre, mds_name, 'mds')
+ lov = gen.lov(lov_name, uuid, mds_uuid, stripe_sz, stripe_cnt, pattern)
+ lustre.appendChild(lov)
+
+ # add an lovconfig entry to the active mdsdev profile
+ lovconfig_name = new_name('LVCFG_' + lov_name)
+ lovconfig_uuid = new_uuid(lovconfig_name)
+ mds = findByName(lustre, mds_name)
+ mds.appendChild(gen.ref("lovconfig", lovconfig_uuid))
+ lovconfig = gen.lovconfig(lovconfig_name, lovconfig_uuid, uuid)
+ lustre.appendChild(lovconfig)
+
+def add_lmv(gen, lustre, options):
+ """ create a lmv """
+
+ lmv_orig = get_option(options, 'lmv')
+ name = new_name(lmv_orig)
+ if name != lmv_orig:
+ warning("name:", lmv_orig, "already used. using:", name)
+
+ uuid = new_uuid(name)
+ ret = findByName(lustre, name, "lmv")
+ if ret:
+ error("LMV: ", name, " already exists.")
+
+ lmv = gen.lmv(name, uuid)
+ lustre.appendChild(lmv)
+
+def new_filesystem(gen, lustre, mds_uuid, obd_uuid, mgmt_uuid):
+ fs_name = new_name("FS_fsname")
+ fs_uuid = new_uuid(fs_name)
+ cobd = lookup(lustre, mds_uuid)
+ #SHOULD appendChild filesystem to real mds not cobd
+ ret = cobd.getElementsByTagName("cacheobd_ref")
+ if ret:
+ cacheobd_uuid = ret[0].getAttribute('uuidref')
+ cacheobd = lookup(lustre, cacheobd_uuid)
+ cacheobd.appendChild(gen.ref("filesystem", fs_uuid))
+ ret = cobd.getElementsByTagName("realobd_ref")
+ if ret:
+ realobd_uuid = ret[0].getAttribute('uuidref')
+ realobd = lookup(lustre, realobd_uuid)
+ realobd.appendChild(gen.ref("filesystem", fs_uuid))
+ else:
+ cobd.appendChild(gen.ref("filesystem", fs_uuid))
+ fs = gen.filesystem(fs_name, fs_uuid, mds_uuid, obd_uuid, mgmt_uuid)
+ lustre.appendChild(fs)
+ return fs_uuid
+
+def get_fs_uuid(gen, lustre, mds_name, obd_name, mgmt_name):
+ mds_uuid = name2uuid(lustre, mds_name, tag='mds', fatal=0)
+ if not mds_uuid:
+ mds_uuid = name2uuid(lustre, mds_name, tag='lmv', fatal=0)
+ if not mds_uuid:
+ mds_uuid = name2uuid(lustre, mds_name, tag='cobd', fatal=1)
+ obd_uuid = name2uuid(lustre, obd_name, tag='lov', fatal=0)
+ if obd_uuid == '':
+ obd_uuid = name2uuid(lustre, obd_name, tag='cobd')
+ if mgmt_name:
+ mgmt_uuid = name2uuid(lustre, mgmt_name, tag='mgmt', fatal=1)
+ else:
+ mgmt_uuid = ''
+ fs_uuid = lookup_filesystem(lustre, mds_uuid, obd_uuid)
+ if not fs_uuid:
+ fs_uuid = new_filesystem(gen, lustre, mds_uuid, obd_uuid, mgmt_uuid)
+ return fs_uuid
+
+def add_mtpt(gen, lustre, options):
+ """ create mtpt on a node """
+ node_name = get_option(options, 'node')
+
+ path = get_option(options, 'path')
+ clientoptions = get_option(options, "clientoptions")
+ fs_name = get_option(options, 'filesystem')
+
+ lov_name = get_option(options, 'lov')
+ ost_name = get_option(options, 'ost')
+ mds_name = get_option(options, 'mds')
+ if mds_name == '':
+ mds_name = get_option(options, 'lmv')
+ if mds_name == '':
+ error("--add mtpt requires either --mds or --lmv.")
+ if lov_name == '':
+ if ost_name == '':
+ error("--add mtpt requires --lov lov_name or --ost ost_name")
+ else:
+ warning("use default value for lov, due no --lov lov_name provided")
+ lov_name = new_name("lov_default")
+ add_default_lov(gen, lustre, mds_name, lov_name)
+ ost_uuid = name2uuid(lustre, ost_name, 'ost', fatal=0)
+ if not ost_uuid:
+ error('add_mtpt:', '"'+ost_name+'"', "ost element not found.")
+ lov = findByName(lustre, lov_name, "lov")
+ lov_add_obd(gen, lustre, lov, ost_uuid, options)
+
+ if fs_name == '':
+ mgmt_name = get_option(options, 'mgmt')
+ fs_uuid = get_fs_uuid(gen, lustre, mds_name, lov_name, mgmt_name)
+ else:
+ fs_uuid = name2uuid(lustre, fs_name, tag='filesystem')
+
+ name = new_name('MNT_'+ node_name)
+
+ ret = findByName(lustre, name, "mountpoint")
+ if ret:
+ # this can't happen, because new_name creates unique names
+ error("MOUNTPOINT: ", name, " already exists.")
+
+ uuid = new_uuid(name)
+ mtpt = gen.mountpoint(name, uuid, fs_uuid, path, clientoptions)
+ node = findByName(lustre, node_name, "node")
+ if not node:
+ error('node:', node_name, "not found.")
+ node_add_profile(gen, node, "mountpoint", uuid)
+ lustre.appendChild(mtpt)
+
+def commit_version(gen, lustre):
+ update = findLastUpdate(lustre)
+ if update:
+ version = int(update.getAttribute("version")) + 1
+ else:
+ version = 1
+
+ new = gen.update(str(version))
+ lustre.appendChild(new)
+
+
+############################################################