Exemplo n.º 1
0
def change_cluster_status(cluster, status, status_description=None):
    ctx = context.ctx()

    # Update cluster status. Race conditions with deletion are still possible,
    # but this reduces probability at least.
    cluster = conductor.cluster_get(ctx, cluster) if cluster else None

    if status_description is not None:
        change_cluster_status_description(cluster, status_description)

    # 'Deleting' is final and can't be changed
    if cluster is None or cluster.status == CLUSTER_STATUS_DELETING:
        return cluster

    update_dict = {"status": status}
    cluster = conductor.cluster_update(ctx, cluster, update_dict)
    conductor.cluster_provision_progress_update(ctx, cluster.id)

    LOG.info("Cluster status has been changed. New status="
             "{status}".format(status=cluster.status))

    sender.status_notify(cluster.id, cluster.name, cluster.status,
                         "update")

    return cluster
Exemplo n.º 2
0
def change_cluster_status(cluster, status, status_description=None):
    ctx = context.ctx()

    # Update cluster status. Race conditions with deletion are still possible,
    # but this reduces probability at least.
    cluster = conductor.cluster_get(ctx, cluster) if cluster else None

    if status_description is not None:
        change_cluster_status_description(cluster, status_description)

    # 'Deleting' is final and can't be changed
    if cluster is None or cluster.status == CLUSTER_STATUS_DELETING:
        return cluster

    update_dict = {"status": status}
    cluster = conductor.cluster_update(ctx, cluster, update_dict)
    conductor.cluster_provision_progress_update(ctx, cluster.id)

    LOG.info(_LI("Cluster status has been changed. New status="
                 "{status}").format(status=cluster.status))

    sender.status_notify(cluster.id, cluster.name, cluster.status,
                         "update")

    return cluster
Exemplo n.º 3
0
def terminate_cluster(id, force=False):
    context.set_current_cluster_id(id)
    cluster = c_u.change_cluster_status(id, c_u.CLUSTER_STATUS_DELETING)

    if cluster is None:
        return

    api.OPS.terminate_cluster(id, force)
    sender.status_notify(cluster.id, cluster.name, cluster.status, "delete")
Exemplo n.º 4
0
def terminate_cluster(id, force=False):
    context.set_current_cluster_id(id)
    cluster = c_u.change_cluster_status(id, c_u.CLUSTER_STATUS_DELETING)

    if cluster is None:
        return

    api.OPS.terminate_cluster(id, force)
    sender.status_notify(cluster.id, cluster.name, cluster.status,
                         "delete")
Exemplo n.º 5
0
    def _make_sample(self):
        ctx = context.ctx()

        self.ctx = ctx
        self.cluster_id = 'someId'
        self.cluster_name = 'someName'
        self.cluster_status = 'someStatus'

        sender.status_notify(self.cluster_id, self.cluster_name,
                             self.cluster_status, "update")

        self.create_mock('update')
Exemplo n.º 6
0
    def _make_sample(self):
        ctx = context.ctx()

        self.ctx = ctx
        self.cluster_id = 'someId'
        self.cluster_name = 'someName'
        self.cluster_status = 'someStatus'

        sender.status_notify(self.cluster_id, self.cluster_name,
                             self.cluster_status, "update")

        self.create_mock('update')
Exemplo n.º 7
0
    def test_update_cluster(self, mock_notify):
        class FakeNotifier(object):
            def info(self, *args):
                self.call = args

        notifier = FakeNotifier()
        mock_notify.return_value = notifier
        ctx = context.ctx()
        sender.status_notify('someId', 'someName', 'someStatus', "update")
        self.expected_args = (ctx, 'sahara.cluster.%s' % 'update', {
            'cluster_id': 'someId',
            'cluster_name': 'someName',
            'cluster_status': 'someStatus',
            'project_id': ctx.tenant_id,
            'user_id': ctx.user_id
        })

        self.assertEqual(self.expected_args, notifier.call)
Exemplo n.º 8
0
    def test_update_cluster(self, mock_notify):
        class FakeNotifier(object):
            def info(self, *args):
                self.call = args

        notifier = FakeNotifier()
        mock_notify.return_value = notifier
        ctx = context.ctx()
        sender.status_notify('someId', 'someName', 'someStatus', "update")
        self.expected_args = (ctx,
                              'sahara.cluster.%s' % 'update',
                              {'cluster_id': 'someId',
                               'cluster_name': 'someName',
                               'cluster_status': 'someStatus',
                               'project_id': ctx.tenant_id,
                               'user_id': ctx.user_id})

        self.assertEqual(self.expected_args,
                         notifier.call)
Exemplo n.º 9
0
def _cluster_create(values, plugin):
    ctx = context.ctx()
    cluster = conductor.cluster_create(ctx, values)
    context.set_current_cluster_id(cluster.id)
    sender.status_notify(cluster.id, cluster.name, "New", "create")
    _add_ports_for_auto_sg(ctx, cluster, plugin)

    # validating cluster
    try:
        plugin.recommend_configs(cluster)
        cluster = c_u.change_cluster_status(cluster,
                                            c_u.CLUSTER_STATUS_VALIDATING)
        plugin.validate(cluster)
        quotas.check_cluster(cluster)
    except Exception as e:
        with excutils.save_and_reraise_exception():
            c_u.change_cluster_status(cluster, c_u.CLUSTER_STATUS_ERROR,
                                      six.text_type(e))

    api.OPS.provision_cluster(cluster.id)

    return cluster
Exemplo n.º 10
0
def _cluster_create(values, plugin):
    ctx = context.ctx()
    cluster = conductor.cluster_create(ctx, values)
    context.set_current_cluster_id(cluster.id)
    sender.status_notify(cluster.id, cluster.name, "New",
                         "create")
    _add_ports_for_auto_sg(ctx, cluster, plugin)

    # validating cluster
    try:
        plugin.recommend_configs(cluster)
        cluster = c_u.change_cluster_status(
            cluster, c_u.CLUSTER_STATUS_VALIDATING)
        plugin.validate(cluster)
        quotas.check_cluster(cluster)
    except Exception as e:
        with excutils.save_and_reraise_exception():
            c_u.change_cluster_status(
                cluster, c_u.CLUSTER_STATUS_ERROR, six.text_type(e))

    api.OPS.provision_cluster(cluster.id)

    return cluster