From 220d6e7958b163e81c3bc44155c13c257462870c Mon Sep 17 00:00:00 2001 From: root Date: Thu, 18 Jun 2020 16:24:29 +0800 Subject: [PATCH] Add resource categroy --- cluster.py | 13 ++++++ resource.py | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++ run.py | 11 +++++ 3 files changed, 141 insertions(+) diff --git a/cluster.py b/cluster.py index f4a498e..e9c4a0e 100644 --- a/cluster.py +++ b/cluster.py @@ -41,6 +41,19 @@ def update_cluster_properties(data): return {'action': False, 'error': _(output)} return {'action': True, 'info': _('Update cluster properties Success')} +def operation_cluster_action(action): + if action == 'start': + status,output = common_utils.run_cmd("pcs cluster start") + if action == 'stop': + status,output = common_utils.run_cmd("pcs cluster start") + if action == 'restart': + status,output = common_utils.run_cmd("pcs cluster stop") + status,output = common_utils.run_cmd("pcs cluster start") + if action == {} or action is None: + return {"action": False, "error": "error info"} + else: + return {"action": True, "info": "Action on node success"} + if __name__ == "__main__": print(common_utils.run_cmd("pcs status")) #print(get_cluster_properties_info()) diff --git a/resource.py b/resource.py index b106ae7..b64e94e 100644 --- a/resource.py +++ b/resource.py @@ -461,6 +461,123 @@ def get_rsc_meta_attributes(): return +#获取资源元属性 +def get_rsc_meta_attributes(category): +''' +{ + "action": true, + "data": { + "target-role": { + "content": { + "values": [ + "Stopped", + "Started" + ], + "default": "Stopped", + "type": "enum", + "dec": "What state should the cluster attempt to keep this resource in?" + }, + "name": "target-role" + }, + "priority": { + "content": { + "type": "integer", + "dec": "If not all resources can be active, the cluster will stop lower priority resources in order to keep higher priority ones active." + }, + "name": "priority" + }, + "is-managed": { + "content": { + "type": "boolean", + "dec": "Is the cluster allowed to start and stop the resource?" + }, + "name": "is-managed" + } + } +} +''' + retjson = {} + + retjson['target-role'] = {} + retjson['target-role']['content'] = {} + retjson['target-role']['name'] = 'target-role' + retjson['target-role']['content']['values'] = ['Stopped', 'Started'] + retjson['target-role']['content']['default'] = 'Stopped' + retjson['target-role']['content']['type'] = "enum" + retjson['target-role']['content']['dec'] = "What state should the cluster attempt to keep this resource in?" + + retjson['priority'] = {} + retjson['priority']['content'] = {} + retjson['priority']['name'] = 'priority' + retjson['priority']['content']['type'] = "integer" + retjson['priority']['content'][ + 'dec'] = "If not all resources can be active, the cluster will stop lower priority resources in order to keep higher priority ones active." + + retjson['is-managed'] = {} + retjson['is-managed']['content'] = {} + retjson['is-managed']['name'] = 'is-managed' + # retjson['is-managed']['content']['values'] = ['true', 'false'] + retjson['is-managed']['content']['type'] = "boolean" + retjson['is-managed']['content']['dec'] = "Is the cluster allowed to start and stop the resource?" + + if category == "group": + return {'action': True, 'data': retjson} + + retjson['resource-stickiness'] = {} + retjson['resource-stickiness']['content'] = {} + retjson['resource-stickiness']['name'] = 'resource-stickiness' + retjson['resource-stickiness']['content']['type'] = "integer" + retjson['resource-stickiness']['content'][ + 'dec'] = "How much does the resource prefer to stay where it is? Defaults to the value of \'default-resource-stickiness\'" + + retjson['migration-threshold'] = {} + retjson['migration-threshold']['content'] = {} + retjson['migration-threshold']['name'] = 'migration-threshold' + retjson['migration-threshold']['content']['type'] = "integer" + retjson['migration-threshold']['content'][ + 'dec'] = "How many failures should occur for this resource on a node before making the node ineligible to host this resource. Default: \'none\'" + + retjson['multiple-active'] = {} + retjson['multiple-active']['content'] = {} + retjson['multiple-active']['name'] = 'multiple-active' + retjson['multiple-active']['content']['values'] = ['stop_start', 'stop_only', 'block'] + retjson['multiple-active']['content']['type'] = "enum" + retjson['multiple-active']['content'][ + 'dec'] = "What should the cluster do if it ever finds the resource active on more than one node." + + retjson['failure-timeout'] = {} + retjson['failure-timeout']['content'] = {} + retjson['failure-timeout']['name'] = 'failure-timeout' + retjson['failure-timeout']['content']['type'] = "integer" + retjson['failure-timeout']['content'][ + 'dec'] = "How many seconds to wait before acting as if the failure had not occurred (and potentially allowing the resource back to the node on which it failed. Default: \'never\'" + + retjson['allow-migrate'] = {} + retjson['allow-migrate']['content'] = {} + retjson['allow-migrate']['name'] = 'allow-migrate' + # retjson['allow-migrate']['content']['values'] = ['true', 'false'] + retjson['allow-migrate']['content']['type'] = "boolean" + retjson['allow-migrate']['content'][ + 'dec'] = "Allow resource migration for resources which support migrate_to/migrate_from actions." + + if category == "primitive": + return {'action': True, 'data': retjson} + + if category == "clone": + retjson['interleave'] = {} + retjson['interleave']['content'] = {} + retjson['interleave']['name'] = 'interleave' + retjson['interleave']['content']['type'] = "boolean" + retjson['interleave']['content']['dec'] = "Changes the behavior of ordering constraints (between clones/masters) so that instances can start/stop as soon as their peer instance has (rather than waiting for every instance of the other clone has)." + + retjson['clone-max'] = {} + retjson['clone-max']['content'] = {} + retjson['clone-max']['name'] = 'clone-max' + retjson['clone-max']['content']['type'] = "integer" + retjson['clone-max']['content']['dec'] = "How many copies of the resource to start. Defaults to the number of nodes in the cluster." + return {'action': True, 'data': retjson} + + return {'action': True, 'data': retjson} if __name__ == '__main__': print(get_resource_info()) diff --git a/run.py b/run.py index e1f8773..66c2cb7 100644 --- a/run.py +++ b/run.py @@ -70,6 +70,12 @@ def create_app(test_config=None): else: return + #local HA operation + @app.route('/api/' + API_VERSION + '/haclusters/1/localnodes/', methods=['GET', 'POST', 'PUT']) + def loocalnodes_ops(action): + if request.method == 'PUT': + return json.dumps(cluster.operation_cluster_action(action)) + # Resource ops @app.route('/api/'+ API_VERSION + '/haclusters/1/resources', methods=['GET', 'POST', 'PUT']) def resource_ops(): @@ -192,6 +198,11 @@ def create_app(test_config=None): return json.dumps(node.get_nodes_action(node_id, action)) + @app.route('/api/' + API_VERSION + '/haclusters/1/resources/meta_attributes/', methods=['GET', 'POST', 'PUT']) + def resource_category(category): + if request.method == 'GET': + return json.dumps(resource.get_rsc_meta_attributes(category)) + return app if __name__ == '__main__': -- Gitee