podman 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/lib/podman.rb +1 -0
  3. data/lib/vagrant/podman/action/build.rb +99 -0
  4. data/lib/vagrant/podman/action/compare_synced_folders.rb +65 -0
  5. data/lib/vagrant/podman/action/connect_networks.rb +80 -0
  6. data/lib/vagrant/podman/action/create.rb +165 -0
  7. data/lib/vagrant/podman/action/destroy.rb +34 -0
  8. data/lib/vagrant/podman/action/destroy_build_image.rb +51 -0
  9. data/lib/vagrant/podman/action/destroy_network.rb +53 -0
  10. data/lib/vagrant/podman/action/forwarded_ports.rb +36 -0
  11. data/lib/vagrant/podman/action/has_ssh.rb +21 -0
  12. data/lib/vagrant/podman/action/host_machine.rb +75 -0
  13. data/lib/vagrant/podman/action/host_machine_build_dir.rb +49 -0
  14. data/lib/vagrant/podman/action/host_machine_port_checker.rb +34 -0
  15. data/lib/vagrant/podman/action/host_machine_port_warning.rb +40 -0
  16. data/lib/vagrant/podman/action/host_machine_required.rb +20 -0
  17. data/lib/vagrant/podman/action/host_machine_sync_folders.rb +176 -0
  18. data/lib/vagrant/podman/action/host_machine_sync_folders_disable.rb +91 -0
  19. data/lib/vagrant/podman/action/init_state.rb +23 -0
  20. data/lib/vagrant/podman/action/is_build.rb +19 -0
  21. data/lib/vagrant/podman/action/is_host_machine_created.rb +32 -0
  22. data/lib/vagrant/podman/action/login.rb +51 -0
  23. data/lib/vagrant/podman/action/prepare_forwarded_port_collision_params.rb +64 -0
  24. data/lib/vagrant/podman/action/prepare_networks.rb +397 -0
  25. data/lib/vagrant/podman/action/prepare_nfs_settings.rb +60 -0
  26. data/lib/vagrant/podman/action/prepare_nfs_valid_ids.rb +22 -0
  27. data/lib/vagrant/podman/action/prepare_ssh.rb +48 -0
  28. data/lib/vagrant/podman/action/pull.rb +30 -0
  29. data/lib/vagrant/podman/action/start.rb +24 -0
  30. data/lib/vagrant/podman/action/stop.rb +24 -0
  31. data/lib/vagrant/podman/action/wait_for_running.rb +71 -0
  32. data/lib/vagrant/podman/action.rb +319 -0
  33. data/lib/vagrant/podman/cap/has_communicator.rb +14 -0
  34. data/lib/vagrant/podman/cap/proxy_machine.rb +15 -0
  35. data/lib/vagrant/podman/cap/public_address.rb +26 -0
  36. data/lib/vagrant/podman/command/exec.rb +112 -0
  37. data/lib/vagrant/podman/command/logs.rb +111 -0
  38. data/lib/vagrant/podman/command/run.rb +76 -0
  39. data/lib/vagrant/podman/communicator.rb +199 -0
  40. data/lib/vagrant/podman/config.rb +368 -0
  41. data/lib/vagrant/podman/driver/compose.rb +315 -0
  42. data/lib/vagrant/podman/driver.rb +417 -0
  43. data/lib/vagrant/podman/errors.rb +108 -0
  44. data/lib/vagrant/podman/executor/local.rb +48 -0
  45. data/lib/vagrant/podman/executor/vagrant.rb +88 -0
  46. data/lib/vagrant/podman/hostmachine/Vagrantfile +3 -0
  47. data/lib/vagrant/podman/plugin.rb +89 -0
  48. data/lib/vagrant/podman/provider.rb +216 -0
  49. data/lib/vagrant/podman/synced_folder.rb +35 -0
  50. data/templates/locales/providers_podman.yml +321 -0
  51. metadata +103 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '082faff2e76df636e5a1a4ca4c00b274b9d4df36bff0561cffe1a1616c5e36df'
4
+ data.tar.gz: e47d60be09054bd2baee911fd6de2613f20533dadebc34dc49d2a68293254879
5
+ SHA512:
6
+ metadata.gz: 893940e9818bb79dfe6c3ca870d4ff63b18ef9b4b43d7fb45d55cb171316f84378992ba513dc5bdd259d1eea24dcd1ed6495b15339008f66602117c1788bc07f
7
+ data.tar.gz: 68da4fd089db40130897028e96b003e0347ab61dffa9ce7ae3b6bc0bf92de98da5c2d9573b7c74d9c931cf2220eddb03789a03d983d96077becb8c80bf8bfff0
data/lib/podman.rb ADDED
@@ -0,0 +1 @@
1
+ require "podman/plugin"
@@ -0,0 +1,99 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: BUSL-1.1
3
+
4
+ require "log4r"
5
+
6
+ require "vagrant/util/ansi_escape_code_remover"
7
+
8
+ module VagrantPlugins
9
+ module PodmanProvider
10
+ module Action
11
+ class Build
12
+ include Vagrant::Util::ANSIEscapeCodeRemover
13
+
14
+ def initialize(app, env)
15
+ @app = app
16
+ @logger = Log4r::Logger.new("vagrant::podman::build")
17
+ end
18
+
19
+ def call(env)
20
+ machine = env[:machine]
21
+ build_dir = env[:build_dir]
22
+ build_dir ||= machine.provider_config.build_dir
23
+ git_repo = env[:git_repo]
24
+ git_repo ||= machine.provider_config.git_repo
25
+
26
+ # If we're not building a container, then just skip this step
27
+ return @app.call(env) if (!build_dir && !git_repo)
28
+
29
+ # Try to read the image ID from the cache file if we've
30
+ # already built it.
31
+ image_file = machine.data_dir.join("podman_build_image")
32
+ image = nil
33
+ if image_file.file?
34
+ image = image_file.read.chomp
35
+ end
36
+
37
+ # Verify the image exists if we have one
38
+ if image && !machine.provider.driver.image?(image)
39
+ machine.ui.output(I18n.t("podman_provider.build_image_invalid"))
40
+ image = nil
41
+ end
42
+
43
+ # If we have no image or we're rebuilding, we rebuild
44
+ if !image || env[:build_rebuild]
45
+ # Build it
46
+ args = machine.provider_config.build_args.clone
47
+ if machine.provider_config.podmanfile
48
+ podmanfile = machine.provider_config.podmanfile
49
+ podmanfile_path = build_dir ? File.join(build_dir, podmanfile) : podmanfile
50
+
51
+ args.push("--file").push(podmanfile_path)
52
+ if build_dir
53
+ machine.ui.output(
54
+ I18n.t("podman_provider.building_named_podmanfile",
55
+ file: machine.provider_config.podmanfile))
56
+ else
57
+ machine.ui.output(
58
+ I18n.t("podman_provider.building_git_repo_named_podmanfile",
59
+ file: machine.provider_config.podmanfile,
60
+ repo: git_repo))
61
+ end
62
+ else
63
+ if build_dir
64
+ machine.ui.output(I18n.t("podman_provider.building"))
65
+ else
66
+ machine.ui.output(
67
+ I18n.t("podman_provider.building_git_repo",
68
+ repo: git_repo))
69
+ end
70
+ end
71
+
72
+ image = machine.provider.driver.build(
73
+ build_dir || git_repo,
74
+ extra_args: args) do |type, data|
75
+ data = remove_ansi_escape_codes(data.chomp).chomp
76
+ env[:ui].detail(data) if data != ""
77
+ end
78
+
79
+ # Output the final image
80
+ machine.ui.detail("\nImage: #{image}")
81
+
82
+ # Store the image ID
83
+ image_file.open("w") do |f|
84
+ f.binmode
85
+ f.write("#{image}\n")
86
+ end
87
+ else
88
+ machine.ui.output(I18n.t("podman_provider.already_built"))
89
+ end
90
+
91
+ # Set the image for creation
92
+ env[:create_image] = image
93
+
94
+ @app.call(env)
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,65 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: BUSL-1.1
3
+
4
+ require "vagrant/action/builtin/mixin_synced_folders"
5
+
6
+ module VagrantPlugins
7
+ module PodmanProvider
8
+ module Action
9
+ class CompareSyncedFolders
10
+ include Vagrant::Action::Builtin::MixinSyncedFolders
11
+
12
+ def initialize(app, env)
13
+ @app = app
14
+ end
15
+
16
+ def call(env)
17
+ machine = env[:machine]
18
+
19
+ # Get the synced folders that are cached, and those that aren't
20
+ cached = synced_folders(machine, cached: true)
21
+ fresh = synced_folders(machine)
22
+
23
+ # Build up a mapping of existing setup synced folders
24
+ existing = {}
25
+ cached.each do |_, fs|
26
+ fs.each do |_, data|
27
+ existing[data[:guestpath]] = data[:hostpath]
28
+ end
29
+ end
30
+
31
+ # Remove the matching folders, and build up non-matching or
32
+ # new synced folders.
33
+ invalids = {}
34
+ fresh.each do |_, fs|
35
+ fs.each do |_, data|
36
+ invalid = false
37
+ old = existing.delete(data[:guestpath])
38
+ if !old
39
+ invalid = true
40
+ else
41
+ old = File.expand_path(old)
42
+ end
43
+
44
+ if !invalid && old
45
+ invalid = true if old != File.expand_path(data[:hostpath])
46
+ end
47
+
48
+ if invalid
49
+ invalids[File.expand_path(data[:guestpath])] = File.expand_path(data[:hostpath])
50
+ end
51
+ end
52
+ end
53
+
54
+ # If we have invalid entries, these are changed or new entries.
55
+ # If we have existing entries, then we removed some entries.
56
+ if !invalids.empty? || !existing.empty?
57
+ machine.ui.warn(I18n.t("podman_provider.synced_folders_changed"))
58
+ end
59
+
60
+ @app.call(env)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,80 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: BUSL-1.1
3
+
4
+ require 'ipaddr'
5
+ require 'log4r'
6
+
7
+ require 'vagrant/util/scoped_hash_override'
8
+
9
+ module VagrantPlugins
10
+ module PodmanProvider
11
+ module Action
12
+ class ConnectNetworks
13
+
14
+ include Vagrant::Util::ScopedHashOverride
15
+
16
+ def initialize(app, env)
17
+ @app = app
18
+ @logger = Log4r::Logger.new('vagrant::plugins::podman::connectnetworks')
19
+ end
20
+
21
+ # Generate CLI arguments for creating the podman network.
22
+ #
23
+ # @param [Hash] options Options from the network config
24
+ # @returns[Array<String> Network create arguments
25
+ def generate_connect_cli_arguments(options)
26
+ options.map do |key, value|
27
+ # If value is false, option is not set
28
+ next if value.to_s == "false"
29
+ # If value is true, consider feature flag with no value
30
+ opt = value.to_s == "true" ? [] : [value]
31
+ opt.unshift("--#{key.to_s.tr("_", "-")}")
32
+ end.flatten.compact
33
+ end
34
+
35
+ # Execute the action
36
+ def call(env)
37
+ # If we are using a host VM, then don't worry about it
38
+ machine = env[:machine]
39
+ if machine.provider.host_vm?
40
+ @logger.debug("Not setting up networks because podman host_vm is in use")
41
+ return @app.call(env)
42
+ end
43
+
44
+ env[:ui].info(I18n.t("podman_provider.network_connect"))
45
+
46
+ connections = env[:podman_connects] || {}
47
+
48
+ machine.config.vm.networks.each_with_index do |args, idx|
49
+ type, options = args
50
+ next if type != :private_network && type != :public_network
51
+
52
+ network_options = scoped_hash_override(options, :podman_connect)
53
+ network_options.delete_if{|k,_| options.key?(k)}
54
+ network_name = connections[idx]
55
+
56
+ if !network_name
57
+ raise Errors::NetworkNameMissing,
58
+ index: idx,
59
+ container: machine.name
60
+ end
61
+
62
+ @logger.debug("Connecting network #{network_name} to container guest #{machine.name}")
63
+ if options[:ip] && options[:type] != "dhcp"
64
+ if IPAddr.new(options[:ip]).ipv4?
65
+ network_options[:ip] = options[:ip]
66
+ else
67
+ network_options[:ip6] = options[:ip]
68
+ end
69
+ end
70
+ network_options[:alias] = options[:alias] if options[:alias]
71
+ connect_opts = generate_connect_cli_arguments(network_options)
72
+ machine.provider.driver.connect_network(network_name, machine.id, connect_opts)
73
+ end
74
+
75
+ @app.call(env)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,165 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: BUSL-1.1
3
+
4
+ module VagrantPlugins
5
+ module PodmanProvider
6
+ module Action
7
+ class Create
8
+ def initialize(app, env)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ @env = env
14
+ @machine = env[:machine]
15
+ @provider_config = @machine.provider_config
16
+ @machine_config = @machine.config
17
+ @driver = @machine.provider.driver
18
+
19
+ params = create_params
20
+
21
+ # If we're running a single command, we modify the params a bit
22
+ if env[:machine_action] == :run_command
23
+ # Use the command that is given to us
24
+ params[:cmd] = env[:run_command]
25
+
26
+ # Don't detach, we want to watch the command run
27
+ params[:detach] = false
28
+
29
+ # No ports should be shared to the host
30
+ params[:ports] = []
31
+
32
+ # Allocate a pty if it was requested
33
+ params[:pty] = true if env[:run_pty]
34
+
35
+ # Remove container after execution
36
+ params[:rm] = true if env[:run_rm]
37
+
38
+ # Name should be unique
39
+ params[:name] = "#{params[:name]}_#{Time.now.to_i}"
40
+
41
+ # We link to our original container
42
+ # TODO
43
+ end
44
+
45
+ env[:ui].output(I18n.t("podman_provider.creating"))
46
+ env[:ui].detail(" Name: #{params[:name]}")
47
+
48
+ env[:ui].detail(" Image: #{params[:image]}")
49
+ if params[:cmd] && !params[:cmd].empty?
50
+ env[:ui].detail(" Cmd: #{params[:cmd].join(" ")}")
51
+ end
52
+ params[:volumes].each do |volume|
53
+ env[:ui].detail("Volume: #{volume}")
54
+ end
55
+ params[:ports].each do |pair|
56
+ env[:ui].detail(" Port: #{pair}")
57
+ end
58
+ params[:links].each do |name, other|
59
+ env[:ui].detail(" Link: #{name}:#{other}")
60
+ end
61
+
62
+ if env[:machine_action] != :run_command
63
+ # For regular "ups" create it and get the CID
64
+ cid = @driver.create(params)
65
+ env[:ui].detail(" \n"+I18n.t(
66
+ "podman_provider.created", id: cid[0...16]))
67
+ @machine.id = cid
68
+ elsif params[:detach]
69
+ env[:ui].detail(" \n"+I18n.t("podman_provider.running_detached"))
70
+ else
71
+ ui_opts = {}
72
+
73
+ # If we're running with a pty, we want the output to look as
74
+ # authentic as possible. We don't prefix things and we don't
75
+ # output a newline.
76
+ if env[:run_pty]
77
+ ui_opts[:prefix] = false
78
+ ui_opts[:new_line] = false
79
+ end
80
+
81
+ # For run commands, we run it and stream back the output
82
+ env[:ui].detail(" \n"+I18n.t("podman_provider.running")+"\n ")
83
+ @driver.create(params, stdin: env[:run_pty]) do |type, data|
84
+ env[:ui].detail(data.chomp, **ui_opts)
85
+ end
86
+ end
87
+
88
+ @app.call(env)
89
+ end
90
+
91
+ def create_params
92
+ container_name = @provider_config.name
93
+ if !container_name
94
+ container_name = "#{@env[:root_path].basename.to_s}_#{@machine.name}"
95
+ container_name.gsub!(/[^-a-z0-9_]/i, "")
96
+ container_name << "_#{Time.now.to_i}"
97
+ end
98
+
99
+ image = @env[:create_image]
100
+ image ||= @provider_config.image
101
+
102
+ links = []
103
+ @provider_config._links.each do |link|
104
+ parts = link.split(":", 2)
105
+ links << parts
106
+ end
107
+
108
+ {
109
+ cmd: @provider_config.cmd,
110
+ detach: true,
111
+ env: @provider_config.env,
112
+ expose: @provider_config.expose,
113
+ extra_args: @provider_config.create_args,
114
+ hostname: @machine_config.vm.hostname,
115
+ image: image,
116
+ links: links,
117
+ name: container_name,
118
+ ports: forwarded_ports(@provider_config.has_ssh),
119
+ privileged: @provider_config.privileged,
120
+ network: @provider_config.network,
121
+ user: @provider_config.user,
122
+ userns: @provider_config.userns,
123
+ pty: false,
124
+ volumes: @provider_config.volumes,
125
+ }
126
+ end
127
+
128
+ def forwarded_ports(include_ssh=false)
129
+ mappings = {}
130
+ random = []
131
+
132
+ @machine.config.vm.networks.each do |type, options|
133
+ next if type != :forwarded_port
134
+
135
+ # Don't include SSH if we've explicitly asked not to
136
+ next if options[:id] == "ssh" && !include_ssh
137
+
138
+ # Skip port if it is disabled
139
+ next if options[:disabled]
140
+
141
+ # If the guest port is 0, put it in the random group
142
+ if options[:guest] == 0
143
+ random << options[:host]
144
+ next
145
+ end
146
+
147
+ mappings["#{options[:host]}/#{options[:protocol]}"] = options
148
+ end
149
+
150
+ # Build the results
151
+ result = random.map(&:to_s)
152
+ result += mappings.values.map do |fp|
153
+ protocol = ""
154
+ protocol = "/udp" if fp[:protocol].to_s == "udp"
155
+ host_ip = ""
156
+ host_ip = "#{fp[:host_ip]}:" if fp[:host_ip]
157
+ "#{host_ip}#{fp[:host]}:#{fp[:guest]}#{protocol}"
158
+ end.compact
159
+
160
+ result
161
+ end
162
+ end
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,34 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: BUSL-1.1
3
+
4
+ module VagrantPlugins
5
+ module PodmanProvider
6
+ module Action
7
+ class Destroy
8
+ def initialize(app, env)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ env[:ui].info I18n.t("podman_provider.messages.destroying")
14
+
15
+ machine = env[:machine]
16
+ driver = machine.provider.driver
17
+
18
+ # If we have a build image, store that
19
+ image_file = machine.data_dir.join("podman_build_image")
20
+ image = nil
21
+ if image_file.file?
22
+ image = image_file.read.chomp
23
+ end
24
+ env[:build_image] = image
25
+
26
+ driver.rm(machine.id)
27
+ machine.id = nil
28
+
29
+ @app.call(env)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,51 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: BUSL-1.1
3
+
4
+ require "log4r"
5
+
6
+ module VagrantPlugins
7
+ module PodmanProvider
8
+ module Action
9
+ class DestroyBuildImage
10
+ def initialize(app, env)
11
+ @app = app
12
+ @logger = Log4r::Logger.new("vagrant::podman::destroybuildimage")
13
+ end
14
+
15
+ def call(env)
16
+ machine = env[:machine]
17
+ image = env[:build_image]
18
+ image_file = nil
19
+
20
+ if !image
21
+ # Try to read the image ID from the cache file if we've
22
+ # already built it.
23
+ image_file = machine.data_dir.join("podman_build_image")
24
+ image = nil
25
+ if image_file.file?
26
+ image = image_file.read.chomp
27
+ end
28
+ end
29
+
30
+ if image
31
+ machine.ui.output(I18n.t("podman_provider.build_image_destroy"))
32
+ if !machine.provider.driver.rmi(image)
33
+ machine.ui.detail(I18n.t(
34
+ "podman_provider.build_image_destroy_in_use"))
35
+ end
36
+ end
37
+
38
+ if image_file && image_file.file?
39
+ begin
40
+ image_file.delete
41
+ rescue Errno::ENOENT
42
+ # Its okay
43
+ end
44
+ end
45
+
46
+ @app.call(env)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,53 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: BUSL-1.1
3
+
4
+ require 'log4r'
5
+
6
+ module VagrantPlugins
7
+ module PodmanProvider
8
+ module Action
9
+ class DestroyNetwork
10
+
11
+ @@lock = Mutex.new
12
+
13
+ def initialize(app, env)
14
+ @app = app
15
+ @logger = Log4r::Logger.new('vagrant::plugins::podman::network')
16
+ end
17
+
18
+ def call(env)
19
+ # If we are using a host VM, then don't worry about it
20
+ machine = env[:machine]
21
+ if machine.provider.host_vm?
22
+ @logger.debug("Not setting up networks because podman host_vm is in use")
23
+ return @app.call(env)
24
+ end
25
+
26
+ @@lock.synchronize do
27
+ machine.env.lock("podman-network-destroy", retry: true) do
28
+ machine.config.vm.networks.each do |type, options|
29
+ next if type != :private_network && type != :public_network
30
+
31
+ vagrant_networks = machine.provider.driver.list_network_names.find_all do |n|
32
+ n.start_with?("vagrant_network")
33
+ end
34
+
35
+ vagrant_networks.each do |network_name|
36
+ if machine.provider.driver.existing_named_network?(network_name) &&
37
+ !machine.provider.driver.network_used?(network_name)
38
+ env[:ui].info(I18n.t("podman_provider.network_destroy", network_name: network_name))
39
+ machine.provider.driver.rm_network(network_name)
40
+ else
41
+ @logger.debug("Network #{network_name} not found or in use")
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ @app.call(env)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,36 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: BUSL-1.1
3
+
4
+ module VagrantPlugins
5
+ module PodmanProvider
6
+ module Action
7
+ class ForwardedPorts
8
+ def initialize(app, env)
9
+ @app = app
10
+ end
11
+
12
+ # Converts the `ports` podman provider param into proper network configs
13
+ # of type :forwarded_port
14
+ def call(env)
15
+ env[:machine].provider_config.ports.each do |p|
16
+ host_ip = nil
17
+ protocol = "tcp"
18
+ host, guest = p.split(":", 2)
19
+ if guest.include?(":")
20
+ host_ip = host
21
+ host, guest = guest.split(":", 2)
22
+ end
23
+
24
+ guest, protocol = guest.split("/", 2) if guest.include?("/")
25
+ env[:machine].config.vm.network "forwarded_port",
26
+ host: host.to_i, guest: guest.to_i,
27
+ host_ip: host_ip,
28
+ protocol: protocol
29
+ end
30
+
31
+ @app.call(env)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,21 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: BUSL-1.1
3
+
4
+ module VagrantPlugins
5
+ module PodmanProvider
6
+ module Action
7
+ # This middleware is used with Call to test if this machine supports
8
+ # SSH.
9
+ class HasSSH
10
+ def initialize(app, env)
11
+ @app = app
12
+ end
13
+
14
+ def call(env)
15
+ env[:result] = env[:machine].provider_config.has_ssh
16
+ @app.call(env)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,75 @@
1
+ # Copyright (c) HashiCorp, Inc.
2
+ # SPDX-License-Identifier: BUSL-1.1
3
+
4
+ require "log4r"
5
+
6
+ module VagrantPlugins
7
+ module PodmanProvider
8
+ module Action
9
+ # This action is responsible for creating the host machine if
10
+ # we need to. The host machine is where Podman containers will
11
+ # live.
12
+ class HostMachine
13
+ def initialize(app, env)
14
+ @app = app
15
+ @logger = Log4r::Logger.new("vagrant::podman::hostmachine")
16
+ end
17
+
18
+ def call(env)
19
+ if !env[:machine].provider.host_vm?
20
+ @logger.info("No host machine needed.")
21
+ return @app.call(env)
22
+ end
23
+
24
+ env[:machine].ui.output(I18n.t(
25
+ "podman_provider.host_machine_needed"))
26
+
27
+ host_machine = env[:machine].provider.host_vm
28
+
29
+ begin
30
+ env[:machine].provider.host_vm_lock do
31
+ setup_host_machine(host_machine, env)
32
+ end
33
+ rescue Vagrant::Errors::EnvironmentLockedError
34
+ sleep 1
35
+ retry
36
+ end
37
+
38
+ @app.call(env)
39
+ end
40
+
41
+ protected
42
+
43
+ def setup_host_machine(host_machine, env)
44
+ # Create a UI for this machine that stays at the detail level
45
+ proxy_ui = host_machine.ui.dup
46
+ proxy_ui.opts[:bold] = false
47
+ proxy_ui.opts[:prefix_spaces] = true
48
+ proxy_ui.opts[:target] = env[:machine].name.to_s
49
+
50
+ # Reload the machine so that if it was created while we didn't
51
+ # hold the lock, we'll see the updated state.
52
+ host_machine.reload
53
+
54
+ # See if the machine is ready already. If not, start it.
55
+ if host_machine.communicate.ready?
56
+ env[:machine].ui.detail(I18n.t("podman_provider.host_machine_ready"))
57
+ else
58
+ env[:machine].ui.detail(
59
+ I18n.t("podman_provider.host_machine_starting"))
60
+ env[:machine].ui.detail(" ")
61
+ host_machine.with_ui(proxy_ui) do
62
+ host_machine.action(:up)
63
+ end
64
+
65
+ # Verify communication is ready. If not, we have a problem.
66
+ if !host_machine.communicate.ready?
67
+ raise Errors::HostVMCommunicatorNotReady,
68
+ id: host_machine.id
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end