From ff58312d3a6a72c4400eda2977b2ecbac4f44efa Mon Sep 17 00:00:00 2001 From: mcabrerizo Date: Tue, 14 Feb 2017 17:17:21 +0100 Subject: [PATCH] Add NIC attach/detach actions --- src/vmm_mad/remotes/vcenter/attach_nic | 32 ++++++++++++++++---------- src/vmm_mad/remotes/vcenter/detach_nic | 27 +++++++++++++--------- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/vmm_mad/remotes/vcenter/attach_nic b/src/vmm_mad/remotes/vcenter/attach_nic index a158d226af..1b04fbad6f 100755 --- a/src/vmm_mad/remotes/vcenter/attach_nic +++ b/src/vmm_mad/remotes/vcenter/attach_nic @@ -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 # @@ -27,22 +27,30 @@ end $: << RUBY_LIB_LOCATION $: << File.dirname(__FILE__) -require 'vcenter_driver' +require 'vcenter_driver2' -deploy_id = ARGV[0] +vm_ref = ARGV[0] mac = ARGV[1] bridge = ARGV[2] model = ARGV[3] -host = ARGV[-1] +vc_cluster_name = ARGV[-1] begin - VCenterDriver::VCenterVm.attach_nic(deploy_id, - mac, - bridge, - model, - host) + + vi_client = VCenterDriver::VIClient.new_from_hostname(vc_cluster_name) + + vm = VCenterDriver::VirtualMachine.new_from_ref(vi_client, vm_ref) + + nic = { + "MAC" => mac, + "BRIDGE" => bridge, + "MODEL" => model + } + + vm.attach_nic(nic) + rescue Exception => e - STDERR.puts "Attach NIC for VM #{deploy_id} on host #{host} failed " + - "due to \"#{e.message}\"" - exit -1 + STDERR.puts "Attach NIC for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\ + "failed due to \"#{e.message}\"" + exit(-1) end diff --git a/src/vmm_mad/remotes/vcenter/detach_nic b/src/vmm_mad/remotes/vcenter/detach_nic index 19b7cfafaf..f8aa0ebd04 100755 --- a/src/vmm_mad/remotes/vcenter/detach_nic +++ b/src/vmm_mad/remotes/vcenter/detach_nic @@ -27,19 +27,24 @@ end $: << RUBY_LIB_LOCATION $: << File.dirname(__FILE__) -require 'vcenter_driver' - -deploy_id = ARGV[0] -mac = ARGV[1] -host = ARGV[3] +require 'vcenter_driver2' +vm_ref = ARGV[0] +mac = ARGV[1] +vc_cluster_name = ARGV[3] begin - VCenterDriver::VCenterVm.detach_nic(deploy_id, - mac, - host) + + vi_client = VCenterDriver::VIClient.new_from_hostname(vc_cluster_name) + + vm = VCenterDriver::VirtualMachine.new_from_ref(vi_client, vm_ref) + + nic = { "MAC" => mac } + + vm.detach_nic(nic) + rescue Exception => e - STDERR.puts "Detach NIC for VM #{deploy_id} on host #{host} failed " + - "due to \"#{e.message}\"" - exit -1 + STDERR.puts "Detach NIC for VM #{vm_ref} on vCenter cluster #{vc_cluster_name} "\ + "failed due to \"#{e.message}\"" + exit(-1) end \ No newline at end of file