Add NIC attach/detach actions

This commit is contained in:
mcabrerizo committed 2017-02-14 17:17:21 +01:00
1 parent 986fce32f0
commit ff58312d3a
2 files changed
+36 -23

No files matched your search

+20 -12
View File
@@ -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
+16 -11
View File
@@ -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