kanrisuru 0.14.0 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -0
  3. data/README.md +5 -5
  4. data/kanrisuru.gemspec +7 -3
  5. data/lib/kanrisuru/command.rb +16 -3
  6. data/lib/kanrisuru/core/apt/parsers/base.rb +1 -1
  7. data/lib/kanrisuru/core/disk/commands/lsblk.rb +6 -11
  8. data/lib/kanrisuru/core/disk/constants.rb +9 -0
  9. data/lib/kanrisuru/core/disk/parser.rb +1 -0
  10. data/lib/kanrisuru/core/disk/parsers/lsblk_version.rb +21 -0
  11. data/lib/kanrisuru/core/disk.rb +1 -0
  12. data/lib/kanrisuru/core/dmi/commands/dmi.rb +1 -1
  13. data/lib/kanrisuru/core/file/commands/chmod.rb +1 -1
  14. data/lib/kanrisuru/core/file/commands/copy.rb +1 -3
  15. data/lib/kanrisuru/core/file/commands/mkdir.rb +11 -6
  16. data/lib/kanrisuru/core/file/commands/rm.rb +4 -1
  17. data/lib/kanrisuru/core/file/commands/touch.rb +2 -1
  18. data/lib/kanrisuru/core/ip/commands/address.rb +64 -47
  19. data/lib/kanrisuru/core/ip/commands/address_label.rb +32 -16
  20. data/lib/kanrisuru/core/ip/commands/link.rb +96 -54
  21. data/lib/kanrisuru/core/ip/commands/link_set_opts.rb +61 -0
  22. data/lib/kanrisuru/core/ip/commands/link_type_opts.rb +313 -0
  23. data/lib/kanrisuru/core/ip/commands/maddress.rb +22 -13
  24. data/lib/kanrisuru/core/ip/commands/neighbour.rb +49 -32
  25. data/lib/kanrisuru/core/ip/commands/route.rb +130 -93
  26. data/lib/kanrisuru/core/ip/commands/rule.rb +37 -22
  27. data/lib/kanrisuru/core/ip/commands.rb +5 -3
  28. data/lib/kanrisuru/core/ip/constants.rb +12 -0
  29. data/lib/kanrisuru/core/ip/parser.rb +1 -0
  30. data/lib/kanrisuru/core/ip/parsers/version.rb +15 -0
  31. data/lib/kanrisuru/core/ip.rb +10 -7
  32. data/lib/kanrisuru/core/system/commands/kill.rb +1 -1
  33. data/lib/kanrisuru/core/user/commands/create_user.rb +9 -17
  34. data/lib/kanrisuru/core/user/commands/delete_user.rb +1 -1
  35. data/lib/kanrisuru/core/user/commands/update_user.rb +14 -23
  36. data/lib/kanrisuru/core/zypper/commands/add_repo.rb +1 -8
  37. data/lib/kanrisuru/core/zypper/commands/add_service.rb +4 -2
  38. data/lib/kanrisuru/core/zypper/commands/info.rb +1 -2
  39. data/lib/kanrisuru/core/zypper/commands/install.rb +2 -3
  40. data/lib/kanrisuru/core/zypper/commands/modify_repo.rb +1 -7
  41. data/lib/kanrisuru/core/zypper/commands/modify_service.rb +3 -1
  42. data/lib/kanrisuru/core/zypper/commands/remove.rb +1 -2
  43. data/lib/kanrisuru/core/zypper/commands/remove_repo.rb +3 -3
  44. data/lib/kanrisuru/core/zypper/commands/remove_service.rb +6 -1
  45. data/lib/kanrisuru/core/zypper/commands/search.rb +1 -3
  46. data/lib/kanrisuru/core/zypper/commands/source_install.rb +2 -0
  47. data/lib/kanrisuru/core/zypper/commands.rb +10 -1
  48. data/lib/kanrisuru/os_package.rb +2 -0
  49. data/lib/kanrisuru/remote/host.rb +1 -3
  50. data/lib/kanrisuru/result.rb +15 -0
  51. data/lib/kanrisuru/version.rb +1 -1
  52. data/spec/functional/core/archive_spec.rb +1 -1
  53. data/spec/functional/core/disk_spec.rb +77 -0
  54. data/spec/functional/core/dmi_spec.rb +78 -0
  55. data/spec/functional/core/file_spec.rb +284 -0
  56. data/spec/functional/core/group_spec.rb +62 -0
  57. data/spec/functional/core/ip_address_label_spec.rb +81 -0
  58. data/spec/functional/core/ip_address_spec.rb +95 -0
  59. data/spec/functional/core/ip_link_spec.rb +814 -0
  60. data/spec/functional/core/ip_maddress_spec.rb +78 -0
  61. data/spec/functional/core/ip_neighbour_spec.rb +119 -0
  62. data/spec/functional/core/ip_route_spec.rb +174 -0
  63. data/spec/functional/core/ip_rule_spec.rb +75 -0
  64. data/spec/functional/core/ip_spec.rb +27 -0
  65. data/spec/functional/core/system_spec.rb +135 -0
  66. data/spec/functional/core/user_spec.rb +97 -0
  67. data/spec/functional/core/zypper_spec.rb +708 -0
  68. data/spec/functional/result_spec.rb +91 -44
  69. data/spec/helper/stub_network.rb +7 -3
  70. data/spec/support/shared_examples/integration/core/transfer.rb +1 -1
  71. data/spec/unit/command_spec.rb +2 -0
  72. data/spec/unit/core/ip_spec.rb +12 -0
  73. metadata +25 -4
@@ -5,50 +5,67 @@ module Kanrisuru
5
5
  module IP
6
6
  def ip_neighbour(action, opts)
7
7
  case action
8
+ when 'show', 'list'
9
+ version = ip_version.to_i
10
+ command = ip_neighbour_show(opts, version)
8
11
  when 'add', 'change', 'replace', 'del', 'delete'
9
- command = Kanrisuru::Command.new('ip neighbour')
10
- command << action
12
+ command = ip_neighbour_modify(action, opts)
13
+ when 'flush'
14
+ command = ip_neighbour_flush(opts)
15
+ end
11
16
 
12
- command.append_arg('to', opts[:to])
13
- command.append_arg('dev', opts[:dev])
17
+ execute_shell(command)
14
18
 
15
- if action != 'del' && action != 'delete'
16
- command.append_arg('lladdr', opts[:lladdr])
17
- command.append_arg('nud', opts[:nud])
18
- end
19
+ Kanrisuru::Result.new(command) do |cmd|
20
+ Parser::Neighbour.parse(cmd, action, version)
21
+ end
22
+ end
19
23
 
20
- command.append_flag('permanent', opts[:permanent])
21
- command.append_flag('noarp', opts[:noarp])
22
- command.append_flag('reachable', opts[:reachable])
23
- command.append_flag('stale', opts[:stale])
24
- when 'show', 'list'
25
- version = ip_version
24
+ def ip_neighbour_show(opts, version)
25
+ command = Kanrisuru::Command.new('ip')
26
+ command.append_flag('-json') if version >= IPROUTE2_JSON_VERSION
27
+ command.append_flag('-s', opts[:stats])
26
28
 
27
- command = Kanrisuru::Command.new('ip')
28
- command.append_flag('-json') if version >= Kanrisuru::Core::IP::IPROUTE2_JSON_VERSION
29
- command.append_flag('-s', opts[:stats])
29
+ command << 'neighbour show'
30
30
 
31
- command << 'neighbour show'
31
+ command.append_arg('to', opts[:to])
32
+ command.append_arg('dev', opts[:dev])
33
+ command.append_arg('nud', opts[:nud])
32
34
 
33
- command.append_arg('to', opts[:to])
34
- command.append_arg('dev', opts[:dev])
35
- command.append_arg('nud', opts[:nud])
35
+ command.append_flag('proxy', opts[:proxy])
36
+ command.append_flag('unused', opts[:unused])
37
+ command
38
+ end
36
39
 
37
- command.append_flag('unused', opts[:unused])
38
- when 'flush'
39
- command = Kanrisuru::Command.new('ip neighbour flush')
40
- command.append_arg('to', opts[:to])
41
- command.append_arg('dev', opts[:dev])
42
- command.append_arg('nud', opts[:nud])
40
+ def ip_neighbour_modify(action, opts)
41
+ command = Kanrisuru::Command.new('ip neighbour')
42
+ command << action
43
+
44
+ command.append_arg('to', opts[:to])
45
+ command.append_arg('dev', opts[:dev])
43
46
 
44
- command.append_flag('unused', opts[:unused])
47
+ if action != 'del' && action != 'delete'
48
+ command.append_arg('lladdr', opts[:lladdr])
49
+ command.append_arg('nud', opts[:nud])
45
50
  end
46
51
 
47
- execute_shell(command)
52
+ command.append_flag('proxy', opts[:proxy])
53
+ command.append_flag('router', opts[:router])
54
+ command.append_flag('extern_learn', opts[:extern_learn])
55
+ command
56
+ end
48
57
 
49
- Kanrisuru::Result.new(command) do |cmd|
50
- Parser::Neighbour.parse(cmd, action, version)
51
- end
58
+ def ip_neighbour_flush(opts)
59
+ command = Kanrisuru::Command.new('ip')
60
+ command.append_flag('-s', opts[:stats])
61
+ command << 'neighbour flush'
62
+
63
+ command.append_arg('to', opts[:to])
64
+ command.append_arg('dev', opts[:dev])
65
+ command.append_arg('nud', opts[:nud])
66
+
67
+ command.append_flag('unused', opts[:unused])
68
+ command
52
69
  end
53
70
  end
54
71
  end
@@ -6,109 +6,146 @@ module Kanrisuru
6
6
  def ip_route(action, opts)
7
7
  case action
8
8
  when 'show', 'list'
9
- version = ip_version
10
-
11
- command = Kanrisuru::Command.new('ip')
12
- command.append_flag('-json') if version >= IPROUTE2_JSON_VERSION
13
- command.append_arg('-family', opts[:family])
14
- command << 'route show'
15
-
16
- command.append_arg('to', opts[:to])
17
- command.append_arg('dev', opts[:dev])
18
- command.append_arg('proto', opts[:proto])
19
- command.append_arg('type', opts[:type])
20
- command.append_arg('via', opts[:via])
21
- command.append_arg('src', opts[:src])
22
- command.append_arg('realms', opts[:realms])
9
+ version = ip_version.to_i
10
+ command = ip_route_show(opts, version)
23
11
  when 'flush'
24
- command = Kanrisuru::Command.new('ip')
25
- command.append_arg('-family', opts[:family])
26
- command << 'route flush'
27
-
28
- command.append_arg('to', opts[:to])
29
- command.append_arg('dev', opts[:dev])
30
- command.append_arg('proto', opts[:proto])
31
- command.append_arg('type', opts[:type])
32
- command.append_arg('via', opts[:via])
33
- command.append_arg('src', opts[:src])
34
- command.append_arg('realm', opts[:realm])
35
- command.append_arg('realms', opts[:realm])
36
- when 'add', 'change', 'append', 'del', 'delete'
37
- command = Kanrisuru::Command.new('ip route')
38
- command << action
39
-
40
- command.append_arg('to', opts[:to])
41
- command.append_arg('tos', opts[:tos])
42
- command.append_arg('dsfield', opts[:dsfield])
43
- command.append_arg('metric', opts[:metric])
44
- command.append_arg('preference', opts[:preference])
45
- command.append_arg('table', opts[:table])
46
- command.append_arg('vrf', opts[:vrf])
47
- command.append_arg('dev', opts[:dev])
48
- command.append_arg('via', opts[:via])
49
- command.append_arg('src', opts[:src])
50
- command.append_arg('realm', opts[:realm])
51
-
52
- command.append_arg('mtu', opts[:mtu])
53
- command.append_arg('window', opts[:window])
54
- command.append_arg('rtt', opts[:rtt])
55
- command.append_arg('rttvar', opts[:rttvar])
56
- command.append_arg('rto_min', opts[:rto_min])
57
- command.append_arg('ssthresh', opts[:ssthresh])
58
- command.append_arg('cwnd', opts[:cwnd])
59
- command.append_arg('initcwnd', opts[:initcwnd])
60
- command.append_arg('initrwnd', opts[:initrwnd])
61
- command.append_arg('features', opts[:features])
62
- command.append_arg('quickack', opts[:quickack])
63
- command.append_arg('fastopen_no_cookie', opts[:fastopen_no_cookie])
64
-
65
- if Kanrisuru::Util.present?(opts[:congctl])
66
- if Kanrisuru::Util.present?(opts[:congctl_lock])
67
- command.append_arg('congctl', opts[:congctl])
68
- else
69
- command.append_arg('congctl lock', opts[:congctl])
70
- end
71
- end
12
+ command = ip_route_flush(opts)
13
+ when 'add', 'change', 'append', 'del', 'delete', 'replace'
14
+ command = ip_route_modify(action, opts)
15
+ when 'get'
16
+ command = ip_route_get(opts)
17
+ end
18
+
19
+ execute_shell(command)
20
+
21
+ Kanrisuru::Result.new(command) do |cmd|
22
+ Parser::Route.parse(cmd, action, version)
23
+ end
24
+ end
25
+
26
+ def ip_route_show(opts, version)
27
+ command = Kanrisuru::Command.new('ip')
28
+ command.append_flag('-json') if version >= IPROUTE2_JSON_VERSION
29
+ command.append_arg('-family', opts[:family])
30
+ command << 'route show'
31
+
32
+ ip_route_common_opts(command, opts)
33
+
34
+ command
35
+ end
72
36
 
73
- command.append_arg('advmss', opts[:advmss])
74
- command.append_arg('reordering', opts[:reordering])
37
+ def ip_route_modify(action, opts)
38
+ command = Kanrisuru::Command.new('ip route')
39
+ command << action
75
40
 
76
- if Kanrisuru::Util.present?(opts[:next_hop])
77
- next_hop = opts[:next_hop]
41
+ command.append_arg('to', opts[:to])
42
+ command.append_arg('tos', opts[:tos])
43
+ command.append_arg('dsfield', opts[:dsfield])
44
+ command.append_arg('metric', opts[:metric])
45
+ command.append_arg('preference', opts[:preference])
46
+ command.append_arg('table', opts[:table])
47
+ command.append_arg('vrf', opts[:vrf])
48
+ command.append_arg('dev', opts[:dev])
49
+ command.append_arg('via', opts[:via])
50
+ command.append_arg('src', opts[:src])
51
+ command.append_arg('realm', opts[:realm])
78
52
 
79
- command << 'next_hop'
80
- command.append_arg('via', next_hop[:via])
81
- command.append_arg('dev', next_hop[:dev])
82
- command.append_arg('weight', next_hop[:weight])
53
+ if Kanrisuru::Util.present?(opts[:mtu])
54
+ if Kanrisuru::Util.present?(opts[:mtu_lock])
55
+ command.append_arg('mtu lock', opts[:mtu])
56
+ else
57
+ command.append_arg('mtu', opts[:mtu])
83
58
  end
59
+ end
84
60
 
85
- command.append_arg('scope', opts[:scope])
86
- command.append_arg('protocol', opts[:protocol])
87
- command.append_flag('onlink', opts[:onlink])
88
- command.append_arg('pref', opts[:pref])
89
- when 'get'
90
- command = Kanrisuru::Command.new('ip route get')
91
-
92
- command.append_arg('to', opts[:to])
93
- command.append_arg('from', opts[:from])
94
- command.append_arg('tos', opts[:tos])
95
- command.append_arg('dsfield', opts[:dsfield])
96
- command.append_arg('iif', opts[:iif])
97
- command.append_arg('oif', opts[:oif])
98
- command.append_arg('mark', opts[:mark])
99
- command.append_arg('vrf', opts[:vrf])
100
- command.append_arg('ipproto', opts[:ipproto])
101
- command.append_arg('sport', opts[:sport])
102
- command.append_arg('dport', opts[:dport])
103
-
104
- command.append_flag('connected', opts[:connected])
61
+ command.append_arg('window', opts[:window])
62
+ command.append_arg('rtt', opts[:rtt])
63
+ command.append_arg('rttvar', opts[:rttvar])
64
+ command.append_arg('rto_min', opts[:rto_min])
65
+ command.append_arg('ssthresh', opts[:ssthresh])
66
+ command.append_arg('cwnd', opts[:cwnd])
67
+ command.append_arg('initcwnd', opts[:initcwnd])
68
+ command.append_arg('initrwnd', opts[:initrwnd])
69
+ command.append_arg('features', opts[:features])
70
+ command.append_arg('quickack', opts[:quickack])
71
+ command.append_arg('fastopen_no_cookie', opts[:fastopen_no_cookie])
72
+
73
+ if Kanrisuru::Util.present?(opts[:congctl])
74
+ if Kanrisuru::Util.present?(opts[:congctl_lock])
75
+ command.append_arg('congctl lock', opts[:congctl])
76
+ else
77
+ command.append_arg('congctl', opts[:congctl])
78
+ end
105
79
  end
106
80
 
107
- execute_shell(command)
81
+ command.append_arg('advmss', opts[:advmss])
82
+ command.append_arg('reordering', opts[:reordering])
108
83
 
109
- Kanrisuru::Result.new(command) do |cmd|
110
- Parser::Route.parse(cmd, action, version)
84
+ if Kanrisuru::Util.present?(opts[:next_hop])
85
+ next_hop = opts[:next_hop]
86
+
87
+ command << 'next_hop'
88
+ command.append_arg('via', next_hop[:via])
89
+ command.append_arg('dev', next_hop[:dev])
90
+ command.append_arg('weight', next_hop[:weight])
111
91
  end
92
+
93
+ command.append_arg('scope', opts[:scope])
94
+ command.append_arg('protocol', opts[:protocol])
95
+ command.append_flag('onlink', opts[:onlink])
96
+ command.append_arg('pref', opts[:pref])
97
+ command.append_arg('nhid', opts[:nhid])
98
+ command
99
+ end
100
+
101
+ def ip_route_flush(opts)
102
+ command = Kanrisuru::Command.new('ip')
103
+ command.append_arg('-family', opts[:family])
104
+ command << 'route flush'
105
+
106
+ ip_route_common_opts(command, opts)
107
+
108
+ command
109
+ end
110
+
111
+ def ip_route_get(opts)
112
+ command = Kanrisuru::Command.new('ip route get')
113
+
114
+ command.append_flag('fibmatch', opts[:fibmatch])
115
+ command.append_arg('to', opts[:to])
116
+ command.append_arg('from', opts[:from])
117
+ command.append_arg('tos', opts[:tos])
118
+ command.append_arg('dsfield', opts[:dsfield])
119
+ command.append_arg('iif', opts[:iif])
120
+ command.append_arg('oif', opts[:oif])
121
+ command.append_arg('mark', opts[:mark])
122
+ command.append_arg('vrf', opts[:vrf])
123
+ command.append_arg('ipproto', opts[:ipproto])
124
+ command.append_arg('sport', opts[:sport])
125
+ command.append_arg('dport', opts[:dport])
126
+
127
+ command.append_flag('connected', opts[:connected])
128
+ command
129
+ end
130
+
131
+ def ip_route_common_opts(command, opts)
132
+ command.append_arg('to', opts[:to])
133
+ command.append_arg('dev', opts[:dev])
134
+ command.append_arg('protocol', opts[:protocol])
135
+ command.append_arg('type', opts[:type])
136
+ command.append_arg('table', opts[:table])
137
+ command.append_arg('tos', opts[:tos])
138
+ command.append_arg('dsfield', opts[:dsfield])
139
+ command.append_arg('via', opts[:via])
140
+ command.append_arg('vrf', opts[:vrf])
141
+ command.append_arg('src', opts[:src])
142
+
143
+ command.append_arg('realm', opts[:realm])
144
+ command.append_arg('realms', opts[:realms])
145
+ command.append_arg('scope', opts[:scope])
146
+
147
+ command.append_flag('cloned', opts[:cloned])
148
+ command.append_flag('cached', opts[:cached])
112
149
  end
113
150
  end
114
151
  end
@@ -6,29 +6,12 @@ module Kanrisuru
6
6
  def ip_rule(action, opts)
7
7
  case action
8
8
  when 'show', 'list'
9
- version = ip_version
10
-
11
- command = Kanrisuru::Command.new('ip')
12
- command.append_flag('-json') if version >= IPROUTE2_JSON_VERSION
13
-
14
- command << 'rule show'
9
+ version = ip_version.to_i
10
+ command = ip_rule_show(opts, version)
15
11
  when 'flush'
16
- command = Kanrisuru::Command.new('ip rule flush')
17
- when 'add', 'delete'
18
- command = Kanrisuru::Command.new('ip rule')
19
- command << action
20
-
21
- command.append_arg('type', opts[:type])
22
- command.append_arg('from', opts[:from])
23
- command.append_arg('to', opts[:to])
24
- command.append_arg('iif', opts[:iif])
25
- command.append_arg('tos', opts[:tos])
26
- command.append_arg('dsfield', opts[:dsfield])
27
- command.append_arg('fwmark', opts[:fwmark])
28
- command.append_arg('priority', opts[:priority])
29
- command.append_arg('table', opts[:table])
30
- command.append_arg('realms', opts[:realms])
31
- command.append_arg('nat', opts[:nat])
12
+ command = ip_rule_flush(opts)
13
+ when 'add', 'delete', 'del'
14
+ command = ip_rule_modify(action, opts)
32
15
  end
33
16
 
34
17
  execute_shell(command)
@@ -37,6 +20,38 @@ module Kanrisuru
37
20
  Parser::Rule.parse(cmd, action, version)
38
21
  end
39
22
  end
23
+
24
+ def ip_rule_modify(action, opts)
25
+ command = Kanrisuru::Command.new('ip rule')
26
+ command << action
27
+
28
+ command.append_arg('type', opts[:type])
29
+ command.append_arg('from', opts[:from])
30
+ command.append_arg('to', opts[:to])
31
+ command.append_arg('iif', opts[:iif])
32
+ command.append_arg('tos', opts[:tos])
33
+ command.append_arg('dsfield', opts[:dsfield])
34
+ command.append_arg('fwmark', opts[:fwmark])
35
+ command.append_arg('priority', opts[:priority])
36
+ command.append_arg('table', opts[:table])
37
+ command.append_arg('realms', opts[:realms])
38
+ command.append_arg('nat', opts[:nat])
39
+ command
40
+ end
41
+
42
+ def ip_rule_flush(opts)
43
+ command = Kanrisuru::Command.new('ip rule flush')
44
+ command.append_arg('protocol', opts[:protocol])
45
+ command
46
+ end
47
+
48
+ def ip_rule_show(_opts, version)
49
+ command = Kanrisuru::Command.new('ip')
50
+ command.append_flag('-json') if version >= IPROUTE2_JSON_VERSION
51
+
52
+ command << 'rule show'
53
+ command
54
+ end
40
55
  end
41
56
  end
42
57
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require_relative 'commands/address'
4
4
  require_relative 'commands/address_label'
5
+ require_relative 'commands/link_type_opts'
6
+ require_relative 'commands/link_set_opts'
5
7
  require_relative 'commands/link'
6
8
  require_relative 'commands/maddress'
7
9
  require_relative 'commands/neighbour'
@@ -15,9 +17,9 @@ module Kanrisuru
15
17
  command = Kanrisuru::Command.new('ip -V')
16
18
  execute_shell(command)
17
19
 
18
- raise 'ip command not found' if command.failure?
19
-
20
- command.to_s.split('ip utility, iproute2-ss')[1].to_i
20
+ Kanrisuru::Result.new(command) do |cmd|
21
+ Parser::Version.parse(cmd)
22
+ end
21
23
  end
22
24
  end
23
25
  end
@@ -4,10 +4,22 @@ module Kanrisuru
4
4
  module Core
5
5
  module IP
6
6
  IPROUTE2_JSON_VERSION = 180_129
7
+
7
8
  IP_ROUTE_TYPES = %w[
8
9
  unicast unreachable blackhole prohibit local
9
10
  broadcast throw nat via anycast multicast
10
11
  ].freeze
12
+
13
+ IP_FAMILIES = %w[inet inet6 link].freeze
14
+ IP_SCOPES = %w[global site link host].freeze
15
+ IP_LINK_TYPES = %w[
16
+ vlan veth vcan vxcan dummy ifb macvlan macvtap
17
+ bridge bond team ipoib ip6tnl ipip sit vxlan
18
+ gre gretap erspan ip6gre ip6gretap ip6erspan
19
+ vti nlmon team_slave bond_slave bridge_slave
20
+ ipvlan ipvtap geneve vrf macsec netdevsim rmnet
21
+ xfrm bareudp hsr
22
+ ].freeze
11
23
  end
12
24
  end
13
25
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'parsers/base'
4
+ require_relative 'parsers/version'
4
5
  require_relative 'parsers/address'
5
6
  require_relative 'parsers/address_label'
6
7
  require_relative 'parsers/link'
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kanrisuru
4
+ module Core
5
+ module IP
6
+ module Parser
7
+ class Version < Base
8
+ def self.parse(command)
9
+ command.to_s.split('ip utility, iproute2-ss')[1].to_i
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -16,25 +16,28 @@ module Kanrisuru
16
16
 
17
17
  def ip(object, action = nil, opts = {})
18
18
  if action.instance_of?(Hash)
19
- opts = action
19
+ opts = action || {}
20
20
  action = 'show'
21
+ elsif action.nil?
22
+ action = 'show'
23
+ opts = {}
21
24
  end
22
25
 
23
26
  case object
24
- when 'link', 'l'
25
- ip_link(action, opts)
26
27
  when 'address', 'addr', 'a'
27
28
  ip_address(action, opts)
28
29
  when 'addrlabel', 'addrl'
29
30
  ip_address_label(action, opts)
31
+ when 'link', 'l'
32
+ ip_link(action, opts)
33
+ when 'maddress', 'maddr', 'm'
34
+ ip_maddress(action, opts)
35
+ when 'neighbour', 'neigh', 'n'
36
+ ip_neighbour(action, opts)
30
37
  when 'route', 'r', 'ro', 'rou', 'rout'
31
38
  ip_route(action, opts)
32
39
  when 'rule', 'ru'
33
40
  ip_rule(action, opts)
34
- when 'neighbour', 'neigh', 'n'
35
- ip_neighbour(action, opts)
36
- when 'maddress', 'maddr', 'm'
37
- ip_maddress(action, opts)
38
41
  end
39
42
  end
40
43
  end
@@ -11,7 +11,7 @@ module Kanrisuru
11
11
 
12
12
  command = Kanrisuru::Command.new('kill')
13
13
  command << "-#{signal}"
14
- command << (pids.instance_of?(Array) ? pids.join(' ') : pids)
14
+ command.append_array(pids)
15
15
 
16
16
  execute_shell(command)
17
17
 
@@ -4,33 +4,25 @@ module Kanrisuru
4
4
  module Core
5
5
  module User
6
6
  def create_user(user, opts = {})
7
- uid = opts[:uid]
8
7
  group = opts[:group]
9
8
  groups = opts[:groups]
10
- home = opts[:home]
11
9
  shell = opts[:shell] || '/bin/false'
12
- createhome = opts[:createhome]
13
- system_opt = opts[:system]
14
- skeleton = opts[:skeleton]
15
- non_unique = opts[:non_unique]
16
- password = opts[:password]
17
- expires = opts[:expires] ## YYYY-MM-DD
18
10
 
19
11
  command = Kanrisuru::Command.new("useradd #{user}")
20
12
 
21
- if Kanrisuru::Util.present?(uid)
22
- command.append_arg('-u', uid)
23
- command.append_flag('-o', non_unique)
13
+ if Kanrisuru::Util.present?(opts[:uid])
14
+ command.append_arg('-u', opts[:uid])
15
+ command.append_flag('-o', opts[:non_unique])
24
16
  end
25
17
 
26
- command.append_flag('-r', system_opt)
18
+ command.append_flag('-r', opts[:system])
27
19
  command.append_arg('-s', shell)
28
- command.append_arg('-d', home)
20
+ command.append_arg('-d', opts[:home])
29
21
 
30
- case createhome
22
+ case opts[:createhome]
31
23
  when true
32
24
  command.append_flag('-m')
33
- command.append_arg('-k', skeleton)
25
+ command.append_arg('-k', opts[:skeleton])
34
26
  when false
35
27
  command.append_flag('-M')
36
28
  end
@@ -43,8 +35,8 @@ module Kanrisuru
43
35
 
44
36
  command.append_arg('-G', groups.join(',')) if Kanrisuru::Util.present?(groups)
45
37
 
46
- command.append_arg('-p', password)
47
- command.append_arg('-e', expires)
38
+ command.append_arg('-p', opts[:password])
39
+ command.append_arg('-e', opts[:expires]) ## YYYY-MM-DD
48
40
 
49
41
  execute_shell(command)
50
42
 
@@ -6,7 +6,7 @@ module Kanrisuru
6
6
  def delete_user(user, opts = {})
7
7
  force = opts[:force]
8
8
 
9
- return false unless get_uid(user)
9
+ return false if get_uid(user).failure?
10
10
 
11
11
  command = Kanrisuru::Command.new("userdel #{user}")
12
12
  command.append_flag('-f', force)