Beispiel #1
0
def scale_cluster(cluster, node_group_names_map, plugin):
    # Now let's work with real node_groups, not names:
    node_groups_map = {}
    for ng in cluster.node_groups:
        if ng.name in node_group_names_map:
            node_groups_map.update({ng: node_group_names_map[ng.name]})
    instances_list = []
    try:
        instances_list = _scale_cluster_instances(
            cluster, node_groups_map, plugin)
        _clean_cluster_from_empty_ng(cluster)
        _await_instances(cluster)
        volumes.attach_to_instances(instances_list)

    except Exception as ex:
        LOG.warn("Can't scale cluster '%s' (reason: %s)", cluster.name, ex)
        with excutils.save_and_reraise_exception():
            _rollback_cluster_scaling(cluster, instances_list, ex)
            instances_list = []
            _clean_cluster_from_empty_ng(cluster)
            if cluster.status == 'Decommissioning':
                context.model_update(cluster, status='Error')
            else:
                context.model_update(cluster, status='Active')
    # we should be here with valid cluster: if instances creation
    # was not successful all extra-instances will be removed above
    if instances_list:
        _configure_instances(cluster)
    return instances_list
Beispiel #2
0
def scale_cluster(cluster_id, data):
    cluster = get_cluster(id=cluster_id)
    plugin = plugin_base.PLUGINS.get_plugin(cluster.plugin_name)
    existing_node_groups = data.get("resize_node_groups", [])
    additional_node_groups = data.get("add_node_groups", [])

    # the next map is the main object we will work with
    # to_be_enlarged : {node_group_name: desired_amount_of_instances}
    to_be_enlarged = {}
    for ng in existing_node_groups:
        to_be_enlarged.update({ng["name"]: ng["count"]})

    additional = construct_ngs_for_scaling(additional_node_groups)

    try:
        context.model_update(cluster, status="Validating")
        plugin.validate_scaling(cluster, to_be_enlarged, additional)
    except Exception:
        with excutils.save_and_reraise_exception():
            context.model_update(cluster, status="Active")

    # If we are here validation is successful.
    # So let's update bd and to_be_enlarged map:
    for add_n_g in additional:
        cluster.node_groups.append(add_n_g)
        to_be_enlarged.update({add_n_g.name: additional[add_n_g]})
    context.model_save(cluster)

    context.spawn(_provision_nodes, cluster_id, to_be_enlarged)
    return cluster
Beispiel #3
0
def terminate_cluster(**args):
    cluster = get_cluster(**args)
    context.model_update(cluster, status="Deleting")

    plugin = plugin_base.PLUGINS.get_plugin(cluster.plugin_name)
    plugin.on_terminate_cluster(cluster)

    i.shutdown_cluster(cluster)
    s.terminate_cluster(cluster)
Beispiel #4
0
    def test_model_update(self):
        _insert_test_object()

        t = context.current().session.query(TestModel).first()

        context.model_update(t, test_field=42)

        db_t = context.model_query(TestModel).first()

        self.assertEqual(t.id, db_t.id)
        self.assertEqual(42, db_t.test_field)
Beispiel #5
0
def create_cluster(values):
    cluster = s.create_cluster(values)
    plugin = plugin_base.PLUGINS.get_plugin(cluster.plugin_name)

    # validating cluster
    try:
        context.model_update(cluster, status="Validating")
        plugin.validate(cluster)
    except Exception as ex:
        with excutils.save_and_reraise_exception():
            context.model_update(cluster, status="Error", status_description=str(ex))

    context.spawn(_provision_cluster, cluster.id)

    return cluster
Beispiel #6
0
def _provision_nodes(cluster_id, node_group_names_map):
    cluster = get_cluster(id=cluster_id)
    plugin = plugin_base.PLUGINS.get_plugin(cluster.plugin_name)

    context.model_update(cluster, status="Scaling")
    instances = i.scale_cluster(cluster, node_group_names_map, plugin)

    if instances:
        context.model_update(cluster, status="Configuring")
        plugin.scale_cluster(cluster, instances)

    # cluster is now up and ready
    context.model_update(cluster, status="Active")
Beispiel #7
0
def create_cluster(cluster):
    try:
        # create all instances
        context.model_update(cluster, status='Spawning')
        _create_instances(cluster)

        # wait for all instances are up and accessible
        context.model_update(cluster, status='Waiting')
        _await_instances(cluster)

        # attach volumes
        volumes.attach(cluster)

        # prepare all instances
        context.model_update(cluster, status='Preparing')
        _configure_instances(cluster)
    except Exception as ex:
        LOG.warn("Can't start cluster '%s' (reason: %s)", cluster.name, ex)
        with excutils.save_and_reraise_exception():
            context.model_update(cluster, status='Error',
                                 status_description=str(ex))
            _rollback_cluster_creation(cluster, ex)
Beispiel #8
0
def _provision_cluster(cluster_id):
    cluster = get_cluster(id=cluster_id)
    plugin = plugin_base.PLUGINS.get_plugin(cluster.plugin_name)

    # updating cluster infra
    context.model_update(cluster, status="InfraUpdating")
    plugin.update_infra(cluster)

    # creating instances and configuring them
    i.create_cluster(cluster)

    # configure cluster
    context.model_update(cluster, status="Configuring")
    plugin.configure_cluster(cluster)

    # starting prepared and configured cluster
    context.model_update(cluster, status="Starting")
    plugin.start_cluster(cluster)

    # cluster is now up and ready
    context.model_update(cluster, status="Active")

    return cluster