Class: OsCtl::ExportFS::Cli::Server

Inherits:
Command
  • Object
show all
Defined in:
lib/osctl/exportfs/cli/server.rb

Constant Summary collapse

FIELDS =
%i[server state netif address].freeze

Instance Method Summary collapse

Methods inherited from Command

#initialize, run

Constructor Details

This class inherits a constructor from OsCtl::ExportFS::Cli::Command

Instance Method Details

#attachObject



81
82
83
84
# File 'lib/osctl/exportfs/cli/server.rb', line 81

def attach
  require_args!('name')
  OsCtl::ExportFS::Operations::Server::Attach.run(args[0])
end

#createObject



37
38
39
40
41
42
43
# File 'lib/osctl/exportfs/cli/server.rb', line 37

def create
  require_args!('name')
  OsCtl::ExportFS::Operations::Server::Create.run(
    args[0],
    options: server_options
  )
end

#deleteObject



45
46
47
48
# File 'lib/osctl/exportfs/cli/server.rb', line 45

def delete
  require_args!('name')
  OsCtl::ExportFS::Operations::Server::Delete.run(args[0])
end

#listObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/osctl/exportfs/cli/server.rb', line 8

def list
  if opts[:list]
    puts FIELDS.join("\n")
    return
  end

  fmt_opts = {
    layout: :columns,
    cols: opts[:output] ? opts[:output].split(',').map(&:to_sym) : FIELDS,
    sort: opts[:sort] && opts[:sort].split(',').map(&:to_sym)
  }

  fmt_opts[:header] = false if opts['hide-header']

  OsCtl::Lib::Cli::OutputFormatter.print(
    OsCtl::ExportFS::Operations::Server::List.run.map do |s|
      cfg = s.open_config

      {
        server: s.name,
        state: s.running? ? 'running' : 'stopped',
        netif: cfg.netif,
        address: cfg.address
      }
    end,
    **fmt_opts
  )
end

#parse_nfs_versions(opt) ⇒ Object (protected)



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/osctl/exportfs/cli/server.rb', line 106

def parse_nfs_versions(opt)
  return if opt.nil?

  ret = opt.split(',')
  choices = OsCtl::ExportFS::Config::Nfsd::VERSIONS

  ret.each do |v|
    unless choices.include?(v)
      raise "invalid NFS version '#{v}', possible values are: #{choices.join(', ')}"
    end
  end

  ret
end

#restartObject



70
71
72
73
74
# File 'lib/osctl/exportfs/cli/server.rb', line 70

def restart
  require_args!('name')
  runsv = OsCtl::ExportFS::Operations::Server::Runsv.new(args[0])
  runsv.restart
end

#server_optionsObject (protected)



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/osctl/exportfs/cli/server.rb', line 88

def server_options
  {
    address: opts['address'],
    netif: opts['netif'],
    nfsd: {
      port: opts['nfsd-port'],
      nproc: opts['nfsd-nproc'],
      tcp: opts['nfsd-tcp'],
      udp: opts['nfsd-udp'],
      versions: parse_nfs_versions(opts['nfs-versions']),
      syslog: opts['nfsd-syslog']
    },
    mountd_port: opts['mountd-port'],
    lockd_port: opts['lockd-port'],
    statd_port: opts['statd-port']
  }
end

#setObject



50
51
52
53
54
55
56
# File 'lib/osctl/exportfs/cli/server.rb', line 50

def set
  require_args!('name')
  OsCtl::ExportFS::Operations::Server::Configure.run(
    OsCtl::ExportFS::Server.new(args[0]),
    server_options
  )
end

#spawnObject



76
77
78
79
# File 'lib/osctl/exportfs/cli/server.rb', line 76

def spawn
  require_args!('name')
  OsCtl::ExportFS::Operations::Server::Spawn.run(args[0])
end

#startObject



58
59
60
61
62
# File 'lib/osctl/exportfs/cli/server.rb', line 58

def start
  require_args!('name')
  runsv = OsCtl::ExportFS::Operations::Server::Runsv.new(args[0])
  runsv.start
end

#stopObject



64
65
66
67
68
# File 'lib/osctl/exportfs/cli/server.rb', line 64

def stop
  require_args!('name')
  runsv = OsCtl::ExportFS::Operations::Server::Runsv.new(args[0])
  runsv.stop
end