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.
This commit is contained in:
tengqm
2015-02-12 15:16:49 +08:00
parent 77022d6512
commit 00a32a8053

View File

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