Class: AugeasProviders::Mounttab::Fstab

Inherits:
Object
  • Object
show all
Defined in:
lib/augeasproviders/mounttab/fstab.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



15
16
17
# File 'lib/augeasproviders/mounttab/fstab.rb', line 15

def resource
  @resource
end

Class Method Details

.atboot(aug, resource) ⇒ Object



113
114
115
# File 'lib/augeasproviders/mounttab/fstab.rb', line 113

def self.atboot(aug, resource)
  resource.should(:atboot)
end

.create(aug, resource) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/augeasproviders/mounttab/fstab.rb', line 48

def self.create(aug, resource)
  aug.set("$resource/spec", resource[:device])
  aug.set("$resource/file", resource[:name])
  aug.set("$resource/vfstype", resource[:fstype])
  insoptions(aug, "$resource", resource)
  aug.set("$resource/dump", resource[:dump].to_s)
  aug.set("$resource/passno", resource[:pass].to_s)
end

.default_fileObject



17
18
19
# File 'lib/augeasproviders/mounttab/fstab.rb', line 17

def self.default_file
  '/etc/fstab'
end

.dump(aug, resource) ⇒ Object



80
81
82
# File 'lib/augeasproviders/mounttab/fstab.rb', line 80

def self.dump(aug, resource)
  aug.get("$target/*[file = '#{resource[:name]}']/dump")
end

.empty_optionsObject



121
122
123
# File 'lib/augeasproviders/mounttab/fstab.rb', line 121

def self.empty_options
  ['', 'defaults']
end

.get_resource(aug, mpath, target) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/augeasproviders/mounttab/fstab.rb', line 25

def self.get_resource(aug, mpath, target)
  entry = {
    :ensure => :present,
    :target => target
  }
  return nil unless entry[:name] = aug.get("#{mpath}/file")
  entry[:device] = aug.get("#{mpath}/spec")
  entry[:fstype] = aug.get("#{mpath}/vfstype")

  options = []
  aug.match("#{mpath}/opt").each do |opath|
    opt = aug.get(opath)
    optv = aug.get("#{opath}/value")
    opt = "#{opt}=#{optv}" if optv
    options << opt
  end
  entry[:options] = options
  entry[:pass] = aug.get("#{mpath}/passno") if aug.match("#{mpath}/passno")
  entry[:dump] = aug.get("#{mpath}/dump") if aug.match("#{mpath}/dump")

  entry
end

.insoptions(aug, entry, resource) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/augeasproviders/mounttab/fstab.rb', line 57

def self.insoptions(aug, entry, resource)
  # Options are defined as a list property, so they get joined with commas.
  # Since Augeas understands elements, access the original array or string.
  values = resource.original_parameters[:options]

  aug.rm("#{entry}/opt")
  insafter = "vfstype"
  if values and not values.empty?
    [values].flatten.each do |opt|
      optk, optv = opt.split("=", 2)
      aug.insert("#{entry}/#{insafter}", "opt", false)
      aug.set("#{entry}/opt[last()]", optk)
      aug.set("#{entry}/opt[last()]/value", optv) if optv
      insafter = "opt[last()]"
    end
  else
    # Strictly this is optional, but only Augeas > 0.10.0 has a lens that
    # knows this is the case, so always fill it in.
    aug.insert("#{entry}/#{insafter}", "opt", false)
    aug.set("#{entry}/opt", "defaults")
  end
end

.lensObject



21
22
23
# File 'lib/augeasproviders/mounttab/fstab.rb', line 21

def self.lens
  'Fstab.lns'
end

.pass(aug, resource) ⇒ Object



94
95
96
# File 'lib/augeasproviders/mounttab/fstab.rb', line 94

def self.pass(aug, resource)
  aug.get("$target/*[file = '#{resource[:name]}']/passno")
end

.set_atboot(aug, resource, value) ⇒ Object



117
118
119
# File 'lib/augeasproviders/mounttab/fstab.rb', line 117

def self.set_atboot(aug, resource, value)
  return
end

.set_dump(aug, resource, value) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/augeasproviders/mounttab/fstab.rb', line 84

def self.set_dump(aug, resource, value)
  # Ensure "defaults" option is always set if dump is being set, as the
  # opts field is optional
  if aug.match("$target/*[file = '#{resource[:name]}']/opt").empty?
    aug.set("$target/*[file = '#{resource[:name]}']/opt", "defaults")
  end

  aug.set("$target/*[file = '#{resource[:name]}']/dump", value.to_s)
end

.set_pass(aug, resource, value) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/augeasproviders/mounttab/fstab.rb', line 98

def self.set_pass(aug, resource, value)
  # Ensure "defaults" option is always set if passno is being set, as the
  # opts field is optional
  if aug.match("$target/*[file = '#{resource[:name]}']/opt").empty?
    aug.set("$target/*[file = '#{resource[:name]}']/opt", "defaults")
  end

  # Ensure dump is always set too
  if aug.match("$target/*[file = '#{resource[:name]}']/dump").empty?
    aug.set("$target/*[file = '#{resource[:name]}']/dump", "0")
  end

  aug.set("$target/*[file = '#{resource[:name]}']/passno", value.to_s)
end