source: TOOLS/ConsoGENCI/trunk/bin/init_alloc_tbl.py @ 2783

Last change on this file since 2783 was 2783, checked in by labetoulle, 8 years ago
  • Run everything (DB inserts + plots) from single bash script
  • Change exit codes (unsigned in bash, so no negative values...) :
    • 0: everything was ok;
    • 1: nothing done, 'cause nothing to do => ok;
    • >= 2: error.
  • DB access now needs password
  • plot_bilan: added date of production and plotted range to image
  • Cleaning (useless comments, ...)
File size: 4.1 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4# ==================================================================== #
5# Author: Sonia Labetoulle                                             #
6# Contact: sonia.labetoulle _at_ ipsl.jussieu.fr                       #
7# Created: 2016                                                        #
8# History:                                                             #
9# Modification:                                                        #
10# ==================================================================== #
11
12# ==================================================================== #
13# ssh readonly@prodiguer-test-db.ipsl.upmc.fr                          #
14# psql -U prodiguer_db_user prodiguer                                  #
15#                                                                      #
16# ssh readonly@prodiguer-test-db.ipsl.upmc.fr -L 5432:localhost:5432   #
17# ==================================================================== #
18
19# this must come first
20from __future__ import print_function, unicode_literals, division
21
22# standard library imports
23
24# Application library imports
25import libconsodb as cdb
26import db_data
27
28
29#######################################################################
30if __name__ == "__main__":
31
32  project_list = [
33    {
34      "name": "gencmip6",
35      "centre": "tgcc",
36      "machine": "curie",
37      "node": "thin/standard",
38      "alloc": 5000000,
39      "start": "2015-01-01 00:00:00",
40      "end": "2015-06-30 23:59:59",
41    },
42    {
43      "name": "gencmip6",
44      "centre": "tgcc",
45      "machine": "curie",
46      "node": "thin/standard",
47      "alloc": 10000000,
48      "start": "2015-07-01 00:00:00",
49      "end": "2015-12-31 23:59:59",
50    },
51    {
52      "name": "gencmip6",
53      "centre": "tgcc",
54      "machine": "curie",
55      "node": "thin/standard",
56      "alloc": 25000000,
57      "start": "2016-01-01 00:00:00",
58      "end": "2016-06-30 23:59:59",
59    },
60    {
61      "name": "gencmip6",
62      "centre": "tgcc",
63      "machine": "curie",
64      "node": "thin/standard",
65      "alloc": 50000000,
66      "start": "2016-07-01 00:00:00",
67      "end": "2016-12-31 23:59:59",
68    },
69    {
70      "name": "rgzi",
71      "centre": "idris",
72      "machine": "ada",
73      "node": "standard",
74      "alloc": 2000000,
75      "start": "2015-01-01 00:00:00",
76      "end": "2015-12-31 23:59:59",
77    },
78    {
79      "name": "rgzi",
80      "centre": "idris",
81      "machine": "ada",
82      "node": "standard",
83      "alloc": 4000000,
84      "start": "2016-01-01 00:00:00",
85      "end": "2016-12-31 23:59:59",
86    },
87    {
88      "name": "gen0826",
89      "centre": "tgcc",
90      "machine": "curie",
91      "node": "fat/large",
92      "alloc": 114000,
93      "start": "2015-01-01 00:00:00",
94      "end": "2015-12-31 23:59:59",
95    },
96    {
97      "name": "gen0826",
98      "centre": "tgcc",
99      "machine": "curie",
100      "node": "hybrid",
101      "alloc": 25000,
102      "start": "2015-01-01 00:00:00",
103      "end": "2015-12-31 23:59:59",
104    },
105    {
106      "name": "gen0826",
107      "centre": "tgcc",
108      "machine": "curie",
109      "node": "thin/standard",
110      "alloc": 114000,
111      "start": "2015-01-01 00:00:00",
112      "end": "2015-12-31 23:59:59",
113    },
114  ]
115
116  conn, cursor = cdb.connect_db(
117    db_data.db_host,
118    db_data.db_name,
119    db_data.db_user,
120    db_data.db_pwd,
121  )
122
123  # Build request
124  table_name = "conso.tbl_allocation"
125  request = (
126    "INSERT INTO " + table_name + " ("
127    "project, centre, machine, node_type, total_hrs, "
128    "start_date, end_date, row_create_date"
129    ") VALUES "
130  )
131
132  lines_req = [
133    (
134      "('{name}', "
135      "'{centre}', "
136      "'{machine}', "
137      "'{node}', "
138      "{alloc}, "
139      "'{start}', "
140      "'{end}', "
141      "{create})"
142    ) .format(
143      name=line["name"],
144      centre=line["centre"],
145      machine=line["machine"],
146      node=line["node"],
147      alloc=line["alloc"],
148      start=line["start"],
149      end=line["end"],
150      create="CURRENT_TIMESTAMP",
151    ) for line in project_list
152  ]
153
154  print(", ".join(lines_req))
155  request = request + ", ".join(lines_req)
156  print(request)
157
158  cdb.insert_db(cursor, request)
159
160  cdb.commit_db(conn)
161
162  cdb.close_db(conn)
163
164  exit(0)
Note: See TracBrowser for help on using the repository browser.