kanmon 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/kanmon.gemspec +2 -2
- data/lib/kanmon.rb +0 -4
- data/lib/kanmon/cli.rb +51 -35
- data/lib/kanmon/config.rb +39 -0
- data/lib/kanmon/error.rb +8 -0
- data/lib/kanmon/server.rb +15 -4
- data/lib/kanmon/version.rb +1 -1
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cd9e1d8a755e41165434ffa463b63985f11d472198afc132c3d6c32ad962196
|
4
|
+
data.tar.gz: cf18367379ee2bd8bf97844cdcba1f0cd49f0103b64c66f5124373218c7de991
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 252463b76b73e7df45e78d08dae7cf93594d0e3e8df629d9d0270473b0f5e837b63836f7d7412da111400ddd9948b3ec71e8c9c05fa505223a2ca9afba5c2a30
|
7
|
+
data.tar.gz: 7511a1468e453590f321400a699ccc704627f00eb2efd96040f32fa39fc737385abba27b9fa044939b5541dab0faa97d5002ae54972dbc62b5ad60f1583056d3
|
data/kanmon.gemspec
CHANGED
@@ -20,10 +20,10 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.add_dependency "yao", ">= 0.
|
23
|
+
spec.add_dependency "yao", ">= 0.12.0"
|
24
24
|
spec.add_dependency "thor", ">= 0.20.0"
|
25
25
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
-
spec.add_development_dependency "rake", "
|
27
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
28
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
29
|
end
|
data/lib/kanmon.rb
CHANGED
data/lib/kanmon/cli.rb
CHANGED
@@ -5,79 +5,95 @@ require "kanmon/version"
|
|
5
5
|
require "kanmon/securitygroup"
|
6
6
|
require "kanmon/server"
|
7
7
|
require "kanmon/exclude_ips"
|
8
|
-
|
9
|
-
module Yao::Resources
|
10
|
-
class Server < Yao::Resources::Base
|
11
|
-
def self.add_security_group(server_id, security_group_name)
|
12
|
-
action(server_id, {"addSecurityGroup": {"name": security_group_name}})
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.remove_security_group(server_id, security_group_name)
|
16
|
-
action(server_id, {"removeSecurityGroup": {"name": security_group_name}})
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
8
|
+
require "kanmon/config"
|
20
9
|
|
21
10
|
module Kanmon
|
22
11
|
class CLI < Thor
|
23
|
-
class_option :
|
12
|
+
class_option :config_file, aliases: "f", type: :string, default: nil, banner: "FILE", desc: "Specifies an alternate configuration file. (Default: ~/.kanmon.yml or ./kanmon.yml)"
|
24
13
|
class_option :target, aliases: "t", type: :string, default: nil, banner: "TARGET", desc: "If more than one Security Group is in the setting, select target"
|
25
14
|
|
26
15
|
desc "open", "Commands about add rules to SecurityGroup"
|
27
16
|
def open
|
28
|
-
|
17
|
+
adapter = load_adapter(config)
|
18
|
+
adapter.open
|
29
19
|
puts "Success!!"
|
30
20
|
rescue Yao::Conflict => e
|
31
21
|
puts "Is not it already opened?" if e.message.include?("Security group rule already exists.")
|
32
22
|
puts e
|
23
|
+
rescue Kanmon::AlreadySecurityExistsError
|
33
24
|
end
|
34
25
|
|
35
26
|
desc "close", "Commands about delete rules from SecurityGroup"
|
27
|
+
method_option :all, aliases: "a", type: :boolean, default: false, desc: "If set, close all Security Groups(Exclusive witeh --target)"
|
36
28
|
def close
|
37
|
-
|
29
|
+
if options[:all] && options[:target].nil?
|
30
|
+
config.targets.each do |name|
|
31
|
+
puts "Checking #{name}"
|
32
|
+
config.set(name)
|
33
|
+
adapter = load_adapter(config)
|
34
|
+
adapter.close
|
35
|
+
end
|
36
|
+
else
|
37
|
+
adapter = load_adapter(config)
|
38
|
+
adapter.close
|
39
|
+
end
|
38
40
|
puts "Success!!"
|
39
41
|
end
|
40
42
|
|
41
|
-
desc "ssh
|
43
|
+
desc "ssh [args]", "Commands about exec ssh"
|
42
44
|
def ssh(*args)
|
43
|
-
|
45
|
+
ssh_args = args.unshift("ssh", config.target)
|
46
|
+
invoke :exec, ssh_args
|
44
47
|
end
|
45
48
|
|
46
49
|
desc "exec COMMAND", "Commands about open, exec command, close"
|
47
50
|
def exec(*args)
|
48
|
-
|
51
|
+
adapter = load_adapter(config)
|
52
|
+
adapter.open do
|
49
53
|
command = Shellwords.join(args)
|
50
54
|
Process.wait spawn(command)
|
51
55
|
end
|
52
56
|
end
|
53
57
|
|
58
|
+
desc "list", "Commands about list targets"
|
59
|
+
def list
|
60
|
+
puts config.targets.sort.join("\n")
|
61
|
+
end
|
62
|
+
|
54
63
|
desc "version", "Commands about show version"
|
55
64
|
def version
|
56
65
|
puts Kanmon::VERSION
|
57
66
|
end
|
58
67
|
|
59
68
|
no_commands do
|
60
|
-
def
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
69
|
+
def config
|
70
|
+
if @__config.nil?
|
71
|
+
@__config = Config.load_file(options[:config_file])
|
72
|
+
end
|
73
|
+
|
74
|
+
if target = options[:target]
|
75
|
+
@__config.set(target)
|
76
|
+
end
|
77
|
+
|
78
|
+
@__config
|
79
|
+
end
|
80
|
+
|
81
|
+
def load_adapter(opts)
|
82
|
+
Kanmon.init_yao
|
65
83
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
84
|
+
adapter = if opts.security_group
|
85
|
+
SecurityGroup.new(opts.security_group, opts.port)
|
86
|
+
elsif opts.server
|
87
|
+
Server.new(opts.server, opts.port)
|
88
|
+
end
|
72
89
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
90
|
+
exclude_ips = ExcludeIps.new(opts.exclude_ips)
|
91
|
+
if exclude_ips.include?(adapter.ip)
|
92
|
+
puts "MyIP(#{adapter.ip}) is included in exclude IPs."
|
93
|
+
exit
|
78
94
|
end
|
79
95
|
|
80
|
-
|
96
|
+
adapter
|
81
97
|
end
|
82
98
|
end
|
83
99
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module Kanmon
|
4
|
+
class Config
|
5
|
+
def self.load_file(filepath)
|
6
|
+
data = if filepath
|
7
|
+
YAML.load_file(filepath)
|
8
|
+
else
|
9
|
+
default_files = [File.expand_path("~/.kanmon.yml"), "./kanmon.yml"]
|
10
|
+
config_file = default_files.find {|path| File.exists?(path)}
|
11
|
+
YAML.load_file(config_file)
|
12
|
+
end
|
13
|
+
|
14
|
+
new(data)
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(data)
|
18
|
+
@data = data
|
19
|
+
end
|
20
|
+
|
21
|
+
def targets
|
22
|
+
@data.keys
|
23
|
+
end
|
24
|
+
|
25
|
+
def set(target)
|
26
|
+
@target = target
|
27
|
+
end
|
28
|
+
|
29
|
+
%w(security_group server port exclude_ips).each do |name|
|
30
|
+
define_method(name) do
|
31
|
+
if @target
|
32
|
+
@data[@target][name]
|
33
|
+
else
|
34
|
+
@data[name]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/kanmon/error.rb
ADDED
data/lib/kanmon/server.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "yao"
|
2
2
|
|
3
3
|
require "kanmon/myip"
|
4
|
+
require "kanmon/error"
|
4
5
|
|
5
6
|
module Kanmon
|
6
7
|
class Server
|
@@ -32,12 +33,21 @@ module Kanmon
|
|
32
33
|
Yao::Server.add_security_group(@id, sg_name)
|
33
34
|
end
|
34
35
|
|
36
|
+
def validate_sg_already_exists
|
37
|
+
if Yao::SecurityGroup.list({name: sg_name}).size > 0
|
38
|
+
puts "Security Group #{sg_name} already exists."
|
39
|
+
puts "Is not it already opened?"
|
40
|
+
raise Kanmon::AlreadySecurityExistsError
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
35
44
|
def remove_sg
|
36
45
|
puts "Remove security group #{sg_name} from server '#{@server.name}'."
|
37
46
|
Yao::Server.remove_security_group(@id, sg_name)
|
38
47
|
end
|
39
48
|
|
40
49
|
def open
|
50
|
+
validate_sg_already_exists
|
41
51
|
create_sg
|
42
52
|
add_sg
|
43
53
|
|
@@ -53,10 +63,11 @@ module Kanmon
|
|
53
63
|
|
54
64
|
def close
|
55
65
|
begin
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
66
|
+
result = Yao::SecurityGroup.find_by_name(sg_name)
|
67
|
+
if @sg = result.first
|
68
|
+
remove_sg
|
69
|
+
delete_sg
|
70
|
+
end
|
60
71
|
rescue => e
|
61
72
|
p e
|
62
73
|
end
|
data/lib/kanmon/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kanmon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuki Koya
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yao
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.12.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.12.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: thor
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 12.3.3
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 12.3.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,6 +101,8 @@ files:
|
|
101
101
|
- kanmon.gemspec
|
102
102
|
- lib/kanmon.rb
|
103
103
|
- lib/kanmon/cli.rb
|
104
|
+
- lib/kanmon/config.rb
|
105
|
+
- lib/kanmon/error.rb
|
104
106
|
- lib/kanmon/exclude_ips.rb
|
105
107
|
- lib/kanmon/myip.rb
|
106
108
|
- lib/kanmon/securitygroup.rb
|
@@ -124,8 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
126
|
- !ruby/object:Gem::Version
|
125
127
|
version: '0'
|
126
128
|
requirements: []
|
127
|
-
|
128
|
-
rubygems_version: 2.7.6
|
129
|
+
rubygems_version: 3.1.2
|
129
130
|
signing_key:
|
130
131
|
specification_version: 4
|
131
132
|
summary: CLI tool of add public IP to Securoity Group on OpenStack.
|