def __init__(self,\ make_lvm_basedir="/home/root/bin/LVM/", \ make_lvm_executable="make_lvm",\ make_lvm_input_file_prefix="make_lvm.input_",\ verbose=False): """ TODO: Determine what you want to instantiate """ self.make_lvm_basedir = make_lvm_basedir self.make_lvm_executable = make_lvm_executable self.make_lvm_input_file_prefix = make_lvm_input_file_prefix self.verbose = verbose # Instantiate an amaxh object of am_aix_hostname self.amxh = am_aix_hostname.am_aix_sap_hostname() self.prefix = self.amxh.get_prefix() # e.g. s030 self.lvm_input_file_name = self.make_lvm_input_file_prefix + \ self.prefix self.lvm_input_file_path = self.make_lvm_basedir + \ self.lvm_input_file_name # Instantiate an amdisplay object self.amd = amdisplay.AmDisplay()
# # 24.09.2018 v 1.0.0/Fist version # # ---------------------------------------------------------------------------- # # ToDo: Further tasks # # ---------------------------------------------------------------------------- # #}}} import subprocess import sys sys.path.append("/usr/local/rootbin/Pythonlib/") import amdisplay amd = amdisplay.AmDisplay() def get_all_pv(): # {{{ """Returns a list of all PV names :returns: list: pv_name """ unix_cmd = ("/usr/sbin/lspv") p = subprocess.Popen(unix_cmd,\ shell=True, stdout=subprocess.PIPE,\ stderr=subprocess.STDOUT) rc = p.wait() pv_list = [] if rc != 0:
class Am_Aix_Lvm: # {{{ """General AIX LVM methods. Not to be confused iwth Am_Aix_Make_Lvm with is for make_lvm - is_aix_lvm - get_vgs - compile_vg_name - is_compiled_name_in_vg_list - is_lv - make_lvm """ def __init__(self): """General purpuse AMGI AIX LVM operations - is_aix_lvm() - get_vgs() - get_vgs_free - compile_vg_name(type="BASE") - is_mirror_pool() - mk_lvm() """ amd = amdisplay.AmDisplay() def is_aix_lvm(self, verbose=False): # {{{ """Checking to see if aixlvm is used: :returns: bool """ self.verbose = verbose unix_cmd = ("lsvg") if self.verbose == 2: print "Debugging:unix_cmd is:{}:".format(unix_cmd) # FOR Debugging p = subprocess.Popen(unix_cmd,\ shell=True, stdout=subprocess.PIPE,\ stderr=subprocess.STDOUT) rc = p.wait() # Unix_cmd has failed if rc != 0: return False # Unix_cmd executed successfully elif rc == 0: return True # }}} def get_vgs(self, verbose=False): # {{{ """Retrieving the list of VGs :returns: list: vgs_list or bool """ self.verbose = verbose vgs_list = [] unix_cmd = ("lsvg") if self.verbose == 2: print "Debugging:unix_cmd is:{}:".format(unix_cmd) # FOR Debugging p = subprocess.Popen(unix_cmd,\ shell=True, stdout=subprocess.PIPE,\ stderr=subprocess.STDOUT) rc = p.wait() # Unix_cmd has failed if rc != 0: return False # Unix_cmd executed successfully elif rc == 0: for line in p.stdout: vgs_list.append(line.strip()) return vgs_list # }}} def compile_vg_name(self, vg_type="BASE"): # {{{ """Compiling the VG name: e.g VGS055BASE or VGS055DBn :vg_type: str: BASE OR DB :returns: str: vg_name """ self.vg_type = vg_type # Checking if vg_type is BASE OR DB if ("BASE" not in self.vg_type) and ("DB" not in self.vg_type): self.amd.err_msg("Unsupported use case.",\ "Use only BASE or DB for volume groups",\ exit_code = 15) # Determining the cluster vg_type : S, I, G, H amh = am_aix_hostname.am_aix_hostname() cluster_type = amh.get_cluster_type() numerical_prefix = amh.get_numerical_prefix() vg_name = "VG" + \ cluster_type + \ numerical_prefix + \ self.vg_type return vg_name # }}} def is_compiled_name_in_vg_list(self, vg_type="BASE"): # {{{ """Determines if a compiled name is part of the existing vgs list :returns: bool """ self.vg_type = vg_type vg_list = self.get_vgs() compiled_vg_name = self.compile_vg_name(vg_type=self.vg_type) print vg_list print compiled_vg_name if compiled_vg_name in vg_list: return True else: return False # }}} def is_lv(self, lv_name, verbose=False): # {{{ """Check if lv exists :lv_name: The name of Logical Volume. e.g "lyceus" :returns: BOOL """ self.lv_name = lv_name self.verbose = verbose unix_cmd=("lslv"\ " {}"\ ).format(lv_name) if self.verbose == 2: print "Debugging:unix_cmd is:{}:".format(unix_cmd) # FOR Debugging p = subprocess.Popen(unix_cmd,\ shell=True, stdout=subprocess.PIPE,\ stderr=subprocess.STDOUT) rc = p.wait() # Unix_cmd has failed if rc != 0: # The LV does not exist return False # Unix_cmd executed successfully elif rc == 0: # The LV exists return True # }}} def is_fs(self, fs_path, verbose=False): # {{{ """Check if fs exists :fs_path: The path of the FS: e.g."/syslink/lyceus" :returns: BOOL """ self.fs_path = fs_path self.verbose = verbose unix_cmd=("lsfs"\ " {}"\ ).format(fs_path) if self.verbose == 2: print "Debugging:unix_cmd is:{}:".format(unix_cmd) # FOR Debugging p = subprocess.Popen(unix_cmd,\ shell=True, stdout=subprocess.PIPE,\ stderr=subprocess.STDOUT) rc = p.wait() # Unix_cmd has failed if rc != 0: # The LV does not exist return False # Unix_cmd executed successfully elif rc == 0: # The LV exists return True # }}} def is_fs_mounted(self, fs_path, verbose=False): # {{{ """Check if fs is mounted. :fs_path: The path of the FS: e.g."/syslink/lyceus" :returns: BOOL """ self.fs_path = fs_path self.verbose = verbose return os.path.ismount(fs_path) # }}} def mount_fs(self, fs_path, verbose=False): # {{{ """Check if fs is mounted. :fs_path: The path of the FS: e.g."/syslink/lyceus" :returns: BOOL """ self.fs_path = fs_path self.verbose = verbose unix_cmd=("/usr/sbin/mount "\ "{}"\ ).format(fs_path) if self.verbose == 2: print "Debugging:unix_cmd is:{}:".format(unix_cmd) # FOR Debugging p = subprocess.Popen(unix_cmd,\ shell=True, stdout=subprocess.PIPE,\ stderr=subprocess.STDOUT) rc = p.wait() # Unix_cmd has failed if rc != 0: return False # Unix_cmd executed successfully elif rc == 0: return True # }}} def umount_fs(self, fs_path, verbose=False): # {{{ """Check if fs is mounted. :fs_path: The path of the FS: e.g."/syslink/lyceus" :returns: BOOL """ self.fs_path = fs_path self.verbose = verbose unix_cmd=("/usr/sbin/umount "\ " -f "\ "{}"\ ).format(fs_path) if self.verbose == 2: print "Debugging:unix_cmd is:{}:".format(unix_cmd) # FOR Debugging p = subprocess.Popen(unix_cmd,\ shell=True, stdout=subprocess.PIPE,\ stderr=subprocess.STDOUT) rc = p.wait() # Unix_cmd has failed if rc != 0: return False # Unix_cmd executed successfully elif rc == 0: time.sleep(2) if verbose: self.amd.ok_msg("FS successfully unmounted:",\ fs_path) return True # }}} # Creating a LV# {{{ def mk_lvm(self, lv_name,\ fs_type="jfs2",\ copies=2,\ vg="rootvg",\ nr_lp=8,\ verbose = False): """Standard AIX mklv method :lv_name: The name of the Logical Volume. e.g. lyceus :fs_type: LV type. jfs2 default :copies: The nr. of PP allocated for each LP :vg: The VG where LV will be created. Default is root :nr_lp: Number of Logical Partitions to be created :returns: bool """ self.name = lv_name self.fs_type = fs_type self.copies = copies self.vg = vg self.nr_lp = nr_lp if not self.is_lv(lv_name): # create the lv # Unix CMD is # /usr/sbin/mklv -y 'lyceus' -t'jfs2' -c'2' rootvg 8 unix_cmd=("/usr/sbin/mklv "\ " -y {} "\ " -t {}"\ " -c {}"\ " {}"\ " {}"\ ).format(lv_name,\ fs_type,\ copies,\ vg,\ nr_lp) if verbose == 2: print "Debugging:unix_cmd is:{}:".format( unix_cmd) # FOR Debugging p = subprocess.Popen(unix_cmd,\ shell=True, stdout=subprocess.PIPE,\ stderr=subprocess.STDOUT) rc = p.wait() # Unix_cmd has failed if rc != 0: self.amd.err_msg("Unable to create Logical Volume",\ lv_name,\ call_admins = True, exit_code = 7) # Unix_cmd executed successfully elif rc == 0: self.amd.ok_msg("The LV:",\ lv_name,\ ": has been successfully created.") return True # LV exists: Nothing to do else: if verbose: self.amd.info_msg("The Logical Volume:",\ lv_name,\ ": exists. Nothing to do") # }}} # Creating a FS# {{{ def mk_fs(self, lv_name,\ mount_point,\ fs_type = "jfs2",\ agblksize = "4096", \ permissions = "rw", \ verbose = False): """Standard AIX mklv method :lv_name: The name of the Logical Volume. e.g. lyceus :mount_point: The FS name/mount_point. eg. /syslink/lyceus :fs_type: LV type. jfs2 default :agblksize: The block size, default 4096 :permissions: the FS premissions :returns: bool """ self.lv_name = lv_name # The name of the device -d self.fs_type = fs_type # The FS type: default = jfs2 self.mount_point = mount_point # The mountpoint of the FS self.permissions = permissions # FS permissions [ro|rw] if not self.is_fs(mount_point): # create the FS # UNIX CMD for FS creation # /usr/sbin/crfs -v jfs2 -d'lyceus' -m'/syslink/lyceus'\ # -A''`locale yesstr | awk -F: '{print $1}'`'' -p'r# {{{ # }}} unix_cmd=("/usr/sbin/crfs"\ " -d {}"\ " -v {} "\ " -m {}"\ " -p {}"\ " -a agblksize={}"\ ).format(lv_name,\ fs_type,\ mount_point,\ permissions,\ agblksize) if verbose: print "Debugging:unix_cmd is:{}:".format( unix_cmd) # FOR Debugging p = subprocess.Popen(unix_cmd,\ shell=True, stdout=subprocess.PIPE,\ stderr=subprocess.STDOUT) rc = p.wait() # Unix_cmd has failed if rc != 0: self.amd.err_msg("Unable to create the Filesystem",\ mount_point,\ call_admins = True, exit_code = 8) # Unix_cmd executed successfully elif rc == 0: self.amd.ok_msg("The Filesystem:",\ mount_point,\ ": has been successfully created.") try: self.mount_fs(mount_point) except Exception as e: amd.err_msg("Unable to mount the FS:",\ mount_point,\ call_admins = True,\ exit_code = 9) else: return True # FS exists: Nothing to do else: if verbose: self.amd.info_msg("The Filesystem:",\ mount_point,\ ": exists. Nothing to do") # }}} # Removing a FS# {{{ def rm_fs(self, mount_point,\ verbose = False): """Removing an AIX Filesystem :mount_point: The FS name/mount_point. eg. /syslink/lyceus :returns: bool """ self.mount_point = mount_point # The mountpoint of the FS # check if FS exists if self.is_fs(mount_point): # Check if the FS exists and it is mounted if self.is_fs_mounted(mount_point): if not self.umount_fs(mount_point, verbose=True): self.amd.err_msg("Unable to unmount FS:",\ mount_point,\ call_admins = True,\ exit_code = 10) # remove the FS # /usr/sbin/rmfs /syslink/lyceus unix_cmd=("/usr/sbin/rmfs"\ " -r "\ " {}"\ ).format(mount_point) if verbose == 2: print "Debugging:unix_cmd is:{}:".format( unix_cmd) # FOR Debugging p = subprocess.Popen(unix_cmd,\ shell=True, stdout=subprocess.PIPE,\ stderr=subprocess.STDOUT) rc = p.wait() # Unix_cmd has failed if rc != 0: self.amd.err_msg("Unable to remove the Filesystem",\ mount_point,\ call_admins = True, exit_code = 8) # Unix_cmd executed successfully elif rc == 0: self.amd.ok_msg("The Filesystem:",\ mount_point,\ ": has been successfully removed.") return True # Inexistent: Nothing to do else: if verbose: self.amd.info_msg("Inexistent Filesystem:",\ mount_point,": Nothing to do")