summaryrefslogtreecommitdiffstats
path: root/server/lib/external-backends
diff options
context:
space:
mode:
authorJannik Schönartz2019-03-25 06:43:55 +0100
committerJannik Schönartz2019-03-25 06:43:55 +0100
commit752d9c18bb531544f28bdbfd00b5eb922e07d3d8 (patch)
tree5c4773c2556b0a3aa928574c7ef63a996113c22d /server/lib/external-backends
parenteslint fix (diff)
downloadbas-752d9c18bb531544f28bdbfd00b5eb922e07d3d8.tar.gz
bas-752d9c18bb531544f28bdbfd00b5eb922e07d3d8.tar.xz
bas-752d9c18bb531544f28bdbfd00b5eb922e07d3d8.zip
[external-backends/idoit] Add server rack segmentation & add multiple ip support
Diffstat (limited to 'server/lib/external-backends')
-rw-r--r--server/lib/external-backends/backends/idoit-backend.js163
1 files changed, 141 insertions, 22 deletions
diff --git a/server/lib/external-backends/backends/idoit-backend.js b/server/lib/external-backends/backends/idoit-backend.js
index ce7680a..c76b6bf 100644
--- a/server/lib/external-backends/backends/idoit-backend.js
+++ b/server/lib/external-backends/backends/idoit-backend.js
@@ -181,19 +181,121 @@ class IdoitBackend extends ExternalBackends {
} 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.location && !client.location.bay) params.categories.C__CATG__LOCATION = { 'data': { 'parent': client.parentId, 'option': client.location.assembly, 'insertion': client.location.insertion, 'pos': client.location.slot } }
if (client.formfactor) params.categories.C__CATG__FORMFACTOR = { 'data': { 'formfactor': client.formfactor, 'rackunits': client.formfactor.rackunits } }
+
+ // Rack segmentation
+ if (client.location.bay) {
+ // Get all assigned objects of the rack (parentid) to check for existing rack segments at slot position.
+ const rackobjectsBody = this.getBody('cmdb.category.read', { 'apikey': c.apikey, 'object': client.parentId, 'objID': client.parentId, 'category': 'C__CATG__OBJECT' }, 'get_rack_objects')
+ const rackobjects = await this.axiosRequest(c.url, [rackobjectsBody], headers)
+
+ // Get the name of the rack
+ const rackBody = this.getBody('cmdb.category.read', { 'apikey': c.apikey, 'object': client.parentId, 'objID': client.parentId, 'category': 'C__CATG__GLOBAL' }, 'get_rack')
+ const rack = await this.axiosRequest(c.url, [rackBody], headers)
+ const rackName = rack[0].result[0].title
+
+ let objectPositionBodies = []
+
+ // For each segmentation object in the rack get the slot number
+ for (let obj in rackobjects[0].result) {
+ const object = rackobjects[0].result[obj]
+ if (object.assigned_object.type !== 'C__OBJTYPE__RACK_SEGMENT') continue
+ objectPositionBodies.push(this.getBody('cmdb.category.read', { 'apikey': c.apikey, 'object': object.objID, 'objID': object.objID, 'category': 'C__CATG__LOCATION' }, 'get_rack_object_position_' + object.objID))
+ }
+ let objectPositions = await this.axiosRequest(c.url, objectPositionBodies, headers)
+ if (objectPositions.length >= 1) objectPositions = objectPositions.filter(x => parseInt(x.result[0].pos.title) === parseInt(client.location.slot))
+
+ // There should only be one segment object for the rack slot if so set it as parent
+ var chassisId
+ if (objectPositions.length === 1) chassisId = parseInt(objectPositions[0].result[0].objID)
+ else {
+ // Create a new rack segment
+ const createSegmentParamObject = {
+ 'apikey': c.apikey,
+ 'type': 92,
+ 'title': rackName + ' Slot ' + client.location.slot,
+ 'categories': {
+ 'C__CATS__CHASSIS': {
+ 'data': {
+ 'front_x': 4,
+ 'front_y': 2,
+ 'rear_x': 0,
+ 'rear_y': 0
+ }
+ },
+ 'C__CATS__CHASSIS_SLOT': [
+ {
+ 'title': 'Bay 1',
+ 'insertion': 'front',
+ 'from_x': 0,
+ 'to_x': 0,
+ 'from_y': 0,
+ 'to_y': 1
+ },
+ {
+ 'title': 'Bay 2',
+ 'insertion': 'front',
+ 'from_x': 1,
+ 'to_x': 1,
+ 'from_y': 0,
+ 'to_y': 1
+ },
+ {
+ 'title': 'Bay 3',
+ 'insertion': 'front',
+ 'from_x': 2,
+ 'to_x': 2,
+ 'from_y': 0,
+ 'to_y': 1
+ },
+ {
+ 'title': 'Bay 4',
+ 'insertion': 'front',
+ 'from_x': 3,
+ 'to_x': 3,
+ 'from_y': 0,
+ 'to_y': 1
+ }
+ ],
+ 'C__CATG__LOCATION': {
+ 'data': {
+ 'parent': parseInt(client.parentId),
+ 'option': client.location.option,
+ 'insertion': client.location.insertion,
+ 'pos': client.location.slot
+ }
+ }
+ }
+ }
+
+ const createSegmentParam = this.getBody('cmdb.object.create', createSegmentParamObject, 'create_segment')
+ const createSegment = await this.axiosRequest(c.url, [createSegmentParam], headers)
+ chassisId = createSegment[0].result.id
+
+ // Set the new rack units height. (Needs an extra request, why? I DONT KNOW... idoit...)
+ const setSegmentSizeParams = this.getBody('cmdb.category.save', { 'apikey': c.apikey,
+ 'object': chassisId,
+ 'objID': chassisId,
+ 'category': 'C__CATG__FORMFACTOR',
+ 'data': { 'rackunits': client.formfactor.rackunits } }, 'set_segment_size')
+ await this.axiosRequest(c.url, [setSegmentSizeParams], headers)
+ }
+ }
}
// Add categories to the object
if (client.uuid) params.categories.C__CATG__MODEL = { 'data': { 'productid': client.uuid } }
- if (client.network) {
- // TOOD:
- // First read if there are current entries.
- // Delete the previous entries.
- // Finally create the new entry.
-
- if (client.network.ip) params.categories.C__CATG__IP = { 'data': { 'category_id': 1, 'ipv4_address': client.network.ip } }
+ if (client.networks) {
+ params.categories.C__CATG__IP = []
+ for (let network of client.networks) {
+ let networkparams = {}
+ if (network.ip) networkparams.ipv4_address = network.ip
+ if (network.hostname) networkparams.hostname = network.hostname
+ if (network.domain) networkparams.domain = network.domain
+ if (network.net) networkparams.net = network.net
+ params.categories.C__CATG__IP.push(networkparams)
+ }
}
// Send the create request.
@@ -205,27 +307,44 @@ class IdoitBackend extends ExternalBackends {
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
+ let macRequests = []
+ if (client.networks) {
+ for (let index in client.networks) {
+ const network = client.networks[index]
+ // For the idresses
+ // network.id = requestCreate[0].result.categories.C__CATG__IP[index]
+
+ const paramsMac = {
+ 'object': requestCreate[0].result.id,
+ 'objID': requestCreate[0].result.id,
+ 'category': 'C__CATG__NETWORK_PORT',
+ 'data': {
+ 'mac': network.mac
+ },
+ 'apikey': c.apikey
+ }
+ const bodyMac = this.getBody('cmdb.category.save', paramsMac, 'add_mac_address')
+ const response = await this.axiosRequest(c.url, [bodyMac], headers)
+ macRequests.push(response)
}
- const bodyMac = this.getBody('cmdb.category.save', paramsMac, 'add_mac_address')
- await this.axiosRequest(c.url, [bodyMac], headers)
+ }
+
+ // If chassis id is set, assign the object to the chassis bay
+ if (chassisId) {
+ const bay = client.location.bay + ''
+ const assignToSlotBody = this.getBody('cmdb.category.save', { 'apikey': c.apikey,
+ 'objID': chassisId,
+ 'object': chassisId,
+ 'category': 'C__CATS__CHASSIS_DEVICES',
+ 'data': { 'assigned_device': requestCreate[0].result.id, 'assigned_slots': [bay] } }, 'assign_to_slot')
+ await this.axiosRequest(c.url, [assignToSlotBody], headers)
}
// Purpose for Clients:
// 1 = Production | 5 = PVS
// 2 = Test | 7 = Pool PC
// 3 = Quality Assurance | 8 = Mitarbeiter Arbeitsplatz
- return { succes: true, 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, macRequests: macRequests }
}
/*