Support to cluster-node-add operation
This commit is contained in:
@@ -106,19 +106,10 @@ class Client(object):
|
||||
return obj
|
||||
|
||||
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):
|
||||
expected_args = inspect.getargspec(method).args
|
||||
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
|
||||
|
||||
def invoke_method(target, method_name, params):
|
||||
@@ -127,14 +118,15 @@ class Client(object):
|
||||
reply = action(**filtered_args)
|
||||
return reply
|
||||
|
||||
kwargs = self.get_options(options)
|
||||
action = kwargs.pop('action')
|
||||
if 'action_args' in kwargs:
|
||||
args = kwargs.pop('action_args')
|
||||
action = options.pop('action')
|
||||
if 'action_args' in options:
|
||||
args = options.pop('action_args')
|
||||
else:
|
||||
args = {}
|
||||
|
||||
args.update(session=self.session)
|
||||
obj = cls.new(**kwargs)
|
||||
reply = invoke_method(obj, action, args)
|
||||
return reply
|
||||
obj = cls.new(**options)
|
||||
try:
|
||||
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
|
||||
# under the License.
|
||||
|
||||
from openstack import utils
|
||||
|
||||
from senlinclient.common import sdk as resource
|
||||
from senlinclient.openstack.clustering import clustering_service
|
||||
|
||||
@@ -208,7 +210,20 @@ class Cluster(resource.Resource):
|
||||
nodes = resource.prop('nodes')
|
||||
|
||||
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):
|
||||
info = {
|
||||
@@ -256,7 +271,7 @@ class ClusterPolicy(resource.Resource):
|
||||
|
||||
|
||||
class ClusterNode(resource.Resource):
|
||||
resources_key = 'policies'
|
||||
resources_key = 'nodes'
|
||||
base_path = '/clusters/%(cluster_id)s/nodes'
|
||||
service = clustering_service.ClusteringService()
|
||||
|
||||
@@ -268,10 +283,7 @@ class ClusterNode(resource.Resource):
|
||||
# Properties
|
||||
id = resource.prop('id')
|
||||
cluster_id = resource.prop('cluster_id')
|
||||
policy_id = resource.prop('policy_id')
|
||||
cooldown = resource.prop('cooldown')
|
||||
level = resource.prop('level', type=int)
|
||||
enabled = resource.prop('enabled')
|
||||
policy_id = resource.prop('node_id')
|
||||
|
||||
|
||||
class Node(resource.Resource):
|
||||
|
@@ -13,6 +13,7 @@
|
||||
import logging
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import encodeutils
|
||||
|
||||
from senlinclient.common import exc
|
||||
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.arg('-n', '--nodes', metavar='<NODE_IDs>',
|
||||
help=_('ID of nodes to be added.'))
|
||||
@utils.arg('id', metavar='<NAME or ID>',
|
||||
@utils.arg('-n', '--nodes', metavar='<NODE>',
|
||||
help=_('ID of nodes to be added; multiple nodes can be separated '
|
||||
'with ","'))
|
||||
@utils.arg('id', metavar='<CLUSTER>',
|
||||
help=_('Name or ID of cluster to operate on.'))
|
||||
def do_cluster_node_add(sc, args):
|
||||
'''Add specified nodes to cluster.'''
|
||||
failure_count = 0
|
||||
for nid in args.nodes:
|
||||
try:
|
||||
params = {'cluster_id': args.id, 'id': nid}
|
||||
sc.create(models.ClusterNode, params)
|
||||
except Exception as ex:
|
||||
failure_count += 1
|
||||
print(ex)
|
||||
if failure_count == len(args.nodes):
|
||||
msg = _('Failed to add any of the specified nodes.')
|
||||
raise exc.CommandError(msg)
|
||||
|
||||
do_cluster_node_list(sc, id=args.id)
|
||||
node_ids = args.nodes.split(',')
|
||||
params = {
|
||||
'id': args.id,
|
||||
'action': 'add_nodes',
|
||||
'action_args': {
|
||||
'nodes': node_ids,
|
||||
}
|
||||
}
|
||||
resp = sc.action(models.Cluster, params)
|
||||
print(encodeutils.safe_decode(resp))
|
||||
|
||||
|
||||
@utils.arg('-n', '--nodes', metavar='<NODE_IDs>',
|
||||
|
Reference in New Issue
Block a user