Class: Bolt::Target
- Inherits:
-
Object
- Object
- Bolt::Target
- Defined in:
- lib/bolt/target.rb
Instance Attribute Summary collapse
-
#inventory ⇒ Object
CODEREVIEW: this feels wrong.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#uri ⇒ Object
CODEREVIEW: this feels wrong.
Class Method Summary collapse
- .from_asserted_args(uri, options = nil) ⇒ Object
-
.from_asserted_hash(hash) ⇒ Object
Satisfies the Puppet datatypes API.
Instance Method Summary collapse
- #detail ⇒ Object
-
#eql?(other) ⇒ Boolean
(also: #==)
TODO: WHAT does equality mean here? should we just compare names? is there something else that is meaninful?.
- #facts ⇒ Object
- #features ⇒ Object (also: #feature_set)
- #hash ⇒ Object
- #host ⇒ Object (also: #safe_name)
-
#initialize(uri, options = nil) ⇒ Target
constructor
URI can be passes as nil.
- #name ⇒ Object
- #password ⇒ Object
- #plugin_hooks ⇒ Object
- #port ⇒ Object
- #protocol ⇒ Object
- #remote? ⇒ Boolean
- #target_alias ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
-
#transport ⇒ Object
transport is separate from protocol for remote targets.
- #update_conf(conf) ⇒ Object
- #user ⇒ Object
- #vars ⇒ Object
Constructor Details
#initialize(uri, options = nil) ⇒ Target
URI can be passes as nil
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/bolt/target.rb', line 192 def initialize(uri, = nil) # lazy-load expensive gem code require 'addressable/uri' @uri = uri @uri_obj = parse(uri) @options = || {} @options.freeze if @options['user'] @user = @options['user'] end if @options['password'] @password = @options['password'] end if @options['port'] @port = @options['port'] end if @options['protocol'] @protocol = @options['protocol'] end if @options['host'] @host = @options['host'] end # WARNING: name should never be updated @name = @options['name'] || @uri end |
Instance Attribute Details
#inventory ⇒ Object
CODEREVIEW: this feels wrong. The altertative is threading inventory through the executor to the RemoteTransport
154 155 156 |
# File 'lib/bolt/target.rb', line 154 def inventory @inventory end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
151 152 153 |
# File 'lib/bolt/target.rb', line 151 def @options end |
#uri ⇒ Object
CODEREVIEW: this feels wrong. The altertative is threading inventory through the executor to the RemoteTransport
154 155 156 |
# File 'lib/bolt/target.rb', line 154 def uri @uri end |
Class Method Details
.from_asserted_args(uri, options = nil) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/bolt/target.rb', line 175 def self.from_asserted_args(uri, = nil) if logger = Logging.logger[self] msg = <<~MSG #{Puppet::Pops::PuppetStack.top_of_stack.join(':')} Deprecation Warning: Starting with Bolt 2.0, 'Target.new(<uri>, <options>)' will no longer be supported. Use 'Target.new(<config>)', where 'config' is a hash with the same structure used to define targets in the inventory V2 file. For more information see https://puppet.com/docs/bolt/latest/writing_plans.html#creating-target-objects MSG logger.warn(msg) end new(uri, ) end |
.from_asserted_hash(hash) ⇒ Object
Satisfies the Puppet datatypes API
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/bolt/target.rb', line 159 def self.from_asserted_hash(hash) if hash['uri'] && hash['options'] logger = Logging.logger[self] msg = <<~MSG #{Puppet::Pops::PuppetStack.top_of_stack.join(':')} Deprecation Warning: Starting with Bolt 2.0, using 'Target.new' with an 'options' hash key will no will no longer be supported. Use 'Target.new(<config>)', where 'config' is a hash with the same structure used to define targets in the inventory V2 file. For more information see https://puppet.com/docs/bolt/latest/writing_plans.html#creating-target-objects MSG logger.warn(msg) end new(hash['uri'], hash['options']) end |
Instance Method Details
#detail ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/bolt/target.rb', line 316 def detail { 'name' => name, 'alias' => target_alias, 'config' => { 'transport' => transport, transport => }, 'vars' => vars, 'facts' => facts, 'features' => features.to_a, 'plugin_hooks' => plugin_hooks } end |
#eql?(other) ⇒ Boolean Also known as: ==
TODO: WHAT does equality mean here? should we just compare names? is there something else that is meaninful?
286 287 288 289 290 291 292 |
# File 'lib/bolt/target.rb', line 286 def eql?(other) if self.class.equal?(other.class) @uri ? @uri == other.uri : @name == other.name else false end end |
#facts ⇒ Object
276 277 278 |
# File 'lib/bolt/target.rb', line 276 def facts @inventory.facts(self) end |
#features ⇒ Object Also known as: feature_set
255 256 257 258 259 260 261 |
# File 'lib/bolt/target.rb', line 255 def features if @inventory @inventory.features(self) else Set.new end end |
#hash ⇒ Object
295 296 297 |
# File 'lib/bolt/target.rb', line 295 def hash @uri.hash ^ @options.hash end |
#host ⇒ Object Also known as: safe_name
331 332 333 |
# File 'lib/bolt/target.rb', line 331 def host @uri_obj&.hostname || @host end |
#name ⇒ Object
336 337 338 |
# File 'lib/bolt/target.rb', line 336 def name @name || @uri end |
#password ⇒ Object
361 362 363 |
# File 'lib/bolt/target.rb', line 361 def password Addressable::URI.unencode_component(@uri_obj&.password) || @password end |
#plugin_hooks ⇒ Object
264 265 266 267 268 269 270 |
# File 'lib/bolt/target.rb', line 264 def plugin_hooks if @inventory @inventory.plugin_hooks(self) else {} end end |
#port ⇒ Object
344 345 346 |
# File 'lib/bolt/target.rb', line 344 def port @uri_obj&.port || @port end |
#protocol ⇒ Object
353 354 355 |
# File 'lib/bolt/target.rb', line 353 def protocol @uri_obj&.scheme || @protocol end |
#remote? ⇒ Boolean
340 341 342 |
# File 'lib/bolt/target.rb', line 340 def remote? @uri_obj&.scheme == 'remote' || @protocol == 'remote' end |
#target_alias ⇒ Object
280 281 282 |
# File 'lib/bolt/target.rb', line 280 def target_alias @inventory.target_alias(self) end |
#to_h ⇒ Object
304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/bolt/target.rb', line 304 def to_h .merge( 'name' => name, 'uri' => uri, 'protocol' => protocol, 'user' => user, 'password' => password, 'host' => host, 'port' => port ) end |
#to_s ⇒ Object
299 300 301 302 |
# File 'lib/bolt/target.rb', line 299 def to_s opts = @options.select { |k, _| PRINT_OPTS.include? k } "Target('#{@uri}', #{opts})" end |
#transport ⇒ Object
transport is separate from protocol for remote targets.
349 350 351 |
# File 'lib/bolt/target.rb', line 349 def transport remote? ? 'remote' : protocol end |
#update_conf(conf) ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/bolt/target.rb', line 225 def update_conf(conf) @protocol = conf[:transport] t_conf = conf[:transports][transport.to_sym] || {} # Override url methods @user = t_conf['user'] @password = t_conf['password'] @port = t_conf['port'] @host = t_conf['host'] # Preserve everything in options so we can easily create copies of a Target. @options = t_conf.merge(@options) self end |
#user ⇒ Object
357 358 359 |
# File 'lib/bolt/target.rb', line 357 def user Addressable::URI.unencode_component(@uri_obj&.user) || @user end |
#vars ⇒ Object
272 273 274 |
# File 'lib/bolt/target.rb', line 272 def vars @inventory.vars(self) end |