Skip to content

Commit

Permalink
Add the veritas vg provisioner
Browse files Browse the repository at this point in the history
Example:

$ svcmgr -s testvgvtrs create

$ svcmgr -s testvgvtrs set \
  --kw disk#0.type=veritas \
  --kw disk#0.pvs=aluadisk_[01] \
  --kw name={svcname}

$ svcmgr -s testvgvtrs provision --local
node-10-1.testvgvtrs.disk#0      expand aluadisk_[01] to aluadisk_0, aluadisk_1
node-10-1.testvgvtrs.disk#0      /opt/VRTS/bin/vxdisksetup -i aluadisk_0
node-10-1.testvgvtrs.disk#0      /opt/VRTS/bin/vxdisksetup -i aluadisk_1
node-10-1.testvgvtrs.disk#0      vxdg init testvgvtrs aluadisk_0 aluadisk_1
node-10-1.testvgvtrs.disk#0      testvgvtrs is already up
node-10-1.testvgvtrs.disk#0      vxvol -g testvgvtrs -f startall

$ svcmgr -s testvgvtrs unprovision --local
node-10-1.testvgvtrs.disk#0      vxvol -g testvgvtrs -f stopall
node-10-1.testvgvtrs.disk#0      vxdg deport testvgvtrs
node-10-1.testvgvtrs.disk#0      /opt/VRTS/bin/vxdiskunsetup -f aluadisk_0
node-10-1.testvgvtrs.disk#0      /opt/VRTS/bin/vxdiskunsetup -f aluadisk_1
  • Loading branch information
cvaroqui committed Jun 11, 2018
1 parent 91577d2 commit 4e98bf2
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 5 deletions.
159 changes: 159 additions & 0 deletions lib/provDiskVeritas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
from __future__ import print_function

import os
import glob
import fnmatch
import re
from stat import *

from rcGlobalEnv import rcEnv
import provisioning
import rcExceptions as ex
from rcUtilities import justcall, lazy

class Prov(provisioning.Prov):
def __init__(self, r):
provisioning.Prov.__init__(self, r)

def is_provisioned(self):
return self.has_it()

def has_it(self):
cmd = ["vxdisk", "list"]
out, err, ret = justcall(cmd)
words = out.split()
if "(%s)" % self.r.name in words or \
" %s " % self.r.name in words:
return True
return False

def unprovisioner(self):
if not self.has_it():
return
if self.r.has_it():
self.destroy_vg()
self.unsetup()

def unsetup(self):
cmd = ["vxdisk", "list"]
out, err, ret = justcall(cmd)
for line in out.splitlines():
words = line.split()
if "(%s)" % self.r.name in words:
cmd = ["/opt/VRTS/bin/vxdiskunsetup", "-f", words[0]]
ret, out, err = self.r.vcall(cmd)
if ret != 0:
raise ex.excError

def destroy_vg(self):
cmd = ["vxdg", "destroy", self.r.name]
ret, out, err = self.r.vcall(cmd)
if ret != 0:
raise ex.excError
self.r.svc.node.unset_lazy("devtree")

def has_pv(self, pv):
cmd = ["vxdisk", "list", pv]
out, err, ret = justcall(cmd)
if ret != 0:
return False
for line in out.splitlines():
if line.startswith("group:"):
if "name=%s "%self.r.name in line:
self.r.log.info("pv %s is already a member of vg %s", pv, self.r.name)
return True
else:
vg = line.split("name=", 1)[0].split()[0]
raise ex.excError("pv %s in use by vg %s" % (pv, vg))
if line.startswith("flags:") and "invalid" in line:
return False
return False

@lazy
def vxdisks(self):
"""
Parse vxdisk list output.
Example:
# vxdisk list
DEVICE TYPE DISK GROUP STATUS
aluadisk_0 auto:cdsdisk aluadisk_0 osvcdg online
aluadisk_1 auto:cdsdisk aluadisk_1 osvcdg online
aluadisk_2 auto:none - - online invalid
"""
cmd = ["vxdisk", "list"]
out, err, ret = justcall(cmd)
data = []
for line in out.splitlines():
words = line.split()
if len(words) < 1:
continue
if words[0] == "DEVICE":
continue
data.append(words[0])
return data

def vxname_glob(self, pattern):
"""
Return the list of vxdisks matching the name globing pattern.
"""
return [name for name in self.vxdisks if fnmatch.fnmatch(name, pattern)]

def sysname_glob(self, pattern):
"""
Return the list of vxdisks matching the system devpath globing pattern.
"""
data = []
for devpath in glob.glob(pattern):
dev = self.node.devtree.get_dev_by_devpath(devpath)
if dev is None:
continue
data.append(dev.alias)
return data

def provisioner(self):
try:
self.pvs = self.r.svc.conf_get(self.r.rid, "pvs")
except ex.RequiredOptNotFound:
raise ex.excError

if self.pvs is None:
# lazy reference not resolvable
raise ex.excError("%s.pvs value is not valid" % self.r.rid)

self.pvs = self.pvs.split()
l = []
for pv in self.pvs:
if os.sep not in pv:
_l = self.vxname_glob(pv)
else:
_l = self.sysname_glob(pv)
if _l:
self.r.log.info("expand %s to %s" % (pv, ', '.join(_l)))
l += _l
self.pvs = l

if len(self.pvs) == 0:
raise ex.excError("no pvs specified")

for pv in self.pvs:
if self.has_pv(pv):
continue
cmd = ["/opt/VRTS/bin/vxdisksetup", "-i", pv]
ret, out, err = self.r.vcall(cmd)
if ret != 0:
raise ex.excError

if self.has_it():
self.r.log.info("vg %s already exists")
return

cmd = ["vxdg", "init", self.r.name] + self.pvs
ret, out, err = self.r.vcall(cmd)
if ret != 0:
raise ex.excError

self.r.can_rollback = True
self.r.svc.node.unset_lazy("devtree")
7 changes: 4 additions & 3 deletions lib/resDiskVgVeritas.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ def __init__(self,
self.label = "vg "+str(name)

def has_it(self):
"""Returns True if the vg is present
"""
Return True if the vg is present
"""
if not which("vxdg"):
raise ex.excError("vxdg command not found")
ret = qcall( [ 'vxdg', 'list', self.name ] )
ret = qcall(["vxdg", "list", self.name])
if ret == 0 :
return True
else:
Expand All @@ -37,7 +38,7 @@ def is_up(self):
return False
if not self.has_it():
return False
cmd = [ 'vxprint', '-ng', self.name ]
cmd = ["vxprint", "-ng", self.name]
ret = qcall(cmd)
if ret == 0 :
return True
Expand Down
4 changes: 2 additions & 2 deletions lib/svcdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -2764,7 +2764,7 @@ def __init__(self):
section="disk",
at=True,
keyword="layout",
rtype="md",
rtype=["md"],
provisioning=True,
text="The md raid layout to use with mdadm create command (see mdadm man for values)"
)
Expand Down Expand Up @@ -3031,7 +3031,7 @@ def __init__(self):
Keyword.__init__(
self,
section="disk",
rtype=["lvm", "vg"],
rtype=["lvm", "vg", "veritas"],
keyword="pvs",
required=True,
text="The list of paths to the physical volumes of the volume group.",
Expand Down
14 changes: 14 additions & 0 deletions usr/share/doc/template.service.disk.veritas.conf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@
#
;name = foo

#
# keyword: pvs
# ----------------------------------------------------------------------------
# scopable: False
# required: True
# provisioning: True
# default: None
# inheritance: leaf > head
# scope order: specific > generic
#
# desc: The list of paths to the physical volumes of the volume group.
#
;pvs = foo

#
# keyword: prkey
# ----------------------------------------------------------------------------
Expand Down

0 comments on commit 4e98bf2

Please sign in to comment.