import Queue
from lib import o2lib
from oxygen_exception_exit_decorator import oxygen_exception_exit
import logging
class AgentFactory( object ):
api_url = ''
api_key = ''
user = ''
password = ''
# agent_count = 1 # default to 0 if not set anywhere else
# agent_pool = Queue.Queue()
# def __init__( self , caller_name , api_url , api_key , user , password , agent_count = 2 ):
def __init__( self , caller_name , api_url , api_key , user , password ):
self.caller_name = caller_name
self.api_url = api_url
self.api_key = api_key
self.user = user
self.password = password
# self.agent_count = agent_count
# for i in range( self.agent_count ): # each agent will get a thread
# self.agent_pool.put( self.create_valid_agent() )
def create_valid_agent( self ):
agent = o2lib.OxygenAdapter( self.api_key , self.caller_name , self.api_url )
return self.login( agent )
@oxygen_exception_exit( logger = logging.getLogger(__name__) )
def login( self , agent ):
user_login = agent.request_login_url()
agent.login_regular_user( user_login.tokenId , self.user , self.password ) # throws an Exception if there's a problem
agent.validate_login( user_login.tokenId ) # throws an Exception if there's a problem
return agent