summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/add_storage.py
diff options
context:
space:
mode:
authorJames Meyer <james.meyer@operamail.com>2012-08-27 20:04:54 (GMT)
committerJames Meyer <james.meyer@operamail.com>2012-08-27 20:04:54 (GMT)
commitd1759e01708595072a4f095ed4321066740d3687 (patch)
tree2dc2e97233a5ad1df1eac9d644cf1ba303842417 /abs/core/LinHES-system/add_storage.py
parent51e0b638f0d58e4e0507425b8512809208fbbaf8 (diff)
downloadlinhes_pkgbuild-d1759e01708595072a4f095ed4321066740d3687.zip
linhes_pkgbuild-d1759e01708595072a4f095ed4321066740d3687.tar.gz
linhes_pkgbuild-d1759e01708595072a4f095ed4321066740d3687.tar.bz2
LinHES-system: new features for add_storage.py
- now writes out conf files in /etc/storage.d for each disk that it adds. These files will be used to determine nfs & smb shares - enabled the autoadding of the disk to storage groups - added --double_myth. This option is used to find the third partiton of the install drive and treat it like any other storage auto_added. The one thing it does differently is that no format/reparition take place
Diffstat (limited to 'abs/core/LinHES-system/add_storage.py')
-rw-r--r--abs/core/LinHES-system/add_storage.py198
1 files changed, 159 insertions, 39 deletions
diff --git a/abs/core/LinHES-system/add_storage.py b/abs/core/LinHES-system/add_storage.py
index 28d679c..db0d9af 100644
--- a/abs/core/LinHES-system/add_storage.py
+++ b/abs/core/LinHES-system/add_storage.py
@@ -11,23 +11,24 @@ import pickle
import commands
import sys,os
import random, string
+import ConfigParser
from MythTV import MythDB, MythBE, Recorded, MythError
from socket import timeout, gethostname
-
-pickle_file="/usr/LH/etc/storage.pkl"
+storage_dir = "/etc/storage.d"
+pickle_file = "%s/storage.pkl" %storage_dir
SG_MAP={ 'Default' :'tv',
- 'LiveTV' :'live_tv',
+ 'LiveTV' :'tv/live',
'Videos' :'video',
- 'Trailers' :'video/trailers',
- 'Coverart' :'video/converart',
- 'Fanart' :'video/fanart',
- 'Banners' :'video/banners',
- 'Screenshots':'video/screenshots',
+ 'Trailers' :'video_stuff/trailers',
+ 'Coverart' :'video_stuff/converart',
+ 'Fanart' :'video_stuff/fanart',
+ 'Banners' :'video_stuff/banners',
+ 'Screenshots':'video_stuff/screenshots',
'DB Backups' :'db_backups'}
FS_LIST=[]
for key in SG_MAP.keys():
@@ -36,15 +37,19 @@ for key in SG_MAP.keys():
class disk_device:
- def __init__(self,device):
+ def __init__(self,device,storage_dir):
device_obj = bus.get_object("org.freedesktop.UDisks", device)
device_props = dbus.Interface(device_obj, dbus.PROPERTIES_IFACE)
+ self.storage_dir = storage_dir
+ self.top_mount_dir = "/storage"
+ self.config = ConfigParser.RawConfigParser()
self.fs_map = self.get_fsmap()
self.is_device = self.get_is_device(device_props)
self.vendor = self.get_vendor(device_props)
self.model = self.get_model(device_props)
- self.mount_path = self.get_mounts(device_props)
+ self.mmount = False
+ self.f = self.get_mounts(device_props)
self.is_mounted = self.get_is_mounted(device_props)
self.parition_size = self.get_partition_size(device_props)
@@ -57,7 +62,14 @@ class disk_device:
self.device_file_path = self.get_device_file_path(device_props)
self.block_partition="%s1" %self.block_path
self.in_use = self.get_in_use()
+ self.uuid=''
+ self.new_mount_point=''
+
+ def set_partition(self,partition):
+ self.block_partition = "%s3" %self.block_path
+ def set_mmount(self,flag):
+ self.mmount = flag
def get_is_device(self,device_props):
return device_props.Get('org.freedesktop.UDisks.Device', "DeviceIsDrive")
@@ -74,6 +86,11 @@ class disk_device:
def get_is_mounted(self,device_props):
return device_props.Get('org.freedesktop.UDisks.Device', "DeviceIsMounted")
+ def get_name(self):
+ filename="%s_%s" %(self.model.replace(' ',''),
+ self.serial_number.replace(' ',''))
+ return filename
+
def get_in_use(self):
in_use = False
for i in self.fs_map:
@@ -82,7 +99,6 @@ class disk_device:
break
return in_use
-
def get_partition_size(self,device_props):
return device_props.Get('org.freedesktop.UDisks.Device', "PartitionSize")
@@ -181,7 +197,7 @@ class disk_device:
if uuid == '':
print "Could not find a UUID for device: %s" %partition
sys.exit(1)
-
+ self.uuid = uuid.strip()
return uuid.strip()
def read_fstab(self):
@@ -211,13 +227,13 @@ class disk_device:
fstab=self.read_fstab()
#determine mount_path
- self.new_mount_point="/data/media/%s_%s" %(self.model.replace(' ',''),self.serial_number.replace(' ',''))
+ self.new_mount_point="%s/%s_%s" %(self.top_mount_dir,self.model.replace(' ',''),self.serial_number.replace(' ',''))
#determine options
new_options = self.find_options_type(fstab)[0]
#find blkid
- self.block_partition="%s1" %self.block_path
+ #self.block_partition="%s1" %self.block_path
uuid=self.find_uuid(self.block_partition)
#construct new line
@@ -260,25 +276,65 @@ class disk_device:
cmd="chmod -R 775 /%s" %self.new_mount_point
runcmd(cmd)
- def add_sg(self,DB,host,SG_MAP):
+ def add_sg(self,DB,host,SG_MAP,weight='0'):
print " Adding to storage groups"
+ sgweight=int(weight)
for key in SG_MAP.iterkeys():
#print key," : ", SG_MAP[key]
- #try:
- gn=key
- hn=host
- dn="%s/%s" %(self.new_mount_point,SG_MAP[key])
- #print dn
- #print gn
- #print hn
- with DB as c:
+ gn=key
+ hn=host
+ dn="%s/%s" %(self.new_mount_point,SG_MAP[key])
+ #print dn
+ #print gn
+ #print hn
+ with DB as c:
+ try:
+ c.execute("""insert into storagegroup (groupname,hostname,dirname) values (%s,%s,%s)""",(gn,hn,dn))
+ print " Adding location: %s to storagegroup %s" %(dn,gn)
+ except:
+ print " *Error inserting %s into storage groups" %dn
+
+ if sgweight > 0:
try:
- c.execute("""insert into storagegroup (groupname,hostname,dirname) values (%s,%s,%s)""",(gn,hn,dn))
- print " Adding location: %s to storagegroup %s" %(dn,gn)
+ #("SGweightPerDir:server2:/mnt/video", 99, "server2");
+ sgw="SGweightPerDir:%s:%s" %(hn,dn)
+ #print sgw
+ #print sgweight
+ #print hn
+
+ c.execute("""insert into settings (value,data,hostname) values (%s,%s,%s)""",(sgw,sgweight,hn))
+ print " Adding storage group weight of %s for %s\n" %(sgweight,gn)
except:
- print " Error inserting %s into storage groups" %dn
+ print " *Error setting storage group weight %s for %s\n" %(sgweight,gn)
+
+ return
+
+ def write_config(self):
+ print " Writing out storage.d conf file"
+ self.config.add_section('storage')
+ self.config.set('storage','uuid',self.uuid)
+ self.config.set('storage','mountpoint',self.new_mount_point)
+ self.config.set('storage','shareable','True')
+ self.config.set('storage','mmount',self.mmount)
+
+
+ filename="%s_%s.conf" %(self.model.replace(' ',''),
+ self.serial_number.replace(' ',''))
+
+ configfile="/etc/storage.d/%s" %filename
+ print " %s" %configfile
+ with open(configfile, 'wb') as configfile:
+ self.config.write(configfile)
return
+ def symlink(self):
+ print " Creating symlink"
+ cmd = "ln -s %s %s/myth " %(self.new_mount_point, self.top_mount_dir)
+ runcmd(cmd)
+
+
+
+#end of class
def runcmd(cmd):
@@ -300,7 +356,7 @@ def scan_system():
ud_manager = dbus.Interface(ud_manager_obj, 'org.freedesktop.UDisks')
current_drive_list=[]
for dev in ud_manager.EnumerateDevices():
- drive = disk_device(dev)
+ drive = disk_device(dev,storage_dir)
if drive.is_device and drive.device_size > 5000 and not drive.is_optical :
current_drive_list.append(drive)
@@ -333,7 +389,7 @@ def search_for_match(system_drive,known_drive_list):
y_drive_hash = "%s_%s_%s" %(y.model,y.parition_size,y.device_file_path)
if system_drive_hash == y_drive_hash :
match_drive = True
- print "No serial number was found, matched using hash method: %s" %system_drive.model
+ print "\n* No serial number was found, matched using hash method: %s" %system_drive.model
break
elif y.serial_number == system_drive.serial_number:
@@ -347,7 +403,7 @@ def search_for_match(system_drive,known_drive_list):
def prompt_to_add(current_drive):
loop = True
while loop:
- str1 = raw_input(" Adding the drive will remove all contents on the drive. \n\nDo you wish enable this drive for MythTV storage(Y/N)?:")
+ str1 = raw_input("\n Adding the drive will remove all contents on the drive. \n Do you wish enable this drive for MythTV storage(Y/N)?:")
if str1 in ['Y','N','y','n']:
loop = False
@@ -361,8 +417,7 @@ def prompt_to_add(current_drive):
def remove_pickle():
try:
- print "Resetting list of known drives."
-
+ print "* Resetting list of known drives."
os.remove(pickle_file)
except:
pass
@@ -390,23 +445,27 @@ def main(scan_only):
#print "--"
if search_for_match(i,known_drive_list) or i.in_use :
- print " Storage is already in use or previously skipped: %s location: %s size: %s" %(i.model,i.block_path,i.device_size)
+ print "\n"
+ print " Storage is already in use or previously skipped:%s" %i.model
+ print " location: %s" %i.block_path
+ print " size: %s" %i.device_size
continue
else:
- print "\n"
if not scan_only:
print "\n"
print "-------------------------------------------------------------"
-
- print "Found new hard drive: %s location: %s size: %s \n" %(i.model,i.block_path,i.device_size)
+ print " Found new hard drive: %s" %i.model
+ print " location: %s" %i.block_path
+ print " size: %s " %i.device_size
if prompt_to_add(i) :
- print "\nDisk will be added to the storage pool!"
+ print "\n Disk will be added to the storage pool!"
process_list.append(i)
else:
process_list.append(i)
-
+ print " End of scan"
+ print "---------------------------------------"
if scan_only:
if len(process_list) > 0:
f = open('/tmp/scan_report', 'w')
@@ -427,20 +486,78 @@ def main(scan_only):
#save new list to disk_device
write_known_drive_list(system_drive_list)
-
+ if len(process_list) > 0:
+ print "\n Adding storage: \n"
for i in process_list:
+ print " Drive: %s" %(i.get_name())
i.partition_disk()
i.format_disk()
i.add_fstab()
i.mount_disk()
i.mkdirs(FS_LIST)
+ i.write_config()
i.add_sg(DB,host,SG_MAP)
+ print "-----"
+
+ #i.add_sg(DB,host,SG_MAP)
+
+def myth_main():
+ global bus
+ bus = dbus.SystemBus()
+ #search for root
+ f = open('/etc/fstab', 'r')
+ fstab=f.readlines()
+ f.close()
+ for i in fstab:
+ split_line=i.split()
+ if not split_line:
+ continue
+
+ try:
+ if split_line[1] == "/" :
+ uuid_device = split_line[0]
+ break
+ except:
+ print "Couldn't find / in fstab"
+ sys.exit(1)
+ if uuid_device.startswith("UUID"):
+ uuid_device = uuid_device.split("=")[1]
+ cmd = "blkid -U %s" %uuid_device
+ device = runcmd(cmd)[1]
+ else:
+ device = uuid_device.strip()
+ #should have something like /dev/sda1
+ #remove all the digits
+ device = ''.join([letter for letter in device if not letter.isdigit()])
+
+
+ system_drive_list = scan_system()
+ for i in system_drive_list:
+ if i.block_path == device:
+ break
+ else:
+ print "Could'nt find root device in block list"
+ sys.exit(1)
+
+ DB = MythDB()
+ host=gethostname()
+
+ print " Drive: %s" %(i.get_name())
+ i.set_mmount(True)
+ i.set_partition("3")
+ i.add_fstab()
+ i.mount_disk()
+ i.write_config()
+ i.add_sg(DB,host,SG_MAP,'99')
+ i.symlink()
+
if __name__ == "__main__":
scan_only = False
+ myth_mount = False
try:
os.remove("/tmp/scan_report")
except:
@@ -455,7 +572,10 @@ if __name__ == "__main__":
if "--report" in sys.argv :
scan_only = True
- main(scan_only)
+ if "--double_myth" in sys.argv:
+ myth_main()
+ else:
+ main(scan_only)