summaryrefslogtreecommitdiffstats
path: root/server/lib
diff options
context:
space:
mode:
authorJannik Schönartz2019-03-18 18:27:55 +0100
committerJannik Schönartz2019-03-18 18:27:55 +0100
commitf486a08621eec271889c4e2108e0038a98e78946 (patch)
tree18150cd68cdcdee42a2a62ce2a124badaf6f4cbb /server/lib
parent[server/log] sql JSON to TEXT for mariadb compatibility (diff)
downloadbas-f486a08621eec271889c4e2108e0038a98e78946.tar.gz
bas-f486a08621eec271889c4e2108e0038a98e78946.tar.xz
bas-f486a08621eec271889c4e2108e0038a98e78946.zip
[server/registration] Add server registration
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/external-backends/backendhelper.js22
-rw-r--r--server/lib/external-backends/backends/idoit-backend.js11
-rw-r--r--server/lib/external-backends/index.js2
-rw-r--r--server/lib/log.js8
4 files changed, 23 insertions, 20 deletions
diff --git a/server/lib/external-backends/backendhelper.js b/server/lib/external-backends/backendhelper.js
index be41ebc..4bd9969 100644
--- a/server/lib/external-backends/backendhelper.js
+++ b/server/lib/external-backends/backendhelper.js
@@ -76,19 +76,19 @@ module.exports = {
return result
},
- deleteClients: function (clientids) {
+ deleteClients: async function (clientids) {
// Get all backends and call deleteClient for each instance.
- return db.backend.findAll({ where: { '$clientMappings.clientid$': clientids }, include: ['clientMappings'] }).then(backends => {
- backends.forEach(backend => {
- const ba = new ExternalBackends()
- const instance = ba.getInstance(backend.type)
- var objectsToDelete = []
- backend.clientMappings.forEach(mapping => {
- objectsToDelete.push(mapping.externalId)
- })
- // If there are objects to delete -> delete them.
- if (objectsToDelete.length > 0) instance.deleteObjects(backend.credentials, objectsToDelete)
+ const backends = await db.backend.findAll({ where: { '$clientMappings.clientid$': clientids }, include: ['clientMappings'] })
+
+ backends.forEach(backend => {
+ const ba = new ExternalBackends()
+ const instance = ba.getInstance(backend.type)
+ var objectsToDelete = []
+ backend.clientMappings.forEach(mapping => {
+ objectsToDelete.push(mapping.externalId)
})
+ // If there are objects to delete -> delete them.
+ if (objectsToDelete.length > 0) instance.deleteObjects(backend.credentials, objectsToDelete)
})
},
diff --git a/server/lib/external-backends/backends/idoit-backend.js b/server/lib/external-backends/backends/idoit-backend.js
index 1fe7b5f..74a59fe 100644
--- a/server/lib/external-backends/backends/idoit-backend.js
+++ b/server/lib/external-backends/backends/idoit-backend.js
@@ -180,9 +180,10 @@ class IdoitBackend extends ExternalBackends {
else if (client.type === 'SERVER') {
params['type'] = 5
- if (client.location) params.categories.C__CATG__LOCATION = { 'data': { 'option': client.location.assembly, 'insertion': client.location.insertion, 'pos': 32 } }
+ if (client.location) params.categories.C__CATG__LOCATION = { 'data': { 'parent': client.parentId, 'option': client.location.assembly, 'insertion': client.location.insertion, 'pos': client.location.pos } }
+ if (client.formfactor) params.categories.C__CATG__FORMFACTOR = { 'data': { 'formfactor': client.formfactor, 'rackunits': client.formfactor.rackunits } }
// TODO: Assign to rack with the given rackid
- }
+ } else if (client.parentId) params.categories.C__CATG__LOCATION = { 'data': { 'parent': client.parentId } }
// Add categories to the object
if (client.uuid) params.categories.C__CATG__MODEL = { 'data': { 'productid': client.uuid } }
@@ -194,17 +195,19 @@ class IdoitBackend extends ExternalBackends {
if (client.network.mac) params.categories.C__CATG__NETWORK_PORT = { 'data': { 'category_id': 1, 'mac': client.network.mac } }
if (client.network.ip) params.categories.C__CATG__IP = { 'data': { 'category_id': 1, 'ipv4_address': client.network.ip } }
}
- if (client.parentId) params.categories.C__CATG__LOCATION = { 'data': { 'parent': client.parentId } }
// Send the create request.
const body = this.getBody('cmdb.object.create', params, 'client_create')
const requestCreate = await this.axiosRequest(c.url, [body], headers)
+
+ // Error handling
if (requestCreate.error) return { error: requestCreate.errno, message: 'Connection was refused.' }
+ else if (requestCreate[0].error) return { error: 'IDOIT_ERROR', message: requestCreate[0].error.message }
// Purpose for Clients:
// 1 = Production | 5 = PVS
// 2 = Test | 7 = Pool PC
// 3 = Quality Assurance | 8 = Mitarbeiter Arbeitsplatz
- return { id: requestCreate[0].result.id, type: params.type, message: requestCreate[0].result.message }
+ return { succes: true, id: requestCreate[0].result.id, type: params.type, message: requestCreate[0].result.message }
}
/*
diff --git a/server/lib/external-backends/index.js b/server/lib/external-backends/index.js
index af7c2a1..41d1c31 100644
--- a/server/lib/external-backends/index.js
+++ b/server/lib/external-backends/index.js
@@ -154,7 +154,7 @@ class ExternalBackends {
* ..., rackid: <RACK_ID>
* location: { assembly: <Horizontal/Vertical>, insertion: <Back/Front/Front and Back>, position: <RU 1 - 46> }
* system: { model: <SYSTEM_MODEL>, manufacturer: <SYSTEM_MANUFACTURER>, serialnumber: <SYSTEM_SERIALNUMBER> },
- * formfactor: { formfactor: <e.g. 19">, rackUnits: <integer> }
+ * formfactor: { formfactor: <e.g. 19">, rackunits: <integer> }
* }
*/
async updateClient (credentials, client) {
diff --git a/server/lib/log.js b/server/lib/log.js
index 3b5dcd3..fede874 100644
--- a/server/lib/log.js
+++ b/server/lib/log.js
@@ -11,11 +11,11 @@ async function log ({ category, description, groupId, clientId, userId }) {
clientId,
userId
})
- if (groupId) entry.groupSnapshot = JSON.stringify(await db.group.findOne({ where: { id: groupId }}))
- if (clientId) entry.clientSnapshot = JSON.stringify(await db.client.findOne({ where: { id: clientId }}))
- if (userId) entry.userSnapshot = JSON.stringify(await db.user.findOne({ where: { id: userId }}))
+ if (groupId) entry.groupSnapshot = JSON.stringify(await db.group.findOne({ where: { id: groupId } }))
+ if (clientId) entry.clientSnapshot = JSON.stringify(await db.client.findOne({ where: { id: clientId } }))
+ if (userId) entry.userSnapshot = JSON.stringify(await db.user.findOne({ where: { id: userId } }))
await entry.save()
return entry
}
-module.exports = log \ No newline at end of file
+module.exports = log