summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-config/mv_fileshare.py
diff options
context:
space:
mode:
authorJames Meyer <james.meyer@operamail.com>2012-09-20 21:10:42 (GMT)
committerJames Meyer <james.meyer@operamail.com>2012-09-20 21:10:42 (GMT)
commit24f531c22f8c07112d4d71ae37f6f65a85f6e815 (patch)
tree3c8b35fb1fc5dd3eada80b8ad2a7f32a5a253511 /abs/core/LinHES-config/mv_fileshare.py
parent269509031d79a1e0b455fa2ad2daeb8477ddc470 (diff)
downloadlinhes_pkgbuild-24f531c22f8c07112d4d71ae37f6f65a85f6e815.zip
linhes_pkgbuild-24f531c22f8c07112d4d71ae37f6f65a85f6e815.tar.gz
linhes_pkgbuild-24f531c22f8c07112d4d71ae37f6f65a85f6e815.tar.bz2
LinHES-config: write out /etc/exports for non-sg systems
Diffstat (limited to 'abs/core/LinHES-config/mv_fileshare.py')
-rwxr-xr-xabs/core/LinHES-config/mv_fileshare.py122
1 files changed, 103 insertions, 19 deletions
diff --git a/abs/core/LinHES-config/mv_fileshare.py b/abs/core/LinHES-config/mv_fileshare.py
index d8866c4..ebb53c7 100755
--- a/abs/core/LinHES-config/mv_fileshare.py
+++ b/abs/core/LinHES-config/mv_fileshare.py
@@ -2,10 +2,12 @@
import logging, os, re
import mv_common
import glob
+from urllib2 import Request, urlopen, URLError, HTTPError
#client side
def setup_nfs_client(systemconfig,data_config):
nfslist=[]
+ nfsmap_serverfile ="nfsmap"
logging.info("____Start of setup_nfs__client____")
scrubnfs(systemconfig.get("TEMPLATES"))
@@ -17,22 +19,28 @@ def setup_nfs_client(systemconfig,data_config):
if not os.path.exists(nfsmap_file):
logging.debug(" Couldn't find local %s",nfsmap_file)
logging.info(" Trying to download nfsmap from MBE")
- nfsmap_file = download_nfsmap(systemconfig.get("dbhost"))
+ nfsmap_file = download_nfsmap(systemconfig.get("dbhost"),nfsmap_serverfile)
nfslist = process_nfsmap_file(nfsmap_file)
+
# if it's an ip parse ip and download file
elif re.search(systemconfig.get("NFSserver"),":nfsmap"):
ip=systemconfig.get("NFSserver").split(":")[0]
- nfsmap_file = download_nfsmap(ip)
+ nfsmap_file = download_nfsmap(ip,nfsmap_serverfile)
nfslist = process_nfsmap_file(nfsmap_file)
#else treat it as a single mount point
else:
item = (systemconfig.get("NFSserver") , systemconfig["NFSmount"])
nfslist.append(item)
else:
- #if standalone or slave try to use MBE
+ #if frontend_only or slave try to use MBE nfs_map_auto
if systemconfig.get("SystemType") == "Frontend_only" or systemconfig["SystemType"] == "Slave_Backend":
- item = (systemconfig.get("dbhost")+":"+ data_config.DATAMOUNT, data_config.DATAMOUNT)
- nfslist.append(item)
+ logging.info(" Central NFS not found, trying to use MBE as nfs server")
+ nfsmap_serverfile = "nfsmap_auto"
+ ip=systemconfig.get("dbhost")
+ nfsmap_file = download_nfsmap(ip,nfsmap_serverfile)
+ nfslist = process_nfsmap_file(nfsmap_file)
+
+
setup_nfs_fstab(nfslist)
logging.info("__End of nfs\n")
@@ -61,10 +69,11 @@ def scrubnfs(templates):
cmd='''sed '/^#STARTSCRUB.*$/,/^#ENDSCRUB.*$/d' %s/fstab.conf.template > /etc/fstab''' %templates
mv_common.runcmd(cmd)
-def download_nfsmap(ip):
+def download_nfsmap(ip,nfsmap_serverfile):
nfsmap_file="/tmp/nfsmap"
- myurl="http://%s:1337/templates/nfsmap" %ip
+ myurl="http://%s:1337/templates/%s" %(ip,nfsmap_serverfile)
req = Request(myurl)
+
try:
f = urlopen(req)
logging.info(" downloading %s", myurl)
@@ -84,6 +93,15 @@ def download_nfsmap(ip):
return nfsmap_file
+def setup_nfs_mkdir(nfs_dirname):
+ logging.info(" Creating NFS mount point %s" , nfs_dirname)
+ try:
+ os.makedirs(nfs_dirname)
+ except:
+ logging.debug(" Failed creating nfs mount point")
+
+
+
def setup_nfs_fstab(nfslist):
logging.info(" Adding nfs paths to fstab")
try:
@@ -92,6 +110,7 @@ def setup_nfs_fstab(nfslist):
f.write(line)
for s, m in nfslist:
line = "%s %s nfs \n" %(s,m)
+ setup_nfs_mkdir(m)
logging.debug(" %s",line)
f.write(line)
line = "#ENDSCRUB\n"
@@ -252,7 +271,7 @@ def scan_for_shares():
share_list = []
for conf_file in file_list:
try:
- logging.debug(" mv_advanced: reading in %s" %conf_file)
+ logging.debug(" mv_fileshare: reading in %s" %conf_file)
config.read(conf_file)
shareable = config.get('storage','shareable')
if shareable == "True" :
@@ -261,24 +280,87 @@ def scan_for_shares():
if config.get('storage','mmount') == "True" :
share_list.append("/myth")
except:
- logging.debug(" mv_advanced: Couldn't open %s for reading" %conf_file)
+ logging.debug(" mv_fileshare: Couldn't open %s for reading" %conf_file)
return share_list
-def setup_etc_exports(shares,data_config):
+def setup_etc_exports(shares,data_config,servername):
#read in /etc/ exports
conf_file="/etc/exports"
excludes = data_config.share_exclude_dir
+ nfsmap_sg_auto_skip = data_config.SG_MAP_AUTONFS_SKIP
+ nfsmap_auto_skip = data_config.MAP_AUTONFS_SKIP
+
+ #print nfsmap_auto_skip
+ nfs_auto_line ="%s:%s %s"
+
+
+ nfs_map_auto = []
+
+ share_list = []
+
+
+ #create the lists for both /etc/exports and nfs_map_auto
+ for share in shares:
+ if share == "/myth":
+ continue
+ os.chdir(share)
+ file_list=glob.glob("*")
+ for dirname in file_list:
+ if os.path.isdir(dirname):
+ tempname = "%s/%s" %(share,dirname)
+ if dirname not in nfsmap_auto_skip:
+ share_list.append(tempname)
+ if dirname not in nfsmap_sg_auto_skip:
+ templine = nfs_auto_line %(servername,tempname,tempname)
+ nfs_map_auto.append(templine)
+
+
+ file_list=glob.glob("media/*")
+ for dirname in file_list:
+ if os.path.isdir(dirname):
+ tempname = "%s/%s" %(share,dirname)
+ if dirname not in nfsmap_auto_skip:
+ share_list.append(tempname)
+ if dirname not in nfsmap_sg_auto_skip:
+ templine = nfs_auto_line %(servername,tempname,tempname)
+ nfs_map_auto.append(templine)
+
+
+
+
new_exports=[]
- new_exports.append("#This file was generated by systemconfig.py -m advanced")
+ new_exports.append("#This file was generated by systemconfig.py -m fileshare")
new_exports.append("#Use exportfs -arv to reread. \n\n")
+ #for exclude in excludes:
+ # share_line='''/%s *(noaccess)''' %exclude
+ # new_exports.append(share_line)
- for share in shares:
+ for share in share_list:
share_line='''%s *(rw,all_squash,anonuid=1000,anongid=1000,no_subtree_check)''' %share
new_exports.append(share_line)
- for exclude in excludes:
- share_line='''/%s *(noaccess)''' %exclude
- new_exports.append(share_line)
+ #for exclude in excludes:
+ #share_line='''/%s *(noaccess)''' %exclude
+ #new_exports.append(share_line)
+
+ #write out nfs_map_auto
+ try:
+
+ logging.info(" writing nfsmap_auto")
+ try:
+ os.makedirs("%s/templates/" %data_config.MYTHHOME)
+ except:
+ pass
+ conf_file_nfs = "%s/templates/nfsmap_auto" %(data_config.MYTHHOME)
+ f=open(conf_file_nfs,'w')
+ for line in nfs_map_auto:
+ f.write(line)
+ f.write("\n")
+ logging.debug("%s" %line)
+ f.close()
+ except:
+ logging.info("* error writing /data/srv/htdocs/nfsmap_auto")
+
try:
logging.info(" writing /etc/exports")
f=open(conf_file,'w')
@@ -292,17 +374,19 @@ def setup_etc_exports(shares,data_config):
-def setup_NFSshares(UseNFS,templatefile,data_config):
+def setup_NFSshares(UseNFS,templatefile,data_config,servername):
if UseNFS == "1":
logging.info(" Activating NFS server")
mv_common.pacinstall("nfs-utils")
mv_common.pacinstall("rpcbind")
shares = scan_for_shares()
- setup_etc_exports(shares,data_config)
+ setup_etc_exports(shares,data_config,servername)
mv_common.add_service("nfsd")
mv_common.add_service("nfs-common")
mv_common.add_service("rpcbind")
+ cmd="exportfs -arv"
+ mv_common.runcmd(cmd)
else:
logging.info(" Removing NFS server")
mv_common.remove_service("nfsd")
@@ -328,7 +412,7 @@ def setup_fileshare(systemconfig,data_config):
setup_nfs_client(systemconfig,data_config)
#server
setup_NFSshares(systemconfig.get("UseNFS"),
- systemconfig.get("TEMPLATES")+"/exports.template",data_config)
+ systemconfig.get("TEMPLATES")+"/exports.template",data_config,systemconfig.get("hostname"))
setup_samba(systemconfig,data_config)
- logging.info("__End of advanced configuration\n")
+ logging.info("__End of fileshare configuration\n")