{"id":15,"date":"2014-09-20T16:20:32","date_gmt":"2014-09-20T14:20:32","guid":{"rendered":"http:\/\/www.underealm.com\/tech\/?p=15"},"modified":"2014-09-23T18:36:45","modified_gmt":"2014-09-23T16:36:45","slug":"xenserver-vm-easy-autostart","status":"publish","type":"post","link":"https:\/\/www.underealm.com\/tech\/2014\/09\/xenserver-vm-easy-autostart\/","title":{"rendered":"XenServer VMs and easy autostart"},"content":{"rendered":"<p>One of the most tedious tasks I find myself doing on XS installation is switching VMs&#8217; autostart off and on. While no big deal it got boring real fast. I thus crafted a couple bash scripts to be run on the XS host that speed the task up.<\/p>\n<pre class=\"toolbar:1\" lang=\"bash\" title=\"autostart_status.sh\"><code>#!\/bin\/bash\r\npool=$(xe pool-list | sed -n \"s\/.*\\uuid.*: \\(.*\\)\/\\1\/p\" | awk '{ system(\"xe pool-param-get param-name=other-config param-key=auto_poweron uuid=\"$0\" 2>&1\") }' | sed 's\/Error: Key auto_poweron not found in map\/false\/g' | sed 's\/false\/INACTIVE\/g' | sed 's\/true\/ACTIVE\/g')\r\nlist=$(xe vm-list | sed -n \"s\/.*\\(uuid\\|name-label\\).*)[ ]*: \\(.*\\)\/\\2\/p\" | awk '{ print $0; } NR%2==1 { system(\"xe vm-param-get param-name=other-config param-key=auto_poweron uuid=\"$0\" 2>&1\" ) }' | sed 's\/Error: Key auto_poweron not found in map\/false\/g' | awk '{id=$0; getline; atrun=$0; getline; print atrun \" \" $0 \" [\" id \"]\"; }' | sort -k 2 | grep -v \"Transfer VM for VDI\" | grep -v \"Control domain on host\" )\r\nactive=$(echo \"$list\" | sed -n \"s\/true \\(.*\\)\/\\1\/p\")\r\ninactive=$(echo \"$list\" | sed -n \"s\/false \\(.*\\)\/\\1\/p\")\r\necho -e \"\\nAuto restart in the pool is $pool\\n\\n\"\r\nif [ \"$active\" != \"\" ]; then\r\n  echo -e \"*** VIRTUAL MACHINES AUTO RESTARTING ***************\\n\\n$active\\n\\n\"\r\nfi\r\nif [ \"$inactive\" != \"\" ]; then\r\n  echo -e \"*** VIRTUAL MACHINES _NOT_ AUTO RESTARTING *********\\n\\n$inactive\\n\\n\"\r\nfi<\/code><\/pre>\n<p>This script will parse all the VMs while skipping a few system instances, and will clearly show which ones are starting automatically, together with the corresponding UUID, so no guesswork or matching is needed.<\/p>\n<pre class=\"nums:false\" lang=\"cmd\"><code># .\/autostart_status.sh\r\n\r\nAuto restart in the pool is ACTIVE\r\n\r\n\r\n*** VIRTUAL MACHINES AUTO RESTARTING ***************\r\n\r\nVM1 [UUID1]\r\n\r\n\r\n*** VIRTUAL MACHINES _NOT_ AUTO RESTARTING *********\r\n\r\nVM2 [UUID2]\r\nVM3 [UUID3]<\/code><\/pre>\n<p>With our UUID in hand, we can now enable\/disable it through this tiny script:<\/p>\n<pre class=\"toolbar:1\" lang=\"bash\" title=\"set_autostart.sh\"><code>#!\/bin\/bash\r\nif [ \"$2\" == \"true\" -o \"$2\" == \"false\" ]; then\r\n        xe vm-param-set other-config:auto_poweron=$2 uuid=$1\r\nelse\r\n        echo Correct syntax: $0 \\<UUID\\> \\<true\\|false\\>\r\nfi<\/code><\/pre>\n<p>With these two scripts the task becomes checking the VM name and switching it on\/off in a matter of seconds. Mission complete.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the most tedious tasks I find myself doing on XS installation is switching VMs&#8217; autostart off and on. While no big deal it got boring real fast. I thus crafted a couple bash scripts to be run on the XS host that speed the task up. #!\/bin\/bash pool=$(xe pool-list | sed -n &#8220;s\/.*\\uuid.*: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[13,5,7,58,12],"class_list":["post-15","post","type-post","status-publish","format-standard","hentry","category-xenserver","tag-bash-script","tag-citrix","tag-scripts","tag-sysad","tag-xen-server"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/posts\/15"}],"collection":[{"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/comments?post=15"}],"version-history":[{"count":0,"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/posts\/15\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/media?parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/categories?post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/tags?post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}