def dumpPolicy( cfgDict, fileName ):
  '''
    to copy updates and removals to the dirac config file (it creates a backup copy, if needed for restoring)
  '''

  fileCFG = CFG()
  #update cfg policy section
  confirmation = raw_input("Do you want to dump your changes? (replay 'yes' or 'y' to confirm): ").strip()
  if confirmation == 'yes' or confirmation == 'y':
    fileCFG.loadFromDict( cfgDict )
    shutil.copyfile( fileName, fileName + ".bkp" ) #creates a backup copy of the dirac config file
    dumpedSucccessfully = fileCFG.writeToFile( fileName )
    if dumpedSucccessfully:
      print "Your update has been dumped successfully!"
    else:
      print "It was not possible to dump your update. Something went wrong!"
Beispiel #2
0
def run(cmd, params):
    '''
    to execute a command among view, test, update, remove, restore
  '''

    cmd = cmd.pop()
    fileCFG = CFG()
    fileName = params['file']
    setup = params['setup']
    fileCFG.loadFromFile(fileName)
    cfgDict = fileCFG.getAsDict()
    policySection = getPolicySection(cfgDict)

    if cmd == 'view':
        viewPolicyDict(policySection)

    elif cmd == 'test':
        policiesThatApply = getPolicies(params)
        viewPolicyDict(policiesThatApply)

    elif cmd == 'update':
        result = updatePolicy(policySection)
        if result['OK']:
            policySection = result['Value']
            cfgDict['Operations'][setup]['ResourceStatus'][
                'Policies'] = policySection
            headLine("A preview of your policy section after the update")
            viewPolicyDict(policySection)
            dumpPolicy(cfgDict, fileName)

    elif cmd == 'remove':
        policies = params['policy']
        policySection = removePolicy(policySection, policies)
        cfgDict['Operations'][setup]['ResourceStatus'][
            'Policies'] = policySection
        headLine("A preview of your policy section after the removal")
        viewPolicyDict(policySection)
        dumpPolicy(cfgDict, fileName)

    elif cmd == 'restore':
        restoreCfgFile(fileName)
        fileCFG.loadFromFile(fileName)
        cfgDict = fileCFG.getAsDict()
        policySection = getPolicySection(cfgDict)
        viewPolicyDict(policySection)
def run( cmd, params):
  '''
    to execute a command among view, test, update, remove, restore
  '''

  cmd = cmd.pop()
  fileCFG = CFG()
  fileName = params[ 'file' ]
  setup = params[ 'setup' ]
  fileCFG.loadFromFile( fileName )
  cfgDict = fileCFG.getAsDict()
  policySection = getPolicySection( cfgDict )

  if cmd == 'view':
    viewPolicyDict( policySection )

  elif cmd == 'test':
    policiesThatApply = getPolicies( params )
    viewPolicyDict( policiesThatApply )

  elif cmd == 'update':
    result = updatePolicy( policySection )
    if result['OK']:
      policySection = result['Value']
      cfgDict['Operations'][setup]['ResourceStatus']['Policies'] = policySection
      headLine( "A preview of your policy section after the update" )
      viewPolicyDict( policySection )
      dumpPolicy( cfgDict, fileName )

  elif cmd == 'remove':
    policies = params[ 'policy' ]
    policySection = removePolicy( policySection, policies )
    cfgDict['Operations'][setup]['ResourceStatus']['Policies'] = policySection
    headLine( "A preview of your policy section after the removal" )
    viewPolicyDict( policySection )
    dumpPolicy( cfgDict, fileName )

  elif cmd == 'restore':
    restoreCfgFile( fileName )
    fileCFG.loadFromFile( fileName )
    cfgDict = fileCFG.getAsDict()
    policySection = getPolicySection( cfgDict )
    viewPolicyDict( policySection )