bcome 0.0.7 → 0.0.8

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: 182bfab8bb82f233dc36d0997b8b04d5c338fdbc
4
- data.tar.gz: 05f502b57479254e9f8242105950e11cae9a890b
3
+ metadata.gz: 6d99a4af143d2075b4f499a92601ccc27a94dd96
4
+ data.tar.gz: 282f22fcfc8fd304bd8f860ee1a727d42e26ab2a
5
5
  SHA512:
6
- metadata.gz: 44c5de8e693ea1a1d7ede4eb64ece7ba5d388a6f3de742fbf234c1a4a17a5bd6845467060084ce019f439cef9e3c7b01fd19e343c56c8abb294598f452b162e5
7
- data.tar.gz: 7269b4533caae53f815e80ceb40ac6ca3c4f071a3ea537752b9a5ee9850c7efac12c88d38c101a4c28d5e48c1d16bc48d7cadeb326b3e4bd43a7933bec005861
6
+ metadata.gz: dd94a30b7aa4c68c3735bf3c60e788745bd330723823cb8e62fd9458175a4185dd359835ccaa6e3373ea0f13e20645ddbaa9b081da29e831169a85e0f47b2bac
7
+ data.tar.gz: 44daa435ece36665e1cc1c9e9e9abe4cdd9412ab6119fb41fa7ba9e5fb31c214c304bb042ad4c52b3a88100d8b37646c93912c737f4f519660bbeb17c84f15c8
data/bin/bcome CHANGED
@@ -33,7 +33,7 @@ Dir[Dir.pwd + "/bcome/filters/**/*.rb"].each {|file| load file }
33
33
  quick_contexts = []
34
34
 
35
35
  BECOME = ::Bcome::WorkspaceContext.new
36
- BOOT = ::Bcome::Boot.new
36
+ ESTATE = ::Bcome::Stack::Estate.new
37
37
  RENDER = ::Bcome::RenderIrb.new
38
38
 
39
39
  ###########################
@@ -50,7 +50,7 @@ if ARGV[0]
50
50
  exit 1
51
51
  end
52
52
 
53
- unless platform = BOOT.resource_for_identifier(platform_key)
53
+ unless platform = ESTATE.resource_for_identifier(platform_key)
54
54
  puts "Cannot find platform named #{platform_key}".failure
55
55
  exit
56
56
  end
@@ -73,13 +73,23 @@ IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
73
73
  ## QUICK CONTEXT & BOOT #
74
74
  #########################
75
75
 
76
- context_object = BOOT
76
+ context_object = ESTATE
77
77
 
78
78
  if quick_contexts.any?
79
+
80
+ is_first_context = true
81
+
79
82
  spawn = false
80
83
  quick_contexts.each do |resource_context_key|
81
84
  next_context_resource = context_object.resource_for_identifier(resource_context_key)
82
85
 
86
+ # Initialize our object namespace, but only from our lowest level namespace object. This
87
+ # ensure we don't load more than we need.
88
+ if is_first_context
89
+ next_context_resource.init
90
+ is_first_context = false
91
+ end
92
+
83
93
  if next_context_resource.nil?
84
94
  puts "Cannot find any resources object named: #{resource_context_key}. Please check your quick contexts and try again".failure
85
95
  exit
@@ -88,6 +98,8 @@ if quick_contexts.any?
88
98
  BECOME.set(next_context_resource, context_object, spawn)
89
99
  context_object = next_context_resource
90
100
  end
101
+ else
102
+ ESTATE.init
91
103
  end
92
104
 
93
105
  ##################
data/lib/bcome/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bcome
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/become_object.rb CHANGED
@@ -12,7 +12,6 @@ module ::Bcome::BecomeObject
12
12
  "#{previous_workspace_object.send(:become_identifier)}> #{identifier}"
13
13
  end
14
14
 
15
-
16
15
  def local_download_path
17
16
  "#{Dir.pwd}/downloads#{namespace}"
18
17
  end
@@ -9,46 +9,97 @@ module ::Bcome::EnvironmentSSH
9
9
  return "ssh -W %h:%p #{bastion_ip_address}"
10
10
  end
11
11
 
12
- def execute_command(commands, node)
12
+ def execute_command(commands, instance)
13
13
  begin
14
- return execute_cmd(commands, node, proxy)
14
+ return execute_cmd(commands, instance, proxy)
15
15
  rescue Net::SSH::AuthenticationFailed
16
- raise "Could not authenticate connection to #{node.identifier}".failure
16
+ raise "Could not authenticate connection to #{instance.identifier}".failure
17
17
  rescue Net::SSH::Disconnect
18
- raise "SSH connection to #{node.identifier} was disconnected".failure
18
+ raise "SSH connection to #{instance.identifier} was disconnected".failure
19
19
  end
20
20
  end
21
21
 
22
- def execute_cmd(raw_commands, node, proxy)
22
+ def execute_cmd(raw_commands, instance, proxy)
23
23
  commands = raw_commands.collect{|raw_command|
24
- raw_command.is_a?(::Bcome::Command) ? raw_command : ::Bcome::Command.new(raw_command, node)
24
+ raw_command.is_a?(::Bcome::Command) ? raw_command : ::Bcome::Command.new(raw_command, instance)
25
25
  }
26
26
 
27
- ssh = ::Bcome::Ssh.new(commands, proxy, node)
27
+ ssh = ::Bcome::Ssh.new(commands, proxy, instance)
28
28
  ssh.execute!
29
29
  return
30
30
  end
31
31
 
32
- def execute_scp_upload(files, remote_path, node)
32
+ def execute_scp_upload(files, remote_path, instance)
33
33
  begin
34
- scp = ::Bcome::Scp.new(proxy, node)
34
+ scp = ::Bcome::Scp.new(proxy, instance)
35
35
  scp.upload!(files, remote_path)
36
36
  rescue Net::SSH::AuthenticationFailed
37
- raise "Could not authenticate connection to #{node.identifier}".failure
37
+ raise "Could not authenticate connection to #{instance.identifier}".failure
38
38
  rescue Net::SSH::Disconnect
39
- raise "SSH connection to #{node.identifier} was disconnected".failure
39
+ raise "SSH connection to #{instance.identifier} was disconnected".failure
40
40
  end
41
41
  end
42
42
 
43
- def execute_scp_download(remote_path, local_path, node)
43
+ def execute_scp_download(remote_path, local_path, instance)
44
44
  begin
45
- scp = ::Bcome::Scp.new(proxy, node)
45
+ scp = ::Bcome::Scp.new(proxy, instance)
46
46
  scp.download!(remote_path, local_path)
47
47
  rescue Net::SSH::AuthenticationFailed
48
- raise "Could not authenticate connection to #{node.identifier}".failure
48
+ raise "Could not authenticate connection to #{instance.identifier}".failure
49
49
  rescue Net::SSH::Disconnect
50
- raise "SSH connection to #{node.identifier} was disconnected".failure
50
+ raise "SSH connection to #{instance.identifier} was disconnected".failure
51
51
  end
52
52
  end
53
53
 
54
+ def bastion_server
55
+ instances.select{|instance| instance.identifier == @ssh_mode[:jump_host_identifier] }.first
56
+ end
57
+
58
+ def ssh_mode_type
59
+ ssh_mode_type = @ssh_mode[:type]
60
+ raise "Invalid ssh mode type #{ssh_mode_type}. Should be one of #{valid_ssh_modes.join(", ")}".failure unless valid_ssh_modes.include?(ssh_mode_type)
61
+ return @ssh_mode[:type]
62
+ end
63
+
64
+ def ssh_mode_user
65
+ return @ssh_mode[:ssh_user]
66
+ end
67
+
68
+ def ssh_nat_user
69
+ return @ssh_mode[:nat_user]
70
+ end
71
+
72
+ def ssh_key_path
73
+ return @ssh_mode[:ssh_key_path]
74
+ end
75
+
76
+ def valid_ssh_modes
77
+ [::SSH_JUMP_MODE_IDENTIFIER, ::SSH_DIRECT_MODE_IDENTIFIER]
78
+ end
79
+
80
+ def bastion_ip_address
81
+ if dynamic_network_lookup?
82
+ return bastion_server.public_ip_address
83
+ else
84
+ bastion_ip_address = @ssh_mode[:jump_host_ip_address]
85
+ raise "No jump_host_ip_address specified in your configuration.".failure unless bastion_ip_address
86
+ return bastion_ip_address
87
+ end
88
+ end
89
+
90
+ def network_lookup
91
+ raise "Missing network lookup in networks_environment configuration".failure unless @network_lookup
92
+ return @network_lookup
93
+ end
94
+
95
+ def network_lookup_type
96
+ type = network_lookup[:type]
97
+ raise "Unknown network lookup type '#{type}" unless ["dynamic", "static"].include?(type)
98
+ return type
99
+ end
100
+
101
+ def dynamic_network_lookup?
102
+ return network_lookup_type == "dynamic"
103
+ end
104
+
54
105
  end
@@ -31,16 +31,16 @@ module ::Bcome::InstanceSsh
31
31
  end
32
32
 
33
33
  def nat_user
34
- return @environment.ssh_nat_user ? @environment.ssh_nat_user : ssh_user
34
+ return environment.ssh_nat_user ? environment.ssh_nat_user : ssh_user
35
35
  end
36
36
 
37
37
  def ssh_user
38
38
  # defined by the environment or we fall back to the local user
39
- return @environment.ssh_mode_user ? @environment.ssh_mode_user : `whoami`.gsub("\n","")
39
+ return environment.ssh_mode_user ? environment.ssh_mode_user : `whoami`.gsub("\n","")
40
40
  end
41
41
 
42
42
  def ssh_key_path
43
- return @environment.ssh_key_path ? @environment.ssh_key_path : "~/.ssh/id_rsa"
43
+ return environment.ssh_key_path ? environment.ssh_key_path : "~/.ssh/id_rsa"
44
44
  end
45
45
 
46
46
  def keys
@@ -48,7 +48,7 @@ module ::Bcome::InstanceSsh
48
48
  end
49
49
 
50
50
  def bastion_ip_address
51
- return @environment.bastion_ip_address
51
+ return environment.bastion_ip_address
52
52
  end
53
53
 
54
54
  def is_direct_ssh?
@@ -64,7 +64,7 @@ module ::Bcome::InstanceSsh
64
64
  end
65
65
 
66
66
  def is_ssh_jump_host?
67
- @meta_data["role"] == ::SSH_JUMP_HOST_ROLE_IDENTIFIER
67
+ @role == ::SSH_JUMP_HOST_ROLE_IDENTIFIER
68
68
  end
69
69
 
70
70
  end
data/lib/nodes/base.rb ADDED
@@ -0,0 +1,39 @@
1
+ module ::Bcome::Node
2
+ class Base
3
+
4
+ include ::Bcome::CommandHelper
5
+
6
+ attr_reader :meta_data
7
+
8
+ def machines
9
+ raise "Should be overriden"
10
+ end
11
+
12
+ def initialize(meta_data)
13
+ construct(meta_data)
14
+ end
15
+
16
+ def method_missing(method_sym, *arguments, &block)
17
+ if instance_variable_defined?("@#{method_sym}")
18
+ return instance_variable_get("@#{method_sym}")
19
+ else
20
+ super
21
+ end
22
+ end
23
+
24
+ def set_parent_reference(parent, parent_reference_key, collection_key)
25
+ instance_variable_get("@#{collection_key}").map{|collection_item|
26
+ collection_item.instance_variable_set("@#{parent_reference_key}", parent)
27
+ }
28
+ end
29
+
30
+ private
31
+
32
+ def construct(meta_data = {})
33
+ meta_data.each do |key, value|
34
+ self.instance_variable_set("@#{key}", value)
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ module ::Bcome::Node
2
+ class Environment < ::Bcome::Node::Base
3
+
4
+ include ::Bcome::EnvironmentSSH
5
+
6
+ def machines
7
+ instances
8
+ end
9
+
10
+ def identifier
11
+ @environment
12
+ end
13
+
14
+ def namespace
15
+ "#{platform.namespace}/#{identifier}"
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,36 @@
1
+ module ::Bcome::Node
2
+ class Estate < ::Bcome::Node::Base
3
+
4
+ include ::Bcome::Selections
5
+
6
+ def machines
7
+ platforms.collect(&:machines).flatten
8
+ end
9
+
10
+ def namespace
11
+ ""
12
+ end
13
+
14
+ def environments
15
+ @environments ||= platforms.collect(&:environments).flatten
16
+ end
17
+
18
+ def list_all
19
+ estate_machine_list = "\n"
20
+ platforms.each do |platform|
21
+ estate_machine_list += "* #{platform.identifier}\n"
22
+ platform.environments.each do |environment|
23
+ estate_machine_list += "\t- #{environment.identifier}\n"
24
+ environment.instances.each do |instance|
25
+ estate_machine_list += "\t\t / #{instance.identifier} (#{instance.public_ip_address})\n"
26
+ end
27
+ end
28
+ end
29
+
30
+ puts estate_machine_list.colorize(:green)
31
+
32
+ return ""
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ module ::Bcome::Node
2
+ class Instance < ::Bcome::Node::Base
3
+
4
+ include ::Bcome::InstanceCommand
5
+ include ::Bcome::InstanceSsh
6
+ include ::Bcome::InstanceCommand
7
+
8
+ def machines
9
+ [self] # for completion
10
+ end
11
+
12
+ def identifier
13
+ @identifier
14
+ end
15
+
16
+ def ip_address
17
+ @environment.ssh_mode_type == ::SSH_DIRECT_MODE_IDENTIFIER ? public_ip_address : @external_network_interface_address
18
+ end
19
+
20
+ def public_ip_address
21
+ @public_ip_address
22
+ end
23
+
24
+ def role
25
+ @role
26
+ end
27
+
28
+ def namespace
29
+ "#{environment.namespace}/#{identifier}"
30
+ end
31
+
32
+ def local_download_path
33
+ "#{Dir.pwd}#{@environment.namespace}/#{identifier}"
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,17 @@
1
+ module ::Bcome::Node
2
+ class Platform < ::Bcome::Node::Base
3
+
4
+ def machines
5
+ environments.collect(&:machines).flatten
6
+ end
7
+
8
+ def identifier
9
+ name
10
+ end
11
+
12
+ def namespace
13
+ "#{estate.namespace}/#{identifier}"
14
+ end
15
+
16
+ end
17
+ end
data/lib/object.rb CHANGED
@@ -1,19 +1,4 @@
1
1
  class Object
2
-
3
- include ::Bcome::CommandHelper
4
-
5
- def list
6
- BOOT.send(:list) ### Our starting point in the hierarchy... maybe this is all ultimately configurable?
7
- end
8
- alias :ls :list
9
-
10
- def become_identifier
11
- ::START_PROMPT
12
- end
13
-
14
- def become(object)
15
- BECOME.set(object, self)
16
- end
17
2
 
18
3
  def toggle_sudo
19
4
  @sudo = @sudo.nil? ? true : (@sudo ? false : true)
@@ -29,51 +14,6 @@ class Object
29
14
  is_sudo? ? "on" : "off"
30
15
  end
31
16
 
32
- def workon(identifier)
33
- resource = resource_for_identifier(identifier)
34
-
35
- unless resource
36
- puts "No matching #{collection_key} for identifier '#{identifier}'. #{available_resources_options_string}".failure
37
- else
38
- puts "\\ \nFrom #{resource.reference_key}, working on #{identifier}\n".command
39
- become(resource)
40
- end
41
- end
42
- alias :w :workon
43
- alias :cd :workon
44
-
45
- def menu_items
46
- [
47
- { :command => "list / ls", :description => "List all available resources at the current context." },
48
- { :command => "describe", :description => "Describe the resource object at the current context." },
49
- { :command => "cd / workon / w", :description => "Select a resource object, and switch to its context.", :usage => "cd 'identifier'" },
50
- { :command => "exit", :description => "Return to the previous context" },
51
- { :command => "exit!", :description => "Close all contexts, and exit Become."},
52
- { :command => "local", :description => "Execute a shell command on your local machine.", :usage => 'local "command"'}
53
- ]
54
- end
55
-
56
- def menu
57
- ::RENDER.menu(menu_items)
58
- end
59
-
60
- def highlight?
61
- false ## override in stack objects that should be highlighted within a list, e.g. instance objects at the environment level that have been selected to workon on
62
- end
63
-
64
- def available_resources_options_string
65
- "Please select from one of '#{all_items.join(', ')}'"
66
- end
67
-
68
- def describe
69
- if self.respond_to?(:do_describe)
70
- message = "\nCollection Key: #{reference_key}\n\nResource: #{self.do_describe}".colorize(:green)
71
- else
72
- message = "\nNothing to describe. Use 'list' to see namespace options".headsup unless self.respond_to?(:do_describe)
73
- end
74
- puts message
75
- end
76
-
77
17
  def set_irb_prompt(conf)
78
18
  conf[:PROMPT][:CUSTOM] = {
79
19
  :PROMPT_N => "\e[1m:\e[m ",
data/lib/ssh.rb CHANGED
@@ -2,16 +2,16 @@ class ::Bcome::Ssh
2
2
 
3
3
  attr_reader :commands
4
4
 
5
- def initialize(commands, proxy, node)
5
+ def initialize(commands, proxy, instance)
6
6
  @commands = commands
7
7
  @proxy = proxy
8
- @node = node
8
+ @instance = instance
9
9
  end
10
10
 
11
11
  def execute!
12
- ::Net::SSH.start(@node.ip_address, @node.ssh_user, :proxy => @proxy, :keys => @node.keys, :paranoid => false) do |ssh|
12
+ ::Net::SSH.start(@instance.ip_address, @instance.ssh_user, :proxy => @proxy, :keys => @instance.keys, :paranoid => false) do |ssh|
13
13
  @commands.each do |command|
14
- puts "(#{@node.identifier}) #{@user}$ #{command.raw_command}".command
14
+ puts "(#{@instance.identifier}) #{@user}$ #{command.raw_command}".command
15
15
  ssh_exec!(ssh, command)
16
16
 
17
17
  puts command.output
data/lib/stack/base.rb ADDED
@@ -0,0 +1,97 @@
1
+ module ::Bcome::Stack
2
+ class Base
3
+
4
+ def machines
5
+ node.machines
6
+ end
7
+
8
+ ###
9
+ ## Construction & Initialisation
10
+ ##
11
+
12
+ def node
13
+ @node ||= construct_node
14
+ end
15
+
16
+ def construct_node
17
+ node_attributes = meta_data
18
+
19
+ node_attributes.merge!({
20
+ collection_key => resources.collect(&:node)
21
+ }) if respond_to?(:collection_key)
22
+
23
+ this_node = node_level_klass.new(node_attributes)
24
+
25
+ this_node.set_parent_reference(this_node, child_reference_key, collection_key) if respond_to?(:collection_key) && respond_to?(:child_reference_key)
26
+ return this_node
27
+ end
28
+
29
+ def node_level_klass
30
+ raise "Should be overidden in derived stack type"
31
+ end
32
+
33
+ def init
34
+ puts "loading resources ... "
35
+ node
36
+ end
37
+
38
+ ###
39
+ ## Core workspace behaviour
40
+ ##
41
+
42
+ def become_identifier
43
+ ::START_PROMPT
44
+ end
45
+
46
+ def become(object)
47
+ BECOME.set(object, self)
48
+ end
49
+
50
+ def workon(identifier)
51
+ resource = resource_for_identifier(identifier)
52
+
53
+ unless resource
54
+ puts "No matching #{collection_key} for identifier '#{identifier}'. #{available_resources_options_string}".failure
55
+ else
56
+ puts "Working on #{identifier} from #{resource.reference_key}".informational
57
+ become(resource)
58
+ end
59
+ end
60
+ alias :w :workon
61
+ alias :cd :workon
62
+
63
+ def menu
64
+ ::RENDER.menu(menu_items)
65
+ end
66
+
67
+ def menu_items
68
+ [
69
+ { :command => "list / ls", :description => "List all available resources at the current context." },
70
+ { :command => "describe", :description => "Describe the resource object at the current context." },
71
+ { :command => "cd / workon / w", :description => "Select a resource object, and switch to its context.", :usage => "cd 'identifier'" },
72
+ { :command => "exit", :description => "Return to the previous context" },
73
+ { :command => "exit!", :description => "Close all contexts, and exit Become."},
74
+ { :command => "local", :description => "Execute a shell command on your local machine.", :usage => 'local "command"'},
75
+ { :command => "machines", :description => "Return all servers below the current level to the console. These objects can be manipulated directly" }
76
+ ]
77
+ end
78
+
79
+ def highlight?
80
+ false ## override in stack objects that should be highlighted within a list, e.g. instance objects at the environment level that have been selected to workon on
81
+ end
82
+
83
+ def available_resources_options_string
84
+ "Please select from one of '#{all_items.join(', ')}'"
85
+ end
86
+
87
+ def describe
88
+ if self.respond_to?(:do_describe)
89
+ message = "\nCollection Key: #{reference_key}\n\nResource: #{self.do_describe}".colorize(:green)
90
+ else
91
+ message = "\nNothing to describe. Use 'list' to see namespace options".headsup unless self.respond_to?(:do_describe)
92
+ end
93
+ puts message
94
+ end
95
+
96
+ end
97
+ end
@@ -1,5 +1,5 @@
1
1
  module ::Bcome::Stack
2
- class Environment
2
+ class Environment < ::Bcome::Stack::Base
3
3
 
4
4
  include ::Bcome::BecomeObject
5
5
  include ::Bcome::Selections
@@ -39,61 +39,6 @@ module ::Bcome::Stack
39
39
  { :command => 'functions', :description => "List all available custom functions" }
40
40
  ]
41
41
  end
42
-
43
- def bastion_server
44
- resources.select{|resource| resource.identifier == @meta_data[:ssh_mode][:jump_host_identifier] }.first
45
- end
46
-
47
- def ssh_mode_type
48
- ssh_mode_type = @meta_data[:ssh_mode][:type]
49
- raise "Invalid ssh mode type #{ssh_mode_type}. Should be one of #{valid_ssh_modes.join(", ")}".failure unless valid_ssh_modes.include?(ssh_mode_type)
50
- return @meta_data[:ssh_mode][:type]
51
- end
52
-
53
- def ssh_mode_user
54
- return @meta_data[:ssh_mode][:ssh_user]
55
- end
56
-
57
- def ssh_nat_user
58
- return @meta_data[:ssh_mode][:nat_user]
59
- end
60
-
61
- def ssh_key_path
62
- return @meta_data[:ssh_mode][:ssh_key_path]
63
- end
64
-
65
- def sudo
66
- toggle_sudo
67
- end
68
-
69
- def valid_ssh_modes
70
- [::SSH_JUMP_MODE_IDENTIFIER, ::SSH_DIRECT_MODE_IDENTIFIER]
71
- end
72
-
73
- def bastion_ip_address
74
- if dynamic_network_lookup?
75
- return bastion_server.public_ip_address
76
- else
77
- bastion_ip_address = @meta_data[:ssh_mode][:jump_host_ip_address]
78
- raise "No jump_host_ip_address specified in your configuration.".failure unless bastion_ip_address
79
- return bastion_ip_address
80
- end
81
- end
82
-
83
- def network_lookup
84
- raise "Missing network lookup in networks_environment configuration".failure unless @meta_data[:network_lookup]
85
- return @meta_data[:network_lookup]
86
- end
87
-
88
- def network_lookup_type
89
- type = network_lookup[:type]
90
- raise "Unknown network lookup type '#{type}" unless ["dynamic", "static"].include?(type)
91
- return type
92
- end
93
-
94
- def dynamic_network_lookup?
95
- return network_lookup_type == "dynamic"
96
- end
97
42
 
98
43
  def do_load_resources
99
44
  if dynamic_network_lookup?
@@ -111,9 +56,9 @@ module ::Bcome::Stack
111
56
  end
112
57
 
113
58
  def do_describe
114
- desc = "#{identifier}"
115
- desc += "\t[ Net lookup: #{network_lookup_type}"
116
- desc += "\t * SSH Mode: #{ssh_mode_type} ]"
59
+ desc = "#{node.identifier}"
60
+ desc += "\t[ Net lookup: #{node.network_lookup_type}"
61
+ desc += "\t * SSH Mode: #{node.ssh_mode_type} ]"
117
62
  end
118
63
 
119
64
  def collection_klass
@@ -124,9 +69,36 @@ module ::Bcome::Stack
124
69
  :environments
125
70
  end
126
71
 
72
+ def child_reference_key
73
+ :environment
74
+ end
75
+
127
76
  def collection_key
128
77
  :instances
129
78
  end
130
79
 
80
+ def node_level_klass
81
+ ::Bcome::Node::Environment
82
+ end
83
+
84
+ def network_lookup
85
+ raise "Missing network lookup in networks_environment configuration".failure unless @meta_data[:network_lookup]
86
+ return @meta_data[:network_lookup]
87
+ end
88
+
89
+ def network_lookup_type
90
+ type = network_lookup[:type]
91
+ raise "Unknown network lookup type '#{type}" unless ["dynamic", "static"].include?(type)
92
+ return type
93
+ end
94
+
95
+ def dynamic_network_lookup?
96
+ return network_lookup_type == "dynamic"
97
+ end
98
+
99
+ def sudo
100
+ toggle_sudo
101
+ end
102
+
131
103
  end
132
104
  end
@@ -0,0 +1,51 @@
1
+ module ::Bcome::Stack
2
+ class Estate < ::Bcome::Stack::Base
3
+
4
+ include ::Bcome::BecomeObject
5
+ include ::Bcome::CommandHelper
6
+
7
+ def config_path
8
+ "#{CONFIGS_PATH}/platform.yml"
9
+ end
10
+
11
+ def collection_klass
12
+ ::PLATFORM_STACK_KLASS
13
+ end
14
+
15
+ def collection_key
16
+ :platforms
17
+ end
18
+
19
+ def to_s
20
+ "Estate"
21
+ end
22
+
23
+ def become_identifier
24
+ ::START_PROMPT
25
+ end
26
+
27
+ def namespace
28
+ starting_namespace
29
+ end
30
+
31
+ def starting_namespace
32
+ "" # Used to determine where to store downloaded file - this is the start point directory, relative to the bcome install directory
33
+ end
34
+
35
+ def init
36
+ puts "loading resources ... "
37
+ n = ::Bcome::Node::Estate.new({ :platforms => resources.collect(&:node) })
38
+ n.set_parent_reference(n, :estate, :platforms)
39
+ return n
40
+ end
41
+
42
+ def node
43
+ @node ||= init
44
+ end
45
+
46
+ def menu_items
47
+ super
48
+ end
49
+
50
+ end
51
+ end
@@ -1,9 +1,7 @@
1
1
  module ::Bcome::Stack
2
- class Instance
2
+ class Instance < ::Bcome::Stack::Base
3
3
 
4
4
  include ::Bcome::BecomeObject
5
- include ::Bcome::InstanceSsh
6
- include ::Bcome::InstanceCommand
7
5
  include ::Bcome::Functions
8
6
 
9
7
  class << self
@@ -32,13 +30,34 @@ module ::Bcome::Stack
32
30
  end
33
31
  end
34
32
 
35
- attr_reader :environment
36
-
33
+ attr_reader :environment, :meta_data
34
+
37
35
  def initialize(meta_data, parent)
38
36
  @meta_data = meta_data
39
37
  @environment = parent
40
38
  end
41
39
 
40
+ def identifier
41
+ node.identifier
42
+ end
43
+
44
+ ## Commands
45
+ def ssh
46
+ node.ssh
47
+ end
48
+
49
+ def put(*params)
50
+ node.put(*params)
51
+ end
52
+
53
+ def run(*params)
54
+ node.run(*params)
55
+ end
56
+
57
+ def get(*params)
58
+ node.get(*params)
59
+ end
60
+
42
61
  def menu_items
43
62
  super + [
44
63
  { :command => "run", :description => "Execute a command.", :usage => "run 'command'" },
@@ -58,10 +77,6 @@ module ::Bcome::Stack
58
77
  toggle_sudo
59
78
  end
60
79
 
61
- def namespace
62
- "#{@environment.namespace}/#{identifier}"
63
- end
64
-
65
80
  def is_sudo?
66
81
  super || @environment.is_sudo?
67
82
  end
@@ -70,38 +85,31 @@ module ::Bcome::Stack
70
85
  false
71
86
  end
72
87
 
73
- def identifier
74
- @meta_data[:identifier]
75
- end
76
-
77
- def ip_address
78
- @environment.ssh_mode_type == ::SSH_DIRECT_MODE_IDENTIFIER ? public_ip_address : @meta_data[:external_network_interface_address]
79
- end
80
-
81
- def public_ip_address
82
- @meta_data[:public_ip_address]
83
- end
84
-
85
- def role
86
- @meta_data[:role]
87
- end
88
-
89
88
  def reference_key
90
89
  :instances
91
90
  end
92
91
 
92
+ def child_reference_key
93
+ :instance
94
+ end
95
+
93
96
  def highlight?
94
97
  @environment.object_in_selections?(self)
95
98
  end
96
99
 
97
100
  def do_describe
98
- description = "#{identifier}#{ is_sudo? ? " MODE: sudo " : "" }"
101
+ description = "#{node.identifier}#{ is_sudo? ? " MODE: sudo " : "" }"
99
102
  description += "\n\t* Internal IP #{@meta_data[:external_network_interface_address]}"
100
- description += "\n\t* External IP #{public_ip_address}" if public_ip_address
101
- description += "\n\t* #{role}" if role
103
+ description += "\n\t* External IP #{node.public_ip_address}" if node.public_ip_address
104
+ description += "\n\t* #{node.role}" if node.role
102
105
  description += "\n"
103
106
  return description
104
107
  end
105
108
 
109
+ def node_level_klass
110
+ ::Bcome::Node::Instance
111
+ end
112
+
113
+
106
114
  end
107
115
  end
@@ -1,5 +1,5 @@
1
1
  module ::Bcome::Stack
2
- class Platform
2
+ class Platform < ::Bcome::Stack::Base
3
3
 
4
4
  include ::Bcome::BecomeObject
5
5
 
@@ -14,8 +14,7 @@ module ::Bcome::Stack
14
14
  end
15
15
  end
16
16
 
17
- attr_reader :identifier
18
- attr_reader :quick_contexts
17
+ attr_reader :identifier, :meta_data, :quick_contexts
19
18
 
20
19
  def initialize(identifier, meta_data)
21
20
  @identifier = identifier
@@ -43,6 +42,10 @@ module ::Bcome::Stack
43
42
  :platforms
44
43
  end
45
44
 
45
+ def child_reference_key
46
+ :platform
47
+ end
48
+
46
49
  def collection_key
47
50
  :environments
48
51
  end
@@ -57,6 +60,10 @@ module ::Bcome::Stack
57
60
  raise "Multiple quick context matches found on platform #{@identifier} for context key #{context_reference}. Cannot load quick context - selection is ambiguous." if matches.size > 1
58
61
  return matches.first
59
62
  end
63
+
64
+ def node_level_klass
65
+ ::Bcome::Node::Platform
66
+ end
60
67
 
61
68
  end
62
69
  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.0.7
4
+ version: 0.0.8
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-19 00:00:00.000000000 Z
11
+ date: 2015-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -125,7 +125,6 @@ files:
125
125
  - lib/bcome.rb
126
126
  - lib/bcome/version.rb
127
127
  - lib/become_object.rb
128
- - lib/boot.rb
129
128
  - lib/command.rb
130
129
  - lib/filters/base.rb
131
130
  - lib/filters/ec2_filter.rb
@@ -136,12 +135,19 @@ files:
136
135
  - lib/helpers/instance_command.rb
137
136
  - lib/helpers/instance_ssh.rb
138
137
  - lib/helpers/selections.rb
138
+ - lib/nodes/base.rb
139
+ - lib/nodes/environment.rb
140
+ - lib/nodes/estate.rb
141
+ - lib/nodes/instance.rb
142
+ - lib/nodes/platform.rb
139
143
  - lib/object.rb
140
144
  - lib/patches/string.rb
141
145
  - lib/render_irb.rb
142
146
  - lib/scp.rb
143
147
  - lib/ssh.rb
148
+ - lib/stack/base.rb
144
149
  - lib/stack/environment.rb
150
+ - lib/stack/estate.rb
145
151
  - lib/stack/instance.rb
146
152
  - lib/stack/platform.rb
147
153
  - lib/workspace_context.rb
data/lib/boot.rb DELETED
@@ -1,33 +0,0 @@
1
- class ::Bcome::Boot
2
-
3
- include ::Bcome::BecomeObject
4
-
5
- def config_path
6
- "#{CONFIGS_PATH}/platform.yml"
7
- end
8
-
9
- def collection_klass
10
- ::PLATFORM_STACK_KLASS
11
- end
12
-
13
- def collection_key
14
- :platforms
15
- end
16
-
17
- def to_s
18
- "Bootup"
19
- end
20
-
21
- def become_identifier
22
- ::START_PROMPT
23
- end
24
-
25
- def namespace
26
- starting_namespace
27
- end
28
-
29
- def starting_namespace
30
- "" # Used to determine where to store downloaded file - this is the start point directory, relative to the bcome install directory
31
- end
32
-
33
- end