summaryrefslogtreecommitdiff
path: root/src/services/api/graphql/recipes/recipe.py
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2021-08-06 14:55:55 -0500
committerJohn Estabrook <jestabro@vyos.io>2021-08-06 14:55:55 -0500
commit56467e9967d9bb3c5588bb76493a71868e177a10 (patch)
tree22196f7442102df1c92a76eac5ff5a8441038bcc /src/services/api/graphql/recipes/recipe.py
parent158d6f2141d5b7c8a0b234d7b4089dd5174c592b (diff)
downloadvyos-1x-56467e9967d9bb3c5588bb76493a71868e177a10.tar.gz
vyos-1x-56467e9967d9bb3c5588bb76493a71868e177a10.zip
Revert "http-api: T2768: example using GraphQL for high-level config operations"
This reverts commit a2b959c50c96698da173b9c4720369a51442cc5c.
Diffstat (limited to 'src/services/api/graphql/recipes/recipe.py')
-rw-r--r--src/services/api/graphql/recipes/recipe.py49
1 files changed, 0 insertions, 49 deletions
diff --git a/src/services/api/graphql/recipes/recipe.py b/src/services/api/graphql/recipes/recipe.py
deleted file mode 100644
index 8fbb9e0bf..000000000
--- a/src/services/api/graphql/recipes/recipe.py
+++ /dev/null
@@ -1,49 +0,0 @@
-from ariadne import convert_camel_case_to_snake
-import vyos.defaults
-from vyos.template import render
-
-class Recipe(object):
- def __init__(self, session, data):
- self._session = session
- 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
- func_base_name = self._name
-
- tmpl_file = f'{func_base_name}.tmpl'
- cmd_file = f'/tmp/{func_base_name}.cmds'
- tmpl_dir = vyos.defaults.directories['api_templates']
-
- try:
- render(cmd_file, tmpl_file, data, location=tmpl_dir)
- commands = []
- with open(cmd_file) as f:
- lines = f.readlines()
- for line in lines:
- commands.append(line.split())
- for cmd in commands:
- if cmd[0] == 'set':
- session.set(cmd[1:])
- elif cmd[0] == 'delete':
- session.delete(cmd[1:])
- else:
- raise ValueError('Operation must be "set" or "delete"')
- session.commit()
- except Exception as error:
- raise error
-
-