Class: OsCtl::ExportFS::Config::TopLevel

Inherits:
Object
  • Object
show all
Includes:
Lib::Utils::File
Defined in:
lib/osctl/exportfs/config/top_level.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ TopLevel

Returns a new instance of TopLevel.

Parameters:



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/osctl/exportfs/config/top_level.rb', line 35

def initialize(server)
  @server = server
  @path = server.config_file

  if File.exist?(path)
    read_config
  else
    @nfsd = Config::Nfsd.new({})
    @exports = Config::Exports.new([])
  end
end

Instance Attribute Details

#addressString?

Returns:

  • (String, nil)


17
18
19
# File 'lib/osctl/exportfs/config/top_level.rb', line 17

def address
  @address
end

#exportsConfig::Exports (readonly)

Returns:



32
33
34
# File 'lib/osctl/exportfs/config/top_level.rb', line 32

def exports
  @exports
end

#lockd_portInteger?

Returns:

  • (Integer, nil)


26
27
28
# File 'lib/osctl/exportfs/config/top_level.rb', line 26

def lockd_port
  @lockd_port
end

#mountd_portInteger?

Returns:

  • (Integer, nil)


23
24
25
# File 'lib/osctl/exportfs/config/top_level.rb', line 23

def mountd_port
  @mountd_port
end

#netifString

Returns:

  • (String)


48
49
50
# File 'lib/osctl/exportfs/config/top_level.rb', line 48

def netif
  @netif || default_netif
end

#nfsdConfig::Nfsd (readonly)

Returns:



20
21
22
# File 'lib/osctl/exportfs/config/top_level.rb', line 20

def nfsd
  @nfsd
end

#pathString (readonly)

Returns:

  • (String)


11
12
13
# File 'lib/osctl/exportfs/config/top_level.rb', line 11

def path
  @path
end

#serverServer (readonly)

Returns:



8
9
10
# File 'lib/osctl/exportfs/config/top_level.rb', line 8

def server
  @server
end

#statd_portInteger?

Returns:

  • (Integer, nil)


29
30
31
# File 'lib/osctl/exportfs/config/top_level.rb', line 29

def statd_port
  @statd_port
end

Instance Method Details

#default_netifObject (protected)



73
74
75
# File 'lib/osctl/exportfs/config/top_level.rb', line 73

def default_netif
  "nfs-#{server.name}"
end

#dumpObject (protected)



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/osctl/exportfs/config/top_level.rb', line 77

def dump
  {
    'address' => address,
    'netif' => @netif == default_netif ? nil : @netif,
    'nfsd' => nfsd.dump,
    'mountd_port' => mountd_port,
    'lockd_port' => lockd_port,
    'statd_port' => statd_port,
    'exports' => exports.dump
  }
end

#read_configObject (protected)



62
63
64
65
66
67
68
69
70
71
# File 'lib/osctl/exportfs/config/top_level.rb', line 62

def read_config
  data = server.synchronize { OsCtl::Lib::ConfigFile.load_yaml_file(path) }
  @netif = data['netif']
  @address = data['address']
  @nfsd = Config::Nfsd.new(data['nfsd'] || {})
  @mountd_port = data['mountd_port']
  @lockd_port = data['lockd_port']
  @statd_port = data['statd_port']
  @exports = Config::Exports.new(data['exports'] || [])
end

#saveObject



52
53
54
55
56
57
58
# File 'lib/osctl/exportfs/config/top_level.rb', line 52

def save
  server.synchronize do
    regenerate_file(path, 0o644) do |new|
      new.write(OsCtl::Lib::ConfigFile.dump_yaml(dump))
    end
  end
end