From b6ca5d6720b4e3bcddfee53f4d0c3eeb7f100861 Mon Sep 17 00:00:00 2001 From: Sergey Lukjanov Date: Tue, 4 Jun 2013 15:20:28 +0400 Subject: [PATCH] Add simple plugin calls and cluster status updates * provisioning plugin is now called while cluster creation * cluster status is now updated while cluster creation Change-Id: I7103589ab3ebe1079079d1773384633a89b1aba0 --- savanna/service/api.py | 39 ++++++++++++++++++++++++++++++++++++ savanna/service/instances.py | 15 ++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/savanna/service/api.py b/savanna/service/api.py index c580f262..347ed731 100644 --- a/savanna/service/api.py +++ b/savanna/service/api.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from savanna import context import savanna.db.storage as s from savanna.openstack.common import log as logging import savanna.plugins.base as plugin_base @@ -30,12 +31,50 @@ get_cluster = s.get_cluster def create_cluster(values): cluster = s.create_cluster(values) + plugin = plugin_base.PLUGINS.get_plugin(cluster.plugin_name) + + # todo validate configs and etc. + + # validating cluster + cluster.status = 'Validating' + context.model_save(cluster) + plugin.validate(cluster) + + # todo run all following commands in background thread + + # updating cluster infra + cluster.status = 'InfraUpdating' + context.model_save(cluster) + plugin.update_infra(cluster) + + # creating instances and configuring them i.create_cluster(cluster) + + # configure cluster + cluster.status = 'Configuring' + context.model_save(cluster) + plugin.configure_cluster(cluster) + + # starting prepared and configured cluster + cluster.status = 'Starting' + context.model_save(cluster) + plugin.start_cluster(cluster) + + # cluster is now up and ready + cluster.status = 'Active' + context.model_save(cluster) + return cluster def terminate_cluster(**args): cluster = get_cluster(**args) + cluster.status = 'Deleting' + context.model_save(cluster) + + plugin = plugin_base.PLUGINS.get_plugin(cluster.plugin_name) + plugin.on_terminate_cluster(cluster) + i.shutdown_cluster(cluster) s.terminate_cluster(cluster) diff --git a/savanna/service/instances.py b/savanna/service/instances.py index 21906690..4e9f6cbd 100644 --- a/savanna/service/instances.py +++ b/savanna/service/instances.py @@ -15,7 +15,7 @@ import time -from savanna.context import ctx +from savanna import context from savanna.db import models as m from savanna.openstack.common import log as logging from savanna.utils.crypto import private_key_to_public_key @@ -26,8 +26,19 @@ LOG = logging.getLogger(__name__) def create_cluster(cluster): try: + # create all instances + cluster.status = 'Spawning' + context.model_save(cluster) _create_instances(cluster) + + # wait for all instances are up and accessible + cluster.status = 'Waiting' + context.model_save(cluster) _await_instances(cluster) + + # prepare all instances + cluster.status = 'Preparing' + context.model_save(cluster) _configure_instances(cluster) except Exception as ex: LOG.warn("Can't start cluster: %s", ex) @@ -36,7 +47,7 @@ def create_cluster(cluster): def _create_instances(cluster): """Create all instances using nova client and persist them into DB.""" - session = ctx().session + session = context.ctx().session aa_groups = _generate_anti_affinity_groups(cluster) for node_group in cluster.node_groups: files = _generate_instance_files(node_group)