Sha256: 09cb0c82c38a3af8a59a195d460b3892c887a4f261e658f941bad9b8fb79fee2

Contents?: true

Size: 1.08 KB

Versions: 9

Compression:

Stored size: 1.08 KB

Contents

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


class Chef
  class Knife
    class JoyentFwCreate < Knife

      include Knife::JoyentBase

      banner "knife joyent fw create (options)"

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

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

      def run
        unless config[:rule]
          show_usage
          exit 1
        end

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

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

          ui.info "Created Firewall Rule: #{r["id"]}"
          msg_pair "RULE", r["rule"]
          msg_pair "ENABLED", (r["enabled"] ? ui.color("✓ YES", :cyan) : "✗ NO")
        end
      rescue => e
        output_error(e)
      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_create.rb
knife-joyent-0.4.12 lib/chef/knife/joyent_fw_create.rb
knife-joyent-0.4.11 lib/chef/knife/joyent_fw_create.rb
knife-joyent-0.4.10 lib/chef/knife/joyent_fw_create.rb
knife-joyent-0.4.9 lib/chef/knife/joyent_fw_create.rb
knife-joyent-0.4.8 lib/chef/knife/joyent_fw_create.rb
knife-joyent-0.4.5 lib/chef/knife/joyent_fw_create.rb
knife-joyent-0.4.4 lib/chef/knife/joyent_fw_create.rb
knife-joyent-0.4.3 lib/chef/knife/joyent_fw_create.rb