Class: Chef::Knife::JoyentFwList

Inherits:
Chef::Knife show all
Includes:
JoyentBase
Defined in:
lib/chef/knife/joyent_fw_list.rb

Instance Method Summary collapse

Methods included from JoyentBase

#connection, #decode_time_attrs, included, #json_decode, #locate_config_value, #msg_pair, #output_error, #pricing

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/chef/knife/joyent_fw_list.rb', line 12

def run
  if name_args.size > 0
    id = name_args.first
    res = self.connection.request(
      :method => "GET",
      :path => "/my/machines/#{id}/fwrules"
    )
  else
    res = self.connection.request(
      :method => "GET",
      :path => "/my/fwrules"
    )
  end

  if res.status == 200
    rules = [
      ui.color('ID', :bold),
      ui.color('Enabled', :bold),
      ui.color('Rule', :bold),
    ]

    res[:body].each do |r|
      rules << r["id"]
      rules << (r["enabled"] ? ui.color("", :cyan) : "")
      rules << r["rule"]
    end
    ui.output ui.list(rules, :uneven_columns_across, 3)
  else
    output_error(res)
  end
end