Class: Chef::Knife::BaseSmuCommand
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::BaseSmuCommand
- Defined in:
- lib/chef/knife/BaseSmuCommand.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #fatal_exit(msg) ⇒ Object
- #get_cli_connection ⇒ Object
- #get_config(key) ⇒ Object
- #get_host ⇒ Object
- #get_password ⇒ Object
- #get_vm(vmname) ⇒ Object
-
#list_tasks(type) ⇒ Object
tasks list.
- #tcp_test_port(hostname, port) ⇒ Object
Class Method Details
.get_common_options ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/chef/knife/BaseSmuCommand.rb', line 24 def self. unless defined? $default $default = Hash.new end option :smu_user, :short => "-u USERNAME", :long => "--smuuser USERNAME", :description => "The username for SMU" $default[:ovmmgr_user] = "ohisc" option :smu_pass, :short => "-p PASSWORD", :long => "--smupass PASSWORD", :description => "The password for SMU" option :smu_host, :long => "--smuhost HOST", :description => "The SMU host" option :smu_port, :long => "--smuport PORT", :description => "The SMU CLI port number to use" $default[:smu_port] = 8002 end |
Instance Method Details
#fatal_exit(msg) ⇒ Object
97 98 99 100 |
# File 'lib/chef/knife/BaseSmuCommand.rb', line 97 def fatal_exit(msg) ui.fatal(msg) exit 1 end |
#get_cli_connection ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/chef/knife/BaseSmuCommand.rb', line 57 def get_cli_connection conn_opts = { :host => get_config(:smu_host), :path => get_config(:smu_path), :port => get_config(:smu_port), :user => get_config(:smu_user), :password => get_config(:smu_pass), } # Grab the smu host from the command line # if tt is not in the config file if not conn_opts[:host] conn_opts[:host] = get_host end # Grab the password from the command line # if tt is not in the config file if not conn_opts[:password] conn_opts[:password] = get_password end if conn_opts[:port] Chef::Log.debug("Waiting for port #{conn_opts[:port]} on #{conn_opts[:host]}...") tcp_test_port(conn_opts[:host],conn_opts[:port]) end return conn_opts end |
#get_config(key) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/chef/knife/BaseSmuCommand.rb', line 50 def get_config(key) key = key.to_sym rval = config[key] || Chef::Config[:knife][key] || $default[key] Chef::Log.debug("value for config item #{key}: #{rval}") rval end |
#get_host ⇒ Object
84 85 86 |
# File 'lib/chef/knife/BaseSmuCommand.rb', line 84 def get_host @host ||= ui.ask("Enter your SMU Host: ") { |q| q.echo = true } end |
#get_password ⇒ Object
88 89 90 |
# File 'lib/chef/knife/BaseSmuCommand.rb', line 88 def get_password @password ||= ui.ask("Enter your password: ") { |q| q.echo = false } end |
#get_vm(vmname) ⇒ Object
92 93 94 |
# File 'lib/chef/knife/BaseSmuCommand.rb', line 92 def get_vm(vmname) return retval end |
#list_tasks(type) ⇒ Object
tasks list
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/chef/knife/BaseSmuCommand.rb', line 130 def list_tasks(type) current = {:errormsg => "", :status => "", :time => "", :poolstatus => ""} conn_opts=get_cli_connection if not type Chef::Log.debug("#{conn_opts[:host]}...list tasks") Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh| output = ssh.exec!("tasks lists") output.each_line do |line| if line.match(/Status:/) current[:status]=line.split[1].strip elsif line.match(/Time:/) line["Time: "]="" current[:time]=line.strip elsif line.match(/ id:/) puts line.split(':')[2].strip elsif line.match(/Error Msg:/) line["Error Msg: "]="" current[:errormsg]=line.strip end end end return current else Chef::Log.debug("#{conn_opts[:host]}...list tasks type=#{type}") Net::SSH.start( conn_opts[:host], conn_opts[:user], :password => conn_opts[:password], :port => conn_opts[:port] ) do|ssh| output = ssh.exec!("tasks list -t #{type}") output.each_line do |line| if line.match(/Status:/) current[:status]=line.split[1].strip elsif line.match(/Time:/) line["Time: "]="" current[:time]=line.strip elsif line.match(/Error Msg:/) line["Error Msg: "]="" current[:errormsg]=line.strip elsif line.match(/ /) puts line end end end return current end end |
#tcp_test_port(hostname, port) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/chef/knife/BaseSmuCommand.rb', line 102 def tcp_test_port(hostname,port) tcp_socket = TCPSocket.new(hostname, port) readable = IO.select([tcp_socket], nil, nil, 5) if readable Chef::Log.debug("accepting connections on #{hostname}, banner is #{tcp_socket.gets}") true else false end rescue Errno::ETIMEDOUT false rescue Errno::EPERM false rescue Errno::ECONNREFUSED sleep 2 false rescue Errno::EHOSTUNREACH, Errno::ENETUNREACH sleep 2 false ensure tcp_socket && tcp_socket.close end |