Skip to content

Commit

Permalink
fix: adding removal of zonecfg provisional network after startup
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkProminic authored Dec 12, 2023
1 parent 38c2bf2 commit 8885044
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/vagrant-zones/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down
26 changes: 26 additions & 0 deletions lib/vagrant-zones/action/network_cleanup.rb
Original file line number Diff line number Diff line change
@@ -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
15 changes: 14 additions & 1 deletion lib/vagrant-zones/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/vagrant-zones/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |-
Expand Down

0 comments on commit 8885044

Please sign in to comment.