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)

Instance Attribute Summary

Attributes inherited from Command

#args, #gopts, #opts

Instance Method Summary collapse

Methods inherited from Command

#initialize, #require_args!, run

Constructor Details

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

Instance Method Details

#attachObject



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

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

#createObject



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

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

#deleteObject



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

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
36
# File 'lib/osctl/exportfs/cli/server.rb', line 8

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

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

  fmt_opts[:header] = false if opts['hide-header']
  cols = opts[:output] ? opts[:output].split(',').map(&:to_sym) : FIELDS

  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,
    cols,
    **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)
      fail "invalid NFS version '#{v}', possible values are: #{choices.join(', ')}"
    end
  end

  ret
end

#restartObject



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

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



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

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

#spawnObject



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

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

#startObject



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

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

#stopObject



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

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