@ -124,56 +124,80 @@ class Netconf(NetconfBase):
# TODO: change .xml to .data_xml, when ncclient supports data_xml on all platforms
# TODO: change .xml to .data_xml, when ncclient supports data_xml on all platforms
@ensure_connected
@ensure_connected
def get ( self , filter = None ):
def get ( self , filter = None , remove_ns = False ):
if isinstance ( filter , list ) :
if isinstance ( filter , list ) :
filter = tuple ( filter )
filter = tuple ( filter )
try :
try :
response = self . m . get ( filter = filter )
resp = self . m . get ( filter = filter )
return remove_namespaces ( response )
if remove_ns :
response = remove_namespaces ( resp )
else :
response = resp . data_xml if hasattr ( resp , ' data_xml ' ) else resp . xml
return response
except RPCError as exc :
except RPCError as exc :
raise Exception ( to_xml ( exc . xml ) )
raise Exception ( to_xml ( exc . xml ) )
@ensure_connected
@ensure_connected
def get_config ( self , source = None , filter = None ):
def get_config ( self , source = None , filter = None , remove_ns = False ):
if isinstance ( filter , list ) :
if isinstance ( filter , list ) :
filter = tuple ( filter )
filter = tuple ( filter )
try :
try :
response = self . m . get_config ( source = source , filter = filter )
resp = self . m . get_config ( source = source , filter = filter )
return remove_namespaces ( response )
if remove_ns :
response = remove_namespaces ( resp )
else :
response = resp . data_xml if hasattr ( resp , ' data_xml ' ) else resp . xml
return response
except RPCError as exc :
except RPCError as exc :
raise Exception ( to_xml ( exc . xml ) )
raise Exception ( to_xml ( exc . xml ) )
@ensure_connected
@ensure_connected
def edit_config ( self , config = None , format = ' xml ' , target = ' candidate ' , default_operation = None , test_option = None , error_option = None ):
def edit_config ( self , config = None , format = ' xml ' , target = ' candidate ' , default_operation = None , test_option = None , error_option = None , remove_ns = False ):
if config is None :
if config is None :
raise ValueError ( ' config value must be provided ' )
raise ValueError ( ' config value must be provided ' )
try :
try :
resp onse = self . m . edit_config ( config , format = format , target = target , default_operation = default_operation , test_option = test_option ,
resp = self . m . edit_config ( config , format = format , target = target , default_operation = default_operation , test_option = test_option ,
error_option = error_option )
error_option = error_option )
return remove_namespaces ( response )
if remove_ns :
response = remove_namespaces ( resp )
else :
response = resp . data_xml if hasattr ( resp , ' data_xml ' ) else resp . xml
return response
except RPCError as exc :
except RPCError as exc :
raise Exception ( to_xml ( exc . xml ) )
raise Exception ( to_xml ( exc . xml ) )
@ensure_connected
@ensure_connected
def commit ( self , confirmed = False , timeout = None , persist = None ):
def commit ( self , confirmed = False , timeout = None , persist = None , remove_ns = False ):
try :
try :
response = self . m . commit ( confirmed = confirmed , timeout = timeout , persist = persist )
resp = self . m . commit ( confirmed = confirmed , timeout = timeout , persist = persist )
return remove_namespaces ( response )
if remove_ns :
response = remove_namespaces ( resp )
else :
response = resp . data_xml if hasattr ( resp , ' data_xml ' ) else resp . xml
return response
except RPCError as exc :
except RPCError as exc :
raise Exception ( to_xml ( exc . xml ) )
raise Exception ( to_xml ( exc . xml ) )
@ensure_connected
@ensure_connected
def validate ( self , source = " candidate " ):
def validate ( self , source = " candidate " , remove_ns = False ):
try :
try :
response = self . m . validate ( source = source )
resp = self . m . validate ( source = source )
return remove_namespaces ( response )
if remove_ns :
response = remove_namespaces ( resp )
else :
response = resp . data_xml if hasattr ( resp , ' data_xml ' ) else resp . xml
return response
except RPCError as exc :
except RPCError as exc :
raise Exception ( to_xml ( exc . xml ) )
raise Exception ( to_xml ( exc . xml ) )
@ensure_connected
@ensure_connected
def discard_changes ( self ):
def discard_changes ( self , remove_ns = False ):
try :
try :
response = self . m . discard_changes ( )
resp = self . m . discard_changes ( )
return remove_namespaces ( response )
if remove_ns :
response = remove_namespaces ( resp )
else :
response = resp . data_xml if hasattr ( resp , ' data_xml ' ) else resp . xml
return response
except RPCError as exc :
except RPCError as exc :
raise Exception ( to_xml ( exc . xml ) )
raise Exception ( to_xml ( exc . xml ) )