mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-23 13:15:14 +09:00
F #4913: Refactor DS stat
This commit is contained in:
1 parent
7596dad33c
commit
50ba69df99
1 file changed
+25
-18
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2016, OpenNebula Project, OpenNebula Systems #
|
||||
# Copyright 2002-2017, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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 #
|
||||
@@ -17,7 +17,7 @@
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
###############################################################################
|
||||
# This script is used retrieve the file size of a disk
|
||||
# This script is used retrieve the file size of a disk
|
||||
###############################################################################
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
@@ -31,7 +31,19 @@ end
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'vcenter_driver'
|
||||
require 'vcenter_driver2'
|
||||
|
||||
################################################################################
|
||||
|
||||
def check_valid(parameter, label)
|
||||
if parameter.nil? || parameter.empty?
|
||||
STDERR.puts "Not enough information to stat the image. " +
|
||||
"Missing '#{label}'."
|
||||
exit -1
|
||||
end
|
||||
end
|
||||
|
||||
################################################################################
|
||||
|
||||
drv_action_enc = ARGV[0]
|
||||
id = ARGV[1]
|
||||
@@ -39,24 +51,21 @@ id = ARGV[1]
|
||||
drv_action =OpenNebula::XMLElement.new
|
||||
drv_action.initialize_xml(Base64.decode64(drv_action_enc), 'DS_DRIVER_ACTION_DATA')
|
||||
|
||||
ds_name = drv_action["/DS_DRIVER_ACTION_DATA/DATASTORE/NAME"]
|
||||
hostname = drv_action["/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VCENTER_CLUSTER"]
|
||||
ds_ref = drv_action["/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VCENTER_DS_REF"]
|
||||
host_id = drv_action["/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VCENTER_CLUSTER"]
|
||||
img_path = drv_action["/DS_DRIVER_ACTION_DATA/IMAGE/PATH"]
|
||||
|
||||
if ds_name.nil? ||
|
||||
hostname.nil? ||
|
||||
img_path.nil?
|
||||
STDERR.puts "Not enough information to stat the image."
|
||||
exit -1
|
||||
end
|
||||
check_valid ds_ref, "ds_ref"
|
||||
check_valid host_id, "vcenter_cluster"
|
||||
check_valid img_path, "img_path"
|
||||
|
||||
if img_path.start_with? "vcenter://"
|
||||
begin
|
||||
img_path = img_path.sub("vcenter://","")
|
||||
host_id = VCenterDriver::VIClient.translate_hostname(hostname)
|
||||
vi_client = VCenterDriver::VIClient.new host_id
|
||||
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
|
||||
ds = VCenterDriver::Datastore.new_from_ref(ds_ref, vi_client)
|
||||
|
||||
ds.stat(img_path)
|
||||
|
||||
puts vi_client.stat(ds_name, img_path)
|
||||
rescue Exception => e
|
||||
STDERR.puts "Error calculating image #{img_path} size."\
|
||||
" Reason: #{e.message}"
|
||||
@@ -65,6 +74,4 @@ if img_path.start_with? "vcenter://"
|
||||
else
|
||||
cmd = "#{File.dirname(__FILE__)}/../fs/stat #{drv_action_enc}"
|
||||
system(cmd)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
Reference in new issue
Block a user