summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2021-11-29 11:27:40 -0600
committerJohn Estabrook <jestabro@vyos.io>2021-11-30 10:43:29 -0600
commita17f8caf10a3e19f52f41e45ab3f28d12f460858 (patch)
treedb429905f6e92349851b197b1c6977018f07d36d /src
parent62e52d071610945bc3c9b8ca803d8ba1a5499876 (diff)
downloadvyos-1x-a17f8caf10a3e19f52f41e45ab3f28d12f460858.tar.gz
vyos-1x-a17f8caf10a3e19f52f41e45ab3f28d12f460858.zip
graphql: T3993: add op-mode requests
(cherry picked from commit 1f926e1b1fe7d82113be55916a55ca7e3cceac76)
Diffstat (limited to 'src')
-rw-r--r--src/services/api/graphql/graphql/directives.py16
-rw-r--r--src/services/api/graphql/graphql/mutations.py7
-rw-r--r--src/services/api/graphql/graphql/schema/schema.graphql2
-rw-r--r--src/services/api/graphql/graphql/schema/show.graphql14
-rw-r--r--src/services/api/graphql/recipes/session.py12
5 files changed, 46 insertions, 5 deletions
diff --git a/src/services/api/graphql/graphql/directives.py b/src/services/api/graphql/graphql/directives.py
index f5cd88acd..55aceca1b 100644
--- a/src/services/api/graphql/graphql/directives.py
+++ b/src/services/api/graphql/graphql/directives.py
@@ -1,5 +1,5 @@
from ariadne import SchemaDirectiveVisitor, ObjectType
-from . mutations import make_configure_resolver, make_config_file_resolver
+from . mutations import *
def non(arg):
pass
@@ -19,7 +19,6 @@ class VyosDirective(SchemaDirectiveVisitor):
class ConfigureDirective(VyosDirective):
"""
Class providing implementation of 'configure' directive in schema.
-
"""
def visit_field_definition(self, field, object_type):
super().visit_field_definition(field, object_type,
@@ -28,10 +27,19 @@ class ConfigureDirective(VyosDirective):
class ConfigFileDirective(VyosDirective):
"""
Class providing implementation of 'configfile' directive in schema.
-
"""
def visit_field_definition(self, field, object_type):
super().visit_field_definition(field, object_type,
make_resolver=make_config_file_resolver)
-directives_dict = {"configure": ConfigureDirective, "configfile": ConfigFileDirective}
+class ShowDirective(VyosDirective):
+ """
+ Class providing implementation of 'show' directive in schema.
+ """
+ def visit_field_definition(self, field, object_type):
+ super().visit_field_definition(field, object_type,
+ make_resolver=make_show_resolver)
+
+directives_dict = {"configure": ConfigureDirective,
+ "configfile": ConfigFileDirective,
+ "show": ShowDirective}
diff --git a/src/services/api/graphql/graphql/mutations.py b/src/services/api/graphql/graphql/mutations.py
index 8a28b13d7..5913ee8b1 100644
--- a/src/services/api/graphql/graphql/mutations.py
+++ b/src/services/api/graphql/graphql/mutations.py
@@ -51,7 +51,8 @@ def make_resolver(mutation_name, class_name, session_func):
klass = type(class_name, (Session,), {})
k = klass(session, data)
method = getattr(k, session_func)
- method()
+ result = method()
+ data['result'] = result
return {
"success": True,
@@ -78,3 +79,7 @@ def make_config_file_resolver(mutation_name):
return make_resolver(mutation_name, class_name, 'load')
else:
raise Exception
+
+def make_show_resolver(mutation_name):
+ class_name = mutation_name
+ return make_resolver(mutation_name, class_name, 'show')
diff --git a/src/services/api/graphql/graphql/schema/schema.graphql b/src/services/api/graphql/graphql/schema/schema.graphql
index 9e97a0d60..764a50130 100644
--- a/src/services/api/graphql/graphql/schema/schema.graphql
+++ b/src/services/api/graphql/graphql/schema/schema.graphql
@@ -9,6 +9,7 @@ type Query {
directive @configure on FIELD_DEFINITION
directive @configfile on FIELD_DEFINITION
+directive @show on FIELD_DEFINITION
type Mutation {
CreateDhcpServer(data: DhcpServerConfigInput) : CreateDhcpServerResult @configure
@@ -18,4 +19,5 @@ type Mutation {
RemoveFirewallAddressGroupMembers(data: RemoveFirewallAddressGroupMembersInput) : RemoveFirewallAddressGroupMembersResult @configure
SaveConfigFile(data: SaveConfigFileInput) : SaveConfigFileResult @configfile
LoadConfigFile(data: LoadConfigFileInput) : LoadConfigFileResult @configfile
+ Show(data: ShowInput) : ShowResult @show
}
diff --git a/src/services/api/graphql/graphql/schema/show.graphql b/src/services/api/graphql/graphql/schema/show.graphql
new file mode 100644
index 000000000..c7709e48b
--- /dev/null
+++ b/src/services/api/graphql/graphql/schema/show.graphql
@@ -0,0 +1,14 @@
+input ShowInput {
+ path: [String!]!
+}
+
+type Show {
+ path: [String]
+ result: String
+}
+
+type ShowResult {
+ data: Show
+ success: Boolean!
+ errors: [String]
+}
diff --git a/src/services/api/graphql/recipes/session.py b/src/services/api/graphql/recipes/session.py
index b96cc1753..c6c3209c0 100644
--- a/src/services/api/graphql/recipes/session.py
+++ b/src/services/api/graphql/recipes/session.py
@@ -63,3 +63,15 @@ class Session(object):
session.commit()
except Exception as error:
raise error
+
+ def show(self):
+ session = self._session
+ data = self._data
+ out = ''
+
+ try:
+ out = session.show(data['path'])
+ except Exception as error:
+ raise error
+
+ return out