-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use ssh gateway only if cct is run outside of admin node #52
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,12 +23,12 @@ def initialize options | |
@environment = {} | ||
@crowbar = options[:crowbar] | ||
@gateway = options[:gateway] | ||
@command = RemoteCommand.new(gateway: options[:gateway]) | ||
set_command_options | ||
@command = RemoteCommand.new(command_options.merge(skip_validation: [:ip])) | ||
end | ||
|
||
def exec! command_name, *params | ||
self.load! | ||
set_command_target | ||
params << update_environment(params) | ||
command.exec!(command_name, params.compact) | ||
end | ||
|
@@ -123,6 +123,7 @@ def load! force: false | |
data = crowbar.node(name) | ||
@data = data | ||
@ip = data["crowbar"]["network"]["admin"]["address"] | ||
command.options.ip = ip | ||
@hostname = data["hostname"] | ||
@domain = data["domain"] | ||
|
||
|
@@ -134,19 +135,11 @@ def load! force: false | |
|
||
private | ||
|
||
def set_command_target | ||
return if command.target | ||
|
||
command.target = self | ||
set_command_options | ||
end | ||
|
||
def set_command_options | ||
return if command_options | ||
|
||
options = {port: port} | ||
options.merge!(timeout: command.options.extended.timeout) | ||
options = {port: port, user: user} | ||
options.merge!(timeout: config["timeout"]) if config["timeout"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Performance/RedundantMerge: Use |
||
options.merge!(password: password) unless password.to_s.empty? | ||
options.merge!(gateway: gateway) if gateway | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Performance/RedundantMerge: Use |
||
options.merge!(logger: log) | ||
@command_options = options | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,11 @@ def initialize logger=nil | |
@admin_node = AdminNode.new | ||
@crowbar = CrowbarApi.new(admin_node.config) | ||
admin_node.crowbar_proxy = Node::CrowbarProxy.new(api: crowbar) | ||
@control_node = ControlNode.new(crowbar: crowbar, gateway: admin_node.attributes) | ||
control_node_options = { crowbar: crowbar } | ||
if !Cct.running_on_admin_node? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/NegatedIf: Favor |
||
control_node_options.merge!(gateway: admin_node.attributes) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Performance/RedundantMerge: Use |
||
end | ||
@control_node = ControlNode.new(control_node_options) | ||
@nodes = Nodes.new(crowbar) | ||
nodes << control_node << admin_node | ||
@command = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,22 +9,20 @@ class RemoteCommand | |
Result = Struct.new(:success?, :output, :error, :exit_code, :host) | ||
|
||
attr_reader :session, :options, :log, :gateway, :proxy | ||
attr_accessor :target | ||
|
||
def initialize opts | ||
@gateway = opts[:gateway] | ||
opts.merge!(gateway) if gateway | ||
@proxy = opts[:proxy] || set_ssh_proxy | ||
@log = BaseLogger.new("SSH") | ||
@options = OpenStruct.new | ||
construct_options(opts) | ||
validate_options | ||
validate_options(opts[:skip_validation]) | ||
end | ||
|
||
def exec! command, params=[], capture_error: false | ||
log.base.level = ::Logger::WARN | ||
connect! | ||
host_ip = gateway ? target.ip : options.ip | ||
host_ip = options.ip | ||
environment = set_environment(params) | ||
full_command = "#{command} #{params.join(" ")}".strip | ||
result = Result.new(false, "", "", 1000, host_ip) | ||
|
@@ -63,7 +61,7 @@ def connect! | |
|
||
def connected? | ||
if gateway | ||
session && session.active? ? true :false | ||
session && session.active? ? true : false | ||
else | ||
session && !session.closed? ? true : false | ||
end | ||
|
@@ -88,7 +86,7 @@ def set_ssh_proxy | |
|
||
def open_session_channel &block | ||
if gateway | ||
session.ssh(target.ip, target.user, target.command_options) do |session| | ||
session.ssh(options.ip, options.user, options.extended.to_h) do |session| | ||
session.open_channel(&block) | ||
end | ||
else | ||
|
@@ -173,9 +171,10 @@ def detect_timeout opts={} | |
timeout.to_i | ||
end | ||
|
||
def validate_options | ||
def validate_options *options_to_skip | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/MethodDefParentheses: Use def with parentheses when there are parameters. (https://github.com/bbatsov/ruby-style-guide#method-parens) |
||
options_to_skip.flatten! | ||
errors = [] | ||
errors.push("missing ip") unless options.ip | ||
errors.push("missing ip") if !options.ip && !options_to_skip.include?(:ip) | ||
errors.push("missing user") unless options.user | ||
errors.unshift("Invalid options: ") unless errors.empty? | ||
raise ValidationError.new(self, errors) unless errors.empty? | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/SpaceInsideHashLiteralBraces: Space inside { missing. (https://github.com/bbatsov/ruby-style-guide#spaces-operators)
Style/SpaceInsideHashLiteralBraces: Space inside } missing. (https://github.com/bbatsov/ruby-style-guide#spaces-operators)