From 00bbd12e6d913ffb04efdbbdc3b1b1d1b18fcd14 Mon Sep 17 00:00:00 2001 From: Manuel Romero Date: Wed, 20 May 2020 14:12:46 +0200 Subject: [PATCH] vmtypes to dbinit --- server/cronjobs/data/vmtypes.json | 62 +++++++++++++++++++++++++++++++ server/cronjobs/db-init.js | 12 +++++- server/mongo.js | 6 ++- 3 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 server/cronjobs/data/vmtypes.json diff --git a/server/cronjobs/data/vmtypes.json b/server/cronjobs/data/vmtypes.json new file mode 100644 index 0000000..42ecfac --- /dev/null +++ b/server/cronjobs/data/vmtypes.json @@ -0,0 +1,62 @@ +[ + { + "_id": "5e73a211710f74000640cbf2", + "type": "Standard_B1ms", + "desc": "1 CPUs - 2GiB RAM", + "costHour": 0.0207 + }, + { + "_id": "5e73a220710f74000640cbf4", + "type": "Standard_B2s", + "desc": "2 CPUs - 4GiB RAM", + "costHour": 0.0416 + }, + { + "_id": "5e73a22b710f74000640cbf6", + "type": "Standard_D2s_v3", + "desc": "2 CPUs - 8GiB RAM", + "costHour": 0.096 + }, + { + "_id": "5e73a240710f74000640cbfa", + "type": "Standard_D4s_v3", + "desc": "4 CPUs - 16GiB RAM", + "costHour": 0.192 + }, + { + "_id": "5e73a251710f74000640cbfe", + "type": "Standard_D8s_v3", + "desc": "8 CPUs - 32GiB RAM", + "costHour": 0.384 + }, + { + "_id": "5e73a262710f74000640cc02", + "type": "Standard_D16s_v3", + "desc": "16 CPUs - 64GiB RAM", + "costHour": 0.768 + }, + { + "_id": "5e92c98ce7b19100066153ab", + "type": "Standard_D32s_v3", + "desc": "32 CPUs - 128GiB RAM", + "costHour": 1.536 + }, + { + "_id": "5ea9016970653300063fbd17", + "type": "Standard_E16s_v3", + "desc": "16 CPUs - 128 GiB RAM - Mem. optimized", + "costHour": 1.008 + }, + { + "_id": "5ea901bd70653300063fbd19", + "type": "Standard_E20s_v3", + "desc": "20 CPUs - 160 GiB RAM - Mem. optimized", + "costHour": 1.26 + }, + { + "_id": "5ea901d670653300063fbd1b", + "type": "Standard_E32s_v3", + "desc": "32 CPUs - 256GiB RAM - Mem. optimized", + "costHour": 2.016 + } +] \ No newline at end of file diff --git a/server/cronjobs/db-init.js b/server/cronjobs/db-init.js index 702d42b..1a91f04 100644 --- a/server/cronjobs/db-init.js +++ b/server/cronjobs/db-init.js @@ -2,6 +2,7 @@ var db = require("../mongo"); var initDataSubscriptions = require("./data/subscriptions.json"); var scenarios1 = require("./data/scenariosQMI-Automation.json"); var scenarios2 = require("./data/scenariosQlik-Secure.json"); +var vmTypes = require("./data/vmtypes.json"); @@ -12,12 +13,19 @@ async function asyncForEach(array, callback) { } async function init() { + // Adding VmTypes + await asyncForEach(vmTypes, async function(v){ + await db.vmtype.add(v); + }); + + // Adding Subscriptions await asyncForEach(initDataSubscriptions, async function(s){ await db.subscription.add(s); }); - + + var subscription; //QMI Automation - var subscription = await db.subscription.getOne({"description": "QMI Automation"}); + subscription = await db.subscription.getOne({"description": "QMI Automation"}); await asyncForEach(scenarios1, async function(s){ s.subscription = subscription._id; await db.scenario.add(s); diff --git a/server/mongo.js b/server/mongo.js index a19df4b..23bf214 100644 --- a/server/mongo.js +++ b/server/mongo.js @@ -58,7 +58,11 @@ const getNewTimeRunning = function (provision) { const get = async (model, filter, select, skip, limit, populates, reply) => { - var sort = {created: -1}; + var sort = {}; + var modelAttributes = Object.keys(model.schema.tree); + if ( modelAttributes.indexOf("created") !== -1) { + sort = {created: -1}; + } try { var exec = model.find(filter, select).sort(sort); var totalDocs = await model.countDocuments(filter);