Statistics
| Branch: | Tag: | Revision:

one / src / vmm_mad / remotes / vcenter / shutdown @ 05ed37c9

History | View | Annotate | Download (1.97 KB)

1
#!/usr/bin/env ruby
2

    
3
# ---------------------------------------------------------------------------- #
4
# Copyright 2010-2015, C12G Labs S.L                                           #
5
#                                                                              #
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may      #
7
# not use this file except in compliance with the License. You may obtain      #
8
# a copy of the License at                                                     #
9
#                                                                              #
10
# http://www.apache.org/licenses/LICENSE-2.0                                   #
11
#                                                                              #
12
# Unless required by applicable law or agreed to in writing, software          #
13
# distributed under the License is distributed on an "AS IS" BASIS,            #
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.     #
15
# See the License for the specific language governing permissions and          #
16
# limitations under the License.                                               #
17
# ---------------------------------------------------------------------------- #
18

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

    
21
if !ONE_LOCATION
22
    RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
23
else
24
    RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
25
end
26

    
27
$: << RUBY_LIB_LOCATION
28
$: << File.dirname(__FILE__)
29

    
30
require 'vcenter_driver'
31
require 'opennebula'
32

    
33
deploy_id = ARGV[0]
34
host      = ARGV[1]
35
vm_id     = ARGV[-2]
36

    
37
vm = OpenNebula::VirtualMachine.new_with_id(vm_id, OpenNebula::Client.new)
38
vm.info
39

    
40
lcm_state   = vm.lcm_state_str
41
keep_disks  = vm.keep_disks?
42

    
43
begin
44
    VCenterDriver::VCenterVm.shutdown(deploy_id, host, lcm_state, keep_disks)
45
rescue Exception => e
46
    STDERR.puts "Shutdown of VM #{deploy_id} on host #{host} failed " +
47
                "due to \"#{e.message}\""
48
    exit -1
49
end