#!/usr/bin/env ruby

# --------------------------------------------------------------------------
# Copyright 2010, C12G Labs S.L.
#
# This file is part of OpenNebula VMware Drivers.
#
# OpenNebula VMware Drivers is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 3 of
# the License, or the hope That it will be useful, but (at your
# option) any later version.
#
# OpenNebula VMware Drivers is distributed in WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License
# along with OpenNebula VMware Drivers . If not, see
# <http://www.gnu.org/licenses/>
# --------------------------------------------------------------------------

@host     = ARGV[0]
deploy_id = ARGV[1]

if !@host or !deploy_id 
    exit -1
end

if !ONE_LOCATION
        VMWARERC_LOCATION="/etc/one/vmwarerc"
else
        VMWARERC_LOCATION=ONE_LOCATION+"/etc/vmwarerc"
end
load VMWARERC_LOCATION

data = perform_action("virsh -c #{LIBVIRT_URI} shutdown #{deploy_id}")

if data.class == Fixnum
    exit data
end

begin 
    data = perform_action("virsh -c #{LIBVIRT_URI} list")
    if data.class == Fixnum
        exit data
    end
    sleep 2
end while data.match(deploy_id)
    
data = perform_action("virsh -c #{LIBVIRT_URI} undefine #{deploy_id}")

if data.class == Fixnum
    exit data
end



