Automating configuration with cli scripts

rdesoju
rdesoju Member Posts: 66

Hi,
Is there an option to automate configuration scripts written with cli commands. For example:

enable
configure
message-pool message-vpn default
create queue <MYQUEUE>
no shutdown
exit
exit
exit

Having a file create_queue.sh with above statements and execute a command something like:
solacectl cli create_queue.sh.
Is there any option to achieve this?

Thanks,
Raghu

Comments

  • uherbst
    uherbst Member, Employee Posts: 44 Solace Employee

    Hi Raghu,
    yes, there are options to do so.

    If you are inside the cli and the script with the commands is located in cliscripts/queue.cli, then you can enter:

    source cliscripts/queue.cli [stop-on-error] [no-prompt]
    

    If you are in a location, where you can start cli (eg with: "docker exec -it solace bash"), you can also do:

    cli -A -s [SCRIPT_NAME]
    

    Beware: cli is not able to replace any variables (eg your queue name in your example) - if you want do that, you have to do that outside the cli (I would do that in the calling bash script and write the cli-script-file with the correct queue name)

    Uli

  • swenhelge
    swenhelge Member, Employee Posts: 65 Solace Employee

    If you need configuration on the Message VPN level (queues, ACLs ...) then a good option may be to use SEMPv2 via e.g. Ansible. Ansible then takes care of doing variable substitutions such as broker connection parameters and queue names.
    There are some examples/open source projects for Ansible:
    https://github.com/streetster/ansible-solace
    https://github.com/srajgopalan/solace-ci-cd-demo

  • rdesoju
    rdesoju Member Posts: 66

    Thank you all for valuable information.

  • Aaron
    Aaron Member, Moderator, Employee Posts: 285 Solace Employee

    Agreed... you should really be using the RESTful SEMPv2 management API, rather than scripting CLI scripts and trying to execute them remotely. It's much safer, cleaner, and doesn't run the the risk of leaving the system in a weird/bad state if a CLI script fails halfway through a configuration item. CLI scripts were great 10 years ago, but SEMPv2 is very much the recommended way of going now.

    For your example, here's how you can create a queue with SEMP in a single command:

    curl http://localhost:8080/SEMP/v2/config/msgVpns/default/queues \
    -X POST \
    -u admin:admin \
    -H "Content-type:application/json" \
    -d '{ "queueName":"testQ",
          "accessType":"exclusive",
          "maxMsgSpoolUsage":200,
          "permission":"consume",
          "ingressEnabled":true,
          "egressEnabled":true }'
    
  • rdesoju
    rdesoju Member Posts: 66

    Thank you for the info @Aaron !

  • fellaamazing
    fellaamazing Member Posts: 7

    @Aaron said:
    Agreed... you should really be using the RESTful SEMPv2 management API, rather than scripting CLI scripts and trying to execute them remotely. It's much safer, cleaner, and doesn't run the the risk of leaving the system in a weird/bad state if a CLI script fails halfway through a configuration item. CLI scripts were great 10 years ago, but SEMPv2 is very much the recommended way of going now.

    For your example, here's how you can create a queue with SEMP in a single command:

    curl http://localhost:8080/SEMP/v2/config/msgVpns/default/queues \
    -X POST \
    -u admin:admin \
    -H "Content-type:application/json" \
    -d '{ "queueName":"testQ",
          "accessType":"exclusive",
          "maxMsgSpoolUsage":200,
        "permission":"consume",
          "ingressEnabled":true,
          "egressEnabled":true }'
    

    Hey there. What's the BASH or powershell script to disable and enable a VPN?
    it's something like that..
    http://10.1.255.255:8080/SEMP/v2/config/msgVpns/v001

    let's assume user name is admin. Password is ADMpwd1

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 568 admin

    Hey @fellaamazing,

    Can you please create a separate question for this? It will likely get more eyes on it and result in a quicker response than commenting at the end of this thread. :)

    Cheers!

  • fellaamazing
    fellaamazing Member Posts: 7

    @marc said:
    Hey @fellaamazing,

    Can you please create a separate question for this? It will likely get more eyes on it and result in a quicker response than commenting at the end of this thread. :)

    Cheers!

    Created: https://solace.community/discussion/863/semp-script-required-for-enabling-disabling-vpn

  • Aaron
    Aaron Member, Moderator, Employee Posts: 285 Solace Employee

    Talked about this thread on my Office Hours. Check it out! https://www.youtube.com/watch?v=bm7z2Bke2po&t=1815s

  • Island
    Island Member, Employee Posts: 2 Solace Employee

    @swenhelge said:
    If you need configuration on the Message VPN level (queues, ACLs ...) then a good option may be to use SEMPv2 via e.g. Ansible. Ansible then takes care of doing variable substitutions such as broker connection parameters and queue names.
    There are some examples/open source projects for Ansible:
    https://github.com/streetster/ansible-solace
    https://github.com/srajgopalan/solace-ci-cd-demo

    https://github.com/flyisland/solconfig , Add another tool for backing up and restoring Solace PubSub+ Broker Configuration with SEMPv2 protocol