diff --git a/savanna/service/validations/base.py b/savanna/service/validations/base.py index 0a958bc566..84be30d82e 100644 --- a/savanna/service/validations/base.py +++ b/savanna/service/validations/base.py @@ -46,12 +46,9 @@ def check_plugin_supports_version(p_name, version): " version '%s'" % (p_name, version)) -def check_image_exists(image_id): - try: - # TODO(aignatov): Check supported images by plugin instead of it - api.get_image(id=image_id) - except nova_ex.NotFound: - raise ex.InvalidException("Requested image '%s' not found" +def check_image_registered(image_id): + if image_id not in [i.id for i in nova.client().images.list_registered()]: + raise ex.InvalidException("Requested image '%s' is not registered" % image_id) @@ -104,7 +101,7 @@ def check_node_group_basic_fields(plugin_name, hadoop_version, ng, check_node_processes(plugin_name, hadoop_version, ng['node_processes']) if ng.get('image_id'): - check_image_exists(ng['image_id']) + check_image_registered(ng['image_id']) def check_flavor_exists(flavor_id): @@ -151,7 +148,7 @@ def check_keypair_exists(keypair): raise ex.InvalidException("Requested keypair '%s' not found" % keypair) -## Cluster templates creation related checks +## Cluster templates related checks def check_cluster_template_unique_name(name): if name in [t.name for t in api.get_cluster_templates()]: @@ -159,6 +156,12 @@ def check_cluster_template_unique_name(name): " already exists" % name) +def check_cluster_template_exists(cluster_template_id): + if not api.get_cluster_templates(id=cluster_template_id): + raise ex.InvalidException("Cluster template with id '%s'" + " doesn't exist" % cluster_template_id) + + ## NodeGroup templates related checks def check_node_group_template_unique_name(name): diff --git a/savanna/service/validations/cluster_templates.py b/savanna/service/validations/cluster_templates.py index a924c0dde6..703becb77b 100644 --- a/savanna/service/validations/cluster_templates.py +++ b/savanna/service/validations/cluster_templates.py @@ -103,7 +103,7 @@ def check_cluster_template_create(data, **kwargs): data['hadoop_version']) if data.get('default_image_id'): - b.check_image_exists(data['default_image_id']) + b.check_image_registered(data['default_image_id']) b.check_all_configurations(data) diff --git a/savanna/service/validations/clusters.py b/savanna/service/validations/clusters.py index c8ebb34d75..629b5da008 100644 --- a/savanna/service/validations/clusters.py +++ b/savanna/service/validations/clusters.py @@ -41,12 +41,14 @@ def check_cluster_create(data, **kwargs): b.check_plugin_name_exists(data['plugin_name']) b.check_plugin_supports_version(data['plugin_name'], data['hadoop_version']) + if data.get('cluster_template_id'): + b.check_cluster_template_exists(data['cluster_template_id']) if data.get('user_keypair_id'): b.check_keypair_exists(data['user_keypair_id']) if data.get('default_image_id'): - b.check_image_exists(data['default_image_id']) + b.check_image_registered(data['default_image_id']) b.check_all_configurations(data)