Cluster creation moved in separate thread

Change-Id: I3ecf6af40c10527a0142d644074dbc66117e5841
This commit is contained in:
Alexander Kuznetsov
2013-06-14 19:46:06 +04:00
parent 56513f6895
commit 7855e1b0a1
2 changed files with 17 additions and 1 deletions

View File

@@ -35,6 +35,12 @@ class Context(object):
self.headers = headers
self._db_session = None
def clone(self):
return Context(self.user_id,
self.tenant_id,
self.auth_token,
self.headers)
@property
def session(self):
if self._db_session is None:

View File

@@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import eventlet
from savanna import context
from savanna.db import storage as s
from savanna.openstack.common import log as logging
@@ -39,8 +40,17 @@ def create_cluster(values):
cluster.status = 'Validating'
context.model_save(cluster)
plugin.validate(cluster)
ctx = context.ctx().clone()
# TODO(slukjanov): run all following commands in background thread
eventlet.spawn(_provision_cluster, cluster.id, ctx)
return cluster
def _provision_cluster(cluster_id, ctx):
context.set_ctx(ctx)
cluster = get_cluster(id=cluster_id)
plugin = plugin_base.PLUGINS.get_plugin(cluster.plugin_name)
# updating cluster infra
cluster.status = 'InfraUpdating'