#NEWLINE# def _get_state( self , name = None ) : #NEWLINE# #INDENT# headers = { #NEWLINE# #INDENT# 'Content-Type' : 'application/json' , #NEWLINE# #UNINDENT# } #NEWLINE# url = '/v1-alpha/state' #NEWLINE# if name : #NEWLINE# #INDENT# url += '?unitName={name}.service' . format ( ** locals ( ) ) #NEWLINE# #UNINDENT# self . conn . request ( 'GET' , url , headers = headers ) #NEWLINE# resp = self . conn . getresponse ( ) #NEWLINE# data = resp . read ( ) #NEWLINE# if ( resp . status not in ( 200 , ) ) : #NEWLINE# #INDENT# errmsg = 'Failed to retrieve state: {} {} - {}' . format ( resp . status , resp . reason , data ) #NEWLINE# raise RuntimeError ( errmsg ) #NEWLINE# #UNINDENT# return json . loads ( data )