本文整理汇总了Python中DIRAC.Interfaces.API.DiracAdmin.DiracAdmin.csCommitChanges方法的典型用法代码示例。如果您正苦于以下问题:Python DiracAdmin.csCommitChanges方法的具体用法?Python DiracAdmin.csCommitChanges怎么用?Python DiracAdmin.csCommitChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.Interfaces.API.DiracAdmin.DiracAdmin
的用法示例。
在下文中一共展示了DiracAdmin.csCommitChanges方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addUserToCS
# 需要导入模块: from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin [as 别名]
# 或者: from DIRAC.Interfaces.API.DiracAdmin.DiracAdmin import csCommitChanges [as 别名]
def addUserToCS(clip, userProps):
"""Add the user to the CS, return list of errors"""
from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin
diracAdmin = DiracAdmin()
exitCode = 0
errorList = []
if not diracAdmin.csModifyUser( clip.uname, userProps, createIfNonExistant = True )['OK']:
errorList.append( ( "add user", "Cannot register user: '%s'" % clip.uname ) )
exitCode = 255
else:
result = diracAdmin.csCommitChanges()
if not result[ 'OK' ]:
errorList.append( ( "commit", result[ 'Message' ] ) )
exitCode = 255
for error in errorList:
gLogger.error( "%s: %s" % error )
if exitCode:
dexit(exitCode)
示例2: DiracAdmin
# 需要导入模块: from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin [as 别名]
# 或者: from DIRAC.Interfaces.API.DiracAdmin.DiracAdmin import csCommitChanges [as 别名]
from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin
diracAdmin = DiracAdmin()
exitCode = 0
testOnly = False
errorList = []
for unprocSw in Script.getUnprocessedSwitches():
if unprocSw[0] in ( "t", "test" ):
testOnly = True
try:
usersCFG = CFG().loadFromFile( args[0] )
except Exception, e:
errorList.append( "file open", "Can't parse file %s: %s" % ( args[0], str( e ) ) )
errorCode = 1
else:
if not diracAdmin.csSyncUsersWithCFG( usersCFG ):
errorList.append( ( "modify users", "Cannot sync with %s" % args[0] ) )
exitCode = 255
if not exitCode and not testOnly:
result = diracAdmin.csCommitChanges()
if not result[ 'OK' ]:
errorList.append( ( "commit", result[ 'Message' ] ) )
exitCode = 255
for error in errorList:
print "ERROR %s: %s" % error
DIRAC.exit( exitCode )
示例3: SoftwareAdder
# 需要导入模块: from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin [as 别名]
# 或者: from DIRAC.Interfaces.API.DiracAdmin.DiracAdmin import csCommitChanges [as 别名]
class SoftwareAdder(object):
"""Container for all the objects and functions to add software to ILCDirac"""
def __init__(self, platform, appName, tarball_loc, appVersion, comment):
from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin
self.diracAdmin = DiracAdmin()
self.modifiedCS = False
self.appVersion = appVersion
self.appName = appName
self.platform = platform
self.softSec = "/Operations/Defaults/AvailableTarBalls"
self.appTar = self.checkForTarBall(tarball_loc)
self.parameter = dict( softSec = self.softSec,
platform = self.platform,
appName = self.appName,
appname = self.appName.lower(),
appTar = self.appTar,
appTar_name = os.path.basename(self.appTar),
appVersion = self.appVersion,
)
self.comment = comment
self.mailadress = '[email protected]'
def checkConsistency(self):
"""checks if platform is defined, application exists, etc."""
gLogger.notice("Checking consistency")
av_platforms = gConfig.getSections(self.softSec, [])
if av_platforms['OK']:
if not self.platform in av_platforms['Value']:
gLogger.error("Platform %s unknown, available are %s." % (self.platform, ", ".join(av_platforms['Value'])))
gLogger.error("If yours is missing add it in CS")
dexit(255)
else:
gLogger.error("Could not find all platforms available in CS")
dexit(255)
av_apps = gConfig.getSections("%(softSec)s/%(platform)s" % self.parameter, [])
if not av_apps['OK']:
gLogger.error("Could not find all applications available in CS")
dexit(255)
def commitToCS(self):
"""write changes to the CS to the server"""
gLogger.notice("Commiting changes to the CS")
if self.modifiedCS:
result = self.diracAdmin.csCommitChanges(False)
if not result[ 'OK' ]:
gLogger.error('Commit failed with message = %s' % (result[ 'Message' ]))
dexit(255)
gLogger.info('Successfully committed changes to CS')
else:
gLogger.info('No modifications to CS required')
def checkForTarBall(self,tarball_loc):
"""checks if the tarball exists"""
gLogger.info("Check if tarball exists at %s" % tarball_loc)
appTar = ''
if tarball_loc:
appTar = tarball_loc
if self.appName == 'slic':
self.appVersion = os.path.basename(tarball_loc).slit("_")[0].split("-")[1]
else:
if self.appVersion:
appTar = "%s%s.tgz" % (self.appName, self.appVersion)
else:
gLogger.notice("Version not defined")
if not os.path.exists(appTar):
gLogger.error("Cannot find the file %s, exiting" % appTar)
dexit(1)
return appTar
def notifyAboutNewSoftware(self):
"""Send an email to the mailing list if a new software version was defined"""
#Only send email when something was actually added
if not self.modifiedCS:
return
subject = '%s %s added to DIRAC CS' % (self.appName, self.appVersion)
msg = 'New application %s %s declared into Configuration service\n %s' % (self.appName,
self.appVersion,
self.comment)
from DIRAC.Core.Security.ProxyInfo import getProxyInfo
from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getUserOption
from DIRAC.FrameworkSystem.Client.NotificationClient import NotificationClient
notifyClient = NotificationClient()
gLogger.notice('Sending mail for software installation to %s' % (self.mailadress))
res = getProxyInfo()
if not res['OK']:
sender = '[email protected]'
else:
if 'username' in res['Value']:
sender = getUserOption(res['Value']['username'],'Email')
else:
sender = '[email protected]'
gLogger.info('*'*80)# surround email with stars
#.........这里部分代码省略.........
示例4: doTheWhizardInstallation
# 需要导入模块: from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin [as 别名]
# 或者: from DIRAC.Interfaces.API.DiracAdmin.DiracAdmin import csCommitChanges [as 别名]
#.........这里部分代码省略.........
myappTar.close()
md5sum = md5.md5(open( appTar, 'r' ).read()).hexdigest()
gLogger.notice("...Done")
gLogger.notice("Registering new Tarball in CS")
tarballurl = {}
av_platforms = gConfig.getSections(softwareSection, [])
if av_platforms['OK']:
if platform not in av_platforms['Value']:
gLogger.error("Platform %s unknown, available are %s." % (platform, ", ".join(av_platforms['Value'])))
gLogger.error("If yours is missing add it in CS")
dexit(255)
else:
gLogger.error("Could not find all platforms available in CS")
dexit(255)
av_apps = gConfig.getSections("%s/%s" % (softwareSection, platform), [])
if not av_apps['OK']:
gLogger.error("Could not find all applications available in CS")
dexit(255)
if appName.lower() in av_apps['Value']:
versions = gConfig.getSections("%s/%s/%s" % (softwareSection, platform, appName.lower()),
[])
if not versions['OK']:
gLogger.error("Could not find all versions available in CS")
dexit(255)
if appVersion in versions['Value']:
gLogger.error('Application %s %s for %s already in CS, nothing to do' % (appName.lower(), appVersion, platform))
dexit(0)
else:
result = diracAdmin.csSetOption("%s/%s/%s/%s/TarBall" % (softwareSection, platform, appName.lower(), appVersion),
os.path.basename(appTar))
if result['OK']:
modifiedCS = True
tarballurl = gConfig.getOption("%s/%s/%s/TarBallURL" % (softwareSection, platform, appName.lower()), "")
if len(tarballurl['Value']) > 0:
res = upload(tarballurl['Value'], appTar)
if not res['OK']:
gLogger.error("Upload to %s failed" % tarballurl['Value'])
dexit(255)
result = diracAdmin.csSetOption("%s/%s/%s/%s/Md5Sum" % (softwareSection, platform, appName.lower(), appVersion),
md5sum)
if result['OK']:
modifiedCS = True
result = diracAdmin.csSetOption("%s/%s/%s/%s/Dependencies/beam_spectra/version" % (softwareSection,
platform,
appName.lower(),
appVersion),
beam_spectra_version)
else:
result = diracAdmin.csSetOption("%s/%s/%s/%s/TarBall" % (softwareSection, platform,
appName.lower(), appVersion),
os.path.basename(appTar))
if result['OK']:
modifiedCS = True
tarballurl = gConfig.getOption("%s/%s/%s/TarBallURL" % (softwareSection, platform, appName.lower()),
"")
if len(tarballurl['Value']) > 0:
res = upload(tarballurl['Value'], appTar)
if not res['OK']:
gLogger.error("Upload to %s failed" % tarballurl['Value'])
dexit(255)
result = diracAdmin.csSetOption("%s/%s/%s/%s/Md5Sum" % (softwareSection, platform, appName.lower(), appVersion),
md5sum)
result = diracAdmin.csSetOption("%s/%s/%s/%s/Dependencies/beam_spectra/version" % (softwareSection,
platform,
appName.lower(),
appVersion),
beam_spectra_version)
gLogger.verbose("Done uploading the tar ball")
os.remove(appTar)
#Set for all new processes the TarBallURL
for process in inputlist.keys():
inputlist[process]['TarBallCSPath'] = tarballurl['Value'] + os.path.basename(appTar)
pl.updateProcessList(inputlist)
pl.writeProcessList()
raw_input("Do you want to upload the process list? Press ENTER to proceed or CTRL-C to abort!")
pl.uploadProcessListToFileCatalog(path_to_process_list, appVersion)
#Commit the changes if nothing has failed and the CS has been modified
if modifiedCS:
result = diracAdmin.csCommitChanges(False)
gLogger.verbose(result)
gLogger.notice('All done OK!')
dexit(0)
示例5: CVMFSAdder
# 需要导入模块: from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin [as 别名]
# 或者: from DIRAC.Interfaces.API.DiracAdmin.DiracAdmin import csCommitChanges [as 别名]
class CVMFSAdder(object):
"""Container for all the objects and functions to add software to ILCDirac"""
def __init__(self, cliParams ):
from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin
self.diracAdmin = DiracAdmin()
self.modifiedCS = False
self.softSec = "/Operations/Defaults/AvailableTarBalls"
self.mailadress = '[email protected]'
self.cliParams = cliParams
self.parameter = dict( softSec = self.softSec,
platform = cliParams.platform,
version = cliParams.version,
basepath = cliParams.basePath,
initsctipt = cliParams.initScriptLocation
)
self.applications = cliParams.applicationList
def checkConsistency(self):
"""checks if platform is defined, application exists, etc."""
gLogger.notice("Checking consistency")
av_platforms = gConfig.getSections(self.softSec, [])
if av_platforms['OK']:
if not self.parameter['platform'] in av_platforms['Value']:
gLogger.error("Platform %s unknown, available are %s." % (self.parameter['platform'], ", ".join(av_platforms['Value'])))
gLogger.error("If yours is missing, add it in CS")
return S_ERROR()
else:
gLogger.error("Could not find all platforms available in CS")
return S_ERROR()
for application in self.applications:
av_apps = gConfig.getSections("%(softSec)s/%(platform)s/" % self.parameter + str(application), [])
if not av_apps['OK']:
gLogger.error("Could not find this application in the CS: '%s'" % application)
gLogger.error("Add its section to the CS, if it is missing")
return S_ERROR()
gLogger.notice("All OK, continuing...")
return S_OK()
def commitToCS(self):
"""write changes to the CS to the server"""
if self.modifiedCS:
gLogger.notice("Commiting changes to the CS")
result = self.diracAdmin.csCommitChanges(False)
if not result[ 'OK' ]:
gLogger.error('Commit failed with message = %s' % (result[ 'Message' ]))
return S_ERROR("Failed to commit to CS")
gLogger.info('Successfully committed changes to CS')
else:
gLogger.info('No modifications to CS required')
return S_OK()
def addAllToCS(self):
"""add all the applications to the CS, take care of special cases (mokka, ildconfig,...)"""
for application in self.applications:
csParameter = dict( CVMFSEnvScript = self.cliParams.initScriptLocation,
CVMFSPath = self.parameter['basepath']
)
if application == 'mokka':
csParameter['CVMFSDBSlice'] = self.cliParams.dbSliceLocation
elif application == 'ildconfig':
del csParameter['CVMFSEnvScript']
csParameter['CVMFSPath'] = self.cliParams.ildConfigPath
csParameter['CVMFSDBSlice'] = self.cliParams.dbSliceLocation
resInsert = self.insertApplicationToCS(application, csParameter)
if not resInsert['OK']:
return resInsert
return S_OK()
def insertApplicationToCS(self, name, csParameter):
"""add given application found via CVMFS to the CS"""
pars = dict(self.parameter)
pars['name'] = name
gLogger.notice("%(name)s: Adding version %(version)s to the CS" % pars)
existingVersions = gConfig.getSections("%(softSec)s/%(platform)s/%(name)s" % pars, [])
if not existingVersions['OK']:
gLogger.error("Could not find all versions available in CS: %s" % existingVersions['Message'])
dexit(255)
if pars['version'] in existingVersions['Value']:
gLogger.always('Application %s %s for %s already in CS, nothing to do' % (name.lower(),
pars['version'],
pars['platform']))
return S_OK()
csPath = self.softSec + ("/%(platform)s/%(name)s/%(version)s/" % pars)
for par, val in csParameter.iteritems():
gLogger.notice("Add: %s = %s" %(csPath+par, val))
result = self.diracAdmin.csSetOption(csPath+par, val)
#.........这里部分代码省略.........