<s> from openstack . compute import base <EOL> from openstack . compute . api import API_OPTIONS <EOL> REBOOT_SOFT , REBOOT_HARD = '<STR_LIT>' , '<STR_LIT>' <EOL> class Server ( base . Resource ) : <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % self . name <EOL> def delete ( self ) : <EOL> """<STR_LIT>""" <EOL> self . manager . delete ( self ) <EOL> def update ( self , name = None , password = None ) : <EOL> """<STR_LIT>""" <EOL> self . manager . update ( self , name , password ) <EOL> def share_ip ( self , ipgroup = None , address = None , configure = True ) : <EOL> """<STR_LIT>""" <EOL> if address == None : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> self . manager . share_ip ( self , ipgroup , address , configure ) <EOL> def unshare_ip ( self , address ) : <EOL> """<STR_LIT>""" <EOL> self . manager . unshare_ip ( self , address ) <EOL> def reboot ( self , type = REBOOT_SOFT ) : <EOL> """<STR_LIT>""" <EOL> self . manager . reboot ( self , type ) <EOL> def rebuild ( self , image ) : <EOL> """<STR_LIT>""" <EOL> self . manager . rebuild ( self , image ) <EOL> def resize ( self , flavor ) : <EOL> """<STR_LIT>""" <EOL> self . manager . resize ( self , flavor ) <EOL> def confirm_resize ( self ) : <EOL> """<STR_LIT>""" <EOL> self . manager . confirm_resize ( self ) <EOL> def revert_resize ( self ) : <EOL> """<STR_LIT>""" <EOL> self . manager . revert_resize ( self ) <EOL> @ property <EOL> def backup_schedule ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . manager . api . backup_schedules . get ( self ) <EOL> @ property <EOL> def public_ip ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . addresses [ '<STR_LIT>' ] : <EOL> return self . addresses [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> else : <EOL> return u'<STR_LIT>' <EOL> @ property <EOL> def private_ip ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . addresses [ '<STR_LIT>' ] : <EOL> return self . addresses [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> else : <EOL> return u'<STR_LIT>' <EOL> class ServerManager ( base . ManagerWithFind ) : <EOL> resource_class = Server <EOL> def get ( self , server ) : <EOL> """<STR_LIT>""" <EOL> return self . _get ( "<STR_LIT>" % base . getid ( server ) , "<STR_LIT>" ) <EOL> def list ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _list ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def create ( self , name , image , flavor , ipgroup = None , meta = None , files = None ) : <EOL> """<STR_LIT>""" <EOL> body = { "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : name , <EOL> "<STR_LIT>" : base . getid ( image ) , <EOL> "<STR_LIT>" : base . getid ( flavor ) , <EOL> } } <EOL> if ipgroup : <EOL> body [ "<STR_LIT>" ] [ "<STR_LIT>" ] = base . getid ( ipgroup ) <EOL> if meta : <EOL> body [ "<STR_LIT>" ] [ "<STR_LIT>" ] = meta <EOL> if files : <EOL> personality = body [ '<STR_LIT>' ] [ '<STR_LIT>' ] = [ ] <EOL> for filepath , file_or_string in files . items ( ) : <EOL> if hasattr ( file_or_string , '<STR_LIT>' ) : <EOL> data = file_or_string . read ( ) <EOL> else : <EOL> data = file_or_string <EOL> personality . append ( { <EOL> '<STR_LIT:path>' : filepath , <EOL> '<STR_LIT>' : data . encode ( '<STR_LIT>' ) , <EOL> } ) <EOL> return self . _create ( "<STR_LIT>" , body , "<STR_LIT>" ) <EOL> def update ( self , server , name = None , password = None ) : <EOL> """<STR_LIT>""" <EOL> if name is None and password is None : <EOL> return <EOL> body = { "<STR_LIT>" : { } } <EOL> if name : <EOL> body [ "<STR_LIT>" ] [ "<STR_LIT:name>" ] = name <EOL> if password : <EOL> body [ "<STR_LIT>" ] [ "<STR_LIT>" ] = password <EOL> self . _update ( "<STR_LIT>" % base . getid ( server ) , body ) <EOL> def delete ( self , server ) : <EOL> """<STR_LIT>""" <EOL> self . _delete ( "<STR_LIT>" % base . getid ( server ) ) <EOL> def share_ip ( self , server , ipgroup = None , address = None , configure = True ) : <EOL> """<STR_LIT>""" <EOL> if address == None : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> if '<STR_LIT>' in API_OPTIONS [ self . api . config . cloud_api ] : <EOL> if ipgroup == None : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> server = base . getid ( server ) <EOL> ipgroup = base . getid ( ipgroup ) <EOL> body = { '<STR_LIT>' : { '<STR_LIT>' : ipgroup , '<STR_LIT>' : configure } } <EOL> self . _update ( "<STR_LIT>" % ( server , address ) , body ) <EOL> else : <EOL> pass <EOL> def unshare_ip ( self , server , address ) : <EOL> """<STR_LIT>""" <EOL> server = base . getid ( server ) <EOL> self . _delete ( "<STR_LIT>" % ( server , address ) ) <EOL> def reboot ( self , server , type = REBOOT_SOFT ) : <EOL> """<STR_LIT>""" <EOL> self . _action ( '<STR_LIT>' , server , { '<STR_LIT:type>' : type } ) <EOL> def rebuild ( self , server , image ) : <EOL> """<STR_LIT>""" <EOL> self . _action ( '<STR_LIT>' , server , { '<STR_LIT>' : base . getid ( image ) } ) <EOL> def resize ( self , server , flavor ) : <EOL> """<STR_LIT>""" <EOL> self . _action ( '<STR_LIT>' , server , { '<STR_LIT>' : base . getid ( flavor ) } ) <EOL> def confirm_resize ( self , server ) : <EOL> """<STR_LIT>""" <EOL> self . _action ( '<STR_LIT>' , server ) <EOL> def revert_resize ( self , server ) : <EOL> """<STR_LIT>""" <EOL> self . _action ( '<STR_LIT>' , server ) <EOL> def _action ( self , action , server , info = None ) : <EOL> """<STR_LIT>""" <EOL> self . api . client . post ( '<STR_LIT>' % base . getid ( server ) , body = { action : info } ) </s>
