bcome 0.2.1 → 0.3.2

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: c7f8aea49653325e3411b5f8b00dc2b8e38b41a2
4
- data.tar.gz: ad51468750bb88a0f0a64f2adabd12c858e3d450
3
+ metadata.gz: 01324b7764e93f79ce32699d34d94965d415cebe
4
+ data.tar.gz: 83ec2d6950806c8296dcbb7973ade7b2f67b7e6e
5
5
  SHA512:
6
- metadata.gz: e611ac95795681ac544705963c6c6f70fb061716821137cc2912238fd44919e72bfc21b23d9e1514ac730286b74629e591264a86ddd2b834b8420ca7b95495f2
7
- data.tar.gz: f17b03b5d9135ac1680a99fd16dabad09747e138638be405d531d54a606ba79ac6392c12188582fc7cf796eb1767f73d432d94cc7791bd99102ec97987dc977e
6
+ metadata.gz: ee0d1b667b905e6707fb63cd9597ecc68d8dc53544609a05236e3486d87ad500611d13ac9399ede75ecf5e84984c00ec245a5b1962b2a548b5bd457c2101ba5c
7
+ data.tar.gz: 6ce03cf191a70e15bb9f112f4928a2fcd5a36908f36c70ece2c1144dcf489fea792708f2c3dcf155da430312fa66c42603eea6926b73dbf5bb3e9e5081642d7e
data/bin/bcome CHANGED
@@ -17,4 +17,12 @@ unless @no_shell
17
17
  IRB.irb nil, @context_object
18
18
  end
19
19
 
20
+ ## We're SSH'ing directly to a node, indicated by an 'ssh' key at the end of our context breadcrumb
21
+ # called with, e.g. bcome platform:environment:node_name:ssh
20
22
  @ssh_to.node.ssh if @ssh_in && @ssh_to
23
+
24
+ ## We're going to directly execute a command on a node, indicated by the method name at the end of our context breadcrumb.
25
+ ## This works for commands specified in the users own personal framework installation, either from a context command or from an orchestration hook
26
+ ## e,g, bcome platform:environment:node_name:bootstrap
27
+ @context_object.send(@direct_execute_method) if @direct_execute_method
28
+
@@ -95,6 +95,19 @@ if quick_contexts.any?
95
95
  end
96
96
 
97
97
  next_context_resource = @context_object.resource_for_identifier(resource_context_key)
98
+
99
+ # If we can't find our context breadcrumb, the user is perhaps specifying a direct command to be run
100
+ # This is used to key into a breadcrumb context object, and then directly execute a custom command (either a context command, or one defined through
101
+ # orchestration on it).
102
+ # e.g. you have a context command called 'deploy'. You may want to do the following:
103
+ # bcome platform:environment:deploy
104
+ unless next_context_resource && index <= (quick_contexts.size - 1)
105
+ if @context_object.respond_to_bcome_context_method?(resource_context_key.to_sym)
106
+ @no_shell = true
107
+ @direct_execute_method = resource_context_key.to_sym
108
+ break
109
+ end
110
+ end
98
111
 
99
112
  # Initialize our object namespace, but only from our lowest level namespace object. This
100
113
  # ensures that we don't load more than we need.
@@ -118,5 +131,6 @@ if quick_contexts.any?
118
131
  B_PIN = @context_object
119
132
  B_PIN.init
120
133
  else
134
+ B_PIN = ESTATE
121
135
  ESTATE.init
122
136
  end
@@ -1,4 +1,3 @@
1
1
 
2
- raise "No context for bcome provided" unless ENV['bcome_context']
3
2
  @no_shell = true
4
3
  load Bcome::Boot.boot_path
@@ -12,6 +12,8 @@ Create your platforms.yml config file in path/to/your/application/bcome/configs
12
12
 
13
13
  Example configurations can be found in path/to/your/application/bcome/configs/platform.yml-example
14
14
 
15
+ * NOTE that you may add any attributes you like onto the platform config: using meta programming, bcome makes these accessible from the shell
16
+
15
17
  ### The network config
16
18
 
17
19
  The network config defines your environments within bcome - what they are, how they are accessed, and whether you with for Bcome to perform network discovery dynamically from EC2, or whether you have listed a static network list.
@@ -20,6 +22,8 @@ Create your network.yml config file in path/to/your/application/bcome/configs
20
22
 
21
23
  Example configurations can be found in path/to/your/application/bcome/configs/network.yml-example
22
24
 
25
+ * NOTE that you may add any attributes you like onto the network config: using meta programming, bcome makes these accessible from the shell
26
+
23
27
  ### Static network instances config
24
28
 
25
29
  A static list of servers may be defined if you do not wish to enable dynamic network discovery.
@@ -0,0 +1,48 @@
1
+ #!/Users/guillaume/.rvm/rubies/ruby-2.1.2-full/bin/ruby
2
+
3
+ ### External script example 1
4
+
5
+ ### Jumping to an environment context, and interacting with machines
6
+ ### Usage: bcome_context="your_platform_key:your_environment_key" bundle exec ./scriptname.rb
7
+
8
+ ## Loading bcome and accessing the loaded contexct
9
+ require 'bcome'
10
+ load Bcome::Boot.no_shell_boot_path
11
+ current_context = B_PIN.node
12
+
13
+ raise "Demo script is for an Environment context" unless current_context.is_a?(Bcome::Node::Environment)
14
+
15
+ puts "You have loaded into a context of type #{current_context.class}, named #{current_context.identifier}\n".magenta
16
+
17
+ ## The 'machines' accessor
18
+ puts "Iterating over servers found at the current context level\n".informational
19
+ machines = current_context.machines
20
+
21
+ machines.each {|machine|
22
+ puts "Identifier:".menu_item_cyan + "\s#{machine.identifier}".informational
23
+ puts "External interface address:".menu_item_cyan + "\s#{machine.external_network_interface_address}".informational
24
+ puts "\n"
25
+ }
26
+
27
+ ## Playing with a machine
28
+ puts "\nDoing things with the machines:".magenta
29
+
30
+ raise "Cannot proceed with demo, no machines found" unless machines.any?
31
+
32
+ machine = machines.first
33
+
34
+ ## Command execution
35
+ puts "\n\nExecuting a command on #{machine.identifier}".magenta
36
+ command = machine.run("whoami")
37
+
38
+ ## File upload
39
+ puts "\n\nFile upload".magenta
40
+ local_path = "~/Desktop/foo"
41
+ remote_path = "/home/guillaume"
42
+ machine.put(local_path, remote_path)
43
+
44
+ ## File download
45
+ puts "\n\nFile download".magenta
46
+ machine.get(remote_path)
47
+
48
+ exit 0
@@ -0,0 +1,44 @@
1
+ #!/Users/guillaume/.rvm/rubies/ruby-2.1.2-full/bin/ruby
2
+
3
+ ### External script example 3
4
+
5
+ ### Load up the entire estate, interact with platforms, environments, and then machines
6
+ ### Usage: bundle exec ./scriptname.rb
7
+
8
+ ## Loading bcome and accessing the loaded contexct
9
+ require 'bcome'
10
+ load Bcome::Boot.no_shell_boot_path
11
+ current_context = B_PIN.node
12
+
13
+ raise "Demo script is for an Platform context" unless current_context.is_a?(Bcome::Node::Estate)
14
+
15
+ estate = current_context
16
+
17
+ ## Can get the machines from the estate
18
+ all_machines = estate.machines
19
+
20
+ puts "Estate has #{all_machines.size} machines".informational
21
+
22
+ platforms = estate.platforms
23
+
24
+ platforms.each {|platform|
25
+
26
+ puts "\nPlatform #{platform.identifier} has #{platform.machines.size} machines".informational
27
+
28
+ ### Get all environments
29
+ environments = platform.environments
30
+
31
+ environments.each {|environment|
32
+ puts "Environment:".magenta + "\s#{environment.identifier}".informational
33
+
34
+ # Machines within this enironment
35
+ machines = environment.machines
36
+ machines.each { |machine|
37
+ puts "Identifier: ".magenta + "\s#{machine.identifier}"
38
+ }
39
+
40
+ }
41
+
42
+ }
43
+
44
+ exit 0
@@ -0,0 +1,36 @@
1
+ #!/Users/guillaume/.rvm/rubies/ruby-2.1.2-full/bin/ruby
2
+
3
+ ### External script example 2
4
+
5
+ ### Jumping to a platform context, accessing environments
6
+ ### Usage: bcome_context="your_platform_key" bundle exec ./scriptname.rb
7
+
8
+ ## Loading bcome and accessing the loaded contexct
9
+ require 'bcome'
10
+ load Bcome::Boot.no_shell_boot_path
11
+ current_context = B_PIN.node
12
+
13
+ raise "Demo script is for an Platform context" unless current_context.is_a?(Bcome::Node::Platform)
14
+
15
+ platform = current_context
16
+
17
+ ## Can get the machines from platform itself
18
+ all_machines = platform.machines
19
+
20
+ puts "Platform has #{all_machines.size} machines".informational
21
+
22
+ ### Get all environments
23
+ environments = platform.environments
24
+
25
+ environments.each {|environment|
26
+ puts "Environment:".magenta + "\s#{environment.identifier}".informational
27
+
28
+ # Machines within this enironment
29
+ machines = environment.machines
30
+ machines.each { |machine|
31
+ puts "Identifier: ".magenta + "\s#{machine.identifier}"
32
+ }
33
+
34
+ }
35
+
36
+ exit 0
@@ -5,6 +5,7 @@
5
5
  # * For SSH access, it is assumed that you are using SSH keys.
6
6
  # * For Jump SSH access, it is assumed that you are using your local user for SSH
7
7
 
8
+ ### NOTE that you may add any attributes you like onto the network config: using meta programming, bcome makes these accessible from the shell
8
9
 
9
10
  ### Example 1: Dynamic network lookup with jump host
10
11
  - :network: "project_foo"
@@ -1,9 +1,13 @@
1
+
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
+
1
4
  ---
2
5
  ## Example platforms list.
3
6
  # Platform have environments
4
7
  # environments have servers
5
8
  - :name: "project_foo"
6
9
  :description: "All the Foo environments"
10
+ :location: "Some information about where this is (optional)"
7
11
  - :name: "project_bar"
8
12
  :description: "All the Bar environments"
9
13
  :quick_contexts:
@@ -0,0 +1,31 @@
1
+ # External Usage
2
+
3
+ Bcome may be used for scripting outside of the bcome shell.
4
+
5
+ This allows for integration with tools such as Capistrano, or for any ad-hoc scripting need.
6
+
7
+ You may
8
+
9
+ * Iterate across your entire estate, and script processes over all your machines, irrespective of which platform they are in (i.e. they may live in separate web hosts, with separate credentials etc: bcome will manage the network connectivity for you.
10
+
11
+ * Iterate across all environments within a given platform.
12
+
13
+ * Iterate across all machines with a given environment.
14
+
15
+ From your scripts, you may execute arbitrary commands on your machines, and access the functionality of the bcome shell.
16
+
17
+ Example scripts:
18
+
19
+ ### Basic usage
20
+
21
+ Access machines within an environment, and interact with them
22
+
23
+ see documentation/example_non_shell_scripts/examples_script_basic_usage.rb
24
+
25
+ ### Jumping to a platform context and interacting with environments (and then the machines within them)
26
+
27
+ see documentation/example_non_shell_scripts/examples_script_platform_level.rb
28
+
29
+ ### Interacting with your entire estate
30
+
31
+ see documentation/example_non_shell_scripts/examples_script_entire_estate.rb
@@ -1,3 +1,3 @@
1
1
  module Bcome
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -56,7 +56,7 @@ module ::Bcome::BecomeObject
56
56
  end
57
57
 
58
58
  def resource_for_identifier(identifier)
59
- return nil unless resources
59
+ return nil unless has_sub_nodes? && resources
60
60
  matches = resources.select{|resource| resource.identifier.to_sym == identifier.to_sym }
61
61
  raise "Retrieved more than one match for #{collection_key} '#{identifier}'. Selection is ambiguous" if matches.size > 1
62
62
  return matches.first
@@ -1,4 +1,4 @@
1
- module ::Bcome::Selections
1
+ module Bcome::Selections
2
2
 
3
3
  def manage_object(method, resource_identifier = nil)
4
4
  unless resource_identifier && resource_identifier.is_a?(String)
@@ -50,23 +50,15 @@ module ::Bcome::Selections
50
50
  end
51
51
 
52
52
  def add(resource_identifier = nil)
53
- if resource_identifier.is_a?(Array)
54
- resource_identifier.each do |ri|
55
- manage_object(:add_object, ri)
56
- end
57
- else
58
- manage_object(:add_object, resource_identifier)
59
- end
53
+ resource_identifier = [resource_identifier] unless resource_identifier.is_a?(Array)
54
+ resource_identifier.each {|ri| manage_object(:add_object, ri) }
55
+ puts "\n" + "#{resource_identifier.join(",")} added.".menu_item_cyan + "\n\nType 'selections' or 's' to review your selections.'".menu_item_white
60
56
  end
61
57
 
62
58
  def remove(resource_identifier = nil)
63
- if resource_identifier.is_a?(Array)
64
- resource_identifier.each do |ri|
65
- manage_object(:remove_object, ri)
66
- end
67
- else
68
- manage_object(:remove_object, resource_identifier)
69
- end
59
+ resource_identifier = [resource_identifier] unless resource_identifier.is_a?(Array)
60
+ resource_identifier.each { |ri| manage_object(:remove_object, ri) }
61
+ puts "\n Nodes removed.".menu_item_cyan
70
62
  end
71
63
 
72
64
  def add!
@@ -90,7 +82,6 @@ module ::Bcome::Selections
90
82
  def add_object(object)
91
83
  return if object_in_selections?(object)
92
84
  @objects = @objects ? (@objects << object) : [object]
93
- puts "\n" + "#{object.identifier} added.".menu_item_cyan + "\sType 'selections' to see currently selections instances.'".menu_item_white
94
85
  return
95
86
  end
96
87
 
@@ -100,7 +91,6 @@ module ::Bcome::Selections
100
91
  puts "\n#{object.identifier} is not within selections".headsup
101
92
  else
102
93
  @objects = @objects - [object]
103
- puts "\n" + "#{object.identifier} removed.".menu_item_cyan + "\sType 'selections' to see currently selections instances.'".menu_item_white
104
94
  end
105
95
  return
106
96
  end
@@ -118,6 +108,7 @@ module ::Bcome::Selections
118
108
  puts @objects.collect {|o| o.do_describe }.join + "\n"
119
109
  end
120
110
  end
111
+ alias :s :selections
121
112
 
122
113
  def no_selections_error
123
114
  puts "No nodes selected".informational
@@ -34,7 +34,6 @@ class String
34
34
  :failure => { :colour => :red },
35
35
  :success => { :colour => :green },
36
36
  :title => { :colour => :green },
37
- :success => { :colour => :green },
38
37
  :command => { :colour => :cyan, :highlight => true },
39
38
  :danger => { :colour => :red },
40
39
  :warning => { :colour => :orange },
@@ -5,12 +5,12 @@ class ::Bcome::RenderIrb
5
5
  print "\n\sNo resources collections found. Maybe you forgot to add any?".headsup
6
6
  else
7
7
  print "\n\s"
8
- puts "#{parent_collection.to_s.menu_title_green}:".menu_title_green
8
+ puts "#{parent_collection.to_s.menu_title_green}\n".menu_title_green
9
9
  items.each do |item|
10
10
  puts "\t*/added".danger + "\n" if item.highlight?
11
11
  print item.do_describe
12
12
  end
13
- print "\n\s\sUse cd [node identifier], e.g. cd \"#{items.first.identifier}\" to work on a given node.\n\n"
13
+ print "\n\s\sUse cd [node identifier], e.g. cd :#{items.first.identifier} OR cd \"#{items.first.identifier}\" to work on a given node.\n\n"
14
14
  end
15
15
  end
16
16
 
@@ -9,6 +9,10 @@ module ::Bcome::Stack
9
9
  node.machines
10
10
  end
11
11
 
12
+ def has_sub_nodes?
13
+ return true
14
+ end
15
+
12
16
  ###
13
17
  ## Construction & Initialisation
14
18
  ##
@@ -21,6 +25,10 @@ module ::Bcome::Stack
21
25
  @node ||= construct_node
22
26
  end
23
27
 
28
+ def respond_to_bcome_context_method?(method_sym)
29
+ return (command_for_context(method_sym) || ::Bcome::Orchestrator::Recipe.by_identifier(method_sym.to_s, self)) ? true : false
30
+ end
31
+
24
32
  def method_missing(method_sym, *arguments, &block)
25
33
  if command_for_context = command_for_context(method_sym)
26
34
  execute_command_for_context(command_for_context)
@@ -31,7 +31,7 @@ module ::Bcome::Stack
31
31
  { :command => "add!", :description => "Add all resources from the current context." },
32
32
  { :command => "remove", :description => "Remove a resource you no longer with to work on.", :usage => "remove 'identifier', OR remove ['array', 'of','identifiers']" },
33
33
  { :command => "clear!", :description => "Remove all selected resources." },
34
- { :command => "selections", :description => "Show all added resources." },
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'" },
36
36
  { :command => "get", :description => "Download from remote from all selected resources (recursive - uses rsync)", :usage => "get 'remote_path'" },
37
37
  { :command => "put", :description => "Copy files up to all selected resources (recursive - uses rsync)", :usage => "put 'local_path', 'remote_path'" },
@@ -42,6 +42,10 @@ module ::Bcome::Stack
42
42
  node.identifier
43
43
  end
44
44
 
45
+ def has_sub_nodes?
46
+ return false
47
+ end
48
+
45
49
  ## Commands
46
50
  def ssh
47
51
  node.ssh
@@ -27,10 +27,10 @@ module ::Bcome::Stack
27
27
  end
28
28
 
29
29
  def do_describe
30
- description = "\n"
31
- description += "\tPlatform Name:".menu_item_cyan + "\s#{identifier.menu_item_green}\n"
30
+ description = "\tPlatform Name:".menu_item_cyan + "\s#{identifier.menu_item_green}\n"
32
31
  description += "\t" + "Description:".menu_item_cyan + "\s#{@meta_data[:description].menu_item_white}" + "\n"
33
32
  description += "\t" + "Location:".menu_item_magenta + "\s#{@meta_data[:location].menu_item_white}" + "\n" if @meta_data[:location]
33
+ description += "\n"
34
34
 
35
35
  return description
36
36
  end
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.2.1
4
+ version: 0.3.2
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-01-12 00:00:00.000000000 Z
11
+ date: 2016-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -117,9 +117,13 @@ files:
117
117
  - bin/boot.rb
118
118
  - bin/boot_no_shell.rb
119
119
  - documentation/configuration.md
120
+ - documentation/example_non_shell_scripts/examples_script_basic_usage.rb
121
+ - documentation/example_non_shell_scripts/examples_script_entire_estate.rb
122
+ - documentation/example_non_shell_scripts/examples_script_platform_level.rb
120
123
  - documentation/examples/functions.yml-example
121
124
  - documentation/examples/network.yml-example
122
125
  - documentation/examples/platform.yml-example
126
+ - documentation/external_usage.md
123
127
  - documentation/functions.md
124
128
  - documentation/installation.md
125
129
  - documentation/usage.md