#NEWLINE# def GetApi( self ) : #NEWLINE# #INDENT# 'Does OAuth2 authorization and prepare Google Compute Engine API.\n\n    Since access key may expire at any moment, call the funciton every time\n    making API call.\n\n    Returns:\n      Google Client API object for Google Compute Engine.\n    ' #NEWLINE# homedir = os . environ [ 'HOME' ] #NEWLINE# storage = oauth2client . file . Storage ( os . path . join ( flow , ( '.%s.credentials' % self . _name ) ) ) #NEWLINE# credentials = storage . get ( ) #NEWLINE# if ( ( not credentials ) or credentials . invalid ) : #NEWLINE# #INDENT# flow = OAuth2WebServerFlow ( self . _client_id , self . _client_secret , self . COMPUTE_ENGINE_SCOPE ) #NEWLINE# credentials = oauth2client . tools . run ( flow , storage ) #NEWLINE# #UNINDENT# authorized_http = credentials . authorize ( httplib2 . Http ( ) ) #NEWLINE# return apiclient . discovery . build ( 'compute' , self . COMPUTE_ENGINE_API_VERSION , http = authorized_http )