forked from sous-chefs/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker_volume.rb
34 lines (30 loc) · 1.12 KB
/
docker_volume.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module DockerCookbook
class DockerVolume < DockerBase
resource_name :docker_volume
property :driver, String, desired_state: false
property :host, [String, nil], default: lazy { ENV['DOCKER_HOST'] }, desired_state: false
property :opts, Hash, desired_state: false
property :volume, Docker::Volume, desired_state: false
property :volume_name, String, name_property: true
load_current_value do
begin
with_retries { volume Docker::Volume.get(volume_name, connection) }
rescue Docker::Error::NotFoundError
current_value_does_not_exist!
end
end
action :create do
converge_by "creating volume #{new_resource.volume_name}" do
opts = {}
opts['Driver'] = driver if property_is_set?(:driver)
opts['DriverOpts'] = opts if property_is_set?(:opts)
Docker::Volume.create(new_resource.volume_name, opts, connection)
end if current_resource.nil?
end
action :remove do
converge_by "removing volume #{new_resource.volume_name}" do
current_resource.volume.remove
end unless current_resource.nil?
end
end
end