1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-12 09:17:41 +03:00

Apply linter rules to vcenter deploy

This commit is contained in:
Tino Vazquez 2018-07-17 16:18:56 +02:00
parent 8f3fdf0a33
commit ebf320f5c3

View File

@ -16,39 +16,40 @@
# limitations under the License. #
# ---------------------------------------------------------------------------- #
ONE_LOCATION = ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' unless defined?(RUBY_LIB_LOCATION)
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' unless defined?(RUBY_LIB_LOCATION)
end
$: << RUBY_LIB_LOCATION
$: << File.dirname(__FILE__)
$LOAD_PATH << RUBY_LIB_LOCATION
$LOAD_PATH << File.dirname(__FILE__)
require 'vcenter_driver'
def is_deploy_id_valid?(deploy_id)
return deploy_id && !deploy_id.empty?
end
dfile = ARGV[0]
cluster_name = ARGV[1]
vm_id = ARGV[2]
## Helpers
def deploy_id_valid?(deploy_id)
deploy_id && !deploy_id.empty?
end
drv_action = OpenNebula::XMLElement.new
drv_action.initialize_xml(Base64.decode64(STDIN.read), 'VM')
deploy_id = drv_action["DEPLOY_ID"]
host_id = drv_action["HISTORY_RECORDS/HISTORY/HID"]
deploy_id = drv_action['DEPLOY_ID']
host_id = drv_action['HISTORY_RECORDS/HISTORY/HID']
begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
one_vm = VCenterDriver::VIHelper.one_item(OpenNebula::VirtualMachine, vm_id)
if is_deploy_id_valid?(deploy_id)
if deploy_id_valid?(deploy_id)
# VM is not new, we just need to reconfigure it and to power it on
vm = VCenterDriver::VirtualMachine.new_one(vi_client, deploy_id, one_vm)
else
@ -67,15 +68,14 @@ begin
vm.poweron
vm.set_running(true)
vm.one_item.update("VCENTER_ESX_HOST = #{vm["runtime.host.name"]}", true)
vm.one_item.update("VCENTER_ESX_HOST = #{vm['runtime.host.name']}", true)
puts vm['_ref']
rescue Exception => e
message = "Deploy of VM #{vm_id} on vCenter cluster #{cluster_name} " +
"with #{dfile} failed due to \"#{e.message}\"\n#{e.backtrace}"
rescue StandardError => e
message = "Deploy of VM #{vm_id} on vCenter cluster #{cluster_name} " \
"with #{dfile} failed due to \"#{e.message}\"\n#{e.backtrace}"
OpenNebula.log_error(message)
exit -1
exit(-1)
ensure
vi_client.close_connection if vi_client
end