summaryrefslogtreecommitdiffstats
path: root/server/api/registrations.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/api/registrations.js')
-rw-r--r--server/api/registrations.js38
1 files changed, 35 insertions, 3 deletions
diff --git a/server/api/registrations.js b/server/api/registrations.js
index 928ee94..f6a8f87 100644
--- a/server/api/registrations.js
+++ b/server/api/registrations.js
@@ -5,6 +5,7 @@ var router = express.Router()
var noAuthRouter = express.Router()
var db = require(path.join(__appdir, 'lib', 'sequelize'))
const ExternalBackends = require(path.join(__appdir, 'lib', 'external-backends'))
+const backendHelper = require(path.join(__appdir, 'lib', 'external-backends', 'backendhelper'))
// GET requests.
@@ -115,7 +116,7 @@ noAuthRouter.post('/group', (req, res) => {
})
/*
- * Adds the client in the database and set parents if a parent was selected.
+ * Adds the client to the database and set parents if a parent was selected. Calls addClient for all external-backends.
*/
noAuthRouter.post('/add', (req, res) => {
const mac = req.body.mac
@@ -129,10 +130,27 @@ noAuthRouter.post('/add', (req, res) => {
var groupids = []
if (parentId) groupids = [parentId]
getNextHookScript(groupids, 0).then(resId => {
- db.client.create({ name: name, ip: ip, mac: mac, uuid: uuid, registrationState: resId }).then(client => {
+ db.client.create({ name: name, ip: ip, mac: mac, uuid: uuid, registrationState: resId }).then(newClient => {
if (parentId) {
- client.addGroup(parentId)
+ newClient.addGroup(parentId)
}
+
+ // Add the client to the backends.
+ const c = { network: { mac: mac, ip: ip } }
+ if (parentId) c.parentId = parentId
+ if (name) c.title = name
+ else c.title = 'Client_' + uuid
+ backendHelper.addClient(c).then(result => {
+ result.forEach(response => {
+ // If the object was created we need to make the objectid / external id mapping.
+ if (response.success && response.create) {
+ db.backend.findOne({ where: { id: response.backendId }, include: ['mappedClients'] }).then(backend => {
+ backend.addMappedClients(newClient, { through: { externalId: response.id, externalType: response.type } })
+ })
+ }
+ })
+ })
+
res.send('#!ipxe\r\nreboot')
})
})
@@ -141,6 +159,20 @@ noAuthRouter.post('/add', (req, res) => {
})
/*
+ * Adds additional information for the backends of the client in the firstregistration.
+ */
+noAuthRouter.post('/addInfo', (req, res) => {
+ const id = req.body.id
+ const systemModel = req.body.sysmodel
+ const systemManufacturer = req.body.sysmanu
+ const systemSerial = req.body.sysserial
+
+ // Add the client to the backends.
+ backendHelper.addClient({ id: id, system: { model: systemModel, manufacturer: systemManufacturer, serialnumber: systemSerial } })
+ res.send({ status: 'success' })
+})
+
+/*
* Open api method for setting the registration state of a given uuid.
*/
noAuthRouter.post('/:uuid/success', (req, res) => {