Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tinova

tinova/shutdown Secret

Created May 26, 2015 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tinova/c5944e6819a4f42911ae to your computer and use it in GitHub Desktop.
Save tinova/c5944e6819a4f42911ae to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# ---------------------------------------------------------------------------- #
# Copyright 2010-2015, C12G Labs S.L #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# ---------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
end
$: << RUBY_LIB_LOCATION
$: << File.dirname(__FILE__)
require 'vmware_driver'
require 'vi_driver'
#------------------------------------------------------------------------------
# Wait the VM to shutdown TIMEOUT (xPOLL_INTERVAL) seconds.
# Set to ~10min
#------------------------------------------------------------------------------
POLL_INTERVAL=2
TIMEOUT=300
deploy_id = ARGV[0]
host = ARGV[1]
VIDriver::initialize(host)
vmware_drv = VMwareDriver.new(host)
vmware_drv.shutdown(deploy_id)
count=0
while (VIDriver::poll_vm(deploy_id).match(/STATE=(.*)/)[1] != "d") do
sleep POLL_INTERVAL
if count > TIMEOUT then
OpenNebula.log_debug("Timeout reached and VM #{deploy_id} is still alive.")
exit -1
end
count+=POLL_INTERVAL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment