source: TOOLS/ConsoGENCI/bin/init_alloc_tbl.py @ 2713

Last change on this file since 2713 was 2713, checked in by labetoulle, 8 years ago

Initial import

File size: 2.3 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4# ==================================================================== #
5# ssh readonly@prodiguer-test-db.ipsl.upmc.fr                          #
6# psql -U prodiguer_db_user prodiguer                                  #
7#                                                                      #
8# ssh readonly@prodiguer-test-db.ipsl.upmc.fr -L 5432:localhost:5432   #
9# ==================================================================== #
10
11# this must come first
12from __future__ import print_function, unicode_literals, division
13
14# standard library imports
15# from pprint import pprint
16
17# Application library imports
18import libconsodb as cdb
19
20
21########################################
22if __name__ == "__main__":
23
24  project_list = [
25    {
26      "name": "gencmip6",
27      "centre": "tgcc",
28      "machine": "curie",
29      "node": "thin",
30      "alloc": 5000000,
31      "start": "20150101",
32      "end": "20150630",
33    },
34    {
35      "name": "gencmip6",
36      "centre": "tgcc",
37      "machine": "curie",
38      "node": "thin",
39      "alloc": 15000000,
40      "start": "20150701",
41      "end": "20151231",
42    },
43    {
44      "name": "rgzi",
45      "centre": "idris",
46      "machine": "ada",
47      "node": "standard",
48      "alloc": 2000000,
49      "start": "20150101",
50      "end": "20151231",
51    },
52  ]
53
54  # Connection info
55  db_host = "134.157.170.104"
56  # db_port = "5432"
57  db_name = "prodiguer"
58  db_user = "prodiguer_db_user"
59  # db_pwd = "secret"
60
61  conn, cursor = cdb.connect_db(db_host, db_name, db_user)
62
63  # Build request
64  table_name = "conso.tbl_allocation"
65  request = (
66    "INSERT INTO " + table_name + " ("
67    "project, centre, machine, node_type, total_hrs, "
68    "start_date, end_date, row_create_date"
69    ") VALUES "
70  )
71
72  lines_req = [
73    (
74      "('{name}', "
75      "'{centre}', "
76      "'{machine}', "
77      "'{node}', "
78      "{alloc}, "
79      "'{start}', "
80      "'{end}', "
81      "{create})"
82    ) .format(
83      name=line["name"],
84      centre=line["centre"],
85      machine=line["machine"],
86      node=line["node"],
87      alloc=line["alloc"],
88      start=line["start"],
89      end=line["end"],
90      create="CURRENT_TIMESTAMP",
91    ) for line in project_list
92  ]
93
94  print(", ".join(lines_req))
95  request = request + ", ".join(lines_req)
96  print(request)
97
98  cdb.insert_db(cursor, request)
99
100  cdb.commit_db(conn)
Note: See TracBrowser for help on using the repository browser.