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