Sha256: 505784e9d249e9db2942318702464e3f71315e3f88c97901916f10cdad0f1df8

Contents?: true

Size: 1.17 KB

Versions: 9

Compression:

Stored size: 1.17 KB

Contents

# encoding: UTF-8
require 'chef/knife/joyent_base'
require 'pp'

class Chef
  class Knife
    class JoyentFwUpdate < Knife

      include Knife::JoyentBase

      banner "knife joyent fw update <rule_id> (options)"

      option :rule,
        :long => "--rule RULE",
        :description => "Firewall Rule Content",
        :required => true

      option :enabled,
        :long => "--enabled",
        :boolean => true,
        :description => "Enable/Disable Rule"


      def run
        id = name_args.first
        unless id || (!config.key?(:rule) || !config.key?(:enabled))
          show_usage
          exit 1
        end

        res = self.connection.request(
          :method => "POST",
          :path => "/my/fwrules/#{id}",
          :body => {
            "enabled" => config[:enabled],
            "rule" => config[:rule],
          }
        )

        unless res.status == 200
          output_error(res)
        else
          r = res.body

          ui.info ui.color("Updated Firewall Rule: #{r["id"]}", :bold)
          msg_pair "RULE", r["rule"]
          msg_pair "ENABLED", (r["enabled"] ? ui.color("✓ YES", :cyan) : "✗ NO")
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
knife-joyent-0.4.14 lib/chef/knife/joyent_fw_update.rb
knife-joyent-0.4.12 lib/chef/knife/joyent_fw_update.rb
knife-joyent-0.4.11 lib/chef/knife/joyent_fw_update.rb
knife-joyent-0.4.10 lib/chef/knife/joyent_fw_update.rb
knife-joyent-0.4.9 lib/chef/knife/joyent_fw_update.rb
knife-joyent-0.4.8 lib/chef/knife/joyent_fw_update.rb
knife-joyent-0.4.5 lib/chef/knife/joyent_fw_update.rb
knife-joyent-0.4.4 lib/chef/knife/joyent_fw_update.rb
knife-joyent-0.4.3 lib/chef/knife/joyent_fw_update.rb