bcome 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5b0ebe228e2ae3369ca4014f664c632673b0a9e
4
- data.tar.gz: 42cb66fcc2405cc00e45d39bbc4b21565f3ae23b
3
+ metadata.gz: 6679955d918e9393a9ec586ca27efefb93877575
4
+ data.tar.gz: 0edac73427d8221c6882854a6dfa5f6990f63aa6
5
5
  SHA512:
6
- metadata.gz: 2f6990c0d55e964ffd126a4d5ab7de6a41d440cb90e3674838a384ff9841b3d07b357c656d67aa14088439ef3aa3f9eb1e6e5ade4b142ae7ce82ac54b826e5d8
7
- data.tar.gz: 4ff8bd98c95b1d727c016afc7f8b93210e06c3d4424eeef1c7f2bc340e6d000672f0e26f927b9c16c46c0009858dbe3a6993e9562458314f6baa901717dc113a
6
+ metadata.gz: 21d4e826fbaf8c9b1467766eeb704c0af00942893ee10b29fb7049d4948471a96d4155d756b7c07a7f19349f4abd8faf349d7f9417f8d7174e9cd8e5d7d6683c
7
+ data.tar.gz: e0c1972cb89cc5ace8ccf739d2301825cc120f6cbc098b71e89497d5e3c6d688eca63521479bf1e06c27f64936264fa9290f3eabe3fc3f16d55a4df7c4e8c46e
data/bin/bcome CHANGED
@@ -21,6 +21,13 @@ end
21
21
  # called with, e.g. bcome platform:environment:node_name:ssh
22
22
  @ssh_to.node.ssh if @ssh_in && @ssh_to
23
23
 
24
+ ## We're directly excuting a command on a n node indicated by a 'run' key at the end of our context breadrumb
25
+ # called with, e.g. bcome platform:environment:node_name:run "command to execute"
26
+ if @run_cmd && @run_on
27
+ params = ARGV[(1..(ARGV.size))].join("\s")
28
+ @run_on.node.run(params)
29
+ end
30
+
24
31
  ## We're going to directly execute a command on a node, indicated by the method name at the end of our context breadcrumb.
25
32
  ## This works for commands specified in the users own personal framework installation, either from a context command or from an orchestration hook
26
33
  ## e,g, bcome platform:environment:node_name:bootstrap
data/bin/boot.rb CHANGED
@@ -67,7 +67,9 @@ if quick_context
67
67
  end
68
68
  end
69
69
 
70
- @no_shell = true if quick_contexts.last == "ssh"
70
+ direct_commands = ["run", "ssh"]
71
+
72
+ @no_shell = true if direct_commands.include?(quick_contexts.last)
71
73
 
72
74
  #########################
73
75
  ## QUICK CONTEXT & BOOT #
@@ -94,6 +96,12 @@ if quick_contexts.any?
94
96
  break
95
97
  end
96
98
 
99
+ if resource_context_key == "run" && index == (quick_contexts.size - 1)
100
+ @run_cmd = true
101
+ @run_on = @context_object
102
+ break
103
+ end
104
+
97
105
  next_context_resource = @context_object.resource_for_identifier(resource_context_key)
98
106
 
99
107
  # If we can't find our context breadcrumb, the user is perhaps specifying a direct command to be run
@@ -101,8 +109,9 @@ if quick_contexts.any?
101
109
  # orchestration on it).
102
110
  # e.g. you have a context command called 'deploy'. You may want to do the following:
103
111
  # bcome platform:environment:deploy
112
+
104
113
  unless next_context_resource && index <= (quick_contexts.size - 1)
105
- if @context_object.respond_to_bcome_context_method?(resource_context_key.to_sym)
114
+ if @context_object.respond_to_bcome_context_method?(resource_context_key.to_sym)
106
115
  @no_shell = true
107
116
  @direct_execute_method = resource_context_key.to_sym
108
117
  break
@@ -34,7 +34,7 @@ Name your configuration file “[platformName]_[EnvironmentName]-instances.yml,
34
34
 
35
35
  Two examples are given below:
36
36
 
37
- Example 1: Static instances accessible directly, without the need to travers a jump host
37
+ Example 1: Static instances accessible directly, without the need to traverse a jump host
38
38
 
39
39
  ```
40
40
  ---
@@ -1,4 +1,4 @@
1
- #!/Users/guillaume/.rvm/rubies/ruby-2.1.2-full/bin/ruby
1
+ #!/usr/bin/ruby
2
2
 
3
3
  ### External script example 1
4
4
 
@@ -1,4 +1,4 @@
1
- #!/Users/guillaume/.rvm/rubies/ruby-2.1.2-full/bin/ruby
1
+ #!/usr/bin/ruby
2
2
 
3
3
  ### External script example 3
4
4
 
@@ -1,4 +1,4 @@
1
- #!/Users/guillaume/.rvm/rubies/ruby-2.1.2-full/bin/ruby
1
+ #!/usr/bin/ruby
2
2
 
3
3
  ### External script example 2
4
4
 
@@ -1,22 +1,10 @@
1
-
1
+ ---
2
2
  ### NOTE that you may add any attributes you like onto the platform config: using meta programming, bcome makes these accessible from the shell
3
3
 
4
- ---
5
- ## Example platforms list.
6
- # Platform have environments
7
- # environments have servers
8
4
  - :name: "project_foo"
9
5
  :description: "All the Foo environments"
10
6
  :location: "Some information about where this is (optional)"
7
+
11
8
  - :name: "project_bar"
12
9
  :description: "All the Bar environments"
13
- :quick_contexts:
14
-
15
- # Quick link example > bcome project_bar:app1
16
- - :ref: "app1" # Provides a quick link to a server named 'app1' within Platform 'project_foo', and environment 'production'
17
- :keys:
18
- - "project_foo"
19
- - "production"
20
- - "app1"
21
-
22
-
10
+ :location: "Some information about where this is (optional)"
@@ -1,5 +1,32 @@
1
1
  # External Usage
2
2
 
3
+ ## Direct SSH to nodes
4
+
5
+ If you know the context breadcrumb for a node, you may SSH to it directly without accessing the node via the shell.
6
+
7
+ For example, you wish to SSH in to server 'instancename' in environment 'environment' for platform 'platform':
8
+
9
+ ```
10
+ > bcome platform:environment:instancename:ssh
11
+ e.g.
12
+ > bcome myplatformname:production:appserver1:ssh
13
+ ```
14
+ !["Direct SSH"](images/direct_ssh.png)
15
+
16
+ ## Direct command execution on a selection
17
+
18
+ You can pass commands directly to be executed on all machines at a specific context level by using the 'run' suffix.
19
+
20
+ For example, you wish to discover the free memory on all machines in platform 'wbz' and environment 'prod':
21
+
22
+ ```
23
+ > bcome wbz:prod:run "free -m"
24
+ ```
25
+
26
+ The command is executed in parallel on all machines, with the output & status returned to the terminal.
27
+
28
+ !["Direct command execution"](images/direct_cmd_execution.png)
29
+
3
30
  ## Scripting
4
31
 
5
32
  Bcome may be used for scripting outside of the bcome shell.
@@ -32,15 +59,3 @@ see documentation/example_non_shell_scripts/examples_script_platform_level.rb
32
59
 
33
60
  see documentation/example_non_shell_scripts/examples_script_entire_estate.rb
34
61
 
35
- ## Direct SSH to nodes
36
-
37
- If you know the context breadcrumb for a node, you may use the bcome gem to SSH to it directly without accessing the node via the bcome shell.
38
-
39
- ```
40
-
41
- > bcome platform:environment:instancename:ssh
42
- e.g.
43
- > bcome myplatformname:production:appserver1:ssh
44
-
45
- ```
46
-
Binary file
@@ -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 / cd
39
+ > cd
40
40
  - Select a resource object, and switch to its context.
41
- e.g. cd 'identifier'
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 / cd
65
+ > cd
66
66
  - Select a resource object, and switch to its context.
67
- e.g. cd 'identifier' OR workon 'identifier' OR w 'identifier'
67
+ e.g. cd 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
- > cd / workon / w
91
+ > cd
92
92
  - Select a resource object, and switch to its context.
93
- e.g. cd 'identifier' OR w 'identifier' OR workon 'identifier'
93
+ e.g. cd identifier
94
94
 
95
95
  > exit
96
96
  - Close the current context
@@ -104,14 +104,14 @@ e.g. local "command"
104
104
 
105
105
  > add
106
106
  - Add a resource you wish to work on.
107
- e.g. add 'identifier', OR add ['array', 'of', 'identifiers']
107
+ e.g. add identifier, OR add [array, of, identifiers]
108
108
 
109
109
  > add!
110
110
  - Add all resources from the current context.
111
111
 
112
112
  > remove
113
113
  - Remove a resource you no longer with to work on.
114
- e.g. remove 'identifier', OR remove ['array', 'of','identifiers']
114
+ e.g. remove identifier, OR remove [array, of, identifiers]
115
115
 
116
116
  > clear!
117
117
  - Remove all selected resources.
@@ -133,7 +133,7 @@ e.g. get 'remotepath'
133
133
  e.g. run 'command'
134
134
 
135
135
  > sudo
136
- - Enters 'sudo' mode, resulting in 'get' or 'put' commands being execute remotely using 'sudo'. This assumes that you have passwordless sudo setup on each respective remote host.
136
+ - Enters 'sudo' mode, resulting in 'get' or 'put' commands being executed remotely using 'sudo'. This assumes that you have passwordless sudo setup on each respective remote host.
137
137
 
138
138
  ### Instance level commands
139
139
 
@@ -146,9 +146,9 @@ e.g. run 'command'
146
146
  > describe
147
147
  - Describe the resource object at the current context.
148
148
 
149
- > workon / w
149
+ > cd
150
150
  - Select a resource object, and switch to its context.
151
- e.g. workon 'identifier'
151
+ e.g. cd identifier
152
152
 
153
153
  > exit
154
154
  - Close the current context
data/lib/bcome/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bcome
2
- VERSION = "0.3.4"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/become_object.rb CHANGED
@@ -50,9 +50,29 @@ module ::Bcome::BecomeObject
50
50
  @resources ||= do_load_resources
51
51
  end
52
52
 
53
+ def resource_identifiers
54
+ @resource_identifiers ||= resources.collect(&:identifier)
55
+ end
56
+
57
+ def identifier_for(resource)
58
+ r = resource.respond_to?(:identifier) ? resource.identifier : resource.to_s
59
+ return r
60
+ end
61
+
62
+ def has_potential_resources?
63
+ respond_to?(:config_path) # No path to config, no resources...
64
+ end
65
+
66
+ def is_stack_level_resource?(constant_name)
67
+ return unless has_potential_resources?
68
+ potential_resource_name = constant_name.to_s
69
+ return false unless resource_identifiers.any?
70
+ return resource_identifiers.select{|resource| identifier_for(resource) == potential_resource_name }.any?
71
+ end
72
+
53
73
  def do_load_resources
54
74
  config = YAML.load_file(config_path)
55
- return collection_klass.collection_from_config(self, config)
75
+ collection_klass.collection_from_config(self, config)
56
76
  end
57
77
 
58
78
  def resource_for_identifier(identifier)
data/lib/nodes/base.rb CHANGED
@@ -13,6 +13,15 @@ module ::Bcome::Node
13
13
  construct(meta_data)
14
14
  end
15
15
 
16
+ ## Runs a command over *every* machine in this node
17
+ def run(raw_command, bootstrap = false)
18
+ return unless machines
19
+ machines.pmap {|machine|
20
+ machine.run([raw_command], bootstrap)
21
+ }
22
+ return
23
+ end
24
+
16
25
  def method_missing(method_sym, *arguments, &block)
17
26
  if instance_variable_defined?("@#{method_sym}")
18
27
  return instance_variable_get("@#{method_sym}")
data/lib/nodes/estate.rb CHANGED
@@ -6,11 +6,19 @@ module ::Bcome::Node
6
6
  def machines
7
7
  platforms.collect(&:machines).flatten
8
8
  end
9
-
9
+
10
10
  def namespace
11
11
  ""
12
12
  end
13
13
 
14
+ def run(raw_command, bootstrap = false)
15
+ return unless platforms
16
+ platforms.pmap {|platform|
17
+ platform.run(raw_command, bootstrap)
18
+ }
19
+ return
20
+ end
21
+
14
22
  def environments
15
23
  @environments ||= platforms.collect(&:environments).flatten
16
24
  end
data/lib/stack/base.rb CHANGED
@@ -9,6 +9,30 @@ module ::Bcome::Stack
9
9
  node.machines
10
10
  end
11
11
 
12
+ def self.const_missing(constant_name)
13
+ ## Hook for direct access to stack level resources by constant name where
14
+ ## cd ServerName should yield the same outcome as cd "ServerName" or cd :ServerName does
15
+ ## This works at all stack levels, and so is applied to environments and platforms too
16
+ stack_level_instance = ::IRB.CurrentContext.workspace.main
17
+ return constant_name.to_s if stack_level_instance.is_stack_level_resource?(constant_name)
18
+ super
19
+ end
20
+
21
+ def method_missing(method_sym, *arguments, &block)
22
+ if command_for_context = command_for_context(method_sym)
23
+ execute_command_for_context(command_for_context)
24
+ elsif recipe = ::Bcome::Orchestrator::Recipe.by_identifier(method_sym.to_s, self)
25
+ puts "Executing Command Recipe #{recipe.recipe_identifier}".informational
26
+ puts "Description: #{recipe.description}".command
27
+ recipe.execute!(machines)
28
+ return
29
+ else
30
+ # Else, this could be a resource level item
31
+ return method_sym.to_s if is_stack_level_resource?(method_sym)
32
+ super
33
+ end
34
+ end
35
+
12
36
  def has_sub_nodes?
13
37
  return true
14
38
  end
@@ -29,19 +53,6 @@ module ::Bcome::Stack
29
53
  return (command_for_context(method_sym) || ::Bcome::Orchestrator::Recipe.by_identifier(method_sym.to_s, self)) ? true : false
30
54
  end
31
55
 
32
- def method_missing(method_sym, *arguments, &block)
33
- if command_for_context = command_for_context(method_sym)
34
- execute_command_for_context(command_for_context)
35
- elsif recipe = ::Bcome::Orchestrator::Recipe.by_identifier(method_sym.to_s, self)
36
- puts "Executing Command Recipe #{recipe.recipe_identifier}".informational
37
- puts "Description: #{recipe.description}".command
38
- recipe.execute!(machines)
39
- return
40
- else
41
- super
42
- end
43
- end
44
-
45
56
  def construct_node
46
57
  node_attributes = meta_data
47
58
 
@@ -59,7 +70,6 @@ module ::Bcome::Stack
59
70
  end
60
71
 
61
72
  def init
62
- puts "loading resources #{self.class} "
63
73
  node
64
74
  end
65
75
 
@@ -97,7 +107,7 @@ module ::Bcome::Stack
97
107
  [
98
108
  { :command => "list / ls", :description => "List all available resources at the current context." },
99
109
  { :command => "describe", :description => "Describe the resource object at the current context." },
100
- { :command => "cd [Node Name]", :description => "Select a resource object, and switch to its context.", :usage => "cd 'YourServerName'" },
110
+ { :command => "cd NodeName", :description => "Select a resource object, and switch to its context.", :usage => "cd YourServerName" },
101
111
  { :command => "exit", :description => "Return to the previous context" },
102
112
  { :command => "exit!", :description => "Close all contexts, and exit Become."},
103
113
  { :command => "local", :description => "Execute a shell command on your local machine.", :usage => 'local "command"'},
@@ -27,9 +27,9 @@ module ::Bcome::Stack
27
27
 
28
28
  def menu_items
29
29
  super + [
30
- { :command => "add", :description => "Add a resource you wish to work on.", :usage => "add 'identifier', OR add ['array', 'of', 'identifiers']" },
30
+ { :command => "add", :description => "Add a resource you wish to work on.", :usage => "add MyServerIdentifier, OR add [array, of, identifiers]" },
31
31
  { :command => "add!", :description => "Add all resources from the current context." },
32
- { :command => "remove", :description => "Remove a resource you no longer with to work on.", :usage => "remove 'identifier', OR remove ['array', 'of','identifiers']" },
32
+ { :command => "remove", :description => "Remove a resource you no longer with to work on.", :usage => "remove MyServerIdentifier, OR remove [array, of, identifiers]" },
33
33
  { :command => "clear!", :description => "Remove all selected resources." },
34
34
  { :command => "selections", :description => "Show all added resources.", :usage => "selections / s"},
35
35
  { :command => "run", :description => "Execute a command on all selected resources", :usage => "run 'command'" },
data/lib/stack/estate.rb CHANGED
@@ -32,7 +32,6 @@ module ::Bcome::Stack
32
32
  end
33
33
 
34
34
  def init
35
- puts "loading resources ... "
36
35
  n = ::Bcome::Node::Estate.new({ :platforms => resources.collect(&:node) })
37
36
  n.set_parent_reference(n, :estate, :platforms)
38
37
  return n
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.3.4
4
+ version: 0.4.0
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: 2016-07-18 00:00:00.000000000 Z
11
+ date: 2016-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -116,8 +116,9 @@ dependencies:
116
116
  version: 1.1.1
117
117
  description: Provides a console interface for traversing a hierarchy of platforms
118
118
  -> environment -> servers, and exposes common administration tools for the managemenent
119
- either of individual servers, or groups or servers. System is driven from simple
120
- configuration, and is extensible. Integrates with AWS EC2 for dynamic network discover.
119
+ either of individual servers, or groups of servers. The system is driven from simple
120
+ configuration and is extensible. It integrates with AWS EC2 for dynamic network
121
+ discovery. Machines may be interacted with directly from the command line.
121
122
  email:
122
123
  - guillaume@webzakimbo.com
123
124
  executables:
@@ -139,6 +140,8 @@ files:
139
140
  - documentation/examples/platform.yml-example
140
141
  - documentation/external_usage.md
141
142
  - documentation/functions.md
143
+ - documentation/images/direct_cmd_execution.png
144
+ - documentation/images/direct_ssh.png
142
145
  - documentation/installation.md
143
146
  - documentation/usage.md
144
147
  - filters/ec2_filter.rb
@@ -213,5 +216,5 @@ rubyforge_project:
213
216
  rubygems_version: 2.2.2
214
217
  signing_key:
215
218
  specification_version: 4
216
- summary: Toolkit for managing servers & organising the management of servers
219
+ summary: Toolkit for managing machines - simplify your workflow.
217
220
  test_files: []