summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/add_storage.py
diff options
context:
space:
mode:
authorJames Meyer <james.meyer@operamail.com>2012-09-10 22:48:23 (GMT)
committerJames Meyer <james.meyer@operamail.com>2012-09-10 22:48:23 (GMT)
commit29864d1a0d4d8981a9f011e8768143daf3e6d72b (patch)
treea8c87fc76e358c4eec6f5a29a0206402fbd4f42e /abs/core/LinHES-system/add_storage.py
parent8fb41ba7d7f748b856bb015edef6c10c2b098e91 (diff)
downloadlinhes_pkgbuild-29864d1a0d4d8981a9f011e8768143daf3e6d72b.zip
linhes_pkgbuild-29864d1a0d4d8981a9f011e8768143daf3e6d72b.tar.gz
linhes_pkgbuild-29864d1a0d4d8981a9f011e8768143daf3e6d72b.tar.bz2
LinHES-system: add_storage.py new features
- add ability to reconstruct /etc/fstab and dir structure based off the contents of /etc/storage.d
Diffstat (limited to 'abs/core/LinHES-system/add_storage.py')
-rw-r--r--abs/core/LinHES-system/add_storage.py205
1 files changed, 193 insertions, 12 deletions
diff --git a/abs/core/LinHES-system/add_storage.py b/abs/core/LinHES-system/add_storage.py
index 260df2a..eec497f 100644
--- a/abs/core/LinHES-system/add_storage.py
+++ b/abs/core/LinHES-system/add_storage.py
@@ -12,6 +12,9 @@ import commands
import sys,os
import random, string
import ConfigParser
+from ConfigParser import SafeConfigParser
+import glob
+
from MythTV import MythDB, MythBE, Recorded, MythError
from socket import timeout, gethostname
@@ -71,6 +74,7 @@ class disk_device:
self.in_use = self.get_in_use()
self.uuid=''
self.new_mount_point=''
+ self.disk_num=''
def set_partition(self,partition):
self.block_partition = "%s%s" %(self.block_path,partition)
@@ -78,6 +82,9 @@ class disk_device:
def set_mmount(self,flag):
self.mmount = flag
+ def set_disk_num(self,num):
+ self.disk_num=num
+
def get_is_device(self,device_props):
return device_props.Get('org.freedesktop.UDisks.Device', "DeviceIsDrive")
@@ -174,7 +181,7 @@ class disk_device:
def find_fstype(self,moutpoint):
fstype="xfs"
- mp=['/myth', '/data/storage/disk0/media']
+ mp=['/myth', '/data/storage/disk0']
for i in self.fs_map:
if i[1] in mp:
fstype = i[2]
@@ -214,7 +221,7 @@ class disk_device:
return fstab
def find_options_type(self,fstab):
- mp=['/myth', '/data/storage/disk0/media']
+ mp=['/myth', '/data/storage/disk0']
for i in fstab:
split_line=i.split()
try:
@@ -239,6 +246,7 @@ class disk_device:
if bind:
new_fstab_list=["/data/storage/disk0" , self.new_mount_point , "none" , "rw,bind", '0', '0']
+ uuid=self.find_uuid(self.block_partition)
else:
#determine options
@@ -266,12 +274,12 @@ class disk_device:
f.close()
return
- def mount_disk(self,mount=True):
+ def mount_disk(self,no_mount=False):
try:
os.stat(self.new_mount_point)
except:
os.makedirs(self.new_mount_point)
- if mount == True:
+ if no_mount == False:
cmd = "mount %s" %self.new_mount_point
runcmd(cmd)
return
@@ -332,6 +340,7 @@ class disk_device:
self.config.set('storage','mountpoint',self.new_mount_point)
self.config.set('storage','shareable','True')
self.config.set('storage','mmount',self.mmount)
+ self.config.set('storage','disk_num',self.disk_num)
filename="%s_%s.conf" %(self.model.replace(' ',''),
@@ -343,13 +352,16 @@ class disk_device:
self.config.write(configfile)
return
+ def symlink_disk(self):
+ print " Creating symlink for disk number"
+ disk_ln="%s/disk%s" %(self.top_mount_dir,self.disk_num)
+ cmd = "ln -s %s %s" %(self.new_mount_point,disk_ln)
+ print cmd
+ runcmd(cmd)
+
def symlink(self):
pass
print " Creating symlink"
- #cmd = "ln -s %s %s/myth " %(self.new_mount_point, self.top_mount_dir)
- #runcmd(cmd)
- #cmd = "ln -s %s %s/disk0 " %(self.new_mount_point, self.top_mount_dir)
- #runcmd(cmd)
cmd = "ln -s %s/media /myth " %(self.new_mount_point)
runcmd(cmd)
@@ -460,7 +472,15 @@ def remove_pickle():
except:
pass
-
+def last_disk_num():
+ parser = SafeConfigParser()
+ num_list = []
+ for conf_file in glob.glob('%s/*.conf' %storage_dir):
+ parser.read(conf_file)
+ disk_num = parser.get('storage', 'disk_num')
+ num_list.append(int(disk_num))
+ num_list.sort()
+ return num_list[-1]
#--------------------------------------------
def main(scan_only, destruction, no_mount, install_call , dir_fe_only):
@@ -523,12 +543,18 @@ def main(scan_only, destruction, no_mount, install_call , dir_fe_only):
#save new list to disk_device
- write_known_drive_list(system_drive_list)
+ #write_known_drive_list(system_drive_list)
+ #disk_num = last_disk_num()
+
+
if len(process_list) > 0:
print "\n Adding storage: \n"
if prompt_to_continue() == True:
+ write_known_drive_list(system_drive_list)
+ disk_num = last_disk_num()
for i in process_list:
print " Drive: %s" %(i.get_name())
+ disk_num = disk_num + 1
if destruction == True:
i.partition_disk()
i.format_disk()
@@ -538,8 +564,10 @@ def main(scan_only, destruction, no_mount, install_call , dir_fe_only):
if dir_fe_only != True:
i.mkdirs(FS_LIST_BE)
i.mkdirs(FS_LIST_FE)
+ i.set_disk_num(disk_num)
i.write_config()
+ i.symlink_disk()
#always create the FE groups(video)..do not need to create Be
if dir_fe_only != True:
i.add_sg(DB,host,SG_MAP_BE)
@@ -600,6 +628,7 @@ def myth_main(no_mount,install_call,dir_fe_only):
print " Drive: %s" %(i.get_name())
i.set_mmount(True)
i.set_partition("7")
+ i.set_disk_num(0)
i.add_fstab(True)
#if not install_call:
i.mount_disk(no_mount)
@@ -612,6 +641,155 @@ def myth_main(no_mount,install_call,dir_fe_only):
i.symlink()
+class reconstruct_path:
+ def __init__(self,conf_file):
+ self.conf_file = conf_file
+ parser = SafeConfigParser()
+ parser.read(self.conf_file)
+
+
+ self.uuid = parser.get('storage', 'uuid')
+ self.mount_point = parser.get('storage', 'mountpoint')
+ self.shareable = parser.get('storage', 'shareable')
+ self.myth_mount = parser.get('storage', 'mmount')
+ self.bind = self.myth_mount
+ self.disk_num = parser.get('storage', 'disk_num')
+ self.top_mount_dir = os.path.dirname(self.mount_point)
+
+ def get_conf(self):
+ return self.conf_file
+
+ def get_uuid(self):
+ return self.uuid
+
+ def get_mount_point(self):
+ return self.mount_point
+
+ def get_shareable(self):
+ return self.shareable
+
+ def get_is_myth_mount(self):
+ return self.myth_mount
+
+ def get_disk_num(self):
+ return self.disk_num
+
+ def create_mount_point(self):
+ try:
+ os.stat(self.mount_point)
+ except:
+ os.makedirs(self.mount_point)
+
+ def find_options_type(self,fstab):
+ mp=['/myth', '/data/storage/disk0']
+ for i in fstab:
+ split_line=i.split()
+ try:
+ if split_line[1] in mp:
+ options = split_line[3]
+ break
+ else:
+ options = "defaults"
+ mount_point = i
+ except:
+ options = "defaults"
+ return options,i
+
+ def read_fstab(self):
+ f = open('/etc/fstab', 'r')
+ fstab=f.readlines()
+ f.close()
+ return fstab
+
+ def check_in_fstab(self,fstab,check_path):
+
+ for line in fstab:
+ if line.find(check_path) > -1:
+ return True
+ return False
+
+ def append_fstab(self,line):
+ new_fstab_line='\t'.join(line)
+ new_fstab_line="%s\n" %new_fstab_line
+
+ f = open('/etc/fstab', 'a')
+ #f = open('/tmp/fstab', 'a')
+ f.write(new_fstab_line)
+ f.write("\n")
+ f.close()
+
+ def symlink(self):
+ print " Creating symlink"
+ if not os.path.exists("/myth"):
+ cmd = "ln -s %s/media /myth " %(self.mount_point)
+ runcmd(cmd)
+ else:
+ print " Skipping symlink, path already present"
+
+ def symlink_disk(self):
+ print " Creating symlink for disk number"
+ disk_ln="%s/disk%s" %(self.top_mount_dir,self.disk_num)
+ cmd = "ln -s %s %s" %(self.mount_point,disk_ln)
+ runcmd(cmd)
+
+
+ def add_fstab(self):
+ new_fstab_list=['UUID=', 'mount_point', 'auto', 'defaults', '0', '1']
+ fstab=self.read_fstab()
+
+ if self.bind == "True":
+ self.symlink()
+
+ if self.check_in_fstab(fstab,self.uuid) == True:
+ print " Found storage in fstab, will not add it"
+ else:
+ print " Adding storage to fstab"
+ if self.bind == "True" :
+ print " Bind mount"
+ new_fstab_list=["/data/storage/disk0" , self.mount_point , "none" , "rw,bind", '0', '0']
+ if self.check_in_fstab(fstab,self.mount_point) == False:
+ self.append_fstab(new_fstab_list)
+ else:
+ print " Found bind storage in fstab, will not add it"
+
+ else:
+ #construct new line
+ new_options = self.find_options_type(fstab)[0]
+ new_fstab_list[0]="UUID=%s" %self.uuid
+ new_fstab_list[1]=self.mount_point
+ new_fstab_list[3]=new_options
+ self.append_fstab(new_fstab_list)
+
+ def mount_disk(self,no_mount=False):
+ try:
+ os.stat(self.mount_point)
+ except:
+ os.makedirs(self.mount_point)
+ if no_mount == False :
+ cmd = "mount %s" %self.mount_point
+ runcmd(cmd)
+ return
+
+def reconstruct_mounts(no_mount):
+ print "Recreating devices based on contents of /etc/storage.d"
+ for conf_file in glob.glob('%s/*.conf' %storage_dir):
+ print "\n"
+ cf = reconstruct_path(conf_file)
+
+ #print cf.get_conf()
+ #print cf.get_uuid()
+ print " %s" %cf.get_mount_point()
+ #print cf.get_shareable()
+ #print cf.get_is_myth_mount()
+ #print cf.get_disk_num()
+
+ cf.create_mount_point()
+ cf.add_fstab()
+ cf.symlink_disk()
+ cf.mount_disk(no_mount)
+
+ pass
+
def usage():
help='''\n
@@ -647,7 +825,7 @@ if __name__ == "__main__":
destruction = True
install_call = False
dir_fe_only = False
-
+ reconstruct = False
try:
os.remove("/tmp/scan_report")
except:
@@ -677,10 +855,13 @@ if __name__ == "__main__":
if "--fe_only" in sys.argv:
dir_fe_only = True
-
+ if "--reconstruct" in sys.argv:
+ reconstruct = True
if "--double_myth" in sys.argv:
myth_main(no_mount,install_call,dir_fe_only)
+ elif reconstruct == True:
+ reconstruct_mounts(no_mount)
else:
main(scan_only,destruction,no_mount, install_call, dir_fe_only)