Support to cluster-node-add operation
This commit is contained in:
@@ -106,19 +106,10 @@ class Client(object):
|
|||||||
return obj
|
return obj
|
||||||
|
|
||||||
def action(self, cls, options):
|
def action(self, cls, options):
|
||||||
'''Examples:
|
|
||||||
<cls> --data '{"alarm_id": "33109eea-24dd-45ff-93f7-82292d1dd38c",
|
|
||||||
"action": "change_state",
|
|
||||||
"action_args": {"next_state": "insufficient data"}'
|
|
||||||
|
|
||||||
<cls> --data '{"id": "a1369557-748f-429c-bd3e-fc385aacaec7",
|
|
||||||
"action": "reboot",
|
|
||||||
"action_args": {"reboot_type": "SOFT"}}'
|
|
||||||
'''
|
|
||||||
def filter_args(method, params):
|
def filter_args(method, params):
|
||||||
expected_args = inspect.getargspec(method).args
|
expected_args = inspect.getargspec(method).args
|
||||||
accepted_args = ([a for a in expected_args if a != 'self'])
|
accepted_args = ([a for a in expected_args if a != 'self'])
|
||||||
filtered_args = [{d: params[d]} for d in accepted_args]
|
filtered_args = dict((d, params[d]) for d in accepted_args)
|
||||||
return filtered_args
|
return filtered_args
|
||||||
|
|
||||||
def invoke_method(target, method_name, params):
|
def invoke_method(target, method_name, params):
|
||||||
@@ -127,14 +118,15 @@ class Client(object):
|
|||||||
reply = action(**filtered_args)
|
reply = action(**filtered_args)
|
||||||
return reply
|
return reply
|
||||||
|
|
||||||
kwargs = self.get_options(options)
|
action = options.pop('action')
|
||||||
action = kwargs.pop('action')
|
if 'action_args' in options:
|
||||||
if 'action_args' in kwargs:
|
args = options.pop('action_args')
|
||||||
args = kwargs.pop('action_args')
|
|
||||||
else:
|
else:
|
||||||
args = {}
|
args = {}
|
||||||
|
|
||||||
args.update(session=self.session)
|
args.update(session=self.session)
|
||||||
obj = cls.new(**kwargs)
|
obj = cls.new(**options)
|
||||||
reply = invoke_method(obj, action, args)
|
try:
|
||||||
return reply
|
return invoke_method(obj, action, args)
|
||||||
|
except Exception as ex:
|
||||||
|
client_exc.parse_exception(ex)
|
||||||
|
@@ -10,6 +10,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from openstack import utils
|
||||||
|
|
||||||
from senlinclient.common import sdk as resource
|
from senlinclient.common import sdk as resource
|
||||||
from senlinclient.openstack.clustering import clustering_service
|
from senlinclient.openstack.clustering import clustering_service
|
||||||
|
|
||||||
@@ -208,7 +210,20 @@ class Cluster(resource.Resource):
|
|||||||
nodes = resource.prop('nodes')
|
nodes = resource.prop('nodes')
|
||||||
|
|
||||||
profile_name = resource.prop('profile_name')
|
profile_name = resource.prop('profile_name')
|
||||||
action = resource.prop('action')
|
# action = resource.prop('action')
|
||||||
|
|
||||||
|
def action(self, session, body):
|
||||||
|
url = utils.urljoin(self.base_path, self.id, 'action')
|
||||||
|
resp = session.put(url, service=self.service, json=body).body
|
||||||
|
return resp
|
||||||
|
|
||||||
|
def add_nodes(self, session, nodes):
|
||||||
|
body = {
|
||||||
|
'add_nodes': {
|
||||||
|
'nodes': nodes,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return self.action(session, body)
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
info = {
|
info = {
|
||||||
@@ -256,7 +271,7 @@ class ClusterPolicy(resource.Resource):
|
|||||||
|
|
||||||
|
|
||||||
class ClusterNode(resource.Resource):
|
class ClusterNode(resource.Resource):
|
||||||
resources_key = 'policies'
|
resources_key = 'nodes'
|
||||||
base_path = '/clusters/%(cluster_id)s/nodes'
|
base_path = '/clusters/%(cluster_id)s/nodes'
|
||||||
service = clustering_service.ClusteringService()
|
service = clustering_service.ClusteringService()
|
||||||
|
|
||||||
@@ -268,10 +283,7 @@ class ClusterNode(resource.Resource):
|
|||||||
# Properties
|
# Properties
|
||||||
id = resource.prop('id')
|
id = resource.prop('id')
|
||||||
cluster_id = resource.prop('cluster_id')
|
cluster_id = resource.prop('cluster_id')
|
||||||
policy_id = resource.prop('policy_id')
|
policy_id = resource.prop('node_id')
|
||||||
cooldown = resource.prop('cooldown')
|
|
||||||
level = resource.prop('level', type=int)
|
|
||||||
enabled = resource.prop('enabled')
|
|
||||||
|
|
||||||
|
|
||||||
class Node(resource.Resource):
|
class Node(resource.Resource):
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
|
from oslo_utils import encodeutils
|
||||||
|
|
||||||
from senlinclient.common import exc
|
from senlinclient.common import exc
|
||||||
from senlinclient.common.i18n import _
|
from senlinclient.common.i18n import _
|
||||||
@@ -430,25 +431,23 @@ def do_cluster_node_list(sc, args):
|
|||||||
utils.print_list(nodes, fields, formatters=formatters, sortby_index=5)
|
utils.print_list(nodes, fields, formatters=formatters, sortby_index=5)
|
||||||
|
|
||||||
|
|
||||||
@utils.arg('-n', '--nodes', metavar='<NODE_IDs>',
|
@utils.arg('-n', '--nodes', metavar='<NODE>',
|
||||||
help=_('ID of nodes to be added.'))
|
help=_('ID of nodes to be added; multiple nodes can be separated '
|
||||||
@utils.arg('id', metavar='<NAME or ID>',
|
'with ","'))
|
||||||
|
@utils.arg('id', metavar='<CLUSTER>',
|
||||||
help=_('Name or ID of cluster to operate on.'))
|
help=_('Name or ID of cluster to operate on.'))
|
||||||
def do_cluster_node_add(sc, args):
|
def do_cluster_node_add(sc, args):
|
||||||
'''Add specified nodes to cluster.'''
|
'''Add specified nodes to cluster.'''
|
||||||
failure_count = 0
|
node_ids = args.nodes.split(',')
|
||||||
for nid in args.nodes:
|
params = {
|
||||||
try:
|
'id': args.id,
|
||||||
params = {'cluster_id': args.id, 'id': nid}
|
'action': 'add_nodes',
|
||||||
sc.create(models.ClusterNode, params)
|
'action_args': {
|
||||||
except Exception as ex:
|
'nodes': node_ids,
|
||||||
failure_count += 1
|
}
|
||||||
print(ex)
|
}
|
||||||
if failure_count == len(args.nodes):
|
resp = sc.action(models.Cluster, params)
|
||||||
msg = _('Failed to add any of the specified nodes.')
|
print(encodeutils.safe_decode(resp))
|
||||||
raise exc.CommandError(msg)
|
|
||||||
|
|
||||||
do_cluster_node_list(sc, id=args.id)
|
|
||||||
|
|
||||||
|
|
||||||
@utils.arg('-n', '--nodes', metavar='<NODE_IDs>',
|
@utils.arg('-n', '--nodes', metavar='<NODE_IDs>',
|
||||||
|
Reference in New Issue
Block a user