diff --git a/install.sh b/install.sh index 720a3548d0..4a71206c09 100755 --- a/install.sh +++ b/install.sh @@ -515,13 +515,21 @@ INSTALL_FILES=( NETWORK_FILES:$VAR_LOCATION/remotes/vnm NETWORK_ETC_FILES:$VAR_LOCATION/remotes/etc/vnm NETWORK_8021Q_FILES:$VAR_LOCATION/remotes/vnm/802.1Q + NETWORK_LXD_FILES:$VAR_LOCATION/remotes/vnm/802.1Q/clean.d NETWORK_VXLAN_FILES:$VAR_LOCATION/remotes/vnm/vxlan + NETWORK_LXD_FILES:$VAR_LOCATION/remotes/vnm/vxlan/clean.d NETWORK_DUMMY_FILES:$VAR_LOCATION/remotes/vnm/dummy + NETWORK_LXD_FILES:$VAR_LOCATION/remotes/vnm/dummy/clean.d NETWORK_BRIDGE_FILES:$VAR_LOCATION/remotes/vnm/bridge + NETWORK_LXD_FILES:$VAR_LOCATION/remotes/vnm/bridge/clean.d NETWORK_EBTABLES_FILES:$VAR_LOCATION/remotes/vnm/ebtables + NETWORK_LXD_FILES:$VAR_LOCATION/remotes/vnm/ebtables/clean.d NETWORK_FW_FILES:$VAR_LOCATION/remotes/vnm/fw + NETWORK_LXD_FILES:$VAR_LOCATION/remotes/vnm/fw/clean.d NETWORK_OVSWITCH_FILES:$VAR_LOCATION/remotes/vnm/ovswitch + NETWORK_LXD_FILES:$VAR_LOCATION/remotes/vnm/ovswitch/clean.d NETWORK_OVSWITCH_VXLAN_FILES:$VAR_LOCATION/remotes/vnm/ovswitch_vxlan + NETWORK_LXD_FILES:$VAR_LOCATION/remotes/vnm/ovswitch_vxlan/clean.d NETWORK_VCENTER_FILES:$VAR_LOCATION/remotes/vnm/vcenter NETWORK_ALIAS_SDNAT_FILES:$VAR_LOCATION/remotes/vnm/alias_sdnat EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples @@ -1194,6 +1202,8 @@ NETWORK_ALIAS_SDNAT_FILES="src/vnm_mad/remotes/alias_sdnat/AliasSDNAT.rb \ src/vnm_mad/remotes/alias_sdnat/pre \ src/vnm_mad/remotes/alias_sdnat/update_sg " +NETWORK_LXD_FILES="src/vnm_mad/remotes/lib/lxd_clean.rb" + #------------------------------------------------------------------------------- # Virtual Network Manager drivers configuration to be installed under $REMOTES_LOCATION/etc/vnm #------------------------------------------------------------------------------- diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 550991f746..5a3d9b1568 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -233,7 +233,7 @@ class VmmAction result, info = vnm.do_action(@id, step[:action], :parameters => params) when :tm - result, info = @tm.do_transfer_action(@id, step[:parameters], stdin=step[:stdin]) + result, info = @tm.do_transfer_action(@id, step[:parameters], stdin = step[:stdin]) else result = DriverExecHelper.const_get(:RESULT)[:failure] @@ -396,32 +396,32 @@ class ExecDriver < VirtualMachineDriver end steps.concat([ - # Execute pre-boot networking setup - { - :driver => :vnm, - :action => :pre - }, - # Boot the Virtual Machine - { - :driver => :vmm, - :action => :deploy, - :parameters => [dfile, :host], - :stdin => domain - }, - # Execute post-boot networking setup - { - :driver => :vnm, - :action => :post, - :parameters => [:deploy_info], - :fail_actions => [ - { - :driver => :vmm, - :action => :cancel, - :parameters => [:deploy_info, :host] - } - ] - } - ]) + # Execute pre-boot networking setup + { + :driver => :vnm, + :action => :pre + }, + # Boot the Virtual Machine + { + :driver => :vmm, + :action => :deploy, + :parameters => [dfile, :host], + :stdin => domain + }, + # Execute post-boot networking setup + { + :driver => :vnm, + :action => :post, + :parameters => [:deploy_info], + :fail_actions => [ + { + :driver => :vmm, + :action => :cancel, + :parameters => [:deploy_info, :host] + } + ] + } + ]) action.run(steps) end @@ -485,31 +485,31 @@ class ExecDriver < VirtualMachineDriver action = VmmAction.new(self, id, :restore, drv_message) steps.concat([ - # Execute pre-boot networking setup - { - :driver => :vnm, - :action => :pre - }, - # Restore the Virtual Machine from checkpoint - { - :driver => :vmm, - :action => :restore, - :parameters => [:checkpoint_file, :host, :deploy_id] - }, - # Execute post-boot networking setup - { - :driver => :vnm, - :action => :post, - :parameters => [:deploy_id], - :fail_actions => [ - { - :driver => :vmm, - :action => :cancel, - :parameters => [:deploy_id, :host] - } - ] - } - ]) + # Execute pre-boot networking setup + { + :driver => :vnm, + :action => :pre + }, + # Restore the Virtual Machine from checkpoint + { + :driver => :vmm, + :action => :restore, + :parameters => [:checkpoint_file, :host, :deploy_id] + }, + # Execute post-boot networking setup + { + :driver => :vnm, + :action => :post, + :parameters => [:deploy_id], + :fail_actions => [ + { + :driver => :vmm, + :action => :cancel, + :parameters => [:deploy_id, :host] + } + ] + } + ]) action.run(steps) end @@ -599,9 +599,7 @@ class ExecDriver < VirtualMachineDriver :stdin => xml_data) end - # # REBOOT action, reboots a running VM - # def reboot(id, drv_message) restart(id, drv_message, :reboot) end @@ -1104,8 +1102,8 @@ class ExecDriver < VirtualMachineDriver # Get TM command tm_command = ensure_xpath(xml_data, id, action, 'TM_COMMAND') || return - tm_command_split = tm_command.split - tm_command_split[0].sub!('.', '_LIVE.') or tm_command_split[0] += '_LIVE' + tm_command_split = tm_command.split + tm_command_split[0].sub!('.', '_LIVE.') || (tm_command_split[0] += '_LIVE') action = VmmAction.new(self, id, :disk_snapshot_create, drv_message) @@ -1183,6 +1181,7 @@ class ExecDriver < VirtualMachineDriver action.run(steps, sg_id) end + private def ensure_xpath(xml_data, id, action, xpath) @@ -1197,12 +1196,43 @@ class ExecDriver < VirtualMachineDriver end def restart(id, drv_message, signal) - data = decode(drv_message) - host = data.elements['HOST'].text - deploy_id = data.elements['DEPLOY_ID'].text + action = VmmAction.new(self, id, signal, drv_message) - do_action("#{deploy_id} #{host}", id, host, ACTION[signal], - :stdin => data) + reboot_step = { + :driver => :vmm, + :action => signal, + :parameters => [:deploy_id, :host] + } + + steps = [reboot_step] + + if @hypervisor == 'lxd' + steps += [ + { + :driver => :vnm, + :action => :clean + }, + { + :driver => :vnm, + :action => :pre + }, + reboot_step, + { + :driver => :vnm, + :action => :post, + :parameters => [:deploy_info], + :fail_actions => [ + { + :driver => :vmm, + :action => :cancel, + :parameters => [:deploy_info, :host] + } + ] + } + ] + end + + action.run(steps) end def destroy(id, drv_message, signal) diff --git a/src/vmm_mad/remotes/lib/lxd/container.rb b/src/vmm_mad/remotes/lib/lxd/container.rb index 6d25fd998c..526ef4b7b5 100644 --- a/src/vmm_mad/remotes/lib/lxd/container.rb +++ b/src/vmm_mad/remotes/lib/lxd/container.rb @@ -225,11 +225,11 @@ class Container end end - def check_stop + def check_stop(force) return if status != 'Running' begin - if ARGV[-1] == '-f' + if force == '-f' stop(:force => true) else stop diff --git a/src/vmm_mad/remotes/lxd/cancel b/src/vmm_mad/remotes/lxd/cancel index 0d5ab5a6af..ce31f8254e 100755 --- a/src/vmm_mad/remotes/lxd/cancel +++ b/src/vmm_mad/remotes/lxd/cancel @@ -16,4 +16,4 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -$(dirname $0)/shutdown $@ '-f' \ No newline at end of file +$(dirname $0)/shutdown "$@" '-f' \ No newline at end of file diff --git a/src/vmm_mad/remotes/lxd/reboot b/src/vmm_mad/remotes/lxd/reboot index 7a107b1c19..3e08de59a1 100755 --- a/src/vmm_mad/remotes/lxd/reboot +++ b/src/vmm_mad/remotes/lxd/reboot @@ -34,5 +34,15 @@ container = Container.get(vm_name, container.config['user.xml'], client) # ------------------------------------------------------------------------------ # Stop the container, start it # ------------------------------------------------------------------------------ -container.check_stop -container.start +case container.config['user.reboot_state'] +when 'STOPPED' + container.start + container.config['user.reboot_state'] = 'RUNNING' +else + force = false + force = true if ARGV[-1] == '-f' + container.check_stop(force) + container.config['user.reboot_state'] = 'STOPPED' +end + +container.update diff --git a/src/vmm_mad/remotes/lxd/reset b/src/vmm_mad/remotes/lxd/reset index a435cd466f..b49ac3f1dc 100755 --- a/src/vmm_mad/remotes/lxd/reset +++ b/src/vmm_mad/remotes/lxd/reset @@ -16,4 +16,4 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -$(dirname $0)/reboot $1 '-f' \ No newline at end of file +$(dirname $0)/reboot "$@" '-f' \ No newline at end of file diff --git a/src/vmm_mad/remotes/lxd/shutdown b/src/vmm_mad/remotes/lxd/shutdown index 071f4d9804..6dc21d3237 100755 --- a/src/vmm_mad/remotes/lxd/shutdown +++ b/src/vmm_mad/remotes/lxd/shutdown @@ -37,7 +37,10 @@ container = Container.get(vm_name, xml, client) # Stop vnc connection and container & unmap devices if not a wild container # ------------------------------------------------------------------------------ container.vnc('stop') -container.check_stop + +force = false +force = true if ARGV[-1] == '-f' +container.check_stop(force) exit 0 if container.wild? diff --git a/src/vnm_mad/remotes/lib/lxd_clean.rb b/src/vnm_mad/remotes/lib/lxd_clean.rb new file mode 100644 index 0000000000..8733d746bb --- /dev/null +++ b/src/vnm_mad/remotes/lib/lxd_clean.rb @@ -0,0 +1,33 @@ +#!/usr/bin/ruby + +$LOAD_PATH << "#{__dir__}/../.." + +require 'vnmmad' +require 'open3' + +template64 = STDIN.read +vnm = VNMMAD::NoVLANDriver.from_base64(template64, nil, nil) + +vm = vnm.vm + +exit 0 unless vm.hypervisor == 'lxd' +OpenNebula.log 'running lxd network post cleanup' + +vm.nics.each do |nic| + next unless nic[:nic] + + veth = nic[:nic][:target] + + cmd = "ip link show #{veth}" + + _o, _e, s = Open3.capture3(cmd) + + next unless s == 0 + + cmd = "ip link delete #{veth}" + OpenNebula.log "Found lingering nic #{veth}\n Running #{cmd}" + + o, e, _s = Open3.capture3(cmd) + + OpenNebula.log "#{o}\n#{e}" +end