Class: Commands::AbstractSSHCommand
Direct Known Subclasses
GetCommand, LogsCommand, PrintHiveVersionCommand, PutCommand, SSHCommand
Constant Summary collapse
- CLOSED_DOWN_STATES =
Set.new(%w(TERMINATED SHUTTING_DOWN COMPLETED FAILED))
- WAITING_OR_RUNNING_STATES =
Set.new(%w(WAITING RUNNING))
Instance Attribute Summary collapse
-
#dest ⇒ Object
Returns the value of attribute dest.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#jobflow_detail ⇒ Object
Returns the value of attribute jobflow_detail.
-
#jobflow_id ⇒ Object
Returns the value of attribute jobflow_id.
-
#key_pair_file ⇒ Object
Returns the value of attribute key_pair_file.
-
#no_wait ⇒ Object
Returns the value of attribute no_wait.
Attributes inherited from Command
#arg, #commands, #description, #logger, #name
Instance Method Summary collapse
- #enact(client) ⇒ Object
- #exec(cmd) ⇒ Object
- #get_scp_opts ⇒ Object
- #get_ssh_opts ⇒ Object
-
#initialize(*args) ⇒ AbstractSSHCommand
constructor
A new instance of AbstractSSHCommand.
- #opts ⇒ Object
- #wait_for_jobflow(client) ⇒ Object
Methods inherited from Command
#get_field, #has_value, #have, #option, #require, #require_single_jobflow, #resolve, #validate
Constructor Details
#initialize(*args) ⇒ AbstractSSHCommand
Returns a new instance of AbstractSSHCommand.
582 583 584 585 586 |
# File 'lib/commands.rb', line 582 def initialize(*args) super(*args) @ssh_opts = ["-o ServerAliveInterval=10", "-o StrictHostKeyChecking=no"] @scp_opts = ["-r"] end |
Instance Attribute Details
#dest ⇒ Object
Returns the value of attribute dest.
577 578 579 |
# File 'lib/commands.rb', line 577 def dest @dest end |
#hostname ⇒ Object
Returns the value of attribute hostname.
577 578 579 |
# File 'lib/commands.rb', line 577 def hostname @hostname end |
#jobflow_detail ⇒ Object
Returns the value of attribute jobflow_detail.
577 578 579 |
# File 'lib/commands.rb', line 577 def jobflow_detail @jobflow_detail end |
#jobflow_id ⇒ Object
Returns the value of attribute jobflow_id.
577 578 579 |
# File 'lib/commands.rb', line 577 def jobflow_id @jobflow_id end |
#key_pair_file ⇒ Object
Returns the value of attribute key_pair_file.
577 578 579 |
# File 'lib/commands.rb', line 577 def key_pair_file @key_pair_file end |
#no_wait ⇒ Object
Returns the value of attribute no_wait.
577 578 579 |
# File 'lib/commands.rb', line 577 def no_wait @no_wait end |
Instance Method Details
#enact(client) ⇒ Object
619 620 621 622 623 624 625 626 627 |
# File 'lib/commands.rb', line 619 def enact(client) self.jobflow_id = require_single_jobflow self.jobflow_detail = client.describe_jobflow_with_id(self.jobflow_id) if ! get_field(:no_wait) then wait_for_jobflow(client) end self.hostname = self.jobflow_detail['Instances']['MasterPublicDnsName'] self.key_pair_file = require(:key_pair_file, "Missing required option --key-pair-file for #{name}") end |
#exec(cmd) ⇒ Object
600 601 602 |
# File 'lib/commands.rb', line 600 def exec(cmd) commands.exec(cmd) end |
#get_scp_opts ⇒ Object
596 597 598 |
# File 'lib/commands.rb', line 596 def get_scp_opts get_field(:scp_opts, []).join(" ") end |
#get_ssh_opts ⇒ Object
592 593 594 |
# File 'lib/commands.rb', line 592 def get_ssh_opts get_field(:ssh_opts, []).join(" ") end |
#opts ⇒ Object
588 589 590 |
# File 'lib/commands.rb', line 588 def opts (get_field(:ssh_opts, []) + get_field(:scp_opts, [])).join(" ") end |
#wait_for_jobflow(client) ⇒ Object
604 605 606 607 608 609 610 611 612 613 614 615 616 617 |
# File 'lib/commands.rb', line 604 def wait_for_jobflow(client) while true do state = resolve(self.jobflow_detail, "ExecutionStatusDetail", "State") if WAITING_OR_RUNNING_STATES.include?(state) then break elsif CLOSED_DOWN_STATES.include?(state) then raise RuntimeError, "Jobflow entered #{state} while waiting to ssh" else logger.info("Jobflow is in state #{state}, waiting....") sleep(30) self.jobflow_detail = client.describe_jobflow_with_id(jobflow_id) end end end |