<s> '''<STR_LIT>''' <EOL> import socket <EOL> from octopus . core . communication . requestmanager import RequestManager <EOL> try : <EOL> import simplejson as json <EOL> except ImportError : <EOL> import json <EOL> from octopus . dispatcher import settings <EOL> from octopus . dispatcher . poolman import IPoolManager , PoolDescription , ComputerDescription , ComputerNotFoundError , PoolManagerError , PoolNotFoundError <EOL> class WebServicePoolManager ( IPoolManager ) : <EOL> def __init__ ( self ) : <EOL> self . requestManager = RequestManager ( settings . WS_BACKEND_URL , settings . WS_BACKEND_PORT ) <EOL> self . defaultPool = PoolDescription ( <NUM_LIT:1> , u'<STR_LIT:default>' , None ) <EOL> self . pools = [ self . defaultPool ] <EOL> self . computers = [ ] <EOL> def getPool ( self , poolName ) : <EOL> for pool in self . pools : <EOL> if pool . name == poolName : <EOL> return pool <EOL> raise PoolNotFoundError ( poolName ) <EOL> def listPools ( self ) : <EOL> poolsDict = json . loads ( self . requestManager . get ( "<STR_LIT>" ) ) <EOL> for pool in poolsDict [ '<STR_LIT>' ] : <EOL> id = int ( pool [ '<STR_LIT:id>' ] ) <EOL> name = str ( pool [ '<STR_LIT:name>' ] ) <EOL> version = str ( pool [ '<STR_LIT:version>' ] ) <EOL> poolDesc = PoolDescription ( id , name , version ) <EOL> computerIds = pool [ '<STR_LIT>' ] <EOL> for computerId in computerIds : <EOL> try : <EOL> computer = self . getComputerById ( int ( computerId ) ) <EOL> computer . pools . append ( poolDesc ) <EOL> except ComputerNotFoundError : <EOL> continue <EOL> self . pools . append ( poolDesc ) <EOL> return self . pools <EOL> def getComputer ( self , computerName ) : <EOL> computerName = socket . getfqdn ( computerName ) <EOL> for computer in self . computers : <EOL> if computer . name == computerName : <EOL> return computer <EOL> raise ComputerNotFoundError ( computerName ) <EOL> def getComputerById ( self , id ) : <EOL> for computer in self . computers : <EOL> if computer . id == id : <EOL> return computer <EOL> raise ComputerNotFoundError ( id ) <EOL> def listComputers ( self ) : <EOL> computersDict = json . loads ( self . requestManager . get ( "<STR_LIT>" ) ) <EOL> for computer in computersDict [ '<STR_LIT>' ] : <EOL> id = int ( computer [ '<STR_LIT:id>' ] ) <EOL> name = str ( computer [ '<STR_LIT>' ] ) <EOL> version = str ( computer [ '<STR_LIT:version>' ] ) <EOL> pools = [ ] <EOL> pools . append ( self . defaultPool ) <EOL> cpucount = computer [ '<STR_LIT>' ] <EOL> cpufreq = computer [ '<STR_LIT>' ] <EOL> cpucores = computer [ '<STR_LIT>' ] <EOL> ramsize = computer [ '<STR_LIT>' ] <EOL> port = <NUM_LIT> <EOL> properties = { } <EOL> computerDesc = ComputerDescription ( id , name , version , pools , cpucount , cpufreq , cpucores , ramsize , port , properties ) <EOL> self . computers . append ( computerDesc ) <EOL> return self . computers <EOL> def listComputersForPool ( self , poolName ) : <EOL> raise PoolNotFoundError ( poolName ) <EOL> def setComputerWorkingFlag ( self , computer , workingFlag ) : <EOL> raise ComputerNotFoundError ( computer ) </s>
