I'm trying to get a Python program, using gsconfig api, to create dynamically a Geoserver layer with data from a native SQL (like you do on the Geoserver web interface).
I can create the workspace and the datastore, but I can't figure out how to create a layer with a sql view of the Postgis database (example: select * from table where _filter_clause_).
This is the current Python code that I have.
from geoserver.catalog import Catalog
if __name__ == '__main__':
cat = Catalog("http://localhost:8080/geoserver/rest", username = "admin", password = "geoserver")
ws = cat.get_workspace ("wsProva")
if ws is None:
ws = cat.create_workspace('wsProva','wsProva')
ds = cat.get_store ("dsProva", "wsProva")
if ds is None:
ds = cat.create_datastore('dsProva','wsProva')
ds.connection_parameters.update (host='localhost', port='5432', database='dbtest', user='userdb', passwd='pwddb', dbtype='postgis', schema='postgis')
cat.save(ds)
I've googled a lot about this issue, but I haven't found anything useful for me. Thanks a lot for your replies.
2020 update,
You can simply use geoserver-rest library (
pip install geoserver-rest
). The example case is below,