summaryrefslogtreecommitdiffstats
path: root/server/lib/external-backends/backends
diff options
context:
space:
mode:
authorJannik Schönartz2019-03-18 22:34:42 +0100
committerJannik Schönartz2019-03-18 22:34:42 +0100
commit5c560ee32d356eebf44b976e876081b161b86ecb (patch)
tree17b842c52b6c04145b2f0f54a6385a18cbb7ee4a /server/lib/external-backends/backends
parent[server/registration] Add server registration (diff)
downloadbas-5c560ee32d356eebf44b976e876081b161b86ecb.tar.gz
bas-5c560ee32d356eebf44b976e876081b161b86ecb.tar.xz
bas-5c560ee32d356eebf44b976e876081b161b86ecb.zip
[server/registration] Add client with json instead of parameters (ipxe)
Diffstat (limited to 'server/lib/external-backends/backends')
-rw-r--r--server/lib/external-backends/backends/idoit-backend.js30
1 files changed, 24 insertions, 6 deletions
diff --git a/server/lib/external-backends/backends/idoit-backend.js b/server/lib/external-backends/backends/idoit-backend.js
index 74a59fe..8c1a4c3 100644
--- a/server/lib/external-backends/backends/idoit-backend.js
+++ b/server/lib/external-backends/backends/idoit-backend.js
@@ -168,7 +168,6 @@ class IdoitBackend extends ExternalBackends {
const c = this.mapCredentials(credentials)
const headers = await this.getHeaders(c)
if (headers.error) return headers
-
let params = {
'apikey': c.apikey,
'title': client.title,
@@ -176,14 +175,15 @@ class IdoitBackend extends ExternalBackends {
'categories': {}
}
- if (client.type === 'CLIENT') params['type'] = 10
- else if (client.type === 'SERVER') {
+ if (client.type === 'CLIENT') {
+ params['type'] = 10
+ if (client.parentId) params.categories.C__CATG__LOCATION = { 'data': { 'parent': client.parentId } }
+ } else if (client.type === 'SERVER') {
params['type'] = 5
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 } }
@@ -192,7 +192,7 @@ class IdoitBackend extends ExternalBackends {
// First read if there are current entries.
// Delete the previous entries.
// Finally create the new entry.
- 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 } }
}
@@ -203,6 +203,24 @@ class IdoitBackend extends ExternalBackends {
// 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 }
+
+ // Add mac address: Network port is a subcategory of network so it need an extra request.
+ if (client.network && client.network.mac) {
+ params.categories.C__CATG__NETWORK_PORT = { 'data': { 'category_id': 1, 'mac': client.network.mac } }
+ const paramsMac = {
+ 'object': requestCreate[0].result.id,
+ 'objID': requestCreate[0].result.id,
+ 'category': 'C__CATG__NETWORK_PORT',
+ 'data': {
+ 'category_id': 1,
+ 'mac': client.network.mac
+ },
+ 'apikey': c.apikey
+ }
+ const bodyMac = this.getBody('cmdb.category.save', paramsMac, 'add_mac_address')
+ const requestMac = await this.axiosRequest(c.url, [bodyMac], headers)
+ }
+
// Purpose for Clients:
// 1 = Production | 5 = PVS
// 2 = Test | 7 = Pool PC