From 00a32a8053a8c7040edf21ba601dc377f719a1d2 Mon Sep 17 00:00:00 2001 From: tengqm Date: Thu, 12 Feb 2015 15:16:49 +0800 Subject: [PATCH] Revised cluster model and clusterpolicy model We make the following operations actions of clusters: - cluster_policy_attach - cluster_policy_detach - cluster_policy_update - cluster_policy_enable - cluster_policy_disable We don't allow create, update, delete operations on the ClusterPolicy model. The reason is due to OpenStack SDK restrictions, we cannot make the ClusterPolicy binding ID transparent, while most of the time users will use cluster ID/name and policy ID/name directly. --- senlinclient/v1/models.py | 61 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/senlinclient/v1/models.py b/senlinclient/v1/models.py index a5b028b..8c4e977 100644 --- a/senlinclient/v1/models.py +++ b/senlinclient/v1/models.py @@ -306,6 +306,64 @@ class Cluster(resource.Resource): } return self.action(session, body) + def policy_attach(self, session, policy_id, priority, level, cooldown, + enabled): + body = { + 'policy_attach': { + 'policy_id': policy_id, + 'priority': priority, + 'level': level, + 'cooldown': cooldown, + 'enabled': enabled, + } + } + return self.action(session, body) + + def policy_detach(self, session, policy_id): + body = { + 'policy_detach': { + 'policy_id': policy_id, + } + } + return self.action(session, body) + + def policy_update(self, session, policy_id, priority, level, cooldown, + enabled): + + body = { + 'policy_update': { + 'policy_id': policy_id, + } + } + if priority is not None: + body['policy_update']['priority'] = priority + if level is not None: + body['policy_update']['level'] = level + if cooldown is not None: + body['policy_update']['cooldown'] = cooldown + if enabled is not None: + body['policy_update']['enabled'] = enabled + + return self.action(session, body) + + def policy_enable(self, session, policy_id): + body = { + 'policy_update': { + 'policy_id': policy_id, + 'enabled': True, + } + } + return self.action(session, body) + + def policy_disable(self, session, policy_id): + body = { + 'policy_update': { + 'policy_id': policy_id, + 'enabled': False, + } + } + return self.action(session, body) + def to_dict(self): info = { 'id': self.id, @@ -339,9 +397,6 @@ class ClusterPolicy(resource.Resource): # Capabilities allow_list = True allow_retrieve = True - allow_create = True - allow_delete = True - allow_update = True # Properties id = resource.prop('id')