Class: OsCtl::ExportFS::Operations::Server::Create

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

Overview

Create the server configuration

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

run

Constructor Details

#initialize(name, opts = {}) ⇒ Create

Returns a new instance of Create.

Parameters:

  • name (String)
  • opts (Hash) (defaults to: {})

    options

Options Hash (opts):

  • :options (Hash)


14
15
16
17
# File 'lib/osctl/exportfs/operations/server/create.rb', line 14

def initialize(name, opts = {})
  @server = Server.new(name)
  @opts = opts
end

Instance Attribute Details

#optsObject (readonly, protected)

Returns the value of attribute opts.



45
46
47
# File 'lib/osctl/exportfs/operations/server/create.rb', line 45

def opts
  @opts
end

#serverObject (readonly, protected)

Returns the value of attribute server.



45
46
47
# File 'lib/osctl/exportfs/operations/server/create.rb', line 45

def server
  @server
end

Instance Method Details

#executeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/osctl/exportfs/operations/server/create.rb', line 19

def execute
  if Dir.exist?(server.dir)
    fail 'server already exists'
  end

  FileUtils.mkdir_p(server.dir)

  server.synchronize do
    FileUtils.mkdir_p(server.nfs_state)

    # Remount the shared dir with --make-shared
    unless Dir.exist?(server.shared_dir)
      FileUtils.mkdir_p(server.shared_dir)
      Sys.bind_mount(server.shared_dir, server.shared_dir)
      Sys.make_shared(server.shared_dir)
    end

    # Initialize the config file
    Operations::Server::Configure.run(server, opts[:options])

    # Create an empty exports file
    File.open(server.exports_file, 'w'){}
  end
end

#symlink!(src, dst) ⇒ Object (protected)

Forcefully create a symlink be removing existing `dst`



48
49
50
51
# File 'lib/osctl/exportfs/operations/server/create.rb', line 48

def symlink!(src, dst)
  File.unlink(dst) if File.exist?(dst)
  File.symlink(src, dst)
end