Exemple #1
0
  DIRACExit( exitCode )

#result = promptUser( 'All the elements that are associated with this site will be banned, are you sure about this action?' )
#if not result['OK'] or result['Value'] is 'n':
#  print 'Script stopped'
#  DIRACExit( 0 )

site = args[0]
comment = args[1]
result = diracAdmin.banSite( site, comment, printOutput = True )
if not result['OK']:
  errorList.append( ( site, result['Message'] ) )
  exitCode = 2
else:
  if email:
    userName = diracAdmin._getCurrentUser()
    if not userName['OK']:
      print('ERROR: Could not obtain current username from proxy')
      exitCode = 2
      DIRACExit( exitCode )
    userName = userName['Value']
    subject = '%s is banned for %s setup' % ( site, setup )
    body = 'Site %s is removed from site mask for %s setup by %s on %s.\n\n' % ( site, setup, userName, time.asctime() )
    body += 'Comment:\n%s' % comment

    addressPath = 'EMail/Production'
    address = Operations().getValue( addressPath, '' )
    if not address:
      gLogger.notice( "'%s' not defined in Operations, can not send Mail\n" % addressPath, body )
    else:
      result = diracAdmin.sendMail( address, subject, body )
errorList = []
setup = gConfig.getValue( '/DIRAC/Setup', '' )
if not setup:
  print 'ERROR: Could not contact Configuration Service'
  exitCode = 2
  DIRACExit( exitCode )

site = args[0]
comment = args[1]
result = diracAdmin.banSiteFromMask( site, comment, printOutput = True )
if not result['OK']:
  errorList.append( ( site, result['Message'] ) )
  exitCode = 2
else:
  if email:
    userName = diracAdmin._getCurrentUser()
    if not userName['OK']:
      print 'ERROR: Could not obtain current username from proxy'
      exitCode = 2
      DIRACExit( exitCode )
    userName = userName['Value']
    subject = '%s is banned for %s setup' % ( site, setup )
    body = 'Site %s is removed from site mask for %s setup by %s on %s.\n\n' % ( site, setup, userName, time.asctime() )
    body += 'Comment:\n%s' % comment

    addressPath = 'EMail/Production'
    address = Operations().getValue( addressPath, '' )
    if not address:
      gLogger.notice( "'%s' not defined in Operations, can not send Mail\n" % addressPath, body )
    else:
      result = diracAdmin.sendMail( address, subject, body )
Exemple #3
0
# # test execution
if __name__ == "__main__":

  if len( sys.argv ) != 5:
    gLogger.error( "Usage:\n python %s userGroup SourceSE TargetSE1 TargetSE2\n" )
    sys.exit( -1 )
  userGroup = sys.argv[1]
  sourceSE = sys.argv[2]
  targetSE1 = sys.argv[3]
  targetSE2 = sys.argv[4]

  gLogger.always( "will use '%s' group" % userGroup )

  admin = DiracAdmin()

  userName = admin._getCurrentUser()
  if not userName["OK"]:
    gLogger.error( userName["Message"] )
    sys.exit( -1 )
  userName = userName["Value"]
  gLogger.always( "current user is '%s'" % userName )

  userGroups = getGroupsForUser( userName )
  if not userGroups["OK"]:
    gLogger.error( userGroups["Message"] )
    sys.exit( -1 )
  userGroups = userGroups["Value"]

  if userGroup not in userGroups:
    gLogger.error( "'%s' is not a member of the '%s' group" % ( userName, userGroup ) )
    sys.exit( -1 )
Exemple #4
0
def main():
    Script.registerSwitch("E:", "email=",
                          "Boolean True/False (True by default)")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument("Site:     Name of the Site")
    Script.registerArgument("Comment:  Reason of the action")
    Script.parseCommandLine(ignoreErrors=True)

    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin
    from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
    from DIRAC import exit as DIRACExit, gConfig, gLogger

    def getBoolean(value):
        if value.lower() == "true":
            return True
        elif value.lower() == "false":
            return False
        else:
            Script.showHelp()

    email = True
    for switch in Script.getUnprocessedSwitches():
        if switch[0] == "email":
            email = getBoolean(switch[1])

    diracAdmin = DiracAdmin()
    exitCode = 0
    errorList = []
    setup = gConfig.getValue("/DIRAC/Setup", "")
    if not setup:
        print("ERROR: Could not contact Configuration Service")
        exitCode = 2
        DIRACExit(exitCode)

    # result = promptUser(
    #     'All the elements that are associated with this site will be active, '
    #     'are you sure about this action?'
    # )
    # if not result['OK'] or result['Value'] is 'n':
    #  print 'Script stopped'
    #  DIRACExit( 0 )

    # parseCommandLine show help when mandatory arguments are not specified or incorrect argument
    site, comment = Script.getPositionalArgs(group=True)
    result = diracAdmin.allowSite(site, comment, printOutput=True)
    if not result["OK"]:
        errorList.append((site, result["Message"]))
        exitCode = 2
    else:
        if email:
            userName = diracAdmin._getCurrentUser()
            if not userName["OK"]:
                print("ERROR: Could not obtain current username from proxy")
                exitCode = 2
                DIRACExit(exitCode)
            userName = userName["Value"]
            subject = "%s is added in site mask for %s setup" % (site, setup)
            body = "Site %s is added to the site mask for %s setup by %s on %s.\n\n" % (
                site,
                setup,
                userName,
                time.asctime(),
            )
            body += "Comment:\n%s" % comment
            addressPath = "EMail/Production"
            address = Operations().getValue(addressPath, "")
            if not address:
                gLogger.notice(
                    "'%s' not defined in Operations, can not send Mail\n" %
                    addressPath, body)
            else:
                result = diracAdmin.sendMail(address, subject, body)
        else:
            print("Automatic email disabled by flag.")

    for error in errorList:
        print("ERROR %s: %s" % error)

    DIRACExit(exitCode)
Exemple #5
0
def main():
    Script.registerSwitch("E:", "email=",
                          "Boolean True/False (True by default)")
    Script.parseCommandLine(ignoreErrors=True)

    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin
    from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
    from DIRAC import exit as DIRACExit, gConfig, gLogger

    def getBoolean(value):
        if value.lower() == 'true':
            return True
        elif value.lower() == 'false':
            return False
        else:
            Script.showHelp()

    email = True
    for switch in Script.getUnprocessedSwitches():
        if switch[0] == "email":
            email = getBoolean(switch[1])

    args = Script.getPositionalArgs()

    if len(args) < 2:
        Script.showHelp()

    diracAdmin = DiracAdmin()
    exitCode = 0
    errorList = []
    setup = gConfig.getValue('/DIRAC/Setup', '')
    if not setup:
        print('ERROR: Could not contact Configuration Service')
        exitCode = 2
        DIRACExit(exitCode)

    # result = promptUser(
    #     'All the elements that are associated with this site will be active, '
    #     'are you sure about this action?'
    # )
    # if not result['OK'] or result['Value'] is 'n':
    #  print 'Script stopped'
    #  DIRACExit( 0 )

    site = args[0]
    comment = args[1]
    result = diracAdmin.allowSite(site, comment, printOutput=True)
    if not result['OK']:
        errorList.append((site, result['Message']))
        exitCode = 2
    else:
        if email:
            userName = diracAdmin._getCurrentUser()
            if not userName['OK']:
                print('ERROR: Could not obtain current username from proxy')
                exitCode = 2
                DIRACExit(exitCode)
            userName = userName['Value']
            subject = '%s is added in site mask for %s setup' % (site, setup)
            body = 'Site %s is added to the site mask for %s setup by %s on %s.\n\n' % (
                site, setup, userName, time.asctime())
            body += 'Comment:\n%s' % comment
            addressPath = 'EMail/Production'
            address = Operations().getValue(addressPath, '')
            if not address:
                gLogger.notice(
                    "'%s' not defined in Operations, can not send Mail\n" %
                    addressPath, body)
            else:
                result = diracAdmin.sendMail(address, subject, body)
        else:
            print('Automatic email disabled by flag.')

    for error in errorList:
        print("ERROR %s: %s" % error)

    DIRACExit(exitCode)
Exemple #6
0
if __name__ == "__main__":

    if len(sys.argv) != 5:
        gLogger.error(
            "Usage:\n python %s userGroup SourceSE TargetSE1 TargetSE2\n")
        sys.exit(-1)
    userGroup = sys.argv[1]
    sourceSE = sys.argv[2]
    targetSE1 = sys.argv[3]
    targetSE2 = sys.argv[4]

    gLogger.always("will use '%s' group" % userGroup)

    admin = DiracAdmin()

    userName = admin._getCurrentUser()
    if not userName["OK"]:
        gLogger.error(userName["Message"])
        sys.exit(-1)
    userName = userName["Value"]
    gLogger.always("current user is '%s'" % userName)

    userGroups = getGroupsForUser(userName)
    if not userGroups["OK"]:
        gLogger.error(userGroups["Message"])
        sys.exit(-1)
    userGroups = userGroups["Value"]

    if userGroup not in userGroups:
        gLogger.error("'%s' is not a member of the '%s' group" %
                      (userName, userGroup))
Exemple #7
0
if __name__ == "__main__":

  from DIRAC.Core.Base.Script import parseCommandLine
  parseCommandLine()

  import DIRAC
  from DIRAC import gLogger, gConfig
  from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getSites
  from DIRAC.DataManagementSystem.Client.FTSClient import FTSClient
  from DIRAC.DataManagementSystem.Client.FTSSite import FTSSite
  from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin
  from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getGroupsForUser
  admin = DiracAdmin()

  currentUser = admin._getCurrentUser()
  if not currentUser["OK"]:
    gLogger.error( currentUser["Message"] )
    DIRAC.exit(-1)
  currentUser = currentUser["Value"]
  
  userGroups = getGroupsForUser( currentUser )
  if not userGroups["OK"]:
    gLogger.error( userGroups["Message"] )
    DIRAC.exit( -1 )
  userGroups = userGroups["Value"]
  
  if "diracAdmin" not in userGroups:
    gLogger.error( "you are not allowed to change FTSSites configuration" )
    DIRAC.exit( -1 )