#!/usr/bin/env ruby

# --------------------------------------------------------------------------
# Copyright 2011, 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/>
# --------------------------------------------------------------------------

ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)

if !ONE_LOCATION
   ETC_LOCATION="/etc/one" if !defined?(ETC_LOCATION)
else
   ETC_LOCATION=ONE_LOCATION+"/etc" if !defined?(ETC_LOCATION)
end

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

if !@host or !deploy_id
    exit -1
end

load ETC_LOCATION + "/vmwarerc"

if USERNAME.class!=String || PASSWORD.class!=String
    warn "Bad ESX credentials, aborting"
    exit -1
end

# Destroy the VM
data = perform_action("virsh -c #{LIBVIRT_URI} destroy #{deploy_id}")

if data.class == Fixnum
    exit data
end

