summaryrefslogtreecommitdiff
path: root/src/services/api/graphql/recipes
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2022-07-25 10:34:17 +0100
committerGitHub <noreply@github.com>2022-07-25 10:34:17 +0100
commit3337aedd5f7ff48bfad051d760023a188fdace70 (patch)
tree3dc5b5c22444430a74f8d0f8a8ed54415a8ccd47 /src/services/api/graphql/recipes
parente1e9f690d3eb4cd03aba118558fffd5b6b2920c8 (diff)
parentf9d6f089014007193996e51757f72a8bf7ec78b9 (diff)
downloadvyos-1x-3337aedd5f7ff48bfad051d760023a188fdace70.tar.gz
vyos-1x-3337aedd5f7ff48bfad051d760023a188fdace70.zip
Merge pull request #1431 from jestabro/gql-dev
graphql: T4567: Merge experimental branch of GraphQL development
Diffstat (limited to 'src/services/api/graphql/recipes')
-rwxr-xr-xsrc/services/api/graphql/recipes/queries/system_status.py45
-rw-r--r--src/services/api/graphql/recipes/session.py14
2 files changed, 59 insertions, 0 deletions
diff --git a/src/services/api/graphql/recipes/queries/system_status.py b/src/services/api/graphql/recipes/queries/system_status.py
new file mode 100755
index 000000000..00c137443
--- /dev/null
+++ b/src/services/api/graphql/recipes/queries/system_status.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2022 VyOS maintainers and contributors
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 or later as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+#
+
+import os
+import sys
+import json
+import importlib.util
+
+from vyos.defaults import directories
+
+OP_PATH = directories['op_mode']
+
+def load_as_module(name: str):
+ path = os.path.join(OP_PATH, name)
+ spec = importlib.util.spec_from_file_location(name, path)
+ mod = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(mod)
+ return mod
+
+def get_system_version() -> dict:
+ show_version = load_as_module('version.py')
+ return show_version.show(raw=True, funny=False)
+
+def get_system_uptime() -> dict:
+ show_uptime = load_as_module('show_uptime.py')
+ return show_uptime.get_raw_data()
+
+def get_system_ram_usage() -> dict:
+ show_ram = load_as_module('memory.py')
+ return show_ram.show(raw=True)
diff --git a/src/services/api/graphql/recipes/session.py b/src/services/api/graphql/recipes/session.py
index 1f844ff70..c436de08a 100644
--- a/src/services/api/graphql/recipes/session.py
+++ b/src/services/api/graphql/recipes/session.py
@@ -136,3 +136,17 @@ class Session:
raise error
return res
+
+ def system_status(self):
+ import api.graphql.recipes.queries.system_status as system_status
+
+ session = self._session
+ data = self._data
+
+ status = {}
+ status['host_name'] = session.show(['host', 'name']).strip()
+ status['version'] = system_status.get_system_version()
+ status['uptime'] = system_status.get_system_uptime()
+ status['ram'] = system_status.get_system_ram_usage()
+
+ return status