cisco-axl 1.1.3 → 1.1.5
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.
|
@@ -23,6 +23,11 @@ let service = new axlService(
|
|
|
23
23
|
(async () => {
|
|
24
24
|
|
|
25
25
|
// Variable needed for script
|
|
26
|
+
var opts = {
|
|
27
|
+
clean: true,
|
|
28
|
+
removeAttributes: false,
|
|
29
|
+
dataContainerIdentifierTails: "_data",
|
|
30
|
+
};
|
|
26
31
|
|
|
27
32
|
// What model are we going to convert our phone into?
|
|
28
33
|
// You can get a list of models in CUCM with the SQL query: 'SELECT name from typemodel'
|
|
@@ -40,7 +45,7 @@ let service = new axlService(
|
|
|
40
45
|
tags.name = phoneNameCopyingFrom;
|
|
41
46
|
|
|
42
47
|
// Execute the AXL call. We set the true flag to clean the output (removes any blank or undefined settings)
|
|
43
|
-
var returnPhoneTags = await service.executeOperation(operation, tags,
|
|
48
|
+
var returnPhoneTags = await service.executeOperation(operation, tags, opts);
|
|
44
49
|
|
|
45
50
|
// Now we're going to add a new phone based on the settings. We will updating a few new settings based on the model we will be converting to.
|
|
46
51
|
operation = "addPhone";
|
|
@@ -15,11 +15,17 @@ let service = new axlService(
|
|
|
15
15
|
);
|
|
16
16
|
|
|
17
17
|
(async () => {
|
|
18
|
+
var opts = {
|
|
19
|
+
clean: true,
|
|
20
|
+
removeAttributes: false,
|
|
21
|
+
dataContainerIdentifierTails: "_data",
|
|
22
|
+
};
|
|
23
|
+
|
|
18
24
|
var operation = "getPhone";
|
|
19
25
|
var tags = await service.getOperationTags(operation);
|
|
20
26
|
tags.name = "CSFUSER001";
|
|
21
27
|
|
|
22
|
-
var returnPhoneTags = await service.executeOperation(operation, tags,
|
|
28
|
+
var returnPhoneTags = await service.executeOperation(operation, tags, opts);
|
|
23
29
|
|
|
24
30
|
operation = "addPhone";
|
|
25
31
|
returnPhoneTags.phone.name = "CSFWORDENJ";
|
|
@@ -25,11 +25,13 @@ let service = new axlService(
|
|
|
25
25
|
|
|
26
26
|
// Make a call to AXL to get the information for the trunk we are copying.
|
|
27
27
|
// Note: we will be sending the clean flag to executeOperation. This will remove any keys in our return json that is empty, undefined or null.
|
|
28
|
-
var
|
|
29
|
-
clean: true
|
|
28
|
+
var opts = {
|
|
29
|
+
clean: true,
|
|
30
|
+
removeAttributes: false,
|
|
31
|
+
dataContainerIdentifierTails: "_data",
|
|
30
32
|
};
|
|
31
33
|
|
|
32
|
-
var returnTrunk = await service.executeOperation(operation, tags,
|
|
34
|
+
var returnTrunk = await service.executeOperation(operation, tags, opts);
|
|
33
35
|
|
|
34
36
|
// Update the JSON with our new values
|
|
35
37
|
operation = "addSipTrunk";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const axlService = require("../../../index");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
|
|
7
|
+
This script will use getPhone to retrieve an existing phone and save as a JSON file. This file can then be edited to use as a template for other operations.
|
|
8
|
+
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// Set up new AXL service (DevNet sandbox credentials: https://devnetsandbox.cisco.com/)
|
|
12
|
+
let service = new axlService(
|
|
13
|
+
"10.10.20.1",
|
|
14
|
+
"administrator",
|
|
15
|
+
"ciscopsdt",
|
|
16
|
+
"14.0"
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
(async () => {
|
|
20
|
+
var operation = "getPhone";
|
|
21
|
+
var tags = await service.getOperationTags(operation);
|
|
22
|
+
tags.name = "SEP112233445566";
|
|
23
|
+
|
|
24
|
+
// Options for executeOperation
|
|
25
|
+
var opts = {
|
|
26
|
+
clean: true, // Remove all null and empty tags
|
|
27
|
+
removeAttributes: true // Remove all attributes and uuid's
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var returnPhoneTags = await service
|
|
31
|
+
.executeOperation(operation, tags, opts)
|
|
32
|
+
.catch((error) => {
|
|
33
|
+
console.log(error);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Let's add some _data fields that we can use to add variables to our template.
|
|
37
|
+
returnPhoneTags._data = {
|
|
38
|
+
firstName: "Tom",
|
|
39
|
+
lastName: "Smith",
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
fs.writeFileSync(
|
|
43
|
+
path.resolve(__dirname, "template.json"),
|
|
44
|
+
JSON.stringify(returnPhoneTags, null, 2),
|
|
45
|
+
(err) => {
|
|
46
|
+
// throws an error, you could also catch it here
|
|
47
|
+
if (err) throw err;
|
|
48
|
+
// success case, the file was saved
|
|
49
|
+
console.log("Template saved!");
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
})();
|
package/index.js
CHANGED
|
@@ -103,6 +103,7 @@ class axlService {
|
|
|
103
103
|
|
|
104
104
|
var clean = opts?.clean ? opts.clean : false;
|
|
105
105
|
var dataContainerIdentifierTails = opts?.dataContainerIdentifierTails ? opts.dataContainerIdentifierTails : '_data';
|
|
106
|
+
var removeAttributes = opts?.removeAttributes ? opts.removeAttributes : false;
|
|
106
107
|
|
|
107
108
|
// Let's remove empty top level strings. Also filter out json-variables
|
|
108
109
|
Object.keys(tags).forEach((k) => (tags[k] == '' || k.includes(dataContainerIdentifierTails)) && delete tags[k]);
|
|
@@ -132,7 +133,10 @@ class axlService {
|
|
|
132
133
|
if (result?.hasOwnProperty("return")) {
|
|
133
134
|
var output = result.return;
|
|
134
135
|
if (clean) {
|
|
135
|
-
|
|
136
|
+
cleanObj(output);
|
|
137
|
+
}
|
|
138
|
+
if(removeAttributes){
|
|
139
|
+
cleanAttributes(output);
|
|
136
140
|
}
|
|
137
141
|
resolve(output);
|
|
138
142
|
|
|
@@ -186,4 +190,22 @@ const cleanObj = (object) => {
|
|
|
186
190
|
return object;
|
|
187
191
|
};
|
|
188
192
|
|
|
193
|
+
const cleanAttributes = (object) => {
|
|
194
|
+
Object.entries(object).forEach(([k, v]) => {
|
|
195
|
+
if (v && typeof v === "object") {
|
|
196
|
+
cleanAttributes(v);
|
|
197
|
+
}
|
|
198
|
+
if (
|
|
199
|
+
(v && typeof v === "object" && 'attributes' in object)
|
|
200
|
+
) {
|
|
201
|
+
if (Array.isArray(object)) {
|
|
202
|
+
object.splice(k, 1);
|
|
203
|
+
} else {
|
|
204
|
+
delete object[k];
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
return object;
|
|
209
|
+
};
|
|
210
|
+
|
|
189
211
|
module.exports = axlService;
|