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:



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/osctl/exportfs/config/top_level.rb', line 40

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?

Parameters:

  • address (String)

Returns:

  • (String, nil)


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

def address
  @address
end

#exportsConfig::Exports (readonly)

Returns:



37
38
39
# File 'lib/osctl/exportfs/config/top_level.rb', line 37

def exports
  @exports
end

#lockd_portInteger?

Parameters:

  • lockd_port (Integer)

Returns:

  • (Integer, nil)


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

def lockd_port
  @lockd_port
end

#mountd_portInteger?

Parameters:

  • mountd_port (Integer)

Returns:

  • (Integer, nil)


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

def mountd_port
  @mountd_port
end

#netifString

Returns:

  • (String)


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

def netif
  @netif || default_netif
end

#nfsdConfig::Nfsd (readonly)

Returns:



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

def nfsd
  @nfsd
end

#pathString (readonly)

Returns:

  • (String)


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

def path
  @path
end

#serverServer (readonly)

Returns:



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

def server
  @server
end

#statd_portInteger?

Parameters:

  • statd_port (Integer)

Returns:

  • (Integer, nil)


34
35
36
# File 'lib/osctl/exportfs/config/top_level.rb', line 34

def statd_port
  @statd_port
end

Instance Method Details

#default_netifObject (protected)



77
78
79
# File 'lib/osctl/exportfs/config/top_level.rb', line 77

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

#dumpObject (protected)



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/osctl/exportfs/config/top_level.rb', line 81

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)



66
67
68
69
70
71
72
73
74
75
# File 'lib/osctl/exportfs/config/top_level.rb', line 66

def read_config
  data = server.synchronize { YAML.load_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



57
58
59
60
61
62
63
# File 'lib/osctl/exportfs/config/top_level.rb', line 57

def save
  server.synchronize do
    regenerate_file(path, 0644) do |new|
      new.write(YAML.dump(dump))
    end
  end
end