diff options
author | John Estabrook <jestabro@vyos.io> | 2021-11-23 14:10:51 -0600 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2021-11-24 13:33:45 -0600 |
commit | f97c72ee7efd7ecd57c72a0387154738922c48f5 (patch) | |
tree | 4468ae825406dd99959d31e8d1ac4b2a01976ecc /src/services/api/graphql/recipes/session.py | |
parent | 114be88565cd09c0a7dcbe67a753d7d2834659b9 (diff) | |
download | vyos-1x-f97c72ee7efd7ecd57c72a0387154738922c48f5.tar.gz vyos-1x-f97c72ee7efd7ecd57c72a0387154738922c48f5.zip |
graphql: T3993: add requests for manipulating firewall groups
(cherry picked from commit ee53af35eb1edb6167a65b290f25a95b2a586498)
Diffstat (limited to 'src/services/api/graphql/recipes/session.py')
-rw-r--r-- | src/services/api/graphql/recipes/session.py | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/src/services/api/graphql/recipes/session.py b/src/services/api/graphql/recipes/session.py index aa3932ab9..b96cc1753 100644 --- a/src/services/api/graphql/recipes/session.py +++ b/src/services/api/graphql/recipes/session.py @@ -1,27 +1,17 @@ from ariadne import convert_camel_case_to_snake import vyos.defaults +from vyos.config import Config from vyos.template import render class Session(object): def __init__(self, session, data): self._session = session - self.data = data + self._data = data self._name = convert_camel_case_to_snake(type(self).__name__) - @property - def data(self): - return self.__data - - @data.setter - def data(self, data): - if isinstance(data, dict): - self.__data = data - else: - raise ValueError("data must be of type dict") - def configure(self): session = self._session - data = self.data + data = self._data func_base_name = self._name tmpl_file = f'{func_base_name}.tmpl' @@ -46,9 +36,16 @@ class Session(object): except Exception as error: raise error + def delete_path_if_childless(self, path): + session = self._session + config = Config(session.get_session_env()) + if not config.list_nodes(path): + session.delete(path) + session.commit() + def save(self): session = self._session - data = self.data + data = self._data if 'file_name' not in data or not data['file_name']: data['file_name'] = '/config/config.boot' @@ -59,7 +56,7 @@ class Session(object): def load(self): session = self._session - data = self.data + data = self._data try: session.load_config(data['file_name']) |