예제 #1
0
파일: api.py 프로젝트: suriya2612/sahara
def cluster_create(context, values):
    values = values.copy()
    cluster = m.Cluster()
    node_groups = values.pop("node_groups", [])
    cluster.update(values)

    session = get_session()
    with session.begin():
        try:
            cluster.save(session=session)
        except db_exc.DBDuplicateEntry as e:
            raise ex.DBDuplicateEntry(
                _("Duplicate entry for Cluster: %s") % e.columns)

        try:
            for ng in node_groups:
                node_group = m.NodeGroup()
                node_group.update({"cluster_id": cluster.id})
                node_group.update(ng)
                node_group.save(session=session)
        except db_exc.DBDuplicateEntry as e:
            raise ex.DBDuplicateEntry(
                _("Duplicate entry for NodeGroup: %s") % e.columns)

    return cluster_get(context, cluster.id)
예제 #2
0
def cluster_create(context, values):
    values = values.copy()
    cluster = m.Cluster()
    node_groups = values.pop("node_groups", [])
    cluster.update(values)

    session = get_session()
    try:
        with session.begin():
            session.add(cluster)
            session.flush(objects=[cluster])

            for ng in node_groups:
                node_group = m.NodeGroup()
                node_group.update(ng)
                node_group.update({"cluster_id": cluster.id})
                session.add(node_group)

    except db_exc.DBDuplicateEntry as e:
        raise ex.DBDuplicateEntry(
            _("Duplicate entry for object %(object)s. Failed on columns: "
              "%(columns)s") % {
                  "object": e.value,
                  "columns": e.columns
              })

    return cluster_get(context, cluster.id)