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
This commit is contained in:
Sergey Lukjanov 2013-06-04 15:20:28 +04:00
parent 2dd094fd3d
commit b6ca5d6720
2 changed files with 52 additions and 2 deletions

View File

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

View File

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