Client support for node replace

This patch adds support for "cluster members replace" at client side.

partial-blueprint: support-cluster-replace-action
https://blueprints.launchpad.net/senlin/+spec/support-cluster-replace-action

Change-Id: Ibb1180402281036aa26b47968c0e6e5c1303f4c4
This commit is contained in:
miaohb 2016-12-10 16:01:46 +08:00
parent 5ad7da62df
commit d724f4109d
4 changed files with 66 additions and 0 deletions

View File

@ -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

View File

@ -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='<OLD_NODE1=NEW_NODE1>',
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='<cluster>',
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")

View File

@ -859,6 +859,27 @@ def do_cluster_node_del(service, args):
print('Request accepted by action: %s' % resp['action'])
@utils.arg('-n', '--nodes', metavar='<OLD_NODE1=NEW_NODE1>', 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='<CLUSTER>',
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='<CAPACITY>', type=int,
help=_('The desired number of nodes of the cluster.'))
@utils.arg('-a', '--adjustment', metavar='<ADJUSTMENT>', type=int,

View File

@ -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