How to automate model creation or deletion in Spectrum via CLI script
search cancel

How to automate model creation or deletion in Spectrum via CLI script

book

Article ID: 13520

calendar_today

Updated On:

Products

Spectrum

Issue/Introduction

In Spectrum, its possible to use the command line interface (CLI) to run commands and incorporate those commands into a shell script (such as bash) to automate various processes, such as creation or deletion of models based on certain criteria.



How can the destruction of models be achieved via an automated process and then creation of new models be achieved using the CLI?

Environment

Release: SDBSFO99000-10.2-Spectrum-Device Based Suite-Server FOC
Component:

Resolution

The Spectrum CLI commands are all listed in the $SPECROOT/vnmsh directory. The specific commands pertaining to model deletion and creation are:


 


create 


destroy


 


You can use these commands in general bash scripts and pipe their output to other system commands.


 


So to utilise these CLI commands, you would write a script, in either bash shell or Perl, identify the models you want using the show command then cut the model_handle from the output for use with destroy command. The following bash shell script can be used as an example where all models exhibiting the DIFFERENT TYPE MODEL alarm (0x10203): are found using ./show alarms output piped into grep and awk to get the relevant model handle and then destroy to delete it:


 



#!/bin/bash


timestamp=`date "+%H%M%d/%m/%Y"`


 


# Check the CLIPATH setting


if [ -z "$CLIPATH" ]


then


CLIPATH=$SPECROOT/vnmsh


export CLIPATH


fi


 


cd $CLIPATH


 


# Connect to the VNM shell


./connect


 


# Using as example alarm to eliminate models - 'DIFFERENT TYPE MODEL - 0x10203'"



probCauseID="0x10203"


 




# For each model with this alarm, we will destroy it,


# after obtaining its IP address (attribute - Network_Address)


# and then create it again


 


for model in `./show alarms -a | grep $probCauseID | awk '{print $5}'`;


do 


echo "-----------------------------------"


echo $timestamp Model Handle of device with Alarm = $model


./current mh=$model


IP=`./show attributes mh=$model | grep Network_Address | grep -v Legacy | awk '{print $3}'`


echo $timestamp IP Address = $IP


 


if [ $interactive -eq 1 ]


then


# Run silent


./destroy model -n mh=$model


else


# Default - Run interactive, where you will be asked if you want to destroy each model


./destroy model mh=$model


fi


 


# You can then rediscover a new model with the same IP address if needed.


./create model ip=$IP


done


 


# Disconnect from the VNM shell


./disconnect


 



Additional Information

Please reference the "Introduction to Command Line Interface (CLI)" section for more information.