<s> """<STR_LIT>""" <EOL> from six . moves import urllib <EOL> from novaclient import base <EOL> from novaclient import client <EOL> from novaclient import exceptions as exc <EOL> class Version ( base . Resource ) : <EOL> """<STR_LIT>""" <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" <EOL> class VersionManager ( base . ManagerWithFind ) : <EOL> resource_class = Version <EOL> def _is_session_client ( self ) : <EOL> return isinstance ( self . api . client , client . SessionClient ) <EOL> def _get_current ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _is_session_client ( ) : <EOL> try : <EOL> url = "<STR_LIT:%s>" % self . api . client . get_endpoint ( ) <EOL> return self . _get ( url , "<STR_LIT:version>" ) <EOL> except exc . NotFound : <EOL> url = "<STR_LIT>" % url . rsplit ( "<STR_LIT:/>" , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> return self . _get ( url , "<STR_LIT:version>" ) <EOL> else : <EOL> all_versions = self . list ( ) <EOL> url = self . client . management_url . rsplit ( "<STR_LIT:/>" , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> for version in all_versions : <EOL> for link in version . links : <EOL> if link [ "<STR_LIT>" ] . rstrip ( '<STR_LIT:/>' ) == url : <EOL> version . append_request_ids ( all_versions . request_ids ) <EOL> return version <EOL> def get_current ( self ) : <EOL> try : <EOL> return self . _get_current ( ) <EOL> except exc . Unauthorized : <EOL> return None <EOL> def list ( self ) : <EOL> """<STR_LIT>""" <EOL> version_url = None <EOL> if self . _is_session_client ( ) : <EOL> endpoint = self . api . client . get_endpoint ( ) <EOL> url = urllib . parse . urlparse ( endpoint ) <EOL> version_url = '<STR_LIT>' % ( url . scheme , url . netloc ) <EOL> return self . _list ( version_url , "<STR_LIT>" ) </s>
