Class: OsCtl::ExportFS::Operations::Export::Remove

Inherits:
Base
  • Object
show all
Includes:
Lib::Utils::File, Lib::Utils::Log, Lib::Utils::System
Defined in:
lib/osctl/exportfs/operations/export/remove.rb

Overview

Remove export from a NFS server

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

run

Constructor Details

#initialize(server, as, host) ⇒ Remove

Returns a new instance of Remove.

Parameters:

  • server (Server)
  • as (String)
  • host (String)


15
16
17
18
19
20
# File 'lib/osctl/exportfs/operations/export/remove.rb', line 15

def initialize(server, as, host)
  @server = server
  @cfg = server.open_config
  @export = cfg.exports.lookup(as, host)
  @sys = OsCtl::Lib::Sys.new
end

Instance Attribute Details

#cfgObject (readonly, protected)

Returns the value of attribute cfg.



33
34
35
# File 'lib/osctl/exportfs/operations/export/remove.rb', line 33

def cfg
  @cfg
end

#exportObject (readonly, protected)

Returns the value of attribute export.



33
34
35
# File 'lib/osctl/exportfs/operations/export/remove.rb', line 33

def export
  @export
end

#serverObject (readonly, protected)

Returns the value of attribute server.



33
34
35
# File 'lib/osctl/exportfs/operations/export/remove.rb', line 33

def server
  @server
end

#sysObject (readonly, protected)

Returns the value of attribute sys.



33
34
35
# File 'lib/osctl/exportfs/operations/export/remove.rb', line 33

def sys
  @sys
end

Instance Method Details

#disable_share(unmount: true) ⇒ Object (protected)

Unexport and unmount the directory from the server namespace



42
43
44
45
46
47
48
49
# File 'lib/osctl/exportfs/operations/export/remove.rb', line 42

def disable_share(unmount: true)
  Operations::Server::Exec.run(server) do
    server.enter_ns
    Operations::Exportfs::Generate.run(server)
    syscmd("exportfs -u \"#{export.host}:#{export.as}\"")
    sys.unmount(export.as) if unmount
  end
end

#executeObject



22
23
24
25
26
27
28
29
30
# File 'lib/osctl/exportfs/operations/export/remove.rb', line 22

def execute
  return if export.nil?

  remove_from_exports

  if server.running?
    disable_share(unmount: cfg.exports.find_by_as(export.as).nil?)
  end
end

#remove_from_exportsObject (protected)

Remove the export from the database



36
37
38
39
# File 'lib/osctl/exportfs/operations/export/remove.rb', line 36

def remove_from_exports
  cfg.exports.remove(export)
  cfg.save
end