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



73
74
75
76
77
78
# File 'lib/puppet/resource_api/transport.rb', line 73

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



81
82
83
84
85
86
87
88
89
# File 'lib/puppet/resource_api/transport.rb', line 81

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. Only already loaded transports are returned. use Puppet::Util::Autoload.new(self, ‘puppet/transport/schema’).loadall(current_environment) to load all transport schemas note that loadall uses ‘require` and thus does not re-load changed files, nor does it re-populate the internal cache



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

def list
  Marshal.load(Marshal.dump(transports))
end

.list_all_transports(force_environment) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

retrieve a Hash of transport schemas, keyed by their name. This uses the Puppet autoloader, provide an environment name as ‘force_environment` to choose where to load from.



42
43
44
45
46
47
48
# File 'lib/puppet/resource_api/transport.rb', line 42

def list_all_transports(force_environment)
  env = Puppet.lookup(:environments).get!(force_environment)
  Puppet.override({ current_environment: env }, 'current env for list_all_transports') do
    load_all_schemas
    Marshal.load(Marshal.dump(transports))
  end
end

.register(schema) ⇒ Object

Raises:

  • (Puppet::DevError)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/puppet/resource_api/transport.rb', line 7

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)
  if schema[:connection_info_order].nil?
    schema[:connection_info_order] = schema[:connection_info].keys
  else
    raise Puppet::DevError, '`:connection_info_order` must be an array, not `%{other_type}`' % { other_type: schema[:connection_info_order].class } unless schema[:connection_info_order].is_a?(Array)
  end

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