-
Notifications
You must be signed in to change notification settings - Fork 170
/
machine_file.rb
60 lines (49 loc) · 1.65 KB
/
machine_file.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require 'chef/provider/lwrp_base'
require 'chef/provisioning/chef_provider_action_handler'
require 'chef/provisioning/machine'
class Chef
class Provider
class MachineFile < Chef::Provider::LWRPBase
provides :machine_file
def action_handler
@action_handler ||= Chef::Provisioning::ChefProviderActionHandler.new(self)
end
use_inline_resources
def whyrun_supported?
true
end
def machine
@machine ||= begin
if new_resource.machine.kind_of?(Chef::Provisioning::Machine)
new_resource.machine
else
run_context.chef_provisioning.connect_to_machine(new_resource.machine, new_resource.chef_server)
end
end
end
action :upload do
if new_resource.content
machine.write_file(action_handler, new_resource.path, new_resource.content)
else
machine.upload_file(action_handler, new_resource.local_path, new_resource.path)
end
# At some point hopefully we will define WindowsMachine.set_attributes
# See https://github.com/chef/chef-provisioning/issues/285 for how to get
# rid of this unless check
unless machine.kind_of?(Chef::Provisioning::Machine::WindowsMachine)
attributes = {}
attributes[:group] = new_resource.group if new_resource.group
attributes[:owner] = new_resource.owner if new_resource.owner
attributes[:mode] = new_resource.mode if new_resource.mode
machine.set_attributes(action_handler, new_resource.path, attributes)
end
end
action :download do
machine.download_file(action_handler, new_resource.path, new_resource.local_path)
end
action :delete do
machine.delete_file(action_handler, new_resource.path)
end
end
end
end