@itentialopensource/adapter-nuage
Version:
Itential Nuage Adapter
1,246 lines (1,125 loc) • 117 kB
JavaScript
/* @copyright Itential, LLC 2019 */
/* eslint import/no-dynamic-require: warn */
/* eslint object-curly-newline: warn */
/* eslint no-underscore-dangle: warn */
/* eslint camelcase: warn */
// Set globals
/* global log */
/* Required libraries. */
const path = require('path');
// const xmldom = require('xmldom');
/* Fetch in the other needed components for the this Adaptor */
const AdapterBaseCl = require(path.join(__dirname, 'adapterBase.js'));
/**
* This is the adapter/interface into Nuage
*/
/* GENERAL ADAPTER FUNCTIONS */
class Nuage extends AdapterBaseCl {
/**
* Nuage Adapter
* @constructor
constructor(prongid, properties) {
// Instantiate the AdapterBase super class
super(prongid, properties);
// Uncomment if you have things to add to the constructor like using your own properties.
// Otherwise the constructor in the adapterBase will be used.
// Capture my own properties - they need to be defined in propertiesSchema.json
if (this.allProps && this.allProps.myownproperty) {
mypropvariable = this.allProps.myownproperty;
}
}
*/
/**
* @callback healthCallback
* @param {Object} result - the result of the get request (contains an id and a status)
*/
/**
* @callback getCallback
* @param {Object} result - the result of the get request (entity/ies)
* @param {String} error - any error that occurred
*/
/**
* @callback createCallback
* @param {Object} item - the newly created entity
* @param {String} error - any error that occurred
*/
/**
* @callback updateCallback
* @param {String} status - the status of the update action
* @param {String} error - any error that occurred
*/
/**
* @callback deleteCallback
* @param {String} status - the status of the delete action
* @param {String} error - any error that occurred
*/
/**
* @summary Determines if this adapter supports the specific entity
*
* @function hasEntity
* @param {String} entityType - the entity type to check for
* @param {String/Array} entityId - the specific entity we are looking for
*
* @param {Callback} callback - An array of whether the adapter can has the
* desired capability or an error
*/
hasEntity(entityType, entityId, callback) {
const origin = `${this.id}-adapter-hasEntity`;
log.trace(origin);
// Make the call -
// verifyCapability(entityType, actionType, entityId, callback)
return this.verifyCapability(entityType, null, entityId, callback);
}
/**
* @summary Provides a way for the adapter to tell north bound integrations
* whether the adapter supports type, action and specific entity
*
* @function verifyCapability
* @param {String} entityType - the entity type to check for
* @param {String} actionType - the action type to check for
* @param {String/Array} entityId - the specific entity we are looking for
*
* @param {Callback} callback - An array of whether the adapter can has the
* desired capability or an error
*/
verifyCapability(entityType, actionType, entityId, callback) {
const meth = 'adapterBase-getQueue';
const origin = `${this.id}-${meth}`;
log.trace(origin);
// if caching
if (this.caching) {
// Make the call - verifyCapability(entityType, actionType, entityId, callback)
return this.requestHandlerInst.verifyCapability(entityType, actionType, entityId, (results, error) => {
if (error) {
return callback(null, error);
}
// if the cache needs to be updated, update and try again
if (results && results[0] === 'needupdate') {
switch (entityType) {
case 'template_entity': {
// if the cache is invalid, update the cache
return this.getEntities(null, null, null, null, (data, err) => {
if (err) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Could not update entity: $VARIABLE$, cache', [entityType], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
// need to check the cache again since it has been updated
return this.requestHandlerInst.verifyCapability(entityType, actionType, entityId, (vcapable, verror) => {
if (verror) {
return callback(null, verror);
}
return this.capabilityResults(vcapable, callback);
});
});
}
default: {
// unsupported entity type
const result = [false];
// put false in array for all entities
if (Array.isArray(entityId)) {
for (let e = 1; e < entityId.length; e += 1) {
result.push(false);
}
}
return callback(result);
}
}
}
// return the results
return this.capabilityResults(results, callback);
});
}
// if no entity id
if (!entityId) {
// need to check the cache again since it has been updated
return this.requestHandlerInst.verifyCapability(entityType, actionType, null, (vcapable, verror) => {
if (verror) {
return callback(null, verror);
}
return this.capabilityResults(vcapable, callback);
});
}
// if not caching
switch (entityType) {
case 'template_entity': {
// need to get the entities to check
return this.getEntities(null, null, null, null, (data, err) => {
if (err) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Could not update entity: $VARIABLE$, cache', [entityType], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
// need to check the cache again since it has been updated
return this.requestHandlerInst.verifyCapability(entityType, actionType, null, (vcapable, verror) => {
if (verror) {
return callback(null, verror);
}
// is the entity in the list?
const isEntity = this.entityInList(entityId, data.response, callback);
const res = [];
// not found
for (let i = 0; i < isEntity.length; i += 1) {
if (vcapable) {
res.push(isEntity[i]);
} else {
res.push(false);
}
}
return callback(res);
});
});
}
default: {
// unsupported entity type
const result = [false];
// put false in array for all entities
if (Array.isArray(entityId)) {
for (let e = 1; e < entityId.length; e += 1) {
result.push(false);
}
}
return callback(result);
}
}
}
/**
* @summary Updates the cache for all entities by call the get All entity method
*
* @function updateEntityCache
*
*/
updateEntityCache() {
const origin = `${this.id}-adapter-updateEntityCache`;
log.trace(origin);
if (this.caching) {
// if the cache is invalid, update the cache
this.getEntities(null, null, null, null, (data, err) => {
if (err) {
log.trace(`${origin}: Could not load template_entity into cache - ${err}`);
}
});
}
}
/**
* @summary get enterprise from nuage
*
* @function getEnterprises
* @param {String} enterpriseId - the id of the enterprise to retrieve (optional)
* @param {getCallback} callback - a callback function to return the result
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
getEnterprises(enterpriseId, callback) {
const meth = 'adapter-getEnterprises';
const origin = `${this.id}-${meth}`;
log.trace(origin);
try {
/* HERE IS WHERE YOU VALIDATE DATA */
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const reqObj = {
addlHeaders: {
'X-Nuage-Organization': 'csp'
}
};
if (enterpriseId) {
reqObj.uriPathVars = [enterpriseId];
}
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('enterprise', 'getEnterprises', reqObj, true, (irReturnData, irReturnError) => {
// if we received an error or their is no response on the results
// return an error
if (irReturnError) {
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
return callback(null, irReturnError);
}
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getEnterprises'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
// return the response
return callback(irReturnData, null);
});
} catch (ex) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
}
/**
* @summary create an enterprise in nuage
*
* @function createEnterprise
* @param {Object} enterprise - the enterprise to be created (required)
* @param {postCallback} callback - a callback function to return the result
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
createEnterprise(enterprise, callback) {
const meth = 'adapter-createEnterprise';
const origin = `${this.id}-${meth}`;
log.trace(origin);
try {
/* HERE IS WHERE YOU VALIDATE DATA */
if (!enterprise) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['enterprise'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const reqObj = {
payload: enterprise,
addlHeaders: {
'X-Nuage-Organization': 'csp'
}
};
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('enterprise', 'createEnterprise', reqObj, true, (irReturnData, irReturnError) => {
// if we received an error or their is no response on the results
// return an error
if (irReturnError) {
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
return callback(null, irReturnError);
}
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['createEnterprise'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
// return the response
return callback(irReturnData);
});
} catch (ex) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
}
/**
* @summary update an enterprise in nuage
*
* @function updateEnterprise
* @param {String} enterpriseId - the id of the enterprise to update (required)
* @param {Object} enterprise - the enterprise to be updated (required)
* @param {deleteCallback} callback - a callback function to return the result
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
updateEnterprise(enterpriseId, enterprise, callback) {
const meth = 'adapter-updateEnterprise';
const origin = `${this.id}-${meth}`;
log.trace(origin);
try {
/* HERE IS WHERE YOU VALIDATE DATA */
if (!enterpriseId) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['enterpriseId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
if (!enterprise) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['enterprise'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const reqObj = {
uriPathVars: [enterpriseId],
payload: enterprise,
addlHeaders: {
'X-Nuage-Organization': 'csp'
}
};
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('enterprise', 'updateEnterprise', reqObj, false, (irReturnData, irReturnError) => {
// if we received an error or their is no response on the results
// return an error
if (irReturnError) {
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
return callback(null, irReturnError);
}
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['updateEnterprise'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
// return the response
return callback(irReturnData, null);
});
} catch (ex) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
}
/**
* @summary delete an enterprise from nuage
*
* @function deleteEnterprise
* @param {String} enterpriseId - the id of the enterprise to be deleted (required)
* @param {deleteCallback} callback - a callback function to return the result
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
deleteEnterprise(enterpriseId, callback) {
const meth = 'adapter-deleteEnterprise';
const origin = `${this.id}-${meth}`;
log.trace(origin);
try {
/* HERE IS WHERE YOU VALIDATE DATA */
if (!enterpriseId) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['enterpriseId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const reqObj = {
uriPathVars: [enterpriseId],
uriQuery: { responseChoice: 1 },
addlHeaders: {
'X-Nuage-Organization': 'csp'
}
};
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('enterprise', 'deleteEnterprise', reqObj, false, (irReturnData, irReturnError) => {
// if we received an error or their is no response on the results
// return an error
if (irReturnError) {
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
return callback(null, irReturnError);
}
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['deleteEnterprise'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
// return the response
return callback(irReturnData, null);
});
} catch (ex) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
}
/**
* @summary get domains from nuage
*
* @function getDomains
* @param {String} domainId - the id of the domain to retrieve (optional)
* @param {getCallback} callback - a callback function to return the result
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
getDomains(domainId, callback) {
const meth = 'adapter-getDomains';
const origin = `${this.id}-${meth}`;
log.trace(origin);
try {
/* HERE IS WHERE YOU VALIDATE DATA */
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const reqObj = {
addlHeaders: {
'X-Nuage-Organization': 'csp'
}
};
if (domainId) {
reqObj.uriPathVars = [domainId];
}
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('domain', 'getDomains', reqObj, true, (irReturnData, irReturnError) => {
// if we received an error or their is no response on the results
// return an error
if (irReturnError) {
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
return callback(null, irReturnError);
}
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDomains'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
// return the response
return callback(irReturnData, null);
});
} catch (ex) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
}
/**
* @summary get enterprise domains from nuage
*
* @function getEnterpriseDomains
* @param {String} enterpriseId - the id of the enterprise to retrieve domains in (required)
* @param {getCallback} callback - a callback function to return the result
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
getEnterpriseDomains(enterpriseId, callback) {
const meth = 'adapter-getEnterpriseDomains';
const origin = `${this.id}-${meth}`;
log.trace(origin);
try {
/* HERE IS WHERE YOU VALIDATE DATA */
if (!enterpriseId) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['enterpriseId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const reqObj = {
uriPathVars: [enterpriseId],
addlHeaders: {
'X-Nuage-Organization': 'csp'
}
};
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('domain', 'getEnterpriseDomains', reqObj, true, (irReturnData, irReturnError) => {
// if we received an error or their is no response on the results
// return an error
if (irReturnError) {
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
return callback(null, irReturnError);
}
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getEnterpriseDomains'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
// return the response
return callback(irReturnData, null);
});
} catch (ex) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
}
/**
* @summary get domain templates from nuage
*
* @function getDomainTemplate
* @param {String} enterpriseId - the id of the enterpriseto retrieve domain templates from (required)
* @param {getCallback} callback - a callback function to return the result
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
getDomainTemplates(enterpriseId, callback) {
const meth = 'adapter-getDomainTemplates';
const origin = `${this.id}-${meth}`;
log.trace(origin);
try {
/* HERE IS WHERE YOU VALIDATE DATA */
if (!enterpriseId) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['enterpriseId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const reqObj = {
uriPathVars: [enterpriseId],
addlHeaders: {
'X-Nuage-Organization': 'csp'
}
};
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('domain', 'getDomainTemplates', reqObj, true, (irReturnData, irReturnError) => {
// if we received an error or their is no response on the results
// return an error
if (irReturnError) {
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
return callback(null, irReturnError);
}
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDomainTemplates'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
// return the response
return callback(irReturnData, null);
});
} catch (ex) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
}
/**
* @summary get a domain template from nuage
*
* @function getDomainTemplate
* @param {String} templateId - the id of the domain template to retrieve (required)
* @param {getCallback} callback - a callback function to return the result
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
getDomainTemplate(templateId, callback) {
const meth = 'adapter-getDomainTemplate';
const origin = `${this.id}-${meth}`;
log.trace(origin);
try {
/* HERE IS WHERE YOU VALIDATE DATA */
if (!templateId) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['templateId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const reqObj = {
uriPathVars: [templateId],
addlHeaders: {
'X-Nuage-Organization': 'csp'
}
};
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('domain', 'getDomainTemplate', reqObj, true, (irReturnData, irReturnError) => {
// if we received an error or their is no response on the results
// return an error
if (irReturnError) {
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
return callback(null, irReturnError);
}
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDomainTemplate'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
// return the response
return callback(irReturnData, null);
});
} catch (ex) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
}
/**
* @summary create a domain in nuage
*
* @function createDomain
* @param {String} enterpriseId - the id of the enterprise where the domain should be created (required)
* @param {Object} domain - the domain to be created (required)
* @param {postCallback} callback - a callback function to return the result
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
createDomain(enterpriseId, domain, callback) {
const meth = 'adapter-createDomain';
const origin = `${this.id}-${meth}`;
log.trace(origin);
try {
/* HERE IS WHERE YOU VALIDATE DATA */
if (!enterpriseId) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['enterpriseId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
if (!domain) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['domain'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const reqObj = {
uriPathVars: [enterpriseId],
payload: domain,
addlHeaders: {
'X-Nuage-Organization': 'csp'
}
};
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('domain', 'createDomain', reqObj, true, (irReturnData, irReturnError) => {
// if we received an error or their is no response on the results
// return an error
if (irReturnError) {
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
return callback(null, irReturnError);
}
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['createDomain'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
// return the response
return callback(irReturnData);
});
} catch (ex) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
}
/**
* @summary create a domain template in nuage
*
* @function createDomainTemplate
* @param {String} enterpriseId - the id of the enterprise where the domain should be created (required)
* @param {Object} template - the domain template to be created (required)
* @param {postCallback} callback - a callback function to return the result
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
createDomainTemplate(enterpriseId, template, callback) {
const meth = 'adapter-createDomainTemplate';
const origin = `${this.id}-${meth}`;
log.trace(origin);
try {
/* HERE IS WHERE YOU VALIDATE DATA */
if (!enterpriseId) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['enterpriseId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
if (!template) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['template'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const reqObj = {
uriPathVars: [enterpriseId],
payload: template,
addlHeaders: {
'X-Nuage-Organization': 'csp'
}
};
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('domain', 'createDomainTemplate', reqObj, true, (irReturnData, irReturnError) => {
// if we received an error or their is no response on the results
// return an error
if (irReturnError) {
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
return callback(null, irReturnError);
}
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['createDomainTemplate'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
// return the response
return callback(irReturnData);
});
} catch (ex) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
}
/**
* @summary update a domain in nuage
*
* @function updateDomain
* @param {String} domainId - the id of the domain to update (required)
* @param {Object} domain - the domain to be updated (required)
* @param {deleteCallback} callback - a callback function to return the result
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
updateDomain(domainId, domain, callback) {
const meth = 'adapter-updateDomain';
const origin = `${this.id}-${meth}`;
log.trace(origin);
try {
/* HERE IS WHERE YOU VALIDATE DATA */
if (!domainId) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['domainId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
if (!domain) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['domain'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const reqObj = {
uriPathVars: [domainId],
payload: domain,
addlHeaders: {
'X-Nuage-Organization': 'csp'
}
};
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('domain', 'updateDomain', reqObj, false, (irReturnData, irReturnError) => {
// if we received an error or their is no response on the results
// return an error
if (irReturnError) {
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
return callback(null, irReturnError);
}
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['updateDomain'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
// return the response
return callback(irReturnData, null);
});
} catch (ex) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
}
/**
* @summary update a domain template in nuage
*
* @function updateDomainTemplate
* @param {String} templateId - the id of the domain template to update (required)
* @param {Object} template - the template to be updated (required)
* @param {deleteCallback} callback - a callback function to return the result
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
updateDomainTemplate(templateId, template, callback) {
const meth = 'adapter-updateDomainTemplate';
const origin = `${this.id}-${meth}`;
log.trace(origin);
try {
/* HERE IS WHERE YOU VALIDATE DATA */
if (!templateId) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['templateId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
if (!template) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['template'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const reqObj = {
uriPathVars: [templateId],
payload: template,
addlHeaders: {
'X-Nuage-Organization': 'csp'
}
};
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('domain', 'updateDomainTemplate', reqObj, false, (irReturnData, irReturnError) => {
// if we received an error or their is no response on the results
// return an error
if (irReturnError) {
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
return callback(null, irReturnError);
}
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['updateDomainTemplate'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
// return the response
return callback(irReturnData, null);
});
} catch (ex) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
}
/**
* @summary delete a domain from nuage
*
* @function deleteDomain
* @param {String} domainId - the id of the domain to be deleted (required)
* @param {deleteCallback} callback - a callback function to return the result
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
deleteDomain(domainId, callback) {
const meth = 'adapter-deleteDomain';
const origin = `${this.id}-${meth}`;
log.trace(origin);
try {
/* HERE IS WHERE YOU VALIDATE DATA */
if (!domainId) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['domainId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const reqObj = {
uriPathVars: [domainId],
uriQuery: { responseChoice: 1 },
addlHeaders: {
'X-Nuage-Organization': 'csp'
}
};
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('domain', 'deleteDomain', reqObj, false, (irReturnData, irReturnError) => {
// if we received an error or their is no response on the results
// return an error
if (irReturnError) {
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
return callback(null, irReturnError);
}
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['deleteDomain'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
// return the response
return callback(irReturnData, null);
});
} catch (ex) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
}
/**
* @summary delete a domain template from nuage
*
* @function deleteDomainTemplate
* @param {String} templateId - the id of the domain to be deleted (required)
* @param {deleteCallback} callback - a callback function to return the result
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
deleteDomainTemplate(templateId, callback) {
const meth = 'adapter-deleteDomainTemplate';
const origin = `${this.id}-${meth}`;
log.trace(origin);
try {
/* HERE IS WHERE YOU VALIDATE DATA */
if (!templateId) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['templateId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const reqObj = {
uriPathVars: [templateId],
uriQuery: { responseChoice: 1 },
addlHeaders: {
'X-Nuage-Organization': 'csp'
}
};
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('domain', 'deleteDomainTemplate', reqObj, false, (irReturnData, irReturnError) => {
// if we received an error or their is no response on the results
// return an error
if (irReturnError) {
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
return callback(null, irReturnError);
}
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['deleteDomainTemplate'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
// return the response
return callback(irReturnData, null);
});
} catch (ex) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
}
/**
* @summary get zones from nuage
*
* @function getZones
* @param {String} zoneId - the id of the zone to retrieve (optional)
* @param {getCallback} callback - a callback function to return the result
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
getZones(zoneId, callback) {
const meth = 'adapter-getZones';
const origin = `${this.id}-${meth}`;
log.trace(origin);
try {
/* HERE IS WHERE YOU VALIDATE DATA */
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const reqObj = {
addlHeaders: {
'X-Nuage-Organization': 'csp'
}
};
if (zoneId) {
reqObj.uriPathVars = [zoneId];
}
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('zone', 'getZones', reqObj, true, (irReturnData, irReturnError) => {
// if we received an error or their is no response on the results
// return an error
if (irReturnError) {
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
return callback(null, irReturnError);
}
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getZones'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
// return the response
return callback(irReturnData, null);
});
} catch (ex) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
}
/**
* @summary get domain zones from nuage
*
* @function getDomainZones
* @param {String} domainId - the id of the domain to retrieve zones in (required)
* @param {getCallback} callback - a callback function to return the result
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
getDomainZones(domainId, callback) {
const meth = 'adapter-getDomainZones';
const origin = `${this.id}-${meth}`;
log.trace(origin);
try {
/* HERE IS WHERE YOU VALIDATE DATA */
if (!domainId) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['domainId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const reqObj = {
uriPathVars: [domainId],
addlHeaders: {
'X-Nuage-Organization': 'csp'
}
};
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('zone', 'getDomainZones', reqObj, true, (irReturnData, irReturnError) => {
// if we received an error or their is no response on the results
// return an error
if (irReturnError) {
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
return callback(null, irReturnError);
}
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDomainZones'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
// return the response
return callback(irReturnData, null);
});
} catch (ex) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
}
/**
* @summary create a zone in nuage
*
* @function createZone
* @param {String} domainId - the id of the domain where the zone should be created (required)
* @param {Object} zone - the zone to be created (required)
* @param {postCallback} callback - a callback function to return the result
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
createZone(domainId, zone, callback) {
const meth = 'adapter-createZone';
const origin = `${this.id}-${meth}`;
log.trace(origin);
try {
/* HERE IS WHERE YOU VALIDATE DATA */
if (!domainId) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['domainId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
if (!zone) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['zone'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
const reqObj = {
uriPathVars: [domainId],
payload: zone,
addlHeaders: {
'X-Nuage-Organization': 'csp'
}
};
// Make the call -
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
return this.requestHandlerInst.identifyRequest('zone', 'createZone', reqObj, true, (irReturnData, irReturnError) => {
// if we received an error or their is no response on the results
// return an error
if (irReturnError) {
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
return callback(null, irReturnError);
}
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['createZone'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
// return the response
return callback(irReturnData);
});
} catch (ex) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
}
/**
* @summary update a zone in nuage
*
* @function updateZone
* @param {String} zoneId - the id of the zone to update (required)
* @param {Object} zone - the zone to be updated (required)
* @param {deleteCallback} callback - a callback function to return the result
*/
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
updateZone(zoneId, zone, callback) {
const meth = 'adapter-updateZone';
const origin = `${this.id}-${meth}`;
log.trace(origin);
try {
/* HERE IS WHERE YOU VALIDATE DATA */
if (!zoneId) {
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['zoneId'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
retu