Spent last few weeks neck deep in Razor, and actually made my first pull request. Here are some other handy things for working with Razor daily. Most of these are handy for working with a larger number of nodes/policies/active models… as well, things get unwieldy past the first 10-15 nodes. Some of these will likely be irrelevant if you have a DevOps broker framework & plugin working.
Get IPs for a policy that has active models
This one is good if you need to get the IPs assigned to the nodes that have been provisioned for a particular policy. You’ll want to change the bits in <> or [] to fit your environment.
for i in `razor active_model | grep <policy_name>| awk ‘{print $3}’`; do razor node $i -f attrib | grep ipaddress_eth[0,1,etc] | awk ‘{print $2}’; done
Get service tags for a policy that has active models
Because we can’t get away from having some manner of identifier for the CMDB, we will occasionally have to grab the service tag or something like that for the boxes:
for i in `razor active_model | grep <policy_name>| awk ‘{print $3}’`; do razor node $i -f attrib | awk ‘$1 == “‘serialnumber'”‘ | awk ‘{print $2}’; done
Reboot Razor Nodes
Mass reboot time! Also, sshpass FTW. If you haven’t set up ssh keys on each box yet… this is a life saver. (Likely avoided with said DevOps framework above, btw).
for i in `razor active_model | grep <policy_name> | awk ‘{print $3}’`; do sshpass -p test1234 ssh -l root `razor node $i -f attrib | grep ipaddress_eth[0,1,etc] | awk ‘{print $2}’` reboot; done
Remove active_model
Now that you’ve rebooted everything with the intention of returning the hosts to the pool, you need to remove the active model for them.
for i in `razor active_model | grep <policy_name>| awk ‘{print $6}’`; do razor active_model remove $i; done
Ping nodes for a given policy with an active model
for i in `razor active_model | grep <policy_name>| awk ‘{print $3}’`; do ping -c 1 `razor node $i -f attrib | grep ipaddress_eth[0,1etc] | awk ‘{print $2}’`; done
These are just some of mine… do you have any handy bash one-liners for working with Razor? Drop a line in the comments. Also, follow me on twitter.
Please advise – can you suggest some examples of the “DevOps broker framework” you mentioned?
Sorry for the late reply, have been neck deep in a number of other projects. In this case I had meant if you were using a Chef/Puppet or similar to manage your nodes. A lot of these bash one-liners (to reboot nodes, etc) could be handled better.