def _link_project_dir(self,unmount=True): """ Link or unlink the /usr/discreet/project directory to the mirror """ # /usr/discreet/project udp = '/usr/discreet/project' udp_target = "%s/project" % self.mirror_path if unmount: if fileutil.exists(udp) and fileutil.islink(udp): os.remove(udp) if fileutil.exists("%s.orig_dlm" % udp): os.rename("%s.orig_dlm" % udp,udp) else: fileutil.symlink(udp_target,udp,archive_tag='orig_dlm')
def _link_clip_dirs(self,unmount=False): """ Link or unlink the /usr/discreet/clip directories for the mirror """ if not os.path.exists('/usr/discreet/clip'): os.mkdir('/usr/discreet/clip') prt = "/usr/discreet/clip/stonefs%s" % self.partition mirror_prt = "%s/clip/stonefs%s" % (self.mirror_path,self.partition) if unmount: if fileutil.exists(prt) and fileutil.islink(prt): os.remove(prt) if fileutil.exists("%s.orig_dlm" % prt): os.rename("%s.orig_dlm" % prt,prt) else: fileutil.symlink(mirror_prt,prt,archive_tag='orig_dlm')
def _create_sw_framestore_map(self,unmount=False): """ Create a custom stone+wire.cfg file for mounting this framestore. FRAMESTORE=smoke01 HADDR=192.168.97.201 ID=201 """ # check the existing sw_framestore_map # for the DL_MIRROR tag in the file. # if it's not there move it aside to be safe cfg = '/usr/discreet/sw/cfg/sw_framestore_map' mirror_cfg = '%s/sw/cfg/sw_framestore_map' % self.mirror_path # get the version # and the ID # out of the mirror's sw_framestore_map f = open(mirror_cfg) for line in f.readlines(): if "VERSION" in line: version = line.strip().split('=')[1].strip() if self.host in line: ID = line.strip().split('ID=')[1].strip() if "INTERFACES" in line: break f.close() if os.path.exists(cfg): # look for the DL_MIRROR f = open(cfg) for line in f.readlines(): if 'DL_MIRROR' in line: f.close() os.remove(cfg) break if os.path.exists(cfg): # move the original file aside os.rename(cfg,"%s.orig_dlm" % cfg) if unmount: # move the original back if fileutil.exists("%s.orig_dlm" % cfg): os.rename("%s.orig_dlm" % cfg,cfg) else: # write the new cfg n = open(cfg,'w') n.write("# DL_MIRROR: Auto-generated %s\n" % cfg) n.write("# Original cfg moved to %s.orig_dlm\n" % cfg) n.write("VERSION=%s\n" % version) n.write("[FRAMESTORES]\n") n.write("FRAMESTORE=%s\tHADDR=localhost\tID=%s\n\n" % (socket.gethostname(),ID)) n.write("[INTERFACES]\n") n.close()
def _link_sw_storage_cfg(self,unmount=True): """ Link or unlink the sw_storage.cfg to the mirror """ cfg = '/usr/discreet/sw/cfg/sw_storage.cfg' cfg_target = "%s/sw/cfg/sw_storage.cfg" % self.mirror_path if unmount: if fileutil.islink(cfg): os.remove(cfg) if fileutil.exists("%s.orig_dlm" % cfg): os.rename("%s.orig_dlm" % cfg,cfg) else: fileutil.symlink(cfg_target,cfg,archive_tag='orig_dlm')
def _link_swdb(self,unmount=False): """ Swap the swdb files for this framestore. """ # check if sw_dbd is running before we do anything command = "ps -C sw_dbd -o pid=" pid = commands.getoutput(command).strip() if pid: log.error("WARNING: sw_dbd is still running") #return False if not os.path.exists('/usr/discreet/sw/swdb'): os.mkdir('/usr/discreet/sw/swdb') db = '/usr/discreet/sw/swdb/part%s.db' % self.partition db_link = '%s/sw/swdb/part%s.db' % (self.mirror_path,self.partition) count = '/usr/discreet/sw/swdb/part%s.count' % self.partition count_link = '%s/sw/swdb/part%s.count' % (self.mirror_path,self.partition) if fileutil.exists(db) and fileutil.islink(db): os.remove(db) elif os.path.exists(db): os.rename(db,"%s.orig_dlm" % db) if fileutil.exists(count) and fileutil.islink(count): os.remove(count) elif os.path.exists(count): os.rename(count,"%s.orig_dlm" % count) if unmount: # move the originals back if os.path.exists("%s.orig_dlm" % db): os.rename("%s.orig_dlm" % db,db) if os.path.exists("%s.orig_dlm" % count): os.rename("%s.orig_dlm" % count,count) else: os.symlink(db_link,db) os.symlink(count_link,count)
def _link_user_dir(self,unmount=True): """ Link or unlink the /usr/discreet/user directory to the mirror """ udu = '/usr/discreet/user' udu_target = "%s/user" % self.mirror_path if unmount: if fileutil.islink(udu): os.remove(udu) if fileutil.exists("%s.orig_dlm" % udu): os.rename("%s.orig_dlm" % udu,udu) else: # /usr/discreet/user fileutil.symlink(udu_target,udu,archive_tag='orig_dlm')