<s> """<STR_LIT>""" <EOL> from datetime import datetime <EOL> from sys import stdin , exit <EOL> from time import sleep <EOL> from functools import partial <EOL> from pprint import pprint <EOL> from account import RS_UN , RS_KEY <EOL> from com . rackspace . cloud . servers . api . client . tests import css , serverManager , flavorManager , imageManager , sharedIpGroupManager <EOL> from com . rackspace . cloud . servers . api . client . sharedipgroup import SharedIpGroup <EOL> from com . rackspace . cloud . servers . api . client . servermanager import rebootType <EOL> from com . rackspace . cloud . servers . api . client . server import Server <EOL> from com . rackspace . cloud . servers . api . client . backupschedule import BackupSchedule <EOL> from com . rackspace . cloud . servers . api . client . errors import CloudServersFault <EOL> from com . rackspace . cloud . servers . api . client . personality import Personality <EOL> from com . rackspace . cloud . servers . api . client . file import File <EOL> from com . rackspace . cloud . servers . api . client . tests . console_util import * <EOL> def showBackupSchedule ( ) : <EOL> """<STR_LIT>""" <EOL> id = getServerId ( ) <EOL> server = serverManager . find ( id ) <EOL> if server : <EOL> schedule = serverManager . getSchedule ( server ) <EOL> print "<STR_LIT>" , id <EOL> print schedule <EOL> else : <EOL> print "<STR_LIT>" <EOL> def setBackupSchedule ( ) : <EOL> """<STR_LIT>""" <EOL> id = getServerId ( ) <EOL> server = serverManager . find ( id ) <EOL> if server : <EOL> backupSchedule = serverManager . getSchedule ( server ) <EOL> print "<STR_LIT>" , id <EOL> print backupSchedule <EOL> newbs = BackupSchedule ( True , daily = "<STR_LIT>" , weekly = "<STR_LIT>" ) <EOL> serverManager . setSchedule ( server , newbs ) <EOL> backupSchedule = serverManager . getSchedule ( server ) <EOL> print "<STR_LIT>" , id <EOL> print backupSchedule <EOL> else : <EOL> print "<STR_LIT>" <EOL> def showStatus ( ) : <EOL> """<STR_LIT>""" <EOL> id = getServerId ( ) <EOL> server = serverManager . find ( id ) <EOL> if server : <EOL> status = serverManager . status ( id ) <EOL> print "<STR_LIT>" , id <EOL> pprint ( status ) <EOL> else : <EOL> print "<STR_LIT>" <EOL> def showDetails ( ) : <EOL> """<STR_LIT>""" <EOL> id = getServerId ( ) <EOL> try : <EOL> server = serverManager . find ( id ) <EOL> except CloudServersFault , cf : <EOL> if cf . code == <NUM_LIT> : <EOL> print "<STR_LIT>" <EOL> return <EOL> print "<STR_LIT>" , server <EOL> pprint ( server ) <EOL> print "<STR_LIT>" , server . lastModified <EOL> def showImageDetails ( ) : <EOL> """<STR_LIT>""" <EOL> id = getImageId ( ) <EOL> try : <EOL> image = imageManager . find ( id ) <EOL> except CloudServersFault , cf : <EOL> if cf . code == <NUM_LIT> : <EOL> print "<STR_LIT>" <EOL> return <EOL> print "<STR_LIT>" , id <EOL> pprint ( image ) <EOL> def deleteServer ( ) : <EOL> """<STR_LIT>""" <EOL> id = getServerId ( ) <EOL> serverToDelete = serverManager . find ( id ) <EOL> if not serverToDelete : <EOL> print "<STR_LIT>" % id <EOL> else : <EOL> pprint ( serverToDelete ) <EOL> status = serverManager . remove ( serverToDelete ) <EOL> pprint ( status ) <EOL> def rebootServer ( ) : <EOL> """<STR_LIT>""" <EOL> id = getServerId ( ) <EOL> serverToReboot = serverManager . find ( id ) <EOL> if not serverToReboot : <EOL> print "<STR_LIT>" % id <EOL> return <EOL> print "<STR_LIT>" <EOL> hard_soft = stdin . readline ( ) . strip ( ) <EOL> if hard_soft in "<STR_LIT>" : <EOL> rType = rebootType . hard <EOL> else : <EOL> rType = rebootType . soft <EOL> sleepTime = getSleepTime ( ) <EOL> serverManager . reboot ( serverToReboot , rType ) <EOL> status = serverToReboot . status <EOL> while status != u"<STR_LIT>" : <EOL> status = serverToReboot . status <EOL> print "<STR_LIT>" , serverToReboot . status <EOL> print "<STR_LIT>" , serverToReboot . progress <EOL> print "<STR_LIT>" , sleepTime <EOL> sleep ( sleepTime ) <EOL> print "<STR_LIT>" <EOL> def notifyCallback ( isError , entity , fault = None ) : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" , isError <EOL> print "<STR_LIT>" , fault <EOL> print "<STR_LIT>" , entity <EOL> def createServer ( ) : <EOL> """<STR_LIT>""" <EOL> print "<STR_LIT>" <EOL> name = stdin . readline ( ) . strip ( ) <EOL> s = Server ( name = name , imageId = <NUM_LIT:3> , flavorId = <NUM_LIT:1> ) <EOL> serverManager . create ( s ) <EOL> serverManager . notify ( s , notifyCallback ) <EOL> pprint ( s ) <EOL> print "<STR_LIT>" , s <EOL> print "<STR_LIT>" <EOL> def createServerAndWait ( ) : <EOL> """<STR_LIT>""" <EOL> print "<STR_LIT>" <EOL> name = stdin . readline ( ) . strip ( ) <EOL> s = Server ( name = name , imageId = <NUM_LIT:3> , flavorId = <NUM_LIT:1> ) <EOL> serverManager . create ( s ) <EOL> pprint ( s ) <EOL> print "<STR_LIT>" , s <EOL> serverManager . wait ( s ) <EOL> print "<STR_LIT>" <EOL> def resizeServer ( ) : <EOL> """<STR_LIT>""" <EOL> id = getServerId ( ) <EOL> server = serverManager . find ( id ) <EOL> if server : <EOL> print "<STR_LIT>" , server <EOL> else : <EOL> print "<STR_LIT>" <EOL> flavorId = <NUM_LIT:2> <EOL> if server . flavorId == <NUM_LIT:2> : <EOL> flavorId = <NUM_LIT:1> <EOL> print "<STR_LIT>" , flavorId <EOL> serverManager . resize ( server , flavorId ) <EOL> serverManager . wait ( server ) <EOL> print "<STR_LIT>" <EOL> action = stdin . readline ( ) . strip ( ) <EOL> if action == '<STR_LIT>' : <EOL> serverManager . confirmResize ( server ) <EOL> serverManager . wait ( server ) <EOL> elif action == '<STR_LIT>' : <EOL> serverManager . revertResize ( server ) <EOL> serverManager . wait ( server ) <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" , server <EOL> def createSharedIpGroup ( ) : <EOL> """<STR_LIT>""" <EOL> print "<STR_LIT>" <EOL> name = stdin . readline ( ) . strip ( ) <EOL> print "<STR_LIT>" <EOL> server = None <EOL> found = False <EOL> id = <NUM_LIT:0> <EOL> while not found and id != - <NUM_LIT:1> : <EOL> id = getServerId ( ) <EOL> server = serverManager . find ( id ) <EOL> found = ( server != None ) <EOL> if found : <EOL> ipg = SharedIpGroup ( name , server . id ) <EOL> sharedIpGroupManager . create ( ipg ) <EOL> print "<STR_LIT>" <EOL> pprint ( ipg ) <EOL> def deleteSharedIpGroup ( ) : <EOL> """<STR_LIT>""" <EOL> print "<STR_LIT>" <EOL> name = getSharedIpGroupId ( ) <EOL> ipg = sharedIpGroupManager . find ( name ) <EOL> if not ipg : <EOL> print "<STR_LIT>" <EOL> else : <EOL> sharedIpGroupManager . remove ( ipg ) <EOL> def addServerToIpGroup ( ) : <EOL> """<STR_LIT>""" <EOL> serverId = getServerId ( ) <EOL> server = serverManager . find ( serverId ) <EOL> print "<STR_LIT>" , server <EOL> sharedIpGroupId = getSharedIpGroupId ( ) <EOL> sharedIpGroup = sharedIpGroupManager . find ( sharedIpGroupId ) <EOL> print "<STR_LIT>" , sharedIpGroup <EOL> ipAddress = getIpAddress ( ) <EOL> serverManager . shareIp ( server , ipAddress , sharedIpGroupId , True ) <EOL> pass <EOL> def testEntityListIter ( ) : <EOL> """<STR_LIT>""" <EOL> serverList = serverManager . createList ( detail = False ) <EOL> expected_length = len ( serverList ) <EOL> actual_length = <NUM_LIT:0> <EOL> for server in serverList : <EOL> actual_length += <NUM_LIT:1> <EOL> print "<STR_LIT>" , '<STR_LIT>' if actual_length == expected_length else '<STR_LIT>' <EOL> actual_length = <NUM_LIT:0> <EOL> serverList = serverManager . createList ( detail = False ) <EOL> while serverList . hasNext ( ) : <EOL> serverList . next ( ) <EOL> actual_length += <NUM_LIT:1> <EOL> print "<STR_LIT>" , '<STR_LIT>' if actual_length == expected_length else '<STR_LIT>' <EOL> actual_length = <NUM_LIT:0> <EOL> serverList . reset ( ) <EOL> for server in serverList : <EOL> actual_length += <NUM_LIT:1> <EOL> print "<STR_LIT>" , '<STR_LIT>' if actual_length == expected_length else '<STR_LIT>' <EOL> def testServerDeltaList ( ) : <EOL> datestr = datetime . now ( ) . strftime ( '<STR_LIT:%s>' ) <EOL> print "<STR_LIT>" <EOL> deltaList = serverManager . createDeltaList ( True , changes_since = datestr ) <EOL> print "<STR_LIT>" , datestr , "<STR_LIT>" <EOL> for item in deltaList : <EOL> print item . id , "<STR_LIT>" , item . name <EOL> def testFaultGeneration ( ) : <EOL> try : <EOL> print "<STR_LIT>" <EOL> serverManager . _cloudServersService . GET ( '<STR_LIT>' , { } ) <EOL> except Exception as e : <EOL> print "<STR_LIT>" , e . __class__ <EOL> print "<STR_LIT>" , e <EOL> def testPersonality ( ) : <EOL> s = Server ( name = "<STR_LIT:test>" , imageId = <NUM_LIT:3> , flavorId = <NUM_LIT:1> ) <EOL> p = Personality ( ) <EOL> f1 = File ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> f2 = File ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> p . files = [ f1 , f2 ] <EOL> s . personality = p <EOL> print "<STR_LIT>" , s . personality <EOL> print "<STR_LIT>" <EOL> for file in p . files : <EOL> print file . path , '<STR_LIT:U+0020>' , file . contents <EOL> print "<STR_LIT>" <EOL> print s . asJSON <EOL> print "<STR_LIT>" <EOL> s . personality = None <EOL> print s . asJSON <EOL> def waitOnFlavor ( ) : <EOL> flavorId = getFlavorId ( ) <EOL> flavor = flavorManager . find ( flavorId ) <EOL> print "<STR_LIT>" , flavor <EOL> flavorManager . wait ( flavor ) <EOL> def waitOnSharedIpGroup ( ) : <EOL> sharedIpGroupId = getSharedIpGroupId ( ) <EOL> sharedIpGroup = sharedIpGroupManager . find ( sharedIpGroupId ) <EOL> print "<STR_LIT>" , sharedIpGroup <EOL> sharedIpGroupManager . wait ( sharedIpGroup ) <EOL> def simpleNotify ( isError , entity , fault = None ) : <EOL> print "<STR_LIT>" <EOL> def _testNotify ( entityId , entityManager ) : <EOL> entity = entityManager . find ( entityId ) <EOL> entityManager . notify ( entity , simpleNotify ) <EOL> dic = { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:id>' : entityId } <EOL> if entity . name == dic [ '<STR_LIT:name>' ] : <EOL> dic [ '<STR_LIT:name>' ] = '<STR_LIT>' <EOL> entity . initFromResultDict ( dic ) <EOL> sleep ( <NUM_LIT:2> ) <EOL> entityManager . stopNotify ( entity , simpleNotify ) <EOL> def testServerNotify ( ) : <EOL> serverId = getServerId ( ) <EOL> _testNotify ( serverId , serverManager ) <EOL> def testImageNotify ( ) : <EOL> imageId = <NUM_LIT:3> <EOL> _testNotify ( imageId , imageManager ) <EOL> def testFlavorNotify ( ) : <EOL> flavorId = <NUM_LIT:1> <EOL> _testNotify ( flavorId , flavorManager ) <EOL> def testSharedIpGroupNotify ( ) : <EOL> sharedIpGroupId = getSharedIpGroupId ( ) <EOL> _testNotify ( sharedIpGroupId , sharedIpGroupManager ) <EOL> choices = dict ( ) <EOL> ls = partial ( lister , manager = serverManager , tag = "<STR_LIT>" ) <EOL> lf = partial ( lister , manager = flavorManager , tag = "<STR_LIT>" ) <EOL> li = partial ( lister , manager = imageManager , tag = "<STR_LIT>" ) <EOL> lsip = partial ( lister , manager = sharedIpGroupManager , tag = "<STR_LIT>" ) <EOL> shortLineLen = <NUM_LIT> <EOL> longLineLen = <NUM_LIT> <EOL> sepLine = '<STR_LIT:->' * shortLineLen <EOL> def groupHeader ( groupName ) : <EOL> groupLen = len ( groupName ) <EOL> numDashes = ( longLineLen - groupLen ) / <NUM_LIT:2> <EOL> return '<STR_LIT:\n>' + '<STR_LIT:->' * numDashes + '<STR_LIT:U+0020>' + groupName + '<STR_LIT:U+0020>' + '<STR_LIT:->' * numDashes <EOL> choicesList = ( <EOL> ( groupHeader ( "<STR_LIT>" ) , ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , lambda : ls ( False ) ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , lambda : ls ( True ) ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , testServerDeltaList ) ) , <EOL> ( sepLine , ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , showStatus ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , showDetails ) ) , <EOL> ( sepLine , ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , createServer ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , createServerAndWait ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , deleteServer ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , rebootServer ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , resizeServer ) ) , <EOL> ( sepLine , ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , showBackupSchedule ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , setBackupSchedule ) ) , <EOL> ( groupHeader ( "<STR_LIT>" ) , ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , lambda : lf ( False ) ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , lambda : lf ( True ) ) ) , <EOL> ( sepLine , ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , lambda : li ( False ) ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , lambda : li ( True ) ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , showImageDetails ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , waitOnFlavor ) ) , <EOL> ( groupHeader ( "<STR_LIT>" ) , ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , lambda : lsip ( False ) ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , lambda : lsip ( True ) ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , createSharedIpGroup ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , deleteSharedIpGroup ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , addServerToIpGroup ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , waitOnSharedIpGroup ) ) , <EOL> ( groupHeader ( "<STR_LIT>" ) , ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , showLimits ) ) , <EOL> ( groupHeader ( "<STR_LIT>" ) , ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , testEntityListIter ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , testPersonality ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , testFaultGeneration ) ) , <EOL> ( groupHeader ( "<STR_LIT>" ) , ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , testServerNotify ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , testImageNotify ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , testFlavorNotify ) ) , <EOL> ( "<STR_LIT>" , ChoiceItem ( "<STR_LIT>" , testSharedIpGroupNotify ) ) , <EOL> ( groupHeader ( "<STR_LIT>" ) , ) , <EOL> ( "<STR_LIT:q>" , ChoiceItem ( "<STR_LIT>" , lambda : exit ( <NUM_LIT:0> ) ) ) , <EOL> ( sepLine , ) , <EOL> ) <EOL> lookupDict = dict ( ) <EOL> for choice in choicesList : <EOL> if not '<STR_LIT:->' in choice [ <NUM_LIT:0> ] : <EOL> lookupDict [ choice [ <NUM_LIT:0> ] ] = choice [ <NUM_LIT:1> ] <EOL> slcu = "<STR_LIT>" <EOL> choice = "<STR_LIT>" <EOL> while <NUM_LIT:1> : <EOL> if choice in lookupDict : <EOL> lookupDict [ choice ] . func ( ) <EOL> else : <EOL> printChoices ( choicesList ) <EOL> choice = raw_input ( "<STR_LIT>" ) <EOL> if choice == "<STR_LIT:q>" : <EOL> print "<STR_LIT>" <EOL> exit ( <NUM_LIT:0> ) </s>
