From 88850440213a7ffce82463b02dab56c8c9d05d69 Mon Sep 17 00:00:00 2001 From: Mark Gilbert <50398495+MarkProminic@users.noreply.github.com> Date: Tue, 12 Dec 2023 04:49:29 -0600 Subject: [PATCH] fix: adding removal of zonecfg provisional network after startup --- lib/vagrant-zones/action.rb | 2 ++ lib/vagrant-zones/action/network_cleanup.rb | 26 +++++++++++++++++++++ lib/vagrant-zones/driver.rb | 15 +++++++++++- lib/vagrant-zones/plugin.rb | 3 +-- locales/en.yml | 2 ++ 5 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 lib/vagrant-zones/action/network_cleanup.rb diff --git a/lib/vagrant-zones/action.rb b/lib/vagrant-zones/action.rb index c1fd130..e2d1efe 100644 --- a/lib/vagrant-zones/action.rb +++ b/lib/vagrant-zones/action.rb @@ -26,6 +26,7 @@ def self.action_up b2.use Start b2.use WaitTillBoot b2.use Setup + b2.use NetworkingCleanup b2.use WaitTillUp b2.use Provision b2.use SetHostname @@ -186,6 +187,7 @@ def self.action_box_remove autoload :Network, action_root.join('network') autoload :Setup, action_root.join('setup') autoload :Start, action_root.join('start') + autoload :NetworkingCleanup, action_root.join('network_cleanup') autoload :IsCreated, action_root.join('is_created') autoload :NotCreated, action_root.join('not_created') autoload :CreateSnapshots, action_root.join('create_zfs_snapshots') diff --git a/lib/vagrant-zones/action/network_cleanup.rb b/lib/vagrant-zones/action/network_cleanup.rb new file mode 100644 index 0000000..2c53c33 --- /dev/null +++ b/lib/vagrant-zones/action/network_cleanup.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'log4r' +require 'securerandom' +require 'digest/md5' + +module VagrantPlugins + module ProviderZone + module Action + # This is use to define the network + class NetworkingCleanup + def initialize(app, _env) + @logger = Log4r::Logger.new('vagrant_zones::action::import') + @app = app + end + + def call(env) + @machine = env[:machine] + @driver = @machine.provider.driver + @driver.network(env[:ui], 'delete_provisional') + @app.call(env) + end + end + end + end +end diff --git a/lib/vagrant-zones/driver.rb b/lib/vagrant-zones/driver.rb index d16d67a..d7ba64a 100644 --- a/lib/vagrant-zones/driver.rb +++ b/lib/vagrant-zones/driver.rb @@ -321,6 +321,7 @@ def network(uii, state) when 'public_network' zonenicdel(uii, opts) if state == 'delete' && !config.on_demand_vnics zonecfgnicconfig(uii, opts) if state == 'config' + zonecfgnicconfigdelete(uii, opts) if state == 'delete_provisional' && config.on_demand_vnics zoneniccreate(uii, opts) if state == 'create' && !config.on_demand_vnics zonenicstpzloginsetup(uii, opts, config) if state == 'setup' && config.setup_method == 'zlogin' when 'private_network' @@ -1075,6 +1076,18 @@ def zonecfgnicconfig(uii, opts) end end + ## zonecfg function for for Networking + def zonecfgnicconfigdelete(uii, opts) + allowed_address = allowedaddress(uii, opts) + vnic_name = vname(uii, opts) + config = @machine.provider_config + uii.info(I18n.t('vagrant_zones.vnic_conf_del')) + uii.info(" #{vnic_name}") + if opts[:provisional] + execute(false, %(#{@pfexec} zonecfg -z #{@machine.name} remove net physical=#{vnic_name})) + end + end + # This helps us set the zone configurations for the zone def zonecfg(uii) name = @machine.name @@ -1343,7 +1356,7 @@ def zoneniczloginsetup_windows(uii, opts, _mac) dns1 = %(netsh int ipv4 set dns name="#{vnic_name}" static #{ip_addresses[0]} primary validate=no) uii.info(I18n.t('vagrant_zones.win_applied_dns1')) if zlogin(uii, dns1) ip_addresses[1..-1].each_with_index do |dns, index| - additional_nameservers = %(netsh int ipv4 add dns name="#{vnic_name}" #{dns} index=#{index + 2}") validate=no) + additional_nameservers = %(netsh int ipv4 add dns name="#{vnic_name}" #{dns} index="#{index + 2}") validate=no) uii.info(I18n.t('vagrant_zones.win_applied_dns2')) if zlogin(uii, additional_nameservers) end end diff --git a/lib/vagrant-zones/plugin.rb b/lib/vagrant-zones/plugin.rb index 1f1edf0..c72dce9 100644 --- a/lib/vagrant-zones/plugin.rb +++ b/lib/vagrant-zones/plugin.rb @@ -20,8 +20,7 @@ class Plugin < Vagrant.plugin('2') require_relative 'config' Config end - provider(:zone, parallel: true) do - ## provider(:zone, parallel: false) do + provider(:zone, parallel: false) do require_relative 'provider' Provider end diff --git a/locales/en.yml b/locales/en.yml index 09b50f4..b196607 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -256,6 +256,8 @@ en: Creating networking interfaces for zone: nat_vnic_setup: |- - Setting up NAT VNIC: + vnic_conf_del: |- + - Deleting zonecg for provisional VNIC: forwarding_nat: |- - Enabling NAT forwarding: configuring_nat: |-