Merge "Fix delete templates that are in use"

This commit is contained in:
Jenkins 2013-07-23 21:53:58 +00:00 committed by Gerrit Code Review
commit ca9c55ff03
3 changed files with 34 additions and 1 deletions

View File

@ -91,6 +91,7 @@ def cluster_templates_update(cluster_template_id):
@rest.delete('/cluster-templates/<cluster_template_id>')
@v.check_exists(api.get_cluster_template, 'cluster_template_id')
@v.validate(None, v_ct.check_cluster_template_usage)
def cluster_templates_delete(cluster_template_id):
api.terminate_cluster_template(id=cluster_template_id)
return u.render()
@ -126,6 +127,7 @@ def node_group_templates_update(node_group_template_id):
@rest.delete('/node-group-templates/<node_group_template_id>')
@v.check_exists(api.get_node_group_template, 'node_group_template_id')
@v.validate(None, v_ngt.check_node_group_template_usage)
def node_group_templates_delete(node_group_template_id):
api.terminate_node_group_template(id=node_group_template_id)
return u.render()

View File

@ -15,6 +15,8 @@
import copy
from savanna import exceptions as ex
from savanna.service import api
import savanna.service.validations.base as b
import savanna.service.validations.node_group_templates as ng_tml
@ -45,8 +47,8 @@ def _build_ng_tmpl_schema_for_cluster_template():
"name", "count"]
return cl_tmpl_ng_tmpl_schema
_cluster_tmpl_ng_tmpl_schema = _build_ng_tmpl_schema_for_cluster_template()
_cluster_tmpl_ng_tmpl_schema = _build_ng_tmpl_schema_for_cluster_template()
CLUSTER_TEMPLATE_SCHEMA = {
"type": "object",
@ -110,3 +112,13 @@ def check_cluster_template_create(data, **kwargs):
if data.get('anti_affinity'):
b.check_node_processes(data['plugin_name'], data['hadoop_version'],
data['anti_affinity'])
def check_cluster_template_usage(cluster_template_id, **kwargs):
clusters = api.get_clusters()
use_cluster_template_ids = [cluster.cluster_template_id
for cluster in clusters]
if cluster_template_id in use_cluster_template_ids:
raise ex.InvalidException(
"Cluster template %s is use" % cluster_template_id)

View File

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from savanna import exceptions as ex
from savanna.service import api
import savanna.service.validations.base as b
NODE_GROUP_TEMPLATE_SCHEMA = {
@ -81,3 +83,20 @@ def check_node_group_template_create(data, **kwargs):
data['hadoop_version'])
b.check_node_group_basic_fields(data['plugin_name'],
data['hadoop_version'], data)
def check_node_group_template_usage(node_group_template_id, **kwargs):
node_groups = []
for cluster in api.get_clusters():
node_groups += cluster.node_groups
for cluster_template in api.get_cluster_templates():
node_groups += cluster_template.node_groups
node_group_template_ids = set([node_group.node_group_template_id
for node_group in node_groups])
if node_group_template_id in node_group_template_ids:
raise ex.InvalidException(
"Node group template %s is use" % node_group_template_id)