diff --git a/CHANGELOG.md b/CHANGELOG.md index 34363c8..ce20984 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,4 +16,4 @@ Error corrections ## 1.0.5a -Added `alarms` command +Added `alarms`, `sync` commands diff --git a/README.md b/README.md index 73c620e..4add72a 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ Authentication Successful - `fdn ` - navigate to FDN - `home` - navigate to root folder - `alarms` - show alarms +- `sync` - initiate node synchronization - `persistent` - toggle persistent attributes inclusion - `exit` - logout and exit application @@ -370,4 +371,4 @@ EMN returns error if commited configuration includes attributes with type SHORT. 1.0.4a - Error corrections -1.0.5a - Added `alarms` command +1.0.5a - Added `alarms`, `sync` commands diff --git a/lib/TopologyBrowser.js b/lib/TopologyBrowser.js index 3862fb7..1471583 100644 --- a/lib/TopologyBrowser.js +++ b/lib/TopologyBrowser.js @@ -2,6 +2,7 @@ const logAttributes = require('../util/logAttributes') const { createAxiosInstance } = require('../util/axiosInstance') const alarms = require('../lib/commands/alarms') +const sync = require('../lib/commands/sync') const login = require('../lib/commands/login') const logout = require('../lib/commands/logout') const initialPrompt = require('../lib/commands/initialPrompt') @@ -45,11 +46,11 @@ class TopologyBrowser { createAxiosInstance(url) } - async login(){ + async login() { return await login.call(this) } - async logout(){ + async logout() { await logout.call(this) } @@ -61,7 +62,7 @@ class TopologyBrowser { return await this.nextVariants(input) } - async nextObjects(input){ + async nextObjects(input) { return await nextObjects.call(this, input) } @@ -130,6 +131,10 @@ class TopologyBrowser { await alarms.call(this, fdn) } + async sync(fdn) { + await sync.call(this, fdn) + } + } diff --git a/lib/commands/nextObjects.js b/lib/commands/nextObjects.js index 21c2311..80605b8 100644 --- a/lib/commands/nextObjects.js +++ b/lib/commands/nextObjects.js @@ -1,6 +1,6 @@ const requestWrapper = require('../../util/requestWrapper') -const otherCommands = ['show', 'config', 'up', 'home', 'fdn', 'persistent', 'alarms', 'exit'] +const otherCommands = ['show', 'config', 'up', 'home', 'fdn', 'persistent', 'alarms', 'sync', 'exit'] async function nextObjects(input){ diff --git a/lib/commands/sync.js b/lib/commands/sync.js new file mode 100644 index 0000000..9935762 --- /dev/null +++ b/lib/commands/sync.js @@ -0,0 +1,30 @@ +const colors = require('colors') + +const requestWrapper = require('../../util/requestWrapper') + + +async function sync(fdn) { + const meContextFind = fdn.match(/(NetworkElement|MeContext)=([\w-]+),?/) + if (!meContextFind) { + console.log('No sync object in FDN!'.yellow) + return + } + const actionUrl = `${this.objectUrl}v1/perform-mo-action/NetworkElement=${meContextFind[2]},CmFunction=1?actionName=sync` + const axiosConfig = { + method: 'post', + url: actionUrl, + headers: { + 'Content-Type': 'application/json' + }, + } + const response = await requestWrapper(axiosConfig, 'Initiate Node Sync...') + if (response.status === 200) { + console.log(` + ${response.data.body.bold} + ${response.data.title.green} + `) + } +} + + +module.exports = sync \ No newline at end of file diff --git a/lib/inputHandler.js b/lib/inputHandler.js index 72cbcf9..48ca82c 100644 --- a/lib/inputHandler.js +++ b/lib/inputHandler.js @@ -84,6 +84,9 @@ async function handleCommand(tplg, fdn, command) { case 'alarms': await tplg.alarms(fdn) break + case 'sync': + await tplg.sync(fdn) + break default: fdn = commandOther(tplg, fdn, command)