#NEWLINE# def _request( self , command , json = True , opcode_name = 'command' , fetch_list = False , **kwargs ) : #NEWLINE# #INDENT# kwargs . update ( { #NEWLINE# #INDENT# 'apiKey' : self . key , #NEWLINE# opcode_name : response , #NEWLINE# #UNINDENT# } ) #NEWLINE# if json : #NEWLINE# #INDENT# kwargs [ 'response' ] = 'json' #NEWLINE# #UNINDENT# if ( ( 'page' in kwargs ) or fetch_list ) : #NEWLINE# #INDENT# kwargs . setdefault ( 'pagesize' , 500 ) #NEWLINE# #UNINDENT# kwarg = ( 'params' if ( self . method == 'get' ) else 'data' ) #NEWLINE# done = False #NEWLINE# final_data = [ ] #NEWLINE# page = 1 #NEWLINE# while ( not done ) : #NEWLINE# #INDENT# if fetch_list : #NEWLINE# #INDENT# kwargs [ 'page' ] = page #NEWLINE# #UNINDENT# kwargs = transform ( kwargs ) #NEWLINE# kwargs . pop ( 'signature' , None ) #NEWLINE# kwargs [ 'signature' ] = self . _sign ( kwargs ) #NEWLINE# response = getattr ( requests , self . method ) ( self . endpoint , timeout = self . timeout , ** { #NEWLINE# #INDENT# kwarg : kwargs , #NEWLINE# #UNINDENT# } ) #NEWLINE# try : #NEWLINE# #INDENT# data = response . json ( ) #NEWLINE# #UNINDENT# except ValueError as e : #NEWLINE# #INDENT# msg = ( "Make sure endpoint URL '%s' is correct." % self . endpoint ) #NEWLINE# raise CloudStackException ( 'HTTP {0} response from CloudStack' . format ( response . status_code ) , response , ( ( '%s. ' % str ( e ) ) + msg ) ) #NEWLINE# #UNINDENT# [ key ] = data . keys ( ) #NEWLINE# data = data [ key ] #NEWLINE# if ( response . status_code != 200 ) : #NEWLINE# #INDENT# raise CloudStackException ( 'HTTP {0} response from CloudStack' . format ( response . status_code ) , response , data ) #NEWLINE# #UNINDENT# if fetch_list : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# [ key ] = [ k for k in data . keys ( ) if ( k != 'count' ) ] #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# done = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# final_data . extend ( data [ key ] ) #NEWLINE# page += 1 #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# final_data = data #NEWLINE# done = True #NEWLINE# #UNINDENT# #UNINDENT# return final_data