Class: Helm::ServerCommand

Inherits:
Object
  • Object
show all
Includes:
Caliph::CommandLineDSL
Defined in:
lib/helm/server-command.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#query_optionsObject

Returns the value of attribute query_options.



59
60
61
# File 'lib/helm/server-command.rb', line 59

def query_options
  @query_options
end

Class Method Details

.abstractObject



15
16
17
# File 'lib/helm/server-command.rb', line 15

def abstract
  @abstract = true
end

.abstract?Boolean



19
20
21
# File 'lib/helm/server-command.rb', line 19

def abstract?
  !!@abstract
end

.inherited(sub) ⇒ Object



11
12
13
# File 'lib/helm/server-command.rb', line 11

def inherited(sub)
  ServerCommand.subclasses << sub
end

.subclassesObject



7
8
9
# File 'lib/helm/server-command.rb', line 7

def subclasses
  @subclasses ||= []
end

.valid_commands(quietly = false) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/helm/server-command.rb', line 23

def valid_commands(quietly = false)
  valid = []
  ServerCommand.subclasses.each do |sub|
    next if sub.abstract?

    methods = sub.instance_methods(false)

    unless methods.include?(:name) and methods.include?(:command)
      unless quietly
        warn "ServerCommand subclass #{sub.name} isn't abstract and doesn't define :name and :command"
        a_method = sub.instance_method(methods.first)
        warn "  (appears to be defined in #{a_method.source_location.first})"
      end
      next
    end

    valid << sub
  end
  valid
end

Instance Method Details

#all_results(results) ⇒ Object



71
72
# File 'lib/helm/server-command.rb', line 71

def all_results(results)
end

#configure_query(query) ⇒ Object



61
62
# File 'lib/helm/server-command.rb', line 61

def configure_query(query)
end

#descObject Also known as: description



49
50
51
# File 'lib/helm/server-command.rb', line 49

def desc
  ""
end

#each_result(execution) ⇒ Object



64
65
66
67
68
69
# File 'lib/helm/server-command.rb', line 64

def each_result(execution)
  format_result(execution)
  if execution.result.exit_code != 0
    throw :fail
  end
end

#format_result(execution) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/helm/server-command.rb', line 74

def format_result(execution)
  result = execution.result
  server = execution.server

  puts "#{server.name} (#{server.public_ip_address})"
  puts "#{result.command.string_format} => #{result.exit_code}"
  puts result.format_streams
  puts
end

#required_optionsObject Also known as: scope_options



54
55
56
# File 'lib/helm/server-command.rb', line 54

def required_options
  []
end

#ssh(server, *command, &block) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/helm/server-command.rb', line 86

def ssh(server, *command, &block)
  cmd("ssh") do |command|
    command.options << "-o BatchMode=yes"
    command.options << "-i " + server.ssh_key_name unless server.ssh_key_name.nil?
    #command.options << "-l " + server.connect_as unless
    #server.connect_as.nil?
    # XXX need to add 'connect_as'
    #command.options << "-p " + server.port unless server.ssh_port.nil?  ##ok
    # XXX need to add "ssh_port"
    command.options << server.public_dns_name || server.public_ip_address
  end - escaped_command(*command, &block)
end

#valid?Boolean



45
46
47
# File 'lib/helm/server-command.rb', line 45

def valid?
  true
end