@itentialopensource/adapter-vmware_vcenter 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AUTH.md +39 -0
- package/BROKER.md +199 -0
- package/CALLS.md +169 -0
- package/CHANGELOG.md +76 -61
- package/CODE_OF_CONDUCT.md +12 -17
- package/CONTRIBUTING.md +88 -74
- package/ENHANCE.md +69 -0
- package/PROPERTIES.md +641 -0
- package/README.md +221 -571
- package/SUMMARY.md +9 -0
- package/SYSTEMINFO.md +11 -0
- package/TROUBLESHOOT.md +47 -0
- package/adapter.js +292 -469
- package/adapterBase.js +1006 -252
- package/entities/.generic/action.json +105 -0
- package/entities/.generic/schema.json +6 -1
- package/error.json +6 -0
- package/package.json +5 -3
- package/pronghorn.json +642 -570
- package/propertiesDecorators.json +14 -0
- package/propertiesSchema.json +421 -0
- package/refs?service=git-upload-pack +0 -0
- package/report/adapterInfo.json +10 -0
- package/report/updateReport1652715810150.json +120 -0
- package/sampleProperties.json +90 -1
- package/test/integration/adapterTestBasicGet.js +1 -1
- package/test/integration/adapterTestIntegration.js +25 -107
- package/test/unit/adapterBaseTestUnit.js +30 -25
- package/test/unit/adapterTestUnit.js +90 -177
- package/utils/adapterInfo.js +206 -0
- package/utils/entitiesToDB.js +12 -57
- package/utils/pre-commit.sh +3 -0
- package/utils/tbScript.js +35 -20
- package/utils/tbUtils.js +49 -31
- package/utils/testRunner.js +16 -16
package/adapter.js
CHANGED
|
@@ -82,10 +82,18 @@ class VmwareVCenter extends AdapterBaseCl {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
|
-
* @
|
|
85
|
+
* @iapGetAdapterWorkflowFunctions
|
|
86
86
|
*/
|
|
87
|
-
|
|
88
|
-
let myIgnore = [
|
|
87
|
+
iapGetAdapterWorkflowFunctions(inIgnore) {
|
|
88
|
+
let myIgnore = [
|
|
89
|
+
'healthCheck',
|
|
90
|
+
'iapGetAdapterWorkflowFunctions',
|
|
91
|
+
'iapHasAdapterEntity',
|
|
92
|
+
'iapVerifyAdapterCapability',
|
|
93
|
+
'iapUpdateAdapterEntityCache',
|
|
94
|
+
'hasEntities',
|
|
95
|
+
'getAuthorization'
|
|
96
|
+
];
|
|
89
97
|
if (!inIgnore && Array.isArray(inIgnore)) {
|
|
90
98
|
myIgnore = inIgnore;
|
|
91
99
|
} else if (!inIgnore && typeof inIgnore === 'string') {
|
|
@@ -96,15 +104,15 @@ class VmwareVCenter extends AdapterBaseCl {
|
|
|
96
104
|
// you can add specific methods that you do not want to be workflow functions to ignore like below
|
|
97
105
|
// myIgnore.push('myMethodNotInWorkflow');
|
|
98
106
|
|
|
99
|
-
return super.
|
|
107
|
+
return super.iapGetAdapterWorkflowFunctions(myIgnore);
|
|
100
108
|
}
|
|
101
109
|
|
|
102
110
|
/**
|
|
103
|
-
*
|
|
111
|
+
* iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
|
|
104
112
|
* allows customers to make changes to adapter configuration without having to be on the
|
|
105
113
|
* file system.
|
|
106
114
|
*
|
|
107
|
-
* @function
|
|
115
|
+
* @function iapUpdateAdapterConfiguration
|
|
108
116
|
* @param {string} configFile - the name of the file being updated (required)
|
|
109
117
|
* @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
|
|
110
118
|
* @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
|
|
@@ -112,36 +120,42 @@ class VmwareVCenter extends AdapterBaseCl {
|
|
|
112
120
|
* @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
|
|
113
121
|
* @param {Callback} callback - The results of the call
|
|
114
122
|
*/
|
|
115
|
-
|
|
116
|
-
const
|
|
123
|
+
iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
|
|
124
|
+
const meth = 'adapter-iapUpdateAdapterConfiguration';
|
|
125
|
+
const origin = `${this.id}-${meth}`;
|
|
117
126
|
log.trace(origin);
|
|
118
|
-
|
|
127
|
+
|
|
128
|
+
super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback);
|
|
119
129
|
}
|
|
120
130
|
|
|
121
131
|
/**
|
|
122
132
|
* See if the API path provided is found in this adapter
|
|
123
133
|
*
|
|
124
|
-
* @function
|
|
134
|
+
* @function iapFindAdapterPath
|
|
125
135
|
* @param {string} apiPath - the api path to check on
|
|
126
136
|
* @param {Callback} callback - The results of the call
|
|
127
137
|
*/
|
|
128
|
-
|
|
129
|
-
const
|
|
138
|
+
iapFindAdapterPath(apiPath, callback) {
|
|
139
|
+
const meth = 'adapter-iapFindAdapterPath';
|
|
140
|
+
const origin = `${this.id}-${meth}`;
|
|
130
141
|
log.trace(origin);
|
|
131
|
-
|
|
142
|
+
|
|
143
|
+
super.iapFindAdapterPath(apiPath, callback);
|
|
132
144
|
}
|
|
133
145
|
|
|
134
146
|
/**
|
|
135
147
|
* @summary Suspends adapter
|
|
136
148
|
*
|
|
137
|
-
* @function
|
|
149
|
+
* @function iapSuspendAdapter
|
|
138
150
|
* @param {Callback} callback - callback function
|
|
139
151
|
*/
|
|
140
|
-
|
|
141
|
-
const
|
|
152
|
+
iapSuspendAdapter(mode, callback) {
|
|
153
|
+
const meth = 'adapter-iapSuspendAdapter';
|
|
154
|
+
const origin = `${this.id}-${meth}`;
|
|
142
155
|
log.trace(origin);
|
|
156
|
+
|
|
143
157
|
try {
|
|
144
|
-
return super.
|
|
158
|
+
return super.iapSuspendAdapter(mode, callback);
|
|
145
159
|
} catch (error) {
|
|
146
160
|
log.error(`${origin}: ${error}`);
|
|
147
161
|
return callback(null, error);
|
|
@@ -151,14 +165,16 @@ class VmwareVCenter extends AdapterBaseCl {
|
|
|
151
165
|
/**
|
|
152
166
|
* @summary Unsuspends adapter
|
|
153
167
|
*
|
|
154
|
-
* @function
|
|
168
|
+
* @function iapUnsuspendAdapter
|
|
155
169
|
* @param {Callback} callback - callback function
|
|
156
170
|
*/
|
|
157
|
-
|
|
158
|
-
const
|
|
171
|
+
iapUnsuspendAdapter(callback) {
|
|
172
|
+
const meth = 'adapter-iapUnsuspendAdapter';
|
|
173
|
+
const origin = `${this.id}-${meth}`;
|
|
159
174
|
log.trace(origin);
|
|
175
|
+
|
|
160
176
|
try {
|
|
161
|
-
return super.
|
|
177
|
+
return super.iapUnsuspendAdapter(callback);
|
|
162
178
|
} catch (error) {
|
|
163
179
|
log.error(`${origin}: ${error}`);
|
|
164
180
|
return callback(null, error);
|
|
@@ -168,29 +184,33 @@ class VmwareVCenter extends AdapterBaseCl {
|
|
|
168
184
|
/**
|
|
169
185
|
* @summary Get the Adaoter Queue
|
|
170
186
|
*
|
|
171
|
-
* @function
|
|
187
|
+
* @function iapGetAdapterQueue
|
|
172
188
|
* @param {Callback} callback - callback function
|
|
173
189
|
*/
|
|
174
|
-
|
|
175
|
-
const
|
|
190
|
+
iapGetAdapterQueue(callback) {
|
|
191
|
+
const meth = 'adapter-iapGetAdapterQueue';
|
|
192
|
+
const origin = `${this.id}-${meth}`;
|
|
176
193
|
log.trace(origin);
|
|
177
|
-
|
|
194
|
+
|
|
195
|
+
return super.iapGetAdapterQueue(callback);
|
|
178
196
|
}
|
|
179
197
|
|
|
180
198
|
/**
|
|
181
199
|
* @summary Runs troubleshoot scripts for adapter
|
|
182
200
|
*
|
|
183
|
-
* @function
|
|
201
|
+
* @function iapTroubleshootAdapter
|
|
184
202
|
* @param {Object} props - the connection, healthcheck and authentication properties
|
|
185
203
|
*
|
|
186
204
|
* @param {boolean} persistFlag - whether the adapter properties should be updated
|
|
187
205
|
* @param {Callback} callback - The results of the call
|
|
188
206
|
*/
|
|
189
|
-
|
|
190
|
-
const
|
|
207
|
+
iapTroubleshootAdapter(props, persistFlag, callback) {
|
|
208
|
+
const meth = 'adapter-iapTroubleshootAdapter';
|
|
209
|
+
const origin = `${this.id}-${meth}`;
|
|
191
210
|
log.trace(origin);
|
|
211
|
+
|
|
192
212
|
try {
|
|
193
|
-
return super.
|
|
213
|
+
return super.iapTroubleshootAdapter(props, persistFlag, this, callback);
|
|
194
214
|
} catch (error) {
|
|
195
215
|
log.error(`${origin}: ${error}`);
|
|
196
216
|
return callback(null, error);
|
|
@@ -200,15 +220,17 @@ class VmwareVCenter extends AdapterBaseCl {
|
|
|
200
220
|
/**
|
|
201
221
|
* @summary runs healthcheck script for adapter
|
|
202
222
|
*
|
|
203
|
-
* @function
|
|
223
|
+
* @function iapRunAdapterHealthcheck
|
|
204
224
|
* @param {Adapter} adapter - adapter instance to troubleshoot
|
|
205
225
|
* @param {Callback} callback - callback function
|
|
206
226
|
*/
|
|
207
|
-
|
|
208
|
-
const
|
|
227
|
+
iapRunAdapterHealthcheck(callback) {
|
|
228
|
+
const meth = 'adapter-iapRunAdapterHealthcheck';
|
|
229
|
+
const origin = `${this.id}-${meth}`;
|
|
209
230
|
log.trace(origin);
|
|
231
|
+
|
|
210
232
|
try {
|
|
211
|
-
return super.
|
|
233
|
+
return super.iapRunAdapterHealthcheck(this, callback);
|
|
212
234
|
} catch (error) {
|
|
213
235
|
log.error(`${origin}: ${error}`);
|
|
214
236
|
return callback(null, error);
|
|
@@ -218,14 +240,16 @@ class VmwareVCenter extends AdapterBaseCl {
|
|
|
218
240
|
/**
|
|
219
241
|
* @summary runs connectivity check script for adapter
|
|
220
242
|
*
|
|
221
|
-
* @function
|
|
243
|
+
* @function iapRunAdapterConnectivity
|
|
222
244
|
* @param {Callback} callback - callback function
|
|
223
245
|
*/
|
|
224
|
-
|
|
225
|
-
const
|
|
246
|
+
iapRunAdapterConnectivity(callback) {
|
|
247
|
+
const meth = 'adapter-iapRunAdapterConnectivity';
|
|
248
|
+
const origin = `${this.id}-${meth}`;
|
|
226
249
|
log.trace(origin);
|
|
250
|
+
|
|
227
251
|
try {
|
|
228
|
-
return super.
|
|
252
|
+
return super.iapRunAdapterConnectivity(callback);
|
|
229
253
|
} catch (error) {
|
|
230
254
|
log.error(`${origin}: ${error}`);
|
|
231
255
|
return callback(null, error);
|
|
@@ -235,14 +259,16 @@ class VmwareVCenter extends AdapterBaseCl {
|
|
|
235
259
|
/**
|
|
236
260
|
* @summary runs basicGet script for adapter
|
|
237
261
|
*
|
|
238
|
-
* @function
|
|
262
|
+
* @function iapRunAdapterBasicGet
|
|
239
263
|
* @param {Callback} callback - callback function
|
|
240
264
|
*/
|
|
241
|
-
|
|
242
|
-
const
|
|
265
|
+
iapRunAdapterBasicGet(callback) {
|
|
266
|
+
const meth = 'adapter-iapRunAdapterBasicGet';
|
|
267
|
+
const origin = `${this.id}-${meth}`;
|
|
243
268
|
log.trace(origin);
|
|
269
|
+
|
|
244
270
|
try {
|
|
245
|
-
return super.
|
|
271
|
+
return super.iapRunAdapterBasicGet(callback);
|
|
246
272
|
} catch (error) {
|
|
247
273
|
log.error(`${origin}: ${error}`);
|
|
248
274
|
return callback(null, error);
|
|
@@ -252,45 +278,48 @@ class VmwareVCenter extends AdapterBaseCl {
|
|
|
252
278
|
/**
|
|
253
279
|
* @summary moves entites into Mongo DB
|
|
254
280
|
*
|
|
255
|
-
* @function
|
|
281
|
+
* @function iapMoveAdapterEntitiesToDB
|
|
256
282
|
* @param {getCallback} callback - a callback function to return the result (Generics)
|
|
257
283
|
* or the error
|
|
258
284
|
*/
|
|
259
|
-
|
|
260
|
-
const
|
|
285
|
+
iapMoveAdapterEntitiesToDB(callback) {
|
|
286
|
+
const meth = 'adapter-iapMoveAdapterEntitiesToDB';
|
|
287
|
+
const origin = `${this.id}-${meth}`;
|
|
261
288
|
log.trace(origin);
|
|
289
|
+
|
|
262
290
|
try {
|
|
263
|
-
return super.
|
|
291
|
+
return super.iapMoveAdapterEntitiesToDB(callback);
|
|
264
292
|
} catch (err) {
|
|
265
293
|
log.error(`${origin}: ${err}`);
|
|
266
294
|
return callback(null, err);
|
|
267
295
|
}
|
|
268
296
|
}
|
|
269
297
|
|
|
298
|
+
/* BROKER CALLS */
|
|
270
299
|
/**
|
|
271
300
|
* @summary Determines if this adapter supports the specific entity
|
|
272
301
|
*
|
|
273
|
-
* @function
|
|
302
|
+
* @function iapHasAdapterEntity
|
|
274
303
|
* @param {String} entityType - the entity type to check for
|
|
275
304
|
* @param {String/Array} entityId - the specific entity we are looking for
|
|
276
305
|
*
|
|
277
306
|
* @param {Callback} callback - An array of whether the adapter can has the
|
|
278
307
|
* desired capability or an error
|
|
279
308
|
*/
|
|
280
|
-
|
|
281
|
-
const origin = `${this.id}-adapter-
|
|
309
|
+
iapHasAdapterEntity(entityType, entityId, callback) {
|
|
310
|
+
const origin = `${this.id}-adapter-iapHasAdapterEntity`;
|
|
282
311
|
log.trace(origin);
|
|
283
312
|
|
|
284
313
|
// Make the call -
|
|
285
|
-
//
|
|
286
|
-
return this.
|
|
314
|
+
// iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
|
|
315
|
+
return this.iapVerifyAdapterCapability(entityType, null, entityId, callback);
|
|
287
316
|
}
|
|
288
317
|
|
|
289
318
|
/**
|
|
290
319
|
* @summary Provides a way for the adapter to tell north bound integrations
|
|
291
320
|
* whether the adapter supports type, action and specific entity
|
|
292
321
|
*
|
|
293
|
-
* @function
|
|
322
|
+
* @function iapVerifyAdapterCapability
|
|
294
323
|
* @param {String} entityType - the entity type to check for
|
|
295
324
|
* @param {String} actionType - the action type to check for
|
|
296
325
|
* @param {String/Array} entityId - the specific entity we are looking for
|
|
@@ -298,15 +327,15 @@ class VmwareVCenter extends AdapterBaseCl {
|
|
|
298
327
|
* @param {Callback} callback - An array of whether the adapter can has the
|
|
299
328
|
* desired capability or an error
|
|
300
329
|
*/
|
|
301
|
-
|
|
302
|
-
const meth = 'adapterBase-
|
|
330
|
+
iapVerifyAdapterCapability(entityType, actionType, entityId, callback) {
|
|
331
|
+
const meth = 'adapterBase-iapVerifyAdapterCapability';
|
|
303
332
|
const origin = `${this.id}-${meth}`;
|
|
304
333
|
log.trace(origin);
|
|
305
334
|
|
|
306
335
|
// if caching
|
|
307
336
|
if (this.caching) {
|
|
308
|
-
// Make the call -
|
|
309
|
-
return this.requestHandlerInst.
|
|
337
|
+
// Make the call - iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
|
|
338
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (results, error) => {
|
|
310
339
|
if (error) {
|
|
311
340
|
return callback(null, error);
|
|
312
341
|
}
|
|
@@ -324,7 +353,7 @@ class VmwareVCenter extends AdapterBaseCl {
|
|
|
324
353
|
}
|
|
325
354
|
|
|
326
355
|
// need to check the cache again since it has been updated
|
|
327
|
-
return this.requestHandlerInst.
|
|
356
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (vcapable, verror) => {
|
|
328
357
|
if (verror) {
|
|
329
358
|
return callback(null, verror);
|
|
330
359
|
}
|
|
@@ -357,7 +386,7 @@ class VmwareVCenter extends AdapterBaseCl {
|
|
|
357
386
|
// if no entity id
|
|
358
387
|
if (!entityId) {
|
|
359
388
|
// need to check the cache again since it has been updated
|
|
360
|
-
return this.requestHandlerInst.
|
|
389
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
|
|
361
390
|
if (verror) {
|
|
362
391
|
return callback(null, verror);
|
|
363
392
|
}
|
|
@@ -378,7 +407,7 @@ class VmwareVCenter extends AdapterBaseCl {
|
|
|
378
407
|
}
|
|
379
408
|
|
|
380
409
|
// need to check the cache again since it has been updated
|
|
381
|
-
return this.requestHandlerInst.
|
|
410
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
|
|
382
411
|
if (verror) {
|
|
383
412
|
return callback(null, verror);
|
|
384
413
|
}
|
|
@@ -419,11 +448,11 @@ class VmwareVCenter extends AdapterBaseCl {
|
|
|
419
448
|
/**
|
|
420
449
|
* @summary Updates the cache for all entities by call the get All entity method
|
|
421
450
|
*
|
|
422
|
-
* @function
|
|
451
|
+
* @function iapUpdateAdapterEntityCache
|
|
423
452
|
*
|
|
424
453
|
*/
|
|
425
|
-
|
|
426
|
-
const origin = `${this.id}-adapter-
|
|
454
|
+
iapUpdateAdapterEntityCache() {
|
|
455
|
+
const origin = `${this.id}-adapter-iapUpdateAdapterEntityCache`;
|
|
427
456
|
log.trace(origin);
|
|
428
457
|
|
|
429
458
|
if (this.caching) {
|
|
@@ -436,6 +465,140 @@ class VmwareVCenter extends AdapterBaseCl {
|
|
|
436
465
|
}
|
|
437
466
|
}
|
|
438
467
|
|
|
468
|
+
/**
|
|
469
|
+
* @summary Determines if this adapter supports any in a list of entities
|
|
470
|
+
*
|
|
471
|
+
* @function hasEntities
|
|
472
|
+
* @param {String} entityType - the entity type to check for
|
|
473
|
+
* @param {Array} entityList - the list of entities we are looking for
|
|
474
|
+
*
|
|
475
|
+
* @param {Callback} callback - A map where the entity is the key and the
|
|
476
|
+
* value is true or false
|
|
477
|
+
*/
|
|
478
|
+
hasEntities(entityType, entityList, callback) {
|
|
479
|
+
const meth = 'adapter-hasEntities';
|
|
480
|
+
const origin = `${this.id}-${meth}`;
|
|
481
|
+
log.trace(origin);
|
|
482
|
+
|
|
483
|
+
try {
|
|
484
|
+
return super.hasEntities(entityType, entityList, callback);
|
|
485
|
+
} catch (err) {
|
|
486
|
+
log.error(`${origin}: ${err}`);
|
|
487
|
+
return callback(null, err);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* @summary Get Appliance that match the deviceName
|
|
493
|
+
*
|
|
494
|
+
* @function getDevice
|
|
495
|
+
* @param {String} deviceName - the deviceName to find (required)
|
|
496
|
+
*
|
|
497
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
498
|
+
* (appliance) or the error
|
|
499
|
+
*/
|
|
500
|
+
getDevice(deviceName, callback) {
|
|
501
|
+
const meth = 'adapter-getDevice';
|
|
502
|
+
const origin = `${this.id}-${meth}`;
|
|
503
|
+
log.trace(origin);
|
|
504
|
+
|
|
505
|
+
try {
|
|
506
|
+
return super.getDevice(deviceName, callback);
|
|
507
|
+
} catch (err) {
|
|
508
|
+
log.error(`${origin}: ${err}`);
|
|
509
|
+
return callback(null, err);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* @summary Get Appliances that match the filter
|
|
515
|
+
*
|
|
516
|
+
* @function getDevicesFiltered
|
|
517
|
+
* @param {Object} options - the data to use to filter the appliances (optional)
|
|
518
|
+
*
|
|
519
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
520
|
+
* (appliances) or the error
|
|
521
|
+
*/
|
|
522
|
+
getDevicesFiltered(options, callback) {
|
|
523
|
+
const meth = 'adapter-getDevicesFiltered';
|
|
524
|
+
const origin = `${this.id}-${meth}`;
|
|
525
|
+
log.trace(origin);
|
|
526
|
+
|
|
527
|
+
try {
|
|
528
|
+
return super.getDevicesFiltered(options, callback);
|
|
529
|
+
} catch (err) {
|
|
530
|
+
log.error(`${origin}: ${err}`);
|
|
531
|
+
return callback(null, err);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* @summary Gets the status for the provided appliance
|
|
537
|
+
*
|
|
538
|
+
* @function isAlive
|
|
539
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
540
|
+
*
|
|
541
|
+
* @param {configCallback} callback - callback function to return the result
|
|
542
|
+
* (appliance isAlive) or the error
|
|
543
|
+
*/
|
|
544
|
+
isAlive(deviceName, callback) {
|
|
545
|
+
const meth = 'adapter-isAlive';
|
|
546
|
+
const origin = `${this.id}-${meth}`;
|
|
547
|
+
log.trace(origin);
|
|
548
|
+
|
|
549
|
+
try {
|
|
550
|
+
return super.isAlive(deviceName, callback);
|
|
551
|
+
} catch (err) {
|
|
552
|
+
log.error(`${origin}: ${err}`);
|
|
553
|
+
return callback(null, err);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* @summary Gets a config for the provided Appliance
|
|
559
|
+
*
|
|
560
|
+
* @function getConfig
|
|
561
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
562
|
+
* @param {String} format - the desired format of the config. (optional)
|
|
563
|
+
*
|
|
564
|
+
* @param {configCallback} callback - callback function to return the result
|
|
565
|
+
* (appliance config) or the error
|
|
566
|
+
*/
|
|
567
|
+
getConfig(deviceName, format, callback) {
|
|
568
|
+
const meth = 'adapter-getConfig';
|
|
569
|
+
const origin = `${this.id}-${meth}`;
|
|
570
|
+
log.trace(origin);
|
|
571
|
+
|
|
572
|
+
try {
|
|
573
|
+
return super.getConfig(deviceName, format, callback);
|
|
574
|
+
} catch (err) {
|
|
575
|
+
log.error(`${origin}: ${err}`);
|
|
576
|
+
return callback(null, err);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* @summary Gets the device count from the system
|
|
582
|
+
*
|
|
583
|
+
* @function iapGetDeviceCount
|
|
584
|
+
*
|
|
585
|
+
* @param {getCallback} callback - callback function to return the result
|
|
586
|
+
* (count) or the error
|
|
587
|
+
*/
|
|
588
|
+
iapGetDeviceCount(callback) {
|
|
589
|
+
const meth = 'adapter-iapGetDeviceCount';
|
|
590
|
+
const origin = `${this.id}-${meth}`;
|
|
591
|
+
log.trace(origin);
|
|
592
|
+
|
|
593
|
+
try {
|
|
594
|
+
return super.iapGetDeviceCount(callback);
|
|
595
|
+
} catch (err) {
|
|
596
|
+
log.error(`${origin}: ${err}`);
|
|
597
|
+
return callback(null, err);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */
|
|
439
602
|
/**
|
|
440
603
|
* Makes the requested generic call
|
|
441
604
|
*
|
|
@@ -546,79 +709,23 @@ class VmwareVCenter extends AdapterBaseCl {
|
|
|
546
709
|
}
|
|
547
710
|
}
|
|
548
711
|
|
|
549
|
-
/* BROKER CALLS */
|
|
550
712
|
/**
|
|
551
|
-
*
|
|
713
|
+
* Makes the requested generic call with no base path or version
|
|
552
714
|
*
|
|
553
|
-
* @function
|
|
554
|
-
* @param {String}
|
|
555
|
-
* @param {
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
*
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
switch (entityType) {
|
|
565
|
-
case 'Device':
|
|
566
|
-
return this.hasDevices(entityList, callback);
|
|
567
|
-
default:
|
|
568
|
-
return callback(null, `${this.id} does not support entity ${entityType}`);
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
/**
|
|
573
|
-
* @summary Helper method for hasEntities for the specific device case
|
|
574
|
-
*
|
|
575
|
-
* @param {Array} deviceList - array of unique device identifiers
|
|
576
|
-
* @param {Callback} callback - A map where the device is the key and the
|
|
577
|
-
* value is true or false
|
|
578
|
-
*/
|
|
579
|
-
hasDevices(deviceList, callback) {
|
|
580
|
-
const origin = `${this.id}-adapter-hasDevices`;
|
|
581
|
-
log.trace(origin);
|
|
582
|
-
|
|
583
|
-
const findings = deviceList.reduce((map, device) => {
|
|
584
|
-
// eslint-disable-next-line no-param-reassign
|
|
585
|
-
map[device] = false;
|
|
586
|
-
log.debug(`In reduce: ${JSON.stringify(map)}`);
|
|
587
|
-
return map;
|
|
588
|
-
}, {});
|
|
589
|
-
const apiCalls = deviceList.map((device) => new Promise((resolve) => {
|
|
590
|
-
this.getDevice(device, (result, error) => {
|
|
591
|
-
if (error) {
|
|
592
|
-
log.debug(`In map error: ${JSON.stringify(device)}`);
|
|
593
|
-
return resolve({ name: device, found: false });
|
|
594
|
-
}
|
|
595
|
-
log.debug(`In map: ${JSON.stringify(device)}`);
|
|
596
|
-
return resolve({ name: device, found: true });
|
|
597
|
-
});
|
|
598
|
-
}));
|
|
599
|
-
Promise.all(apiCalls).then((results) => {
|
|
600
|
-
results.forEach((device) => {
|
|
601
|
-
findings[device.name] = device.found;
|
|
602
|
-
});
|
|
603
|
-
log.debug(`FINDINGS: ${JSON.stringify(findings)}`);
|
|
604
|
-
return callback(findings);
|
|
605
|
-
}).catch((errors) => {
|
|
606
|
-
log.error('Unable to do device lookup.');
|
|
607
|
-
return callback(null, { code: 503, message: 'Unable to do device lookup.', error: errors });
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
/**
|
|
612
|
-
* @summary Get Appliance that match the deviceName
|
|
613
|
-
*
|
|
614
|
-
* @function getDevice
|
|
615
|
-
* @param {String} deviceName - the deviceName to find (required)
|
|
616
|
-
*
|
|
617
|
-
* @param {getCallback} callback - a callback function to return the result
|
|
618
|
-
* (appliance) or the error
|
|
715
|
+
* @function genericAdapterRequestNoBasePath
|
|
716
|
+
* @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
|
|
717
|
+
* @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
|
|
718
|
+
* @param {Object} queryData - the parameters to be put on the url (optional).
|
|
719
|
+
* Can be a stringified Object.
|
|
720
|
+
* @param {Object} requestBody - the body to add to the request (optional).
|
|
721
|
+
* Can be a stringified Object.
|
|
722
|
+
* @param {Object} addlHeaders - additional headers to be put on the call (optional).
|
|
723
|
+
* Can be a stringified Object.
|
|
724
|
+
* @param {getCallback} callback - a callback function to return the result (Generics)
|
|
725
|
+
* or the error
|
|
619
726
|
*/
|
|
620
|
-
|
|
621
|
-
const meth = 'adapter-
|
|
727
|
+
genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
|
|
728
|
+
const meth = 'adapter-genericAdapterRequestNoBasePath';
|
|
622
729
|
const origin = `${this.id}-${meth}`;
|
|
623
730
|
log.trace(origin);
|
|
624
731
|
|
|
@@ -629,365 +736,81 @@ class VmwareVCenter extends AdapterBaseCl {
|
|
|
629
736
|
}
|
|
630
737
|
|
|
631
738
|
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
632
|
-
if (
|
|
633
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['
|
|
739
|
+
if (uriPath === undefined || uriPath === null || uriPath === '') {
|
|
740
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
|
|
634
741
|
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
635
742
|
return callback(null, errorObj);
|
|
636
743
|
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
// need to get the device so we can convert the deviceName to an id
|
|
640
|
-
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
641
|
-
const opts = {
|
|
642
|
-
filter: {
|
|
643
|
-
name: deviceName
|
|
644
|
-
}
|
|
645
|
-
};
|
|
646
|
-
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
647
|
-
// if we received an error or their is no response on the results return an error
|
|
648
|
-
if (ferr) {
|
|
649
|
-
return callback(null, ferr);
|
|
650
|
-
}
|
|
651
|
-
if (devs.list.length < 1) {
|
|
652
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
653
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
654
|
-
return callback(null, errorObj);
|
|
655
|
-
}
|
|
656
|
-
// get the uuid from the device
|
|
657
|
-
const { uuid } = devs.list[0];
|
|
658
|
-
|
|
659
|
-
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
660
|
-
// !! you can also replace with a specific call if that is easier
|
|
661
|
-
const uriPath = `/call/toget/device/${uuid}`;
|
|
662
|
-
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
663
|
-
// if we received an error or their is no response on the results return an error
|
|
664
|
-
if (error) {
|
|
665
|
-
return callback(null, error);
|
|
666
|
-
}
|
|
667
|
-
if (!result.response || !result.response.applianceMo) {
|
|
668
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevice'], null, null, null);
|
|
669
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
670
|
-
return callback(null, errorObj);
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
// return the response
|
|
674
|
-
// !! format the data we send back
|
|
675
|
-
// !! these fields are config manager fields you need to map to the data we receive
|
|
676
|
-
const thisDevice = result.response;
|
|
677
|
-
thisDevice.name = thisDevice.systemName;
|
|
678
|
-
thisDevice.ostype = `System-${thisDevice.systemType}`;
|
|
679
|
-
thisDevice.port = thisDevice.systemPort;
|
|
680
|
-
thisDevice.ipaddress = thisDevice.systemIP;
|
|
681
|
-
return callback(thisDevice);
|
|
682
|
-
});
|
|
683
|
-
});
|
|
684
|
-
} catch (ex) {
|
|
685
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
744
|
+
if (restMethod === undefined || restMethod === null || restMethod === '') {
|
|
745
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
|
|
686
746
|
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
687
747
|
return callback(null, errorObj);
|
|
688
748
|
}
|
|
689
|
-
}
|
|
690
749
|
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
*
|
|
697
|
-
* @param {getCallback} callback - a callback function to return the result
|
|
698
|
-
* (appliances) or the error
|
|
699
|
-
*/
|
|
700
|
-
getDevicesFiltered(options, callback) {
|
|
701
|
-
const meth = 'adapter-getDevicesFiltered';
|
|
702
|
-
const origin = `${this.id}-${meth}`;
|
|
703
|
-
log.trace(origin);
|
|
704
|
-
|
|
705
|
-
// verify the required fields have been provided
|
|
706
|
-
if (options === undefined || options === null || options === '' || options.length === 0) {
|
|
707
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['options'], null, null, null);
|
|
708
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
709
|
-
return callback(null, errorObj);
|
|
750
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
751
|
+
// remove any leading / and split the uripath into path variables
|
|
752
|
+
let myPath = uriPath;
|
|
753
|
+
while (myPath.indexOf('/') === 0) {
|
|
754
|
+
myPath = myPath.substring(1);
|
|
710
755
|
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
// const maxResults = options.limit;
|
|
756
|
+
const pathVars = myPath.split('/');
|
|
757
|
+
const queryParamsAvailable = queryData;
|
|
758
|
+
const queryParams = {};
|
|
759
|
+
const bodyVars = requestBody;
|
|
716
760
|
|
|
717
|
-
//
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
// eslint-disable-next-line prefer-destructuring
|
|
723
|
-
filterName = options.filter.name;
|
|
724
|
-
} else {
|
|
725
|
-
filterName = [options.filter.name];
|
|
761
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
762
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
763
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
764
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
765
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
726
766
|
}
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
// TODO - get sort and order working
|
|
730
|
-
/*
|
|
731
|
-
if (options && options.sort) {
|
|
732
|
-
reqObj.uriOptions.sort = JSON.stringify(options.sort);
|
|
733
|
-
}
|
|
734
|
-
if (options && options.order) {
|
|
735
|
-
reqObj.uriOptions.order = options.order;
|
|
736
|
-
}
|
|
737
|
-
*/
|
|
738
|
-
try {
|
|
739
|
-
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
740
|
-
// !! you can also replace with a specific call if that is easier
|
|
741
|
-
const uriPath = '/call/toget/devices';
|
|
742
|
-
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
743
|
-
// if we received an error or their is no response on the results return an error
|
|
744
|
-
if (error) {
|
|
745
|
-
return callback(null, error);
|
|
746
|
-
}
|
|
747
|
-
if (!result.response) {
|
|
748
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
|
|
749
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
750
|
-
return callback(null, errorObj);
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
// !! go through the response - may have to look for sub object
|
|
754
|
-
// handle an array of devices
|
|
755
|
-
if (Array.isArray(result.response)) {
|
|
756
|
-
const myDevices = [];
|
|
757
|
-
|
|
758
|
-
for (let d = 0; d < result.response.length; d += 1) {
|
|
759
|
-
// !! format the data we send back
|
|
760
|
-
// !! these fields are config manager fields you need to map to the data we receive
|
|
761
|
-
const thisDevice = result.response;
|
|
762
|
-
thisDevice.name = thisDevice.systemName;
|
|
763
|
-
thisDevice.ostype = `System-${thisDevice.systemType}`;
|
|
764
|
-
thisDevice.port = thisDevice.systemPort;
|
|
765
|
-
thisDevice.ipaddress = thisDevice.systemIP;
|
|
766
|
-
|
|
767
|
-
// if there is no filter - return the device
|
|
768
|
-
if (filterName.length === 0) {
|
|
769
|
-
myDevices.push(thisDevice);
|
|
770
|
-
} else {
|
|
771
|
-
// if we have to match a filter
|
|
772
|
-
let found = false;
|
|
773
|
-
for (let f = 0; f < filterName.length; f += 1) {
|
|
774
|
-
if (thisDevice.name.indexOf(filterName[f]) >= 0) {
|
|
775
|
-
found = true;
|
|
776
|
-
break;
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
// matching device
|
|
780
|
-
if (found) {
|
|
781
|
-
myDevices.push(thisDevice);
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
log.debug(`${origin}: Found #${myDevices.length} devices.`);
|
|
786
|
-
log.debug(`Devices: ${JSON.stringify(myDevices)}`);
|
|
787
|
-
return callback({ total: myDevices.length, list: myDevices });
|
|
788
|
-
}
|
|
789
|
-
// handle a single device response
|
|
790
|
-
// !! format the data we send back
|
|
791
|
-
// !! these fields are config manager fields you need to map to the data we receive
|
|
792
|
-
const thisDevice = result.response;
|
|
793
|
-
thisDevice.name = thisDevice.systemName;
|
|
794
|
-
thisDevice.ostype = `System-${thisDevice.systemType}`;
|
|
795
|
-
thisDevice.port = thisDevice.systemPort;
|
|
796
|
-
thisDevice.ipaddress = thisDevice.systemIP;
|
|
797
|
-
|
|
798
|
-
// if there is no filter - return the device
|
|
799
|
-
if (filterName.length === 0) {
|
|
800
|
-
log.debug(`${origin}: Found #1 device.`);
|
|
801
|
-
log.debug(`Device: ${JSON.stringify(thisDevice)}`);
|
|
802
|
-
return callback({ total: 1, list: [thisDevice] });
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
// if there is a filter need to check for matching device
|
|
806
|
-
let found = false;
|
|
807
|
-
for (let f = 0; f < filterName.length; f += 1) {
|
|
808
|
-
if (thisDevice.name.indexOf(filterName[f]) >= 0) {
|
|
809
|
-
found = true;
|
|
810
|
-
break;
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
// matching device
|
|
814
|
-
if (found) {
|
|
815
|
-
log.debug(`${origin}: Found #1 device.`);
|
|
816
|
-
log.debug(`Device Found: ${JSON.stringify(thisDevice)}`);
|
|
817
|
-
return callback({ total: 1, list: [thisDevice] });
|
|
818
|
-
}
|
|
819
|
-
// not a matching device
|
|
820
|
-
log.debug(`${origin}: No matching device found.`);
|
|
821
|
-
return callback({ total: 0, list: [] });
|
|
822
|
-
});
|
|
823
|
-
} catch (ex) {
|
|
824
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
825
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
826
|
-
return callback(null, errorObj);
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
/**
|
|
831
|
-
* @summary Gets the status for the provided appliance
|
|
832
|
-
*
|
|
833
|
-
* @function isAlive
|
|
834
|
-
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
835
|
-
*
|
|
836
|
-
* @param {configCallback} callback - callback function to return the result
|
|
837
|
-
* (appliance isAlive) or the error
|
|
838
|
-
*/
|
|
839
|
-
isAlive(deviceName, callback) {
|
|
840
|
-
const meth = 'adapter-isAlive';
|
|
841
|
-
const origin = `${this.id}-${meth}`;
|
|
842
|
-
log.trace(origin);
|
|
843
|
-
|
|
844
|
-
// verify the required fields have been provided
|
|
845
|
-
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
846
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
847
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
848
|
-
return callback(null, errorObj);
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
try {
|
|
852
|
-
// need to get the device so we can convert the deviceName to an id
|
|
853
|
-
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
854
|
-
const opts = {
|
|
855
|
-
filter: {
|
|
856
|
-
name: deviceName
|
|
857
|
-
}
|
|
858
|
-
};
|
|
859
|
-
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
860
|
-
// if we received an error or their is no response on the results return an error
|
|
861
|
-
if (ferr) {
|
|
862
|
-
return callback(null, ferr);
|
|
863
|
-
}
|
|
864
|
-
if (devs.list.length < 1) {
|
|
865
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
866
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
867
|
-
return callback(null, errorObj);
|
|
868
|
-
}
|
|
869
|
-
// get the uuid from the device
|
|
870
|
-
const { uuid } = devs.list[0];
|
|
871
|
-
|
|
872
|
-
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
873
|
-
// !! you can also replace with a specific call if that is easier
|
|
874
|
-
const uriPath = `/call/toget/status/${uuid}`;
|
|
875
|
-
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
876
|
-
// if we received an error or their is no response on the results return an error
|
|
877
|
-
if (error) {
|
|
878
|
-
return callback(null, error);
|
|
879
|
-
}
|
|
880
|
-
// !! should update this to make sure we are checking for the appropriate object/field
|
|
881
|
-
if (!result.response || !result.response.returnObj || !Object.hasOwnProperty.call(result.response.returnObj, 'statusField')) {
|
|
882
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['isAlive'], null, null, null);
|
|
883
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
884
|
-
return callback(null, errorObj);
|
|
885
|
-
}
|
|
767
|
+
});
|
|
886
768
|
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
769
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
|
|
770
|
+
const reqObj = {
|
|
771
|
+
payload: bodyVars,
|
|
772
|
+
uriPathVars: pathVars,
|
|
773
|
+
uriQuery: queryParams,
|
|
774
|
+
uriOptions: {}
|
|
775
|
+
};
|
|
776
|
+
// add headers if provided
|
|
777
|
+
if (addlHeaders) {
|
|
778
|
+
reqObj.addlHeaders = addlHeaders;
|
|
895
779
|
}
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
/**
|
|
899
|
-
* @summary Gets a config for the provided Appliance
|
|
900
|
-
*
|
|
901
|
-
* @function getConfig
|
|
902
|
-
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
903
|
-
* @param {String} format - the desired format of the config. (optional)
|
|
904
|
-
*
|
|
905
|
-
* @param {configCallback} callback - callback function to return the result
|
|
906
|
-
* (appliance config) or the error
|
|
907
|
-
*/
|
|
908
|
-
getConfig(deviceName, format, callback) {
|
|
909
|
-
const meth = 'adapter-getConfig';
|
|
910
|
-
const origin = `${this.id}-${meth}`;
|
|
911
|
-
log.trace(origin);
|
|
912
780
|
|
|
913
|
-
//
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
781
|
+
// determine the call and return flag
|
|
782
|
+
let action = 'getGenericsNoBase';
|
|
783
|
+
let returnF = true;
|
|
784
|
+
if (restMethod.toUpperCase() === 'POST') {
|
|
785
|
+
action = 'createGenericNoBase';
|
|
786
|
+
} else if (restMethod.toUpperCase() === 'PUT') {
|
|
787
|
+
action = 'updateGenericNoBase';
|
|
788
|
+
} else if (restMethod.toUpperCase() === 'PATCH') {
|
|
789
|
+
action = 'patchGenericNoBase';
|
|
790
|
+
} else if (restMethod.toUpperCase() === 'DELETE') {
|
|
791
|
+
action = 'deleteGenericNoBase';
|
|
792
|
+
returnF = false;
|
|
918
793
|
}
|
|
919
794
|
|
|
920
795
|
try {
|
|
921
|
-
//
|
|
922
|
-
//
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
// if we received an error or their is no response on the results return an error
|
|
930
|
-
if (ferr) {
|
|
931
|
-
return callback(null, ferr);
|
|
796
|
+
// Make the call -
|
|
797
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
798
|
+
return this.requestHandlerInst.identifyRequest('.generic', action, reqObj, returnF, (irReturnData, irReturnError) => {
|
|
799
|
+
// if we received an error or their is no response on the results
|
|
800
|
+
// return an error
|
|
801
|
+
if (irReturnError) {
|
|
802
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
803
|
+
return callback(null, irReturnError);
|
|
932
804
|
}
|
|
933
|
-
if (
|
|
934
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth,
|
|
805
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
806
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequestNoBasePath'], null, null, null);
|
|
935
807
|
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
936
808
|
return callback(null, errorObj);
|
|
937
809
|
}
|
|
938
|
-
// get the uuid from the device
|
|
939
|
-
const { uuid } = devs.list[0];
|
|
940
|
-
|
|
941
|
-
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
942
|
-
// !! you can also replace with a specific call if that is easier
|
|
943
|
-
const uriPath = `/call/toget/config/${uuid}`;
|
|
944
|
-
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
945
|
-
// if we received an error or their is no response on the results return an error
|
|
946
|
-
if (error) {
|
|
947
|
-
return callback(null, error);
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
// return the result
|
|
951
|
-
const newResponse = {
|
|
952
|
-
response: JSON.stringify(result.response, null, 2)
|
|
953
|
-
};
|
|
954
|
-
return callback(newResponse);
|
|
955
|
-
});
|
|
956
|
-
});
|
|
957
|
-
} catch (ex) {
|
|
958
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
959
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
960
|
-
return callback(null, errorObj);
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
/**
|
|
965
|
-
* @summary Gets the device count from the system
|
|
966
|
-
*
|
|
967
|
-
* @function getCount
|
|
968
|
-
*
|
|
969
|
-
* @param {getCallback} callback - callback function to return the result
|
|
970
|
-
* (count) or the error
|
|
971
|
-
*/
|
|
972
|
-
getCount(callback) {
|
|
973
|
-
const meth = 'adapter-getCount';
|
|
974
|
-
const origin = `${this.id}-${meth}`;
|
|
975
|
-
log.trace(origin);
|
|
976
|
-
|
|
977
|
-
// verify the required fields have been provided
|
|
978
|
-
|
|
979
|
-
try {
|
|
980
|
-
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
981
|
-
// !! you can also replace with a specific call if that is easier
|
|
982
|
-
const uriPath = '/call/toget/count';
|
|
983
|
-
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
984
|
-
// if we received an error or their is no response on the results return an error
|
|
985
|
-
if (error) {
|
|
986
|
-
return callback(null, error);
|
|
987
|
-
}
|
|
988
810
|
|
|
989
|
-
|
|
990
|
-
return
|
|
811
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
812
|
+
// return the response
|
|
813
|
+
return callback(irReturnData, null);
|
|
991
814
|
});
|
|
992
815
|
} catch (ex) {
|
|
993
816
|
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|