<s> import os <EOL> import sys <EOL> import logging <EOL> from optparse import OptionParser <EOL> from ksscommand import KssCommand , KssCommandException , KssCommandOptException <EOL> import __cmd__ <EOL> try : <EOL> import karesansui <EOL> from karesansui import __version__ <EOL> from karesansui . lib . virt . virt import KaresansuiVirtConnection , VIR_DOMAIN_PAUSED <EOL> from karesansui . lib . utils import load_locale <EOL> except ImportError , e : <EOL> print >> sys . stderr , "<STR_LIT>" % e <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> _ = load_locale ( ) <EOL> usage = '<STR_LIT>' <EOL> def getopts ( ) : <EOL> optp = OptionParser ( usage = usage , version = __version__ ) <EOL> optp . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:name>' , help = _ ( '<STR_LIT>' ) ) <EOL> return optp . parse_args ( ) <EOL> def chkopts ( opts ) : <EOL> if not opts . name : <EOL> raise KssCommandOptException ( '<STR_LIT>' ) <EOL> class ResumeGuest ( KssCommand ) : <EOL> def process ( self ) : <EOL> ( opts , args ) = getopts ( ) <EOL> chkopts ( opts ) <EOL> self . up_progress ( <NUM_LIT:10> ) <EOL> conn = KaresansuiVirtConnection ( readonly = False ) <EOL> try : <EOL> conn . set_domain_name ( opts . name ) <EOL> active_guests = conn . list_active_guest ( ) <EOL> inactive_guests = conn . list_inactive_guest ( ) <EOL> if opts . name in active_guests or opts . name in inactive_guests : <EOL> try : <EOL> self . up_progress ( <NUM_LIT:10> ) <EOL> conn . resume_guest ( ) <EOL> self . up_progress ( <NUM_LIT:30> ) <EOL> except Exception , e : <EOL> self . logger . error ( '<STR_LIT>' % ( opts . name ) ) <EOL> print >> sys . stderr , _ ( '<STR_LIT>' ) % ( opts . name ) <EOL> raise e <EOL> self . up_progress ( <NUM_LIT:10> ) <EOL> status = conn . guest . status ( ) <EOL> self . up_progress ( <NUM_LIT:10> ) <EOL> if status != VIR_DOMAIN_PAUSED : <EOL> self . logger . info ( '<STR_LIT>' % ( opts . name ) ) <EOL> print >> sys . stdout , _ ( '<STR_LIT>' ) % ( opts . name ) <EOL> else : <EOL> self . logger . error ( '<STR_LIT>' % ( opts . name ) ) <EOL> print >> sys . stderr , _ ( '<STR_LIT>' ) % ( opts . name ) <EOL> return False <EOL> return True <EOL> finally : <EOL> conn . close ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> target = ResumeGuest ( ) <EOL> sys . exit ( target . run ( ) ) </s>
