-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59b3a2f
commit a3c10a3
Showing
4 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
Puppet::Type.type(:download).provide(:download_linux) do | ||
|
||
def check_created_file(file) | ||
if File.exists?(file) | ||
if File.zero?(file) | ||
self.debug("Found #{file} but empty") | ||
return false | ||
else | ||
self.debug("Found #{file}") | ||
return true | ||
end | ||
else | ||
self.debug("Not found #{file}") | ||
return false | ||
end | ||
end | ||
|
||
def run_wget_command(url) | ||
|
||
command = ["wget"] | ||
command.push(url) | ||
command.push("-O ", resource[:creates]) | ||
|
||
if resource[:cwd] | ||
Dir.chdir resource[:cwd] do | ||
run_command(command) | ||
end | ||
else | ||
run_command(command) | ||
end | ||
end | ||
|
||
private | ||
|
||
def run_command(command) | ||
command = command.join ' ' | ||
output = Puppet::Util::Execution.execute(command, { | ||
:uid => 'root', | ||
:gid => 'root', | ||
:failonfail => false, | ||
:combine => true, | ||
:override_locale => true, | ||
}) | ||
[output, $CHILD_STATUS.dup] | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
Puppet::Type.newtype(:download) do | ||
@doc = 'download files' | ||
|
||
newparam(:name) do | ||
desc "An arbitrary tag for your own reference" | ||
isnamevar | ||
end | ||
|
||
newproperty(:url) do | ||
desc 'URL to download' | ||
|
||
defaultto { @resource[:name] } | ||
|
||
# If needing to run the SQL command, return a fake value that will trigger | ||
# a sync, else return the expected SQL command so no sync takes place | ||
def retrieve | ||
if @resource.should_run_wget | ||
return :notrun | ||
else | ||
return self.should | ||
end | ||
end | ||
|
||
def sync | ||
output, status = provider.run_wget_command(value) | ||
self.fail("Error executing wget; returned #{status}: '#{output}'") unless status == 0 | ||
end | ||
end | ||
|
||
newparam(:cwd, :parent => Puppet::Parameter::Path) do | ||
desc "The working directory under which the wget command should be executed." | ||
defaultto("/tmp") | ||
end | ||
|
||
newparam(:creates) do | ||
desc "file created" | ||
|
||
def matches(value) | ||
provider.check_created_file(value) | ||
end | ||
end | ||
|
||
newparam(:refreshonly, :boolean => true) do | ||
desc "If 'true', it will only be executed via a notify/subscribe event." | ||
|
||
defaultto(:false) | ||
newvalues(:true, :false) | ||
end | ||
|
||
def should_run_wget(refreshing = false) | ||
creates_param = @parameters[:creates] | ||
return false if !creates_param.nil? && !creates_param.value.nil? && creates_param.matches(creates_param.value) | ||
return false if !refreshing && @parameters[:refreshonly].value == :true | ||
true | ||
end | ||
|
||
def refresh | ||
self.property(:command).sync if self.should_run_wget(true) | ||
end | ||
|
||
end |