
Signed-off-by: Aline Manera <alinefm@linux.vnet.ibm.com> --- src/kimchi/control/peers.py | 29 ++++++++++++++++++++++++++ src/kimchi/model/peers.py | 50 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/kimchi/control/peers.py create mode 100644 src/kimchi/model/peers.py diff --git a/src/kimchi/control/peers.py b/src/kimchi/control/peers.py new file mode 100644 index 0000000..f72a38c --- /dev/null +++ b/src/kimchi/control/peers.py @@ -0,0 +1,29 @@ +# +# Project Kimchi +# +# Copyright IBM, Corp. 2014 +# +# 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 kimchi.control.base import SimpleCollection +from kimchi.control.utils import UrlSubNode + + +@UrlSubNode("peers", True) +class Peers(SimpleCollection): + def __init__(self, model): + super(Peers, self).__init__(model) + self.role_key = 'peers' + self.admin_methods = ['GET'] diff --git a/src/kimchi/model/peers.py b/src/kimchi/model/peers.py new file mode 100644 index 0000000..d0f8808 --- /dev/null +++ b/src/kimchi/model/peers.py @@ -0,0 +1,50 @@ +# +# Project Kimchi +# +# Copyright IBM, Corp. 2014 +# +# 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 re +import socket + +from kimchi.config import config +from kimchi.utils import kimchi_log, run_command + + +class PeersModel(object): + def __init__(self, **kargs): + # TODO: only register server on openSLP if federation feature is + # enabled + # register server on openslp + hostname = socket.getfqdn(config.get("server", "host")) + port = config.get("server", "ssl_port") + + cmd = ["slptool", "register", + "service:kimchid://%s:%s" % (hostname, port)] + out, error, ret = run_command(cmd) + if len(out) != 0: + kimchi_log.info("Unable to register server on openSLP") + + def get_list(self): + peers = [] + + cmd = ["slptool", "findsrvs", "service:kimchid"] + out, error, ret = run_command(cmd) + for server in out.strip().split("\n"): + match = re.match("service:kimchid://(.*?),.*", server) + peers.append("https://" + match.group(1)) + + return peers -- 1.9.3