Exemple #1
0
def main():
  print """##############################################################
#Config file should be in same folder where the python script is there
#Config should contain aws region, aws credential details and tagging information filename
#########################################################
  """
  configFile = raw_input('Enter the config file-name : ')
  chkObject =  checkValidation()
  fileCheck, filestatus = chkObject.fileExists(configFile)
  region,akey,skey,infoFile='','','',''
  if fileCheck:
    parsFile = open(configFile)
    confList = parsFile.readlines()
    for cL in confList:
      ccL = cL.strip()
      l = ccL.split(':')
      if l[0] == 'ak':
        akey = l[1]
      elif l[0] == 'sk':
        skey = l[1]
      elif l[0] == 'region':
        region = l[1]
      elif l[0] == 'filename':
        infoFile = l[1]	

    if chkObject.customCheck(region,akey,skey,infoFile):
      taggerVal = parsefile(infoFile)
      for tv in taggerVal.items():
        addTag(region, akey, skey, tv[0],tv[1])
    else:
      print "Error in either region or aws-key or filename"
  else:
    print filestatus
Exemple #2
0
def main():
	
  """Main function asks the config file where all the needed information are mentioned
     Checks the validity of the file and content then sent to tag as per the operation. 
  """
	
  print """##############################################################
#Config file should be in same folder where the python script is there
#Config should contain aws region, aws credential details and tagging information filename
#########################################################
  """
  configFile = raw_input('Enter the config file-name : ')
  chkObject =  CheckValidation()
  fileCheck, filestatus = chkObject.fileExists(configFile)
  region,akey,skey,infoFile,operation='','','','',''
  if fileCheck:
    parsFile = open(configFile)
    confList = parsFile.readlines()
    for cL in confList:
      ccL = cL.strip()
      l = ccL.split(':')
      if l[0] == 'ak':
        akey = l[1]
      elif l[0] == 'sk':
        skey = l[1]
      elif l[0] == 'region':
        region = l[1]
      elif l[0] == 'operation':
        operation = l[1]
      elif l[0] == 'filename':
        infoFile = l[1]	

    if chkObject.customCheck(region,akey,skey,infoFile,operation):
      taggerVal = parsefile(infoFile)
      ec2 = ConnectAws()
      ec2Obj = ec2.ec2Instance(akey, skey, region)
      for tv in taggerVal.items():
        if operation == "add":
          addTag(ec2Obj, tv[0],tv[1])
        elif operation == "remove":
          removeTag(ec2Obj, tv[0],tv[1])
        else:
          print "Error in Word operation usage: small letter <add> or <remove>"
    else:
      print "Error in either region or aws-key or filename"
  else:
    print filestatus