Class: Puppet::X::Jenkins::Provider::Cli
- Inherits:
-
Provider
- Object
- Provider
- Puppet::X::Jenkins::Provider::Cli
show all
- Defined in:
- lib/puppet/x/jenkins/provider/cli.rb
Defined Under Namespace
Classes: AuthError, NetError, UnknownError
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.cli(command, options = {}, cli_pre_cmd = []) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/puppet/x/jenkins/provider/cli.rb', line 121
def self.cli(command, options = {}, cli_pre_cmd = [])
if options.nil? || !options.key?(:stdinjson) && !options.key?(:stdin)
return execute_with_retry(command, options, cli_pre_cmd)
end
if options.key?(:stdinjson)
data = options.delete(:stdinjson)
input = JSON.pretty_generate(data)
end
input = options.delete(:stdin) if options.key?(:stdin)
tmpfile_as_param = if options.key?(:tmpfile_as_param)
options[:tmpfile_as_param]
else
false
end
Puppet.debug("#{sname} stdin:\n#{input}")
tmp = Tempfile.open(sname)
tmp.write input
tmp.flush
options[:stdinfile] = tmp.path
begin
Etc.getpwnam('jenkins')
FileUtils.chown 'jenkins', 'jenkins', tmp.path if tmpfile_as_param && File.exist?(tmp.path)
rescue
FileUtils.chmod 0o644, tmp.path if tmpfile_as_param && File.exist?(tmp.path)
end
result = execute_with_retry(command, options, cli_pre_cmd)
tmp.close
tmp.unlink
result
end
|
.clihelper(command, options = {}) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/puppet/x/jenkins/provider/cli.rb', line 99
def self.clihelper(command, options = {})
catalog = options.key?(:catalog) ? options[:catalog] : nil
config = Puppet::X::Jenkins::Config.new(catalog)
puppet_helper = config[:puppet_helper]
cli_remoting_free = config[:cli_remoting_free]
if cli_remoting_free
cli_pre_cmd = ['/bin/cat', puppet_helper, '|']
cli_cmd = ['groovy', '='] + [command]
options[:tmpfile_as_param] = true
else
cli_pre_cmd = []
cli_cmd = ['groovy', puppet_helper] + [command]
end
cli_pre_cmd.flatten!
cli_cmd.flatten!
cli(cli_cmd, options, cli_pre_cmd)
end
|
.inherited(subclass) ⇒ Object
push a shallow copy of the class confines into the subclass this includes the confine(s) needed for commands
The subclass seems to function with an empty @commands and any value we try to push in will get reselt by ::initvars.
22
23
24
|
# File 'lib/puppet/x/jenkins/provider/cli.rb', line 22
def self.inherited(subclass)
subclass.instance_variable_set(:@confine_collection, @confine_collection.dup)
end
|
.prefetch(resources) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/puppet/x/jenkins/provider/cli.rb', line 45
def self.prefetch(resources)
Puppet.debug("#{sname} prefetch: #{resources.each_key.collect.to_a}")
catalog = resources.first[1].catalog
instances(catalog).each do |prov|
if (resource = resources[prov.name])
resource.provider = prov
end
end
end
|
.sname ⇒ Object
41
42
43
|
# File 'lib/puppet/x/jenkins/provider/cli.rb', line 41
def self.sname
to_s[%r{.+::(Jenkins.+)}, 1]
end
|
Instance Method Details
#cli(command, options = nil) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/puppet/x/jenkins/provider/cli.rb', line 87
def cli(command, options = nil)
if resource && resource.catalog
options ||= {}
options[:catalog] ||= resource.catalog
end
args = []
args << command
args << options unless options.nil?
self.class.cli(*args)
end
|
#clihelper(command, options = nil) ⇒ Object
if the provider instance has a resource (which it should outside of testing), add :catalog to the options hash so the caller doesn’t have to
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/puppet/x/jenkins/provider/cli.rb', line 75
def clihelper(command, options = nil)
if resource && resource.catalog
options ||= {}
options[:catalog] ||= resource.catalog
end
args = []
args << command
args << options unless options.nil?
self.class.clihelper(*args)
end
|
#create ⇒ Object
57
58
59
|
# File 'lib/puppet/x/jenkins/provider/cli.rb', line 57
def create
@property_hash[:ensure] = :present
end
|
#destroy ⇒ Object
65
66
67
|
# File 'lib/puppet/x/jenkins/provider/cli.rb', line 65
def destroy
@property_hash[:ensure] = :absent
end
|
#exists? ⇒ Boolean
61
62
63
|
# File 'lib/puppet/x/jenkins/provider/cli.rb', line 61
def exists?
@property_hash[:ensure] == :present
end
|
#flush ⇒ Object
69
70
71
|
# File 'lib/puppet/x/jenkins/provider/cli.rb', line 69
def flush
@property_hash.clear
end
|