Class: Puppet::Provider::NetworkDevice

Inherits:
Puppet::Provider show all
Defined in:
lib/puppet/provider/network_device.rb

Overview

This is the base class of all prefetched network device provider

Constant Summary

Constants inherited from Puppet::Provider

Confine

Constants included from Util

Util::ALNUM, Util::ALPHA, Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE, Util::ESCAPED, Util::HEX, Util::HttpProxy, Util::PUPPET_STACK_INSERTION_FRAME, Util::RESERVED, Util::RFC_3986_URI_REGEX, Util::UNRESERVED, Util::UNSAFE

Constants included from Util::POSIX

Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS

Constants included from Util::SymbolicFileMode

Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit

Constants included from Util::Docs

Util::Docs::HEADER_LEVELS

Instance Attribute Summary collapse

Attributes inherited from Puppet::Provider

#resource

Attributes included from Util::Docs

#doc, #nodoc

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Puppet::Provider

#<=>, #clear, command, #command, commands, declared_feature?, default?, default_match, defaultfor, execpipe, #execpipe, execute, #execute, fact_match, feature_match, #get, has_command, initvars, #inspect, mk_resource_methods, #name, notdefaultfor, optional_commands, post_resource_eval, #set, some_default_match, specificity, supports_parameter?, #to_s

Methods included from Util::Logging

#clear_deprecation_warnings, #debug, #deprecation_warning, #format_backtrace, #format_exception, #get_deprecation_offender, #log_and_raise, #log_deprecations_to_file, #log_exception, #puppet_deprecation_warning, #send_log, setup_facter_logging!, #warn_once

Methods included from Util

absolute_path?, benchmark, chuser, clear_environment, create_erb, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, format_backtrace_array, format_puppetstack_frame, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, resolve_stackframe, rfc2396_escape, safe_posix_fork, set_env, skip_external_facts, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, uri_unescape, which, withenv, withumask

Methods included from Util::POSIX

#get_posix_field, #gid, groups_of, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid

Methods included from Util::SymbolicFileMode

#display_mode, #normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?

Methods included from Util::Docs

#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub

Methods included from Util::Warnings

clear_warnings, debug_once, maybe_log, notice_once, warnonce

Methods included from Confiner

#confine, #confine_collection, #suitable?

Methods included from Util::Errors

#adderrorcontext, #devfail, #error_context, error_location, error_location_with_space, error_location_with_unknowns, #exceptwrap, #fail

Constructor Details

#initialize(device, *args) ⇒ NetworkDevice

Returns a new instance of NetworkDevice.



36
37
38
39
40
41
42
43
44
# File 'lib/puppet/provider/network_device.rb', line 36

def initialize(device, *args)
  super(*args)

  @device = device

  # Make a duplicate, so that we have a copy for comparison
  # at the end.
  @properties = @property_hash.dup
end

Instance Attribute Details

#deviceObject



34
35
36
# File 'lib/puppet/provider/network_device.rb', line 34

def device
  @device
end

Class Method Details

.device(url) ⇒ Object



5
6
7
# File 'lib/puppet/provider/network_device.rb', line 5

def self.device(url)
  raise "This provider doesn't implement the necessary device method"
end

.instancesObject



64
65
# File 'lib/puppet/provider/network_device.rb', line 64

def self.instances
end

.lookup(device, name) ⇒ Object



9
10
11
# File 'lib/puppet/provider/network_device.rb', line 9

def self.lookup(device, name)
  raise "This provider doesn't implement the necessary lookup method"
end

.prefetch(resources) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/puppet/provider/network_device.rb', line 13

def self.prefetch(resources)
  resources.each do |name, resource|
    device = Puppet::Util::NetworkDevice.current || device(resource[:device_url])
    result = lookup(device, name)
    if result
      result[:ensure] = :present
      resource.provider = new(device, result)
    else
      resource.provider = new(device, :ensure => :absent)
    end
  end
rescue => detail
  # Preserving behavior introduced in #6907
  # TRANSLATORS "prefetch" is a program name and should not be translated
  Puppet.log_exception(detail, _("Could not perform network device prefetch: %{detail}") % { detail: detail })
end

Instance Method Details

#createObject



46
47
48
49
50
51
52
53
54
# File 'lib/puppet/provider/network_device.rb', line 46

def create
  @property_hash[:ensure] = :present
  self.class.resource_type.validproperties.each do |property|
    val = resource.should(property)
    if val
      @property_hash[property] = val
    end
  end
end

#destroyObject



56
57
58
# File 'lib/puppet/provider/network_device.rb', line 56

def destroy
  @property_hash[:ensure] = :absent
end

#exists?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/puppet/provider/network_device.rb', line 30

def exists?
  @property_hash[:ensure] != :absent
end

#flushObject



60
61
62
# File 'lib/puppet/provider/network_device.rb', line 60

def flush
  @property_hash.clear
end

#former_propertiesObject



67
68
69
# File 'lib/puppet/provider/network_device.rb', line 67

def former_properties
  @properties.dup
end

#propertiesObject



71
72
73
# File 'lib/puppet/provider/network_device.rb', line 71

def properties
  @property_hash.dup
end