<s> """<STR_LIT>""" <EOL> from apscheduler . schedulers . background import BackgroundScheduler <EOL> from pytz import utc <EOL> from . . logger import log <EOL> from base import CliTask <EOL> from . . account . service import AzureAccount <EOL> from . . utils . collector import DataCollector <EOL> from . . utils . output import DataOutput <EOL> from . . instance . image import Image <EOL> from . . help import Help <EOL> class ComputeImageTask ( CliTask ) : <EOL> """<STR_LIT>""" <EOL> def process ( self ) : <EOL> self . manual = Help ( ) <EOL> if self . __help ( ) : <EOL> return <EOL> self . result = DataCollector ( ) <EOL> self . out = DataOutput ( <EOL> self . result , <EOL> self . global_args [ '<STR_LIT>' ] , <EOL> self . global_args [ '<STR_LIT>' ] <EOL> ) <EOL> self . load_config ( ) <EOL> self . account = AzureAccount ( self . config ) <EOL> self . image = Image ( self . account ) <EOL> if self . command_args [ '<STR_LIT:list>' ] : <EOL> self . __list ( ) <EOL> if self . command_args [ '<STR_LIT>' ] : <EOL> self . __show ( ) <EOL> elif self . command_args [ '<STR_LIT>' ] : <EOL> self . __create ( ) <EOL> elif self . command_args [ '<STR_LIT>' ] : <EOL> self . __delete ( ) <EOL> elif self . command_args [ '<STR_LIT>' ] : <EOL> self . __replicate ( ) <EOL> elif self . command_args [ '<STR_LIT>' ] : <EOL> self . __replication_status ( self . command_args [ '<STR_LIT>' ] ) <EOL> elif self . command_args [ '<STR_LIT>' ] : <EOL> self . __unreplicate ( ) <EOL> elif self . command_args [ '<STR_LIT>' ] : <EOL> self . __publish ( ) <EOL> elif self . command_args [ '<STR_LIT>' ] : <EOL> self . __update ( ) <EOL> def __help ( self ) : <EOL> if self . command_args [ '<STR_LIT>' ] : <EOL> self . manual . show ( '<STR_LIT>' ) <EOL> else : <EOL> return False <EOL> return self . manual <EOL> def __create ( self ) : <EOL> self . result . add ( <EOL> '<STR_LIT>' + self . command_args [ '<STR_LIT>' ] , <EOL> self . image . create ( <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> self . account . storage_container ( ) <EOL> ) <EOL> ) <EOL> self . out . display ( ) <EOL> def __delete ( self ) : <EOL> self . result . add ( <EOL> '<STR_LIT>' + self . command_args [ '<STR_LIT>' ] , <EOL> self . image . delete ( <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> ) <EOL> ) <EOL> self . out . display ( ) <EOL> def __list ( self ) : <EOL> self . result . add ( '<STR_LIT>' , self . image . list ( ) ) <EOL> self . out . display ( ) <EOL> def __show ( self ) : <EOL> self . result . add ( '<STR_LIT:image>' , self . image . show ( self . command_args [ '<STR_LIT>' ] ) ) <EOL> self . out . display ( ) <EOL> def __replicate ( self ) : <EOL> image_name = self . command_args [ '<STR_LIT>' ] <EOL> self . result . add ( <EOL> '<STR_LIT>' + <EOL> self . command_args [ '<STR_LIT>' ] + '<STR_LIT::>' + self . command_args [ '<STR_LIT>' ] , <EOL> self . image . replicate ( <EOL> image_name , <EOL> self . command_args [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) , <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> self . command_args [ '<STR_LIT>' ] <EOL> ) <EOL> ) <EOL> if not self . command_args [ '<STR_LIT>' ] : <EOL> self . out . display ( ) <EOL> if self . command_args [ '<STR_LIT>' ] : <EOL> if not self . command_args [ '<STR_LIT>' ] : <EOL> progress = BackgroundScheduler ( timezone = utc ) <EOL> progress . add_job ( <EOL> lambda : self . image . print_replication_status ( image_name ) , <EOL> '<STR_LIT>' , <EOL> minutes = <NUM_LIT:5> <EOL> ) <EOL> progress . start ( ) <EOL> try : <EOL> self . image . wait_for_replication_completion ( image_name ) <EOL> self . image . print_replication_status ( image_name ) <EOL> except KeyboardInterrupt : <EOL> raise SystemExit ( '<STR_LIT>' ) <EOL> finally : <EOL> progress . shutdown ( ) <EOL> if not self . command_args [ '<STR_LIT>' ] : <EOL> print <EOL> log . info ( '<STR_LIT>' , image_name ) <EOL> def __replication_status ( self , image_name ) : <EOL> self . result . add ( <EOL> '<STR_LIT>' + image_name , <EOL> self . image . replication_status ( image_name ) <EOL> ) <EOL> self . out . display ( ) <EOL> def __unreplicate ( self ) : <EOL> self . result . add ( <EOL> '<STR_LIT>' + self . command_args [ '<STR_LIT>' ] , <EOL> self . image . unreplicate ( <EOL> self . command_args [ '<STR_LIT>' ] <EOL> ) <EOL> ) <EOL> self . out . display ( ) <EOL> def __publish ( self ) : <EOL> scope = '<STR_LIT>' <EOL> if self . command_args [ '<STR_LIT>' ] : <EOL> scope = '<STR_LIT>' <EOL> elif self . command_args [ '<STR_LIT>' ] : <EOL> scope = '<STR_LIT>' <EOL> self . result . add ( <EOL> '<STR_LIT>' + self . command_args [ '<STR_LIT>' ] , <EOL> self . image . publish ( <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> scope <EOL> ) <EOL> ) <EOL> self . out . display ( ) <EOL> def __update ( self ) : <EOL> log . info ( <EOL> '<STR_LIT>' , self . command_args [ '<STR_LIT>' ] <EOL> ) <EOL> update_elements = { <EOL> '<STR_LIT:description>' : <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> '<STR_LIT:label>' : <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : <EOL> self . command_args [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : <EOL> self . command_args [ '<STR_LIT>' ] <EOL> } <EOL> for name , value in update_elements . iteritems ( ) : <EOL> if value is not None : <EOL> log . info ( '<STR_LIT>' , name , value ) <EOL> self . image . update ( <EOL> self . command_args [ '<STR_LIT>' ] , update_elements <EOL> ) </s>
