Those options were wrongly added to Wok configuration.
This patch makes all the adjustments needed to read the information from
the plugin config file. And also move federation information under
/config API (instead of, /config/capabilities) as it is part of Kimchi
configuration and does not depend on any other tool support.
Signed-off-by: Aline Manera <alinefm(a)linux.vnet.ibm.com>
---
config.py.in | 11 ++++++++++-
docs/API.md | 2 +-
docs/README-federation.md | 4 ++--
kimchi.conf | 8 ++++++++
model/config.py | 13 ++++++-------
model/peers.py | 14 ++++++++------
model/storagepools.py | 8 ++++----
tests/test_config.py.in | 4 ++++
tests/test_rest.py | 6 +++---
ui/js/src/kimchi.api.js | 16 ++++++++++++++++
ui/js/src/kimchi.main.js | 16 ++++++++++++----
11 files changed, 74 insertions(+), 28 deletions(-)
diff --git a/config.py.in b/config.py.in
index 8b43b4e..44a49f2 100644
--- a/config.py.in
+++ b/config.py.in
@@ -1,7 +1,7 @@
#
# Project Kimchi
#
-# Copyright IBM, Corp. 2013-2015
+# Copyright IBM, Corp. 2013-2016
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -22,6 +22,7 @@ import libvirt
import os
import platform
import threading
+from cherrypy.lib.reprconf import Parser
from wok.config import CACHEEXPIRES, PluginConfig, PluginPaths
from wok.xmlutils.utils import xpath_get_text
@@ -55,6 +56,14 @@ def get_screenshot_path():
return os.path.join(PluginPaths('kimchi').state_dir, 'screenshots')
+def get_config():
+ plugin_conf = PluginPaths('kimchi').conf_file
+ return Parser().dict_from_file(plugin_conf)
+
+
+config = get_config()
+
+
def find_qemu_binary(find_emulator=False):
try:
connect = libvirt.open(None)
diff --git a/docs/API.md b/docs/API.md
index 1b01a6e..5122a0c 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -698,6 +698,7 @@ Contains information about Kimchi configuration.
**Methods:**
* **GET**: Retrieve configuration information
+ * federation: True if federation feature is enabled, False otherwise.
* version: The version of the kimchi service
* **POST**: *See Configuration Actions*
@@ -728,7 +729,6 @@ creation.
system; False, otherwise
* repo_mngt_tool: 'deb', 'yum' or None - when the repository
management
tool is not identified
- * federation: 'on' if federation feature is enabled, 'off'
otherwise.
* **POST**: *See Configuration Actions*
**Actions (POST):**
diff --git a/docs/README-federation.md b/docs/README-federation.md
index c184f4f..3554757 100644
--- a/docs/README-federation.md
+++ b/docs/README-federation.md
@@ -46,9 +46,9 @@ To enable it, do the following:
4. Start slpd service and make sure it is up while running Wok
sudo service slpd start
-5. Enable federation on Wok by editing the /etc/wok/wok.conf file:
+5. Enable federation on Wok by editing the /etc/wok/plugins.d/kimchi.conf file:
- federation = on
+ federation = True
6. Then start Wok service
sudo service wokd start
diff --git a/kimchi.conf b/kimchi.conf
index 8df72f3..0ea916a 100644
--- a/kimchi.conf
+++ b/kimchi.conf
@@ -5,6 +5,14 @@ enable = True
# Root URI for Kimchi APIs
uri = "/plugins/kimchi"
+[kimchi]
+# Federation feature: register Wok server on openSLP and discover peers
+# in the same network. Check README-federation for more details.
+federation = False
+
+# Automatically create ISO pool on server start up
+create_iso_pool = True
+
[/]
tools.trailing_slash.on = False
request.methods_with_bodies = ('POST', 'PUT')
diff --git a/model/config.py b/model/config.py
index da5248c..6cd9f07 100644
--- a/model/config.py
+++ b/model/config.py
@@ -21,12 +21,11 @@ import cherrypy
from multiprocessing.pool import ThreadPool
from wok.basemodel import Singleton
-from wok.config import config as kconfig
-
from wok.exception import NotFoundError
from wok.utils import run_command, wok_log
-from wok.plugins.kimchi.config import find_qemu_binary, get_kimchi_version
+from wok.plugins.kimchi.config import config, find_qemu_binary
+from wok.plugins.kimchi.config import get_kimchi_version
from wok.plugins.kimchi.distroloader import DistroLoader
from wok.plugins.kimchi.model.featuretests import FeatureTests
from wok.plugins.kimchi.model.featuretests import FEATURETEST_POOL_NAME
@@ -40,7 +39,9 @@ class ConfigModel(object):
pass
def lookup(self, name):
- return {'version': get_kimchi_version()}
+ kconfig = config.get('kimchi', {})
+ return {'federation': kconfig.get('federation', False),
+ 'version': get_kimchi_version()}
class CapabilitiesModel(object):
@@ -117,11 +118,9 @@ class CapabilitiesModel(object):
'qemu_spice': self._qemu_support_spice(),
'qemu_stream': self.qemu_stream,
'screenshot': VMScreenshot.get_stream_test_result(),
- 'federation': kconfig.get("server",
"federation"),
'kernel_vfio': self.kernel_vfio,
'nm_running': FeatureTests.is_nm_running(),
- 'mem_hotplug_support': self.mem_hotplug_support
- }
+ 'mem_hotplug_support': self.mem_hotplug_support}
class DistrosModel(object):
diff --git a/model/peers.py b/model/peers.py
index 7577364..f0bc13a 100644
--- a/model/peers.py
+++ b/model/peers.py
@@ -1,7 +1,7 @@
#
# Project Kimchi
#
-# Copyright IBM, Corp. 2014-2015
+# Copyright IBM, Corp. 2014-2016
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -21,19 +21,21 @@ import cherrypy
import re
import socket
-from wok.config import config
+from wok.config import config as wok_config
from wok.utils import run_command, wok_log
+from wok.plugins.kimchi.config import config
+
class PeersModel(object):
def __init__(self, **kargs):
# check federation feature is enabled on Kimchi server
- if config.get("server", "federation") == "off":
+ if not config.get('kimchi', {}).get('federation', False):
return
# register server on openslp
- hostname = socket.getfqdn(config.get("server", "host"))
- port = config.get("server", "ssl_port")
+ hostname = socket.getfqdn(wok_config.get("server", "host"))
+ port = wok_config.get("server", "ssl_port")
self.url = hostname + ":" + port
cmd = ["slptool", "register",
@@ -54,7 +56,7 @@ class PeersModel(object):
def get_list(self):
# check federation feature is enabled on Kimchi server
- if config.get("server", "federation") == "off":
+ if not config.get('kimchi', {}).get('federation', False):
return []
cmd = ["slptool", "findsrvs", "service:wokd"]
diff --git a/model/storagepools.py b/model/storagepools.py
index 4861df0..685d38b 100644
--- a/model/storagepools.py
+++ b/model/storagepools.py
@@ -1,7 +1,7 @@
#
# Project Kimchi
#
-# Copyright IBM, Corp. 2014-2015
+# Copyright IBM, Corp. 2014-2016
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -22,13 +22,13 @@ import lxml.etree as ET
import sys
from lxml.builder import E
-from wok.config import config, PluginPaths
+from wok.config import PluginPaths
from wok.exception import InvalidOperation, MissingParameter
from wok.exception import NotFoundError, OperationFailed
from wok.utils import add_task, run_command, wok_log
from wok.xmlutils.utils import xpath_get_text
-from wok.plugins.kimchi.config import get_kimchi_version
+from wok.plugins.kimchi.config import config, get_kimchi_version
from wok.plugins.kimchi.model.config import CapabilitiesModel
from wok.plugins.kimchi.model.host import DeviceModel
from wok.plugins.kimchi.model.libvirtstoragepool import StoragePoolDef
@@ -78,7 +78,7 @@ class StoragePoolsModel(object):
if default_pool == 'default':
pools[default_pool] = {'path': '/var/lib/libvirt/images'}
- if config.get("server", "create_iso_pool") ==
"true":
+ if config.get('kimchi', {}).get('create_iso_pool', False):
pools['ISO'] = {'path': '/var/lib/kimchi/isos'}
error_msg = ("Please, check the configuration in %s/template.conf to "
diff --git a/tests/test_config.py.in b/tests/test_config.py.in
index abb1d75..43a9003 100644
--- a/tests/test_config.py.in
+++ b/tests/test_config.py.in
@@ -79,6 +79,10 @@ class ConfigTests(unittest.TestCase):
'enable': True,
'uri': '/plugins/kimchi'
},
+ 'kimchi': {
+ 'federation': False,
+ 'create_iso_pool': True
+ },
'/': {
'tools.trailing_slash.on': False,
'request.methods_with_bodies': ('POST', 'PUT'),
diff --git a/tests/test_rest.py b/tests/test_rest.py
index 9fa3795..f4c4f4e 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -1226,7 +1226,7 @@ class RestTests(unittest.TestCase):
def test_config(self):
resp = self.request('/plugins/kimchi/config').read()
conf = json.loads(resp)
- keys = ["version"]
+ keys = ["federation", "version"]
self.assertEquals(keys, sorted(conf.keys()))
def test_capabilities(self):
@@ -1234,8 +1234,8 @@ class RestTests(unittest.TestCase):
conf = json.loads(resp)
keys = [u'libvirt_stream_protocols', u'qemu_stream',
u'qemu_spice',
- u'screenshot', u'kernel_vfio', u'federation',
- u'nm_running', u'mem_hotplug_support']
+ u'screenshot', u'kernel_vfio', u'nm_running',
+ u'mem_hotplug_support']
self.assertEquals(sorted(keys), sorted(conf.keys()))
def test_peers(self):
diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js
index 445cc80..a1df9f8 100644
--- a/ui/js/src/kimchi.api.js
+++ b/ui/js/src/kimchi.api.js
@@ -22,6 +22,22 @@ var kimchi = {
trackingTasks: [],
/**
+ * Get Kimchi details
+ */
+ getConfig : function(suc, err, done) {
+ done = typeof done !== 'undefined' ? done: function(){};
+ wok.requestJSON({
+ url : "plugins/kimchi/config",
+ type : "GET",
+ contentType : "application/json",
+ dataType : "json",
+ success: suc,
+ error: err,
+ complete: done
+ });
+ },
+
+ /**
*
* Get host capabilities
* suc: callback if succeed err: callback if failed
diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js
index 2fdeb85..fbfd4ce 100644
--- a/ui/js/src/kimchi.main.js
+++ b/ui/js/src/kimchi.main.js
@@ -1,7 +1,7 @@
/*
* Project Kimchi
*
- * Copyright IBM, Corp. 2013-2014
+ * Copyright IBM, Corp. 2013-2016
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,12 +15,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+kimchi.config = undefined;
+kimchi.getConfig(function(result) {
+ kimchi.config = result;
+
+ if(kimchi.config.federation == true)
+ $('#peers').removeClass('hide-content');
+}, function() {
+ kimchi.config = {}
+});
+
kimchi.capabilities = undefined;
kimchi.getCapabilities(function(result) {
kimchi.capabilities = result;
-
- if(kimchi.capabilities.federation=="on")
- $('#peers').removeClass('hide-content');
}, function() {
kimchi.capabilities = {};
});
--
2.5.0