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
- .connect(name, connection_info) ⇒ Object
- .inject_device(name, transport) ⇒ Object
-
.list ⇒ Object
retrieve a Hash of transport schemas, keyed by their name.
-
.list_all_transports(force_environment) ⇒ Object
private
retrieve a Hash of transport schemas, keyed by their name.
- .register(schema) ⇒ Object
Class Method Details
.connect(name, connection_info) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/puppet/resource_api/transport.rb', line 52 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
60 61 62 63 64 65 66 67 68 |
# File 'lib/puppet/resource_api/transport.rb', line 60 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 |
.list ⇒ Object
retrieve a Hash of transport schemas, keyed by their name. Only already loaded transports are returned.
24 25 26 |
# File 'lib/puppet/resource_api/transport.rb', line 24 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 a environment name as ‘force_environment` to choose where to load from.
33 34 35 36 37 38 39 |
# File 'lib/puppet/resource_api/transport.rb', line 33 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
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# 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) unless transports[schema[:name]].nil? raise Puppet::DevError, 'Transport `%{name}` is already registered for `%{environment}`' % { name: schema[:name], environment: current_environment, } end transports[schema[:name]] = Puppet::ResourceApi::TransportSchemaDef.new(schema) end |