[Kimchi-devel] [PATCH 07/15] V3 Ginger Base : control files

chandra at linux.vnet.ibm.com chandra at linux.vnet.ibm.com
Wed Oct 7 10:43:05 UTC 2015


From: chandrureddy <chandra at linux.vnet.ibm.com>

---
 src/wok/plugins/gingerbase/control/Makefile.am     |  25 ++++
 src/wok/plugins/gingerbase/control/__init__.py     |  26 ++++
 src/wok/plugins/gingerbase/control/cpuinfo.py      |  37 ++++++
 src/wok/plugins/gingerbase/control/debugreports.py |  61 +++++++++
 src/wok/plugins/gingerbase/control/host.py         | 145 +++++++++++++++++++++
 src/wok/plugins/kimchi/control/debugreports.py     |  61 ---------
 6 files changed, 294 insertions(+), 61 deletions(-)
 create mode 100644 src/wok/plugins/gingerbase/control/Makefile.am
 create mode 100644 src/wok/plugins/gingerbase/control/__init__.py
 create mode 100644 src/wok/plugins/gingerbase/control/cpuinfo.py
 create mode 100644 src/wok/plugins/gingerbase/control/debugreports.py
 create mode 100644 src/wok/plugins/gingerbase/control/host.py
 delete mode 100644 src/wok/plugins/kimchi/control/debugreports.py

diff --git a/src/wok/plugins/gingerbase/control/Makefile.am b/src/wok/plugins/gingerbase/control/Makefile.am
new file mode 100644
index 0000000..49da0ae
--- /dev/null
+++ b/src/wok/plugins/gingerbase/control/Makefile.am
@@ -0,0 +1,25 @@
+#
+# Ginger Base
+#
+# Copyright IBM Corp, 2015
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+control_PYTHON = *.py
+
+controldir = $(pythondir)/wok/plugins/gingerbase/control
+
+install-data-local:
+	$(MKDIR_P) $(DESTDIR)$(controldir)
diff --git a/src/wok/plugins/gingerbase/control/__init__.py b/src/wok/plugins/gingerbase/control/__init__.py
new file mode 100644
index 0000000..b4d8dfd
--- /dev/null
+++ b/src/wok/plugins/gingerbase/control/__init__.py
@@ -0,0 +1,26 @@
+#
+# Project Ginger Base
+#
+# Copyright IBM, Corp. 2015
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+import os
+
+
+from wok.control.utils import load_url_sub_node
+
+
+sub_nodes = load_url_sub_node(os.path.dirname(__file__), __name__)
diff --git a/src/wok/plugins/gingerbase/control/cpuinfo.py b/src/wok/plugins/gingerbase/control/cpuinfo.py
new file mode 100644
index 0000000..f992bf5
--- /dev/null
+++ b/src/wok/plugins/gingerbase/control/cpuinfo.py
@@ -0,0 +1,37 @@
+#
+# Project Ginger Base
+#
+# Copyright IBM, Corp. 2014-2015
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+
+from wok.control.base import Resource
+
+
+class CPUInfo(Resource):
+    def __init__(self, model):
+        super(CPUInfo, self).__init__(model)
+        self.admin_methods = ['GET']
+        self.role_key = 'host'
+        self.uri_fmt = "/host/cpuinfo"
+
+    @property
+    def data(self):
+        return {'threading_enabled': self.info['guest_threads_enabled'],
+                'sockets': self.info['sockets'],
+                'cores': self.info['cores_available'],
+                'threads_per_core': self.info['threads_per_core']
+                }
diff --git a/src/wok/plugins/gingerbase/control/debugreports.py b/src/wok/plugins/gingerbase/control/debugreports.py
new file mode 100644
index 0000000..2e76654
--- /dev/null
+++ b/src/wok/plugins/gingerbase/control/debugreports.py
@@ -0,0 +1,61 @@
+#
+# Project Ginger Base
+#
+# Copyright IBM, Corp. 2013-2015
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+from wok.control.base import AsyncCollection, Resource
+from wok.control.utils import internal_redirect
+from wok.control.utils import UrlSubNode
+
+
+ at UrlSubNode('debugreports', True)
+class DebugReports(AsyncCollection):
+    def __init__(self, model):
+        super(DebugReports, self).__init__(model)
+        self.resource = DebugReport
+        self.role_key = 'host'
+        self.admin_methods = ['GET', 'POST']
+
+    def _get_resources(self, filter_params):
+        res_list = super(DebugReports, self)._get_resources(filter_params)
+        return sorted(res_list, key=lambda x: x.data['time'], reverse=True)
+
+
+class DebugReport(Resource):
+    def __init__(self, model, ident):
+        super(DebugReport, self).__init__(model, ident)
+        self.role_key = 'host'
+        self.admin_methods = ['GET', 'PUT', 'POST']
+        self.uri_fmt = '/debugreports/%s'
+        self.content = DebugReportContent(model, ident)
+
+    @property
+    def data(self):
+        return {'name': self.ident,
+                'uri': self.info['uri'],
+                'time': self.info['ctime']}
+
+
+class DebugReportContent(Resource):
+    def __init__(self, model, ident):
+        super(DebugReportContent, self).__init__(model, ident)
+        self.role_key = 'host'
+        self.admin_methods = ['GET']
+
+    def get(self):
+        self.lookup()
+        raise internal_redirect(self.info['uri'])
diff --git a/src/wok/plugins/gingerbase/control/host.py b/src/wok/plugins/gingerbase/control/host.py
new file mode 100644
index 0000000..b923569
--- /dev/null
+++ b/src/wok/plugins/gingerbase/control/host.py
@@ -0,0 +1,145 @@
+#
+# Project Ginger Base
+#
+# Copyright IBM, Corp. 2013-2015
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+from wok.control.base import Collection, Resource
+from wok.control.utils import UrlSubNode
+from wok.exception import NotFoundError
+
+from cpuinfo import CPUInfo
+
+
+ at UrlSubNode('host', True)
+class Host(Resource):
+    def __init__(self, model, id=None):
+        super(Host, self).__init__(model, id)
+        self.role_key = 'host'
+        self.admin_methods = ['GET', 'POST']
+        self.uri_fmt = '/host/%s'
+        self.reboot = self.generate_action_handler('reboot')
+        self.shutdown = self.generate_action_handler('shutdown')
+        self.stats = HostStats(self.model)
+        self.partitions = Partitions(self.model)
+        # self.devices = Devices(self.model)
+        self.packagesupdate = PackagesUpdate(self.model)
+        self.repositories = Repositories(self.model)
+        self.swupdate = self.generate_action_handler_task('swupdate')
+        self.cpuinfo = CPUInfo(self.model)
+        self.capabilities = Capabilities(self.model)
+
+    @property
+    def data(self):
+        return self.info
+
+
+class HostStats(Resource):
+    def __init__(self, model, id=None):
+        super(HostStats, self).__init__(model, id)
+        self.role_key = 'host'
+        self.admin_methods = ['GET']
+        self.history = HostStatsHistory(self.model)
+
+    @property
+    def data(self):
+        return self.info
+
+
+class HostStatsHistory(Resource):
+    @property
+    def data(self):
+        return self.info
+
+
+class Capabilities(Resource):
+    def __init__(self, model, id=None):
+        super(Capabilities, self).__init__(model, id)
+
+    @property
+    def data(self):
+        return self.info
+
+
+class Partitions(Collection):
+    def __init__(self, model):
+        super(Partitions, self).__init__(model)
+        self.role_key = 'storage'
+        self.admin_methods = ['GET']
+        self.resource = Partition
+
+    # Defining get_resources in order to return list of partitions in UI
+    # sorted by their path
+    def _get_resources(self, flag_filter):
+        res_list = super(Partitions, self)._get_resources(flag_filter)
+        res_list = filter(lambda x: x.info['available'], res_list)
+        res_list.sort(key=lambda x: x.info['path'])
+        return res_list
+
+
+class Partition(Resource):
+    def __init__(self, model, id):
+        self.role_key = 'storage'
+        self.admin_methods = ['GET']
+        super(Partition, self).__init__(model, id)
+
+    @property
+    def data(self):
+        if not self.info['available']:
+            raise NotFoundError("GGBPART0001E", {'name': self.info['name']})
+
+        return self.info
+
+
+class PackagesUpdate(Collection):
+    def __init__(self, model):
+        super(PackagesUpdate, self).__init__(model)
+        self.role_key = 'host'
+        self.admin_methods = ['GET']
+        self.resource = PackageUpdate
+
+
+class PackageUpdate(Resource):
+    def __init__(self, model, id=None):
+        super(PackageUpdate, self).__init__(model, id)
+        self.role_key = 'host'
+        self.admin_methods = ['GET']
+
+    @property
+    def data(self):
+        return self.info
+
+
+class Repositories(Collection):
+    def __init__(self, model):
+        super(Repositories, self).__init__(model)
+        self.role_key = 'host'
+        self.admin_methods = ['GET', 'POST']
+        self.resource = Repository
+
+
+class Repository(Resource):
+    def __init__(self, model, id):
+        super(Repository, self).__init__(model, id)
+        self.role_key = 'host'
+        self.admin_methods = ['GET', 'PUT', 'POST', 'DELETE']
+        self.uri_fmt = "/host/repositories/%s"
+        self.enable = self.generate_action_handler('enable')
+        self.disable = self.generate_action_handler('disable')
+
+    @property
+    def data(self):
+        return self.info
diff --git a/src/wok/plugins/kimchi/control/debugreports.py b/src/wok/plugins/kimchi/control/debugreports.py
deleted file mode 100644
index b5a3072..0000000
--- a/src/wok/plugins/kimchi/control/debugreports.py
+++ /dev/null
@@ -1,61 +0,0 @@
-#
-# Project Kimchi
-#
-# Copyright IBM, Corp. 2013-2015
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library 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
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
-
-from wok.control.base import AsyncCollection, Resource
-from wok.control.utils import internal_redirect
-from wok.control.utils import UrlSubNode
-
-
- at UrlSubNode('debugreports', True)
-class DebugReports(AsyncCollection):
-    def __init__(self, model):
-        super(DebugReports, self).__init__(model)
-        self.resource = DebugReport
-        self.role_key = 'host'
-        self.admin_methods = ['GET', 'POST']
-
-    def _get_resources(self, filter_params):
-        res_list = super(DebugReports, self)._get_resources(filter_params)
-        return sorted(res_list, key=lambda x: x.data['time'], reverse=True)
-
-
-class DebugReport(Resource):
-    def __init__(self, model, ident):
-        super(DebugReport, self).__init__(model, ident)
-        self.role_key = 'host'
-        self.admin_methods = ['GET', 'PUT', 'POST']
-        self.uri_fmt = '/debugreports/%s'
-        self.content = DebugReportContent(model, ident)
-
-    @property
-    def data(self):
-        return {'name': self.ident,
-                'uri': self.info['uri'],
-                'time': self.info['ctime']}
-
-
-class DebugReportContent(Resource):
-    def __init__(self, model, ident):
-        super(DebugReportContent, self).__init__(model, ident)
-        self.role_key = 'host'
-        self.admin_methods = ['GET']
-
-    def get(self):
-        self.lookup()
-        raise internal_redirect(self.info['uri'])
-- 
2.1.0




More information about the Kimchi-devel mailing list