Stop services or servers in bulk using Cloud SDK

Version 1
    Share This:

    With CLM 4.0, BMC Cloud Lifecycle Management Python Software Development Kit got released! Today latest release i.e. CLM 4.5 is released. SDK has cool features to do any action that can be performed through web browser using command-line interface and python API.


    So let's talk about a tip on using SDK...


    While doing my dev work, I generally have to spawn various VMs and I tend to forget that some infrastructure will keep me billed till the point I keep the VM running. So here is a little trick that I learnt while trying to turn off all VMs with single command-line.


    clm login --url "http://host:port/csm" --user "<<user>>" --password "<<password>>"
    foreach ($soi in (clm service-list -n --filter status=running))
         if( $soi -ne "Name" -and $soi -ne "")
              $clmcmd = "clm service-stop --servicename $soi";
              echo $clmcmd;
              Invoke-Expression $clmcmd;


    When this command is issued in windows powershell, it will stop all the services and hence servers if it was running!


    Let's look at it closely...


    clm service-list -n --filter state=running


    service-list queried all services. -n switch tells SDK to return only names of services. --filter can be anything. For our case, we filtered services to include only ones that are in running state. Once the list of names are fetched, they are split and foreach iterates through each of them.


    So, for each service name, if(...) condition ensures headers and blank lines are ignored.


    clm service-stop --servicename $soi


    This command gets issued for each service name. service-stop initiates stop operation for specified service on CLM server. In the snippet above I have constructed the string in $clmcmd variable just to print it on console and then execute. You can directly execute the command instead.


    One can create similar snippet for linux also ... it's quite easy. If I get some time, I will post another post.

    This is what I love about command-line! One can chain multiple commands to do any bulk ops... awesome.