From 59aa23b2f5b4985305f809ba11124a8eeedf39b6 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 1 Mar 2019 15:21:29 -0500 Subject: [PATCH] Add noderename command --- confluent_client/bin/noderename | 52 +++++++++++++++++++ confluent_server/confluent/messages.py | 7 +++ .../plugins/configuration/attributes.py | 11 ++-- 3 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 confluent_client/bin/noderename diff --git a/confluent_client/bin/noderename b/confluent_client/bin/noderename new file mode 100644 index 00000000..3308a293 --- /dev/null +++ b/confluent_client/bin/noderename @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2019 Lenovo +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import optparse +import os +import signal +import sys +try: + signal.signal(signal.SIGPIPE, signal.SIG_DFL) +except AttributeError: + pass + +path = os.path.dirname(os.path.realpath(__file__)) +path = os.path.realpath(os.path.join(path, '..', 'lib', 'python')) +if path.startswith('/opt'): + sys.path.append(path) + +import confluent.client as client + +argparser = optparse.OptionParser(usage="Usage: %prog ") +(options, args) = argparser.parse_args() +try: + noderange = args[0] +except IndexError: + argparser.print_help() + sys.exit(1) +client.check_globbing(noderange) +identifystate = None +if len(sys.argv) > 2: + newname = sys.argv[2] +else: + argparser.print_help() + sys.exit(1) +session = client.Command() +exitcode = 0 +sys.exit( + session.simple_noderange_command(noderange, 'attributes/rename', newname)) + diff --git a/confluent_server/confluent/messages.py b/confluent_server/confluent/messages.py index bf5acf46..b317aa44 100644 --- a/confluent_server/confluent/messages.py +++ b/confluent_server/confluent/messages.py @@ -278,6 +278,13 @@ class RenamedResource(ConfluentMessage): pass +class RenamedNode(ConfluentMessage): + def __init__(self, name, rename): + self.desc = 'New Name' + kv = {'rename': {'value': rename}} + self.kvpairs = {name: kv} + + class AssignedResource(ConfluentMessage): notnode = True readonly = True diff --git a/confluent_server/confluent/plugins/configuration/attributes.py b/confluent_server/confluent/plugins/configuration/attributes.py index df9da5ae..e9b3b1fc 100644 --- a/confluent_server/confluent/plugins/configuration/attributes.py +++ b/confluent_server/confluent/plugins/configuration/attributes.py @@ -165,7 +165,7 @@ def update_nodegroup(group, element, configmanager, inputdata): namemap = {} namemap[group] = inputdata.attribs['rename'] configmanager.rename_nodegroups(namemap) - return yield_rename_resources(namemap) + return yield_rename_resources(namemap, isnode=False) try: clearattribs = [] for attrib in inputdata.attribs.iterkeys(): @@ -205,9 +205,12 @@ def create(nodes, element, configmanager, inputdata): if nodes is not None and element[-1] == 'expression': return _expand_expression(nodes, configmanager, inputdata) -def yield_rename_resources(namemap): +def yield_rename_resources(namemap, isnode): for node in namemap: - yield msg.RenamedResource(node, namemap[node]) + if isnode: + yield msg.RenamedNode(node, namemap[node]) + else: + yield msg.RenamedResource(node, namemap[node]) def update_nodes(nodes, element, configmanager, inputdata): updatedict = {} @@ -221,7 +224,7 @@ def update_nodes(nodes, element, configmanager, inputdata): rename = inputdata.get_attributes(node) namemap[node] = rename['rename'] configmanager.rename_nodes(namemap) - return yield_rename_resources(namemap) + return yield_rename_resources(namemap, isnode=True) for node in nodes: updatenode = inputdata.get_attributes(node, allattributes.node) clearattribs = []