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.
43 44 45 |
# File 'lib/osctl/exportfs/operations/export/add.rb', line 43 def cfg @cfg end |
#export ⇒ Object (readonly, protected)
Returns the value of attribute export.
43 44 45 |
# File 'lib/osctl/exportfs/operations/export/add.rb', line 43 def export @export end |
#server ⇒ Object (readonly, protected)
Returns the value of attribute server.
43 44 45 |
# File 'lib/osctl/exportfs/operations/export/add.rb', line 43 def server @server end |
#sys ⇒ Object (readonly, protected)
Returns the value of attribute sys.
43 44 45 |
# File 'lib/osctl/exportfs/operations/export/add.rb', line 43 def sys @sys end |
Instance Method Details
#add_to_exports ⇒ Object (protected)
Add the export to the database
46 47 48 49 |
# File 'lib/osctl/exportfs/operations/export/add.rb', line 46 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
53 54 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 |
# File 'lib/osctl/exportfs/operations/export/add.rb', line 53 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
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/osctl/exportfs/operations/export/add.rb', line 22 def execute if !Dir.exist?(export.dir) fail "dir #{export.dir} not found" end ex = cfg.exports.find_by_as(export.as) if ex && ex.dir != export.dir fail "source directory mismatch: expected '#{ex.dir}', got '#{export.dir}'" elsif ex && ex.host == export.host fail "export of #{export.as} to #{export.host} already exists" end add_to_exports if server.running? enable_share(propagate: ex.nil?) end end |