bcome 0.0.6 → 0.0.7
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/bin/bcome-setup +1 -1
- data/documentation/examples/functions.yml-example +21 -0
- data/documentation/functions.md +28 -0
- data/documentation/usage.md +6 -6
- data/lib/bcome/version.rb +1 -1
- data/lib/functions.rb +70 -0
- data/lib/helpers/instance_ssh.rb +1 -1
- data/lib/helpers/selections.rb +8 -4
- data/lib/object.rb +2 -1
- data/lib/stack/environment.rb +7 -1
- data/lib/stack/instance.rb +3 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 182bfab8bb82f233dc36d0997b8b04d5c338fdbc
|
4
|
+
data.tar.gz: 05f502b57479254e9f8242105950e11cae9a890b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44c5de8e693ea1a1d7ede4eb64ece7ba5d388a6f3de742fbf234c1a4a17a5bd6845467060084ce019f439cef9e3c7b01fd19e343c56c8abb294598f452b162e5
|
7
|
+
data.tar.gz: 7269b4533caae53f815e80ceb40ac6ca3c4f071a3ea537752b9a5ee9850c7efac12c88d38c101a4c28d5e48c1d16bc48d7cadeb326b3e4bd43a7933bec005861
|
data/bin/bcome-setup
CHANGED
@@ -26,7 +26,7 @@ gem_install_path = File.dirname(__FILE__)
|
|
26
26
|
conf_example_path = "#{gem_install_path}/../documentation/examples"
|
27
27
|
application_path = Dir.pwd
|
28
28
|
|
29
|
-
["platform.yml-example","network.yml-example"].each do |example_conf|
|
29
|
+
["platform.yml-example","network.yml-example", "functions.yml-example"].each do |example_conf|
|
30
30
|
transfer_cmd = "rsync -aq #{conf_example_path}/#{example_conf} #{application_path}/#{config_dir}/#{example_conf}"
|
31
31
|
system(transfer_cmd)
|
32
32
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
:single_functions:
|
3
|
+
- :description: "Find open files that are open, but have been deleted"
|
4
|
+
:ref: "openfiles"
|
5
|
+
:command: "lsof -nP +L1"
|
6
|
+
|
7
|
+
- :description: "Show free disk space"
|
8
|
+
:ref: "space"
|
9
|
+
:command: "df -h"
|
10
|
+
|
11
|
+
- :description: "Free system memory"
|
12
|
+
:ref: "mem"
|
13
|
+
:command: "free -m"
|
14
|
+
|
15
|
+
- :description: "Find large files in /var"
|
16
|
+
:ref: "large"
|
17
|
+
:command: "du -a /var | sort -n -r | head -n 10"
|
18
|
+
|
19
|
+
- :description: "CPU usage as a percentage"
|
20
|
+
:ref: "cpu"
|
21
|
+
:command: "cat <(grep 'cpu ' /proc/stat) <(sleep 1 && grep 'cpu ' /proc/stat) | awk -v RS=\"\" '{print ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}'"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
## Functions
|
2
|
+
|
3
|
+
Functions are shortcuts to SSH commands accessible from the shell that can be executed in sequence over a selection of instances (if you're at the environment level), or on a specific instance, if you're at a node level.
|
4
|
+
|
5
|
+
An example functions config can be found in bcome/config/functions.yml-example. Rename this file to functions.yml and you will have access to the functions within from the shell.
|
6
|
+
|
7
|
+
### Example usage
|
8
|
+
|
9
|
+
Define the function in the functions.yml config
|
10
|
+
|
11
|
+
```
|
12
|
+
[...]
|
13
|
+
|
14
|
+
- :description: "Free system memory"
|
15
|
+
:ref: "mem"
|
16
|
+
:command: "free -m"
|
17
|
+
|
18
|
+
[...]
|
19
|
+
```
|
20
|
+
|
21
|
+
Then enter the shell, navigate to an environment level, select the nodes you wish to work on (those on which the function command will be executed), and invoke it:
|
22
|
+
|
23
|
+
```
|
24
|
+
bcome> F 'mem'
|
25
|
+
|
26
|
+
```
|
27
|
+
|
28
|
+
The command will then be invoked on every selected node with the output returned to the shell.
|
data/documentation/usage.md
CHANGED
@@ -36,9 +36,9 @@ or, if with bundler
|
|
36
36
|
> describe
|
37
37
|
- Describe the resource object at the current context.
|
38
38
|
|
39
|
-
> workon / w
|
39
|
+
> workon / w / cd
|
40
40
|
- Select a resource object, and switch to its context.
|
41
|
-
e.g.
|
41
|
+
e.g. cd 'identifier'
|
42
42
|
|
43
43
|
> exit
|
44
44
|
- Close the current context
|
@@ -62,9 +62,9 @@ e.g. local "command"
|
|
62
62
|
> describe
|
63
63
|
- Describe the resource object at the current context.
|
64
64
|
|
65
|
-
> workon / w
|
65
|
+
> workon / w / cd
|
66
66
|
- Select a resource object, and switch to its context.
|
67
|
-
e.g. workon 'identifier' OR w 'identifier'
|
67
|
+
e.g. cd 'identifier' OR workon 'identifier' OR w 'identifier'
|
68
68
|
|
69
69
|
> exit
|
70
70
|
- Close the current context
|
@@ -88,9 +88,9 @@ e.g. local "command"
|
|
88
88
|
> describe
|
89
89
|
- Describe the resource object at the current context.
|
90
90
|
|
91
|
-
> workon / w
|
91
|
+
> cd / workon / w
|
92
92
|
- Select a resource object, and switch to its context.
|
93
|
-
e.g. workon 'identifier'
|
93
|
+
e.g. cd 'identifier' OR w 'identifier' OR workon 'identifier'
|
94
94
|
|
95
95
|
> exit
|
96
96
|
- Close the current context
|
data/lib/bcome/version.rb
CHANGED
data/lib/functions.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
module Bcome::Functions
|
2
|
+
|
3
|
+
CONFIGS_PATH = "bcome/config"
|
4
|
+
|
5
|
+
def functions
|
6
|
+
unless cmd_functions
|
7
|
+
puts "You don't yet have any custom functions defined. Have a read of the docs and define some. They're pretty useful.".informational
|
8
|
+
else
|
9
|
+
puts
|
10
|
+
cmd_functions.each_with_index do |cmd_function, i|
|
11
|
+
puts "#{cmd_function[:ref].informational}"
|
12
|
+
puts "Description: " + cmd_function[:description]
|
13
|
+
puts "Command: > " + cmd_function[:command]
|
14
|
+
puts "USAGE: > F \"#{cmd_function[:ref]}\""
|
15
|
+
puts
|
16
|
+
end
|
17
|
+
end
|
18
|
+
return
|
19
|
+
end
|
20
|
+
|
21
|
+
def F(reference)
|
22
|
+
if self.is_a?(Bcome::Stack::Environment) && no_selections?
|
23
|
+
puts "You are an an Environment level, and have not selected any nodes to workon.".failure
|
24
|
+
else
|
25
|
+
command = cmd_for_ref(reference)
|
26
|
+
if command
|
27
|
+
puts "#{"Executing command '#{command[:ref]}': ".informational} > #{command[:command].command}"
|
28
|
+
puts run command[:command]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def cmd_for_ref(reference)
|
34
|
+
commands = cmd_functions.select{|command| command[:ref].to_s == reference.to_s }
|
35
|
+
raise "Multiple commands found for reference '#{reference}'. Your functions list is ambiguous.".failure if commands.size > 1
|
36
|
+
unless commands.any?
|
37
|
+
puts "No command found for reference '#{reference}'".failure
|
38
|
+
return nil
|
39
|
+
end
|
40
|
+
return commands.first
|
41
|
+
end
|
42
|
+
|
43
|
+
def cmd_functions
|
44
|
+
return unless has_functions_config?
|
45
|
+
@cmd_functions ||= load_cmd_functions
|
46
|
+
end
|
47
|
+
|
48
|
+
def has_cmd_functions?
|
49
|
+
!cmd_functions.nil?
|
50
|
+
end
|
51
|
+
|
52
|
+
def load_cmd_functions
|
53
|
+
configs = YAML.load_file(cmd_config_path)
|
54
|
+
unless configs.has_key?(:single_functions)
|
55
|
+
raise "Invalid functions configuration. Please check your yaml".failure
|
56
|
+
else
|
57
|
+
return configs[:single_functions]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def cmd_config_path
|
62
|
+
"#{CONFIGS_PATH}/functions.yml"
|
63
|
+
end
|
64
|
+
|
65
|
+
def has_functions_config?
|
66
|
+
File.exist?(cmd_config_path)
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
end
|
data/lib/helpers/instance_ssh.rb
CHANGED
data/lib/helpers/selections.rb
CHANGED
@@ -22,8 +22,12 @@ module ::Bcome::Selections
|
|
22
22
|
return
|
23
23
|
end
|
24
24
|
|
25
|
+
def no_selections?
|
26
|
+
!@objects || @objects.empty?
|
27
|
+
end
|
28
|
+
|
25
29
|
def put(local_path, remote_path)
|
26
|
-
if
|
30
|
+
if no_selections?
|
27
31
|
no_selections_error
|
28
32
|
return
|
29
33
|
end
|
@@ -35,7 +39,7 @@ module ::Bcome::Selections
|
|
35
39
|
end
|
36
40
|
|
37
41
|
def get(remote_path)
|
38
|
-
if
|
42
|
+
if no_selections?
|
39
43
|
no_selections_error
|
40
44
|
return
|
41
45
|
end
|
@@ -90,7 +94,7 @@ module ::Bcome::Selections
|
|
90
94
|
end
|
91
95
|
|
92
96
|
def remove_object(object)
|
93
|
-
return if
|
97
|
+
return if no_selections?
|
94
98
|
unless object_in_selections?(object)
|
95
99
|
print "\n#{object.identifier} is not within selections\n".headsup
|
96
100
|
else
|
@@ -105,7 +109,7 @@ module ::Bcome::Selections
|
|
105
109
|
end
|
106
110
|
|
107
111
|
def selections
|
108
|
-
if
|
112
|
+
if no_selections?
|
109
113
|
print "\nNo added nodes.\n".headsup
|
110
114
|
else
|
111
115
|
print "\nAdded nodes: #{@objects.collect(&:identifier).join(", ")}\n".headsup
|
data/lib/object.rb
CHANGED
@@ -40,12 +40,13 @@ class Object
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
alias :w :workon
|
43
|
+
alias :cd :workon
|
43
44
|
|
44
45
|
def menu_items
|
45
46
|
[
|
46
47
|
{ :command => "list / ls", :description => "List all available resources at the current context." },
|
47
48
|
{ :command => "describe", :description => "Describe the resource object at the current context." },
|
48
|
-
{ :command => "workon
|
49
|
+
{ :command => "cd / workon / w", :description => "Select a resource object, and switch to its context.", :usage => "cd 'identifier'" },
|
49
50
|
{ :command => "exit", :description => "Return to the previous context" },
|
50
51
|
{ :command => "exit!", :description => "Close all contexts, and exit Become."},
|
51
52
|
{ :command => "local", :description => "Execute a shell command on your local machine.", :usage => 'local "command"'}
|
data/lib/stack/environment.rb
CHANGED
@@ -5,6 +5,7 @@ module ::Bcome::Stack
|
|
5
5
|
include ::Bcome::Selections
|
6
6
|
include ::Bcome::FogHelper
|
7
7
|
include ::Bcome::EnvironmentSSH
|
8
|
+
include ::Bcome::Functions
|
8
9
|
|
9
10
|
class << self
|
10
11
|
def collection_from_config(parent, configuration)
|
@@ -34,7 +35,8 @@ module ::Bcome::Stack
|
|
34
35
|
{ :command => "run", :description => "Execute a command on all selected resources", :usage => "run 'command'" },
|
35
36
|
{ :command => "get", :description => "Download from remote from all selected resources (recursive - uses rsync)", :usage => "get 'remote_path'" },
|
36
37
|
{ :command => "put", :description => "Copy files up to all selected resources (recursive - uses rsync)", :usage => "put 'local_path', 'remote_path'" },
|
37
|
-
{ :command => "sudo", :description => "Run 'get' and 'put' in sudo mode (assumes you have passwordless sudo setup)" }
|
38
|
+
{ :command => "sudo", :description => "Run 'get' and 'put' in sudo mode (assumes you have passwordless sudo setup)" },
|
39
|
+
{ :command => 'functions', :description => "List all available custom functions" }
|
38
40
|
]
|
39
41
|
end
|
40
42
|
|
@@ -55,6 +57,10 @@ module ::Bcome::Stack
|
|
55
57
|
def ssh_nat_user
|
56
58
|
return @meta_data[:ssh_mode][:nat_user]
|
57
59
|
end
|
60
|
+
|
61
|
+
def ssh_key_path
|
62
|
+
return @meta_data[:ssh_mode][:ssh_key_path]
|
63
|
+
end
|
58
64
|
|
59
65
|
def sudo
|
60
66
|
toggle_sudo
|
data/lib/stack/instance.rb
CHANGED
@@ -4,6 +4,7 @@ module ::Bcome::Stack
|
|
4
4
|
include ::Bcome::BecomeObject
|
5
5
|
include ::Bcome::InstanceSsh
|
6
6
|
include ::Bcome::InstanceCommand
|
7
|
+
include ::Bcome::Functions
|
7
8
|
|
8
9
|
class << self
|
9
10
|
def collection_from_fog_data(parent, fog_instances)
|
@@ -44,7 +45,8 @@ module ::Bcome::Stack
|
|
44
45
|
{ :command => "put", :description => "Copy files to remote (recursive - uses rsync)", :usage => "put 'local_path', 'remote_path'" },
|
45
46
|
{ :command => "get", :description => "Download from remote (recursive - uses rsync).", :usage => "get 'remote_path'"},
|
46
47
|
{ :command => "ssh", :description => "Initiate an SSH connection." },
|
47
|
-
{ :command => "sudo", :description => "Run 'get' and 'put' in sudo mode (assumes you have passwordless sudo setup)" }
|
48
|
+
{ :command => "sudo", :description => "Run 'get' and 'put' in sudo mode (assumes you have passwordless sudo setup)" },
|
49
|
+
{ :command => 'functions', :description => "List all available custom functions" }
|
48
50
|
]
|
49
51
|
end
|
50
52
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bcome
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillaume Roderick (Webzakimbo)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -115,8 +115,10 @@ files:
|
|
115
115
|
- bin/bcome
|
116
116
|
- bin/bcome-setup
|
117
117
|
- documentation/configuration.md
|
118
|
+
- documentation/examples/functions.yml-example
|
118
119
|
- documentation/examples/network.yml-example
|
119
120
|
- documentation/examples/platform.yml-example
|
121
|
+
- documentation/functions.md
|
120
122
|
- documentation/installation.md
|
121
123
|
- documentation/usage.md
|
122
124
|
- filters/ec2_filter.rb
|
@@ -127,6 +129,7 @@ files:
|
|
127
129
|
- lib/command.rb
|
128
130
|
- lib/filters/base.rb
|
129
131
|
- lib/filters/ec2_filter.rb
|
132
|
+
- lib/functions.rb
|
130
133
|
- lib/helpers/command_helper.rb
|
131
134
|
- lib/helpers/environment_ssh.rb
|
132
135
|
- lib/helpers/fog_helper.rb
|