kanrisuru 0.16.9 → 0.16.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +108 -32
- data/lib/kanrisuru/core/find/commands/find.rb +3 -1
- data/lib/kanrisuru/version.rb +1 -1
- data/spec/functional/core/find_spec.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: deee19d7cfafee6dd2ab48a0400ba7b18909de35a0c6f60e9e8c17c6c9ac3eab
|
4
|
+
data.tar.gz: 59a153f5f7b94fedfa06baf22a7a47d70a3fce9b66a04705dce91e58f063140a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a4413a7e8da493e0059e15fc2742c17ae19977c830a77f2c3aea9432677fcecdb7f9191f4342fbc9a4d4159f2897c873f993de9db6d4f9bee0ce349251850a9
|
7
|
+
data.tar.gz: f6c9c82523ddad69b3b8db6ecdc9a6032d1e85e693892516a65295905b3cc2911bd484fbaeb859d5e9fe70ae660012326d01ed6da81cf7bb50dd73608f9b3e66
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -15,15 +15,11 @@
|
|
15
15
|
<img src="https://img.shields.io/codeclimate/maintainability/avamia/kanrisuru?style=flat-square" alt="Code Climate maintainability" />
|
16
16
|
</p>
|
17
17
|
|
18
|
-
Kanrisuru
|
18
|
+
Kanrisuru manages remote infrastructure with plain ruby objects. The goal with Kanrisuru is to provide a clean objected oriented wrapper over the most commonly used linux commands, with a clean command interface, and with any usable output, present that as parsed structured data. Kanrisuru doesn't use remote agents to run commands on hosts, nor does the project rely on a large complex set of dependencies.
|
19
19
|
|
20
|
-
|
20
|
+
## Getting Started
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
If you want to dynamically interact with a host, eg: If you need to dynamically scale your infrastructure by continually monitoring specific stats from a centralized system, Kanrisuru can help you accomplish this.
|
25
|
-
|
26
|
-
## Installation
|
22
|
+
Kanrisuru requires ruby `2.5.0` at a minimum.
|
27
23
|
|
28
24
|
Add this line to your application's Gemfile:
|
29
25
|
|
@@ -43,48 +39,128 @@ Or install it yourself as:
|
|
43
39
|
$ gem install kanrisuru
|
44
40
|
```
|
45
41
|
|
46
|
-
##
|
47
|
-
|
42
|
+
## Documentation
|
43
|
+
You can find the official documentation https://kanrisuru.com
|
48
44
|
|
45
|
+
## Usage Guide
|
49
46
|
### Host
|
47
|
+
To connect with Kanrisuru to a remote host, provide the login credentials to instantiate a `Kanrisuru::Remote::Host` instance.
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
host = Kanrisuru::Remote::Host.new(
|
51
|
+
host: 'remote-host-name',
|
52
|
+
username: 'ubuntu',
|
53
|
+
keys: ['~/.ssh/id_rsa']
|
54
|
+
)
|
55
|
+
```
|
56
|
+
|
57
|
+
#### run a simple echo command on the remote host
|
58
|
+
```ruby
|
59
|
+
host.env['VAR'] = 'world'
|
60
|
+
result = host.echo('hello $VAR')
|
61
|
+
result.success?
|
62
|
+
true
|
63
|
+
|
64
|
+
result.to_s
|
65
|
+
'hello world'
|
66
|
+
```
|
67
|
+
|
68
|
+
#### build a custom command
|
69
|
+
```ruby
|
70
|
+
command = Kanrisuru::Command.new('wc')
|
71
|
+
command << '/home/ubuntu/file1.txt'
|
72
|
+
|
73
|
+
host.execute_shell(command)
|
74
|
+
result = Kanrisuru::Result.new(command) do |cmd|
|
75
|
+
items = cmd.to_s.split
|
76
|
+
|
77
|
+
struct = Kanrisuru::Core::File::FileCount.new
|
78
|
+
struct.lines = items[0]
|
79
|
+
struct.words = items[1]
|
80
|
+
struct.characters = items[2]
|
81
|
+
struct
|
82
|
+
end
|
83
|
+
```
|
84
|
+
The `Kanrisuru::Result` class will only run the parsing block if the command run on the remote host was succeful. The final line will be used to build the result object to be read easily. This instance will also dynamically add getter methods to read the underlying data struct for easier querying capabiltiies.
|
85
|
+
|
50
86
|
```ruby
|
51
|
-
|
52
|
-
|
53
|
-
result.to_s # => 'ubuntu'
|
87
|
+
result.success?
|
88
|
+
true
|
54
89
|
|
55
|
-
result
|
56
|
-
|
90
|
+
result.lines
|
91
|
+
8
|
92
|
+
|
93
|
+
result.characters
|
94
|
+
150
|
95
|
+
|
96
|
+
result.words
|
97
|
+
85
|
57
98
|
```
|
58
99
|
|
59
|
-
### Cluster
|
100
|
+
### Cluster
|
101
|
+
Kanrisuru can manage multiple hosts at the same time with the `Kanrisuru::Remote::Cluster`.
|
102
|
+
|
103
|
+
#### To instantiate a cluster, add 1 or more hosts:
|
60
104
|
```ruby
|
61
105
|
cluster = Kanrisuru::Remote::Cluster.new({
|
62
|
-
host: '
|
106
|
+
host: 'remote-host-1',
|
107
|
+
username: 'ubuntu',
|
108
|
+
keys: ['~/.ssh/remote_1_id_rsa']
|
109
|
+
}, {
|
110
|
+
host: 'remote-host-2',
|
111
|
+
username: 'centos',
|
112
|
+
keys: ['~/.ssh/remote_2_id_rsa']
|
63
113
|
}, {
|
64
|
-
host: '
|
114
|
+
host: 'remote-host-3',
|
115
|
+
username: 'opensuse',
|
116
|
+
keys: ['~/.ssh/remote_3_id_rsa']
|
65
117
|
})
|
66
|
-
|
67
|
-
cluster.whoami # => {host: 'host1', result: 'ubuntu'}, {host: 'host2', result: 'alice'}
|
68
|
-
cluster.pwd # => {host: 'host1', result: '/home/ubuntu'}, {host: 'host2', result: '/home/alice'}
|
69
|
-
|
70
|
-
cluster.each do |host|
|
71
|
-
host.pwd.path # => /home/ubuntu
|
72
|
-
end
|
73
118
|
```
|
74
119
|
|
75
|
-
|
120
|
+
#### You can also add a host to a cluster that's already been created
|
76
121
|
```ruby
|
77
|
-
host = Kanrisuru::Remote::Host.new(host: '
|
122
|
+
host = Kanrisuru::Remote::Host.new(host: 'remote-host-4', username: 'rhel', keys: ['~/.ssh/remote_4_id_rsa'])
|
78
123
|
|
79
|
-
|
80
|
-
|
124
|
+
cluster << host
|
125
|
+
```
|
81
126
|
|
82
|
-
|
83
|
-
command.to_s #=> Linux
|
127
|
+
Kanrisuru at this point only runs commands sequentially. We plan on creating a parallel run mode in a future release.
|
84
128
|
|
85
|
-
|
129
|
+
#### To run across all hosts with a single command, cluster will return a array of result hashes
|
130
|
+
```ruby
|
131
|
+
cluster.whoami
|
132
|
+
[
|
133
|
+
{
|
134
|
+
:host => "remote-host-1",
|
135
|
+
:result => #<Kanrisuru::Result:0x640 @status=0 @data=#<struct Kanrisuru::Core::Path::UserName user="ubuntu"> @command=sudo -u ubuntu /bin/bash -c "whoami">
|
136
|
+
},
|
137
|
+
{
|
138
|
+
:host => "remote-host-2",
|
139
|
+
:result => #<Kanrisuru::Result:0x700 @status=0 @data=#<struct Kanrisuru::Core::Path::UserName user="centos"> @command=sudo -u centos /bin/bash -c "whoami">
|
140
|
+
},
|
141
|
+
{
|
142
|
+
:host => "remote-host-3",
|
143
|
+
:result => #<Kanrisuru::Result:0x760 @status=0 @data=#<struct Kanrisuru::Core::Path::UserName user="opensuse"> @command=sudo -u opensuse /bin/bash -c "whoami">
|
144
|
+
},
|
145
|
+
{
|
146
|
+
:host => "remote-host-4",
|
147
|
+
:result => #<Kanrisuru::Result:0x820 @status=0 @data=#<struct Kanrisuru::Core::Path::UserName user="rhel"> @command=sudo -u rhel /bin/bash -c "whoami">
|
148
|
+
}
|
149
|
+
]
|
150
|
+
```
|
86
151
|
|
87
|
-
|
152
|
+
#### You can also access each host individually to run a command conditionaly within an iterable block
|
153
|
+
```ruby
|
154
|
+
cluster.each do |host|
|
155
|
+
case host.os.release
|
156
|
+
when 'ubuntu', 'debian'
|
157
|
+
host.apt('update')
|
158
|
+
when 'centos', 'redhat', 'fedora'
|
159
|
+
host.yum('update')
|
160
|
+
when 'opensuse_leap', 'sles'
|
161
|
+
host.zypper('update')
|
162
|
+
end
|
163
|
+
end
|
88
164
|
```
|
89
165
|
|
90
166
|
## Development
|
@@ -36,6 +36,7 @@ module Kanrisuru
|
|
36
36
|
|
37
37
|
command.append_arg('-path', opts[:path])
|
38
38
|
command.append_arg('-name', opts[:name])
|
39
|
+
command.append_arg('-iname', opts[:iname])
|
39
40
|
command.append_arg('-gid', opts[:gid])
|
40
41
|
command.append_arg('-uid', opts[:uid])
|
41
42
|
command.append_arg('-user', opts[:user])
|
@@ -58,7 +59,8 @@ module Kanrisuru
|
|
58
59
|
command.append_arg('-regextype', opts[:regex_type])
|
59
60
|
end
|
60
61
|
|
61
|
-
command.append_arg('-regex', "'#{regex}'") if Kanrisuru::Util.present?(regex)
|
62
|
+
command.append_arg('-regex', "'#{opts[:regex]}'") if Kanrisuru::Util.present?(opts[:regex])
|
63
|
+
command.append_arg('-iregex', "'#{opts[:iregex]}'") if Kanrisuru::Util.present?(opts[:iregex])
|
62
64
|
|
63
65
|
if size.instance_of?(String)
|
64
66
|
regex = Regexp.new(/^([-+])?(\d+)([bcwkMG])*$/)
|
data/lib/kanrisuru/version.rb
CHANGED
@@ -64,12 +64,24 @@ RSpec.describe Kanrisuru::Core::Find do
|
|
64
64
|
mmin: '300'),
|
65
65
|
'find /var/log -atime +1 -ctime +2 -mtime +3 -amin 100 -cmin 200 -mmin 300')
|
66
66
|
|
67
|
+
expect_command(host.find(
|
68
|
+
paths: '/dev',
|
69
|
+
iname: 'tty*'
|
70
|
+
),
|
71
|
+
"find /dev -iname tty*")
|
72
|
+
|
67
73
|
expect_command(host.find(
|
68
74
|
paths: '/dev',
|
69
75
|
regex: '/dev/tty[0-9]*'
|
70
76
|
),
|
71
77
|
"find /dev -regex '/dev/tty[0-9]*'")
|
72
78
|
|
79
|
+
expect_command(host.find(
|
80
|
+
paths: '/dev',
|
81
|
+
iregex: '/dev/tty[0-9]*'
|
82
|
+
),
|
83
|
+
"find /dev -iregex '/dev/tty[0-9]*'")
|
84
|
+
|
73
85
|
expect_command(host.find(
|
74
86
|
paths: '/dev',
|
75
87
|
regex_type: 'posix-egrep',
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kanrisuru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.16.
|
4
|
+
version: 0.16.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Mammina
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parallel_tests
|