Module: Puppet::ResourceApi::Transport

Defined in:
lib/puppet/resource_api/transport.rb

Overview

Remote target transport API

Defined Under Namespace

Classes: Wrapper

Class Method Summary collapse

Class Method Details

.connect(name, connection_info) ⇒ Object


30
31
32
33
34
35
# File 'lib/puppet/resource_api/transport.rb', line 30

def connect(name, connection_info)
  validate(name, connection_info)
  require "puppet/transport/#{name}"
  class_name = name.split('_').map { |e| e.capitalize }.join
  Puppet::Transport.const_get(class_name).new(get_context(name), wrap_sensitive(name, connection_info))
end

.inject_device(name, transport) ⇒ Object


38
39
40
41
42
43
44
45
46
# File 'lib/puppet/resource_api/transport.rb', line 38

def inject_device(name, transport)
  transport_wrapper = Puppet::ResourceApi::Transport::Wrapper.new(name, transport)

  if Puppet::Util::NetworkDevice.respond_to?(:set_device)
    Puppet::Util::NetworkDevice.set_device(name, transport_wrapper)
  else
    Puppet::Util::NetworkDevice.instance_variable_set(:@current, transport_wrapper)
  end
end

.listObject

retrieve a Hash of transport schemas, keyed by their name.


24
25
26
27
# File 'lib/puppet/resource_api/transport.rb', line 24

def list
  init_transports
  Marshal.load(Marshal.dump(@transports[@environment]))
end

.register(schema) ⇒ Object

Raises:

  • (Puppet::DevError)

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/puppet/resource_api/transport.rb', line 5

def register(schema)
  raise Puppet::DevError, 'requires a hash as schema, not `%{other_type}`' % { other_type: schema.class } unless schema.is_a? Hash
  raise Puppet::DevError, 'requires a `:name`' unless schema.key? :name
  raise Puppet::DevError, 'requires `:desc`' unless schema.key? :desc
  raise Puppet::DevError, 'requires `:connection_info`' unless schema.key? :connection_info
  raise Puppet::DevError, '`:connection_info` must be a hash, not `%{other_type}`' % { other_type: schema[:connection_info].class } unless schema[:connection_info].is_a?(Hash)

  init_transports
  unless @transports[@environment][schema[:name]].nil?
    raise Puppet::DevError, 'Transport `%{name}` is already registered for `%{environment}`' % {
      name: schema[:name],
      environment: @environment,
    }
  end
  @transports[@environment][schema[:name]] = Puppet::ResourceApi::TransportSchemaDef.new(schema)
end