Class: OsCtl::ExportFS::Operations::Export::Add
- Includes:
- Lib::Utils::File, Lib::Utils::Log, Lib::Utils::System
- Defined in:
- lib/osctl/exportfs/operations/export/add.rb
Overview
Add export to a NFS server
Instance Attribute Summary collapse
-
#cfg ⇒ Object
readonly
protected
Returns the value of attribute cfg.
-
#export ⇒ Object
readonly
protected
Returns the value of attribute export.
-
#server ⇒ Object
readonly
protected
Returns the value of attribute server.
-
#sys ⇒ Object
readonly
protected
Returns the value of attribute sys.
Instance Method Summary collapse
-
#add_to_exports ⇒ Object
protected
Add the export to the database.
-
#enable_share(propagate: true) ⇒ Object
protected
Propagate the directory from the host to the server using the shared directory and then export it.
- #execute ⇒ Object
-
#initialize(server, export) ⇒ Add
constructor
A new instance of Add.
Methods inherited from Base
Constructor Details
Instance Attribute Details
#cfg ⇒ Object (readonly, protected)
Returns the value of attribute cfg.
45 46 47 |
# File 'lib/osctl/exportfs/operations/export/add.rb', line 45 def cfg @cfg end |
#export ⇒ Object (readonly, protected)
Returns the value of attribute export.
45 46 47 |
# File 'lib/osctl/exportfs/operations/export/add.rb', line 45 def export @export end |
#server ⇒ Object (readonly, protected)
Returns the value of attribute server.
45 46 47 |
# File 'lib/osctl/exportfs/operations/export/add.rb', line 45 def server @server end |
#sys ⇒ Object (readonly, protected)
Returns the value of attribute sys.
45 46 47 |
# File 'lib/osctl/exportfs/operations/export/add.rb', line 45 def sys @sys end |
Instance Method Details
#add_to_exports ⇒ Object (protected)
Add the export to the database
48 49 50 51 |
# File 'lib/osctl/exportfs/operations/export/add.rb', line 48 def add_to_exports cfg.exports << export cfg.save end |
#enable_share(propagate: true) ⇒ Object (protected)
Propagate the directory from the host to the server using the shared directory and then export it
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/osctl/exportfs/operations/export/add.rb', line 55 def enable_share(propagate: true) if propagate hash = Digest::SHA2.hexdigest(export.dir) shared = File.join(server.shared_dir, hash) Dir.mkdir(shared) sys.bind_mount(export.dir, shared) end begin Operations::Server::Exec.run(server) do server.enter_ns if propagate FileUtils.mkdir_p(export.as) sys.move_mount( File.join(RunState::CURRENT_SERVER, 'shared', hash), export.as ) Operations::Exportfs::Generate.run(server) end syscmd("exportfs -i -o \"#{export.}\" \"#{export.host}:#{export.as}\"") end ensure if propagate sys.unmount(shared) Dir.rmdir(shared) end end end |
#execute ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/osctl/exportfs/operations/export/add.rb', line 23 def execute unless Dir.exist?(export.dir) raise "dir #{export.dir} not found" end ex = cfg.exports.find_by_as(export.as) if ex && ex.dir != export.dir raise "source directory mismatch: expected '#{ex.dir}', got '#{export.dir}'" elsif ex && ex.host == export.host raise "export of #{export.as} to #{export.host} already exists" end add_to_exports return unless server.running? enable_share(propagate: ex.nil?) end |