<s> import os <EOL> import web <EOL> import simplejson as json <EOL> import karesansui <EOL> from karesansui . lib . rest import Rest , auth <EOL> from karesansui . lib . const import VIRT_COMMAND_APPLY_SNAPSHOT <EOL> from karesansui . lib . utils import is_param , is_int <EOL> from karesansui . lib . virt . snapshot import KaresansuiVirtSnapshot <EOL> from karesansui . db . access . machine import findbyguest1 <EOL> from karesansui . db . access . snapshot import findbyname_guestby1 as s_findbyname_guestby1 <EOL> from karesansui . db . access . _2pysilhouette import save_job_collaboration <EOL> from karesansui . db . access . machine2jobgroup import new as m2j_new <EOL> from karesansui . db . model . _2pysilhouette import Job , JobGroup <EOL> from pysilhouette . command import dict2command <EOL> class GuestBy1CurrentSnapshot ( Rest ) : <EOL> @ auth <EOL> def _PUT ( self , * param , ** params ) : <EOL> ( host_id , guest_id ) = self . chk_guestby1 ( param ) <EOL> if guest_id is None : return web . notfound ( ) <EOL> if is_param ( self . input , '<STR_LIT:id>' ) is False or is_int ( self . input . id ) is False : <EOL> return web . badrequest ( "<STR_LIT>" ) <EOL> snapshot_id = str ( self . input . id ) <EOL> snapshot = s_findbyname_guestby1 ( self . orm , snapshot_id , guest_id ) <EOL> if snapshot is None : <EOL> pass <EOL> model = findbyguest1 ( self . orm , guest_id ) <EOL> kvs = KaresansuiVirtSnapshot ( readonly = False ) <EOL> snapshot_list = [ ] <EOL> try : <EOL> domname = kvs . kvc . uuid_to_domname ( model . uniq_key ) <EOL> if not domname : return web . notfound ( ) <EOL> self . view . is_creatable = kvs . isSupportedDomain ( domname ) <EOL> try : <EOL> snapshot_list = kvs . listNames ( domname ) [ domname ] <EOL> except : <EOL> pass <EOL> finally : <EOL> kvs . finish ( ) <EOL> if not snapshot_id in snapshot_list : <EOL> self . logger . debug ( _ ( "<STR_LIT>" ) % snapshot_id ) <EOL> action_cmd = dict2command ( <EOL> "<STR_LIT>" % ( karesansui . config [ '<STR_LIT>' ] , <EOL> VIRT_COMMAND_APPLY_SNAPSHOT ) , <EOL> { "<STR_LIT:name>" : domname , "<STR_LIT:id>" : snapshot_id } ) <EOL> cmdname = '<STR_LIT>' <EOL> _jobgroup = JobGroup ( cmdname , karesansui . sheconf [ '<STR_LIT>' ] ) <EOL> _job = Job ( '<STR_LIT>' % cmdname , <NUM_LIT:0> , action_cmd ) <EOL> _jobgroup . jobs . append ( _job ) <EOL> _machine2jobgroup = m2j_new ( machine = model , <EOL> jobgroup_id = - <NUM_LIT:1> , <EOL> uniq_key = karesansui . sheconf [ '<STR_LIT>' ] , <EOL> created_user = self . me , <EOL> modified_user = self . me , <EOL> ) <EOL> save_job_collaboration ( self . orm , <EOL> self . pysilhouette . orm , <EOL> _machine2jobgroup , <EOL> _jobgroup , <EOL> ) <EOL> self . view . currentsnapshot = snapshot <EOL> return web . accepted ( url = web . ctx . path ) <EOL> urls = ( <EOL> '<STR_LIT>' , GuestBy1CurrentSnapshot , <EOL> ) </s>
