diff --git a/senlinclient/v1/client.py b/senlinclient/v1/client.py index 1852b39e..d5a27f88 100644 --- a/senlinclient/v1/client.py +++ b/senlinclient/v1/client.py @@ -214,6 +214,14 @@ class Client(object): """ return self.service.cluster_del_nodes(cluster, nodes) + def cluster_replace_nodes(self, cluster, nodes): + """Replace the nodes in a cluster with specified nodes + + Doc link: + http://developer.openstack.org/api-ref-clustering-v1.html#clusterAction + """ + return self.service.cluster_replace_nodes(cluster, nodes) + def cluster_resize(self, cluster, **params): """Resize cluster diff --git a/senlinclient/v1/cluster.py b/senlinclient/v1/cluster.py index b43a430c..1b98a444 100644 --- a/senlinclient/v1/cluster.py +++ b/senlinclient/v1/cluster.py @@ -723,6 +723,42 @@ class ClusterNodeDel(command.Command): print('Request accepted by action: %s' % resp['action']) +class ClusterNodeReplace(command.Command): + """Replace the nodes in a cluster with specified nodes.""" + log = logging.getLogger(__name__ + ".ClusterNodeReplace") + + def get_parser(self, prog_name): + parser = super(ClusterNodeReplace, self).get_parser(prog_name) + parser.add_argument( + '--nodes', + metavar='', + required=True, + help=_("OLD_NODE is the name or ID of a node to be replaced, " + "NEW_NODE is the name or ID of a node as replacement. " + "This can be specified multiple times, or once with " + "node-pairs separated by a comma ','."), + action='append' + ) + parser.add_argument( + 'cluster', + metavar='', + help=_('Name or ID of cluster to operate on') + ) + return parser + + def take_action(self, parsed_args): + self.log.debug("take_action(%s)", parsed_args) + senlin_client = self.app.client_manager.clustering + nodepairs = {} + for nodepair in parsed_args.nodes: + key = nodepair.split('=')[0] + value = nodepair.split('=')[1] + nodepairs[key] = value + resp = senlin_client.cluster_replace_nodes(parsed_args.cluster, + nodepairs) + print('Request accepted by action: %s' % resp['action']) + + class CheckCluster(command.Command): """Check the cluster(s).""" log = logging.getLogger(__name__ + ".CheckCluster") diff --git a/senlinclient/v1/shell.py b/senlinclient/v1/shell.py index 7ba78a90..8930b374 100644 --- a/senlinclient/v1/shell.py +++ b/senlinclient/v1/shell.py @@ -859,6 +859,27 @@ def do_cluster_node_del(service, args): print('Request accepted by action: %s' % resp['action']) +@utils.arg('-n', '--nodes', metavar='', required=True, + help=_("OLD_NODE is the name or ID of a node to be replaced, " + "NEW_NODE is the name or ID of a node as replacement. " + "This can be specified multiple times, or once with " + "node-pairs separated by a comma ','."), + action='append') +@utils.arg('id', metavar='', + help=_('Name or ID of cluster to operate on.')) +def do_cluster_node_replace(service, args): + """Replace the nodes in cluster with specified nodes.""" + show_deprecated('senlin cluster-node-replace', + 'openstack cluster node members replace') + nodepairs = {} + for nodepair in args.nodes: + key = nodepair.split('=')[0] + value = nodepair.split('=')[1] + nodepairs[key] = value + resp = service.cluster_replace_nodes(args.id, nodepairs) + print('Request accepted by action: %s' % resp['action']) + + @utils.arg('-c', '--capacity', metavar='', type=int, help=_('The desired number of nodes of the cluster.')) @utils.arg('-a', '--adjustment', metavar='', type=int, diff --git a/setup.cfg b/setup.cfg index 90740cc7..ab1d0a55 100644 --- a/setup.cfg +++ b/setup.cfg @@ -43,6 +43,7 @@ openstack.clustering.v1 = cluster_members_list = senlinclient.v1.cluster:ClusterNodeList cluster_members_add = senlinclient.v1.cluster:ClusterNodeAdd cluster_members_del = senlinclient.v1.cluster:ClusterNodeDel + cluster_members_replace = senlinclient.v1.cluster:ClusterNodeReplace cluster_node_check = senlinclient.v1.node:CheckNode cluster_node_create = senlinclient.v1.node:CreateNode cluster_node_delete = senlinclient.v1.node:DeleteNode