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
18
19
# File 'lib/osctl/exportfs/operations/server/create.rb', line 14

def initialize(name, opts = {})
  super()
  @server = Server.new(name)
  @opts = opts
  @sys = OsCtl::Lib::Sys.new
end

Instance Attribute Details

#optsObject (readonly, protected)

Returns the value of attribute opts.



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

def opts
  @opts
end

#serverObject (readonly, protected)

Returns the value of attribute server.



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

def server
  @server
end

#sysObject (readonly, protected)

Returns the value of attribute sys.



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

def sys
  @sys
end

Instance Method Details

#executeObject



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

def execute
  if Dir.exist?(server.dir)
    raise '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.new(server.exports_file, 'w').close
  end
end

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

Forcefully create a symlink be removing existing ‘dst`



51
52
53
54
# File 'lib/osctl/exportfs/operations/server/create.rb', line 51

def symlink!(src, dst)
  FileUtils.rm_f(dst)
  File.symlink(src, dst)
end