Skip to content

Commit

Permalink
(network-#2) Add :provider_options feature
Browse files Browse the repository at this point in the history
This feature allows providers to present and handle an arbitrary hash of
values so that the type interface isn't cluttered with provider specific
properties and still enables the providers to be fully functional.
  • Loading branch information
adrienthebo committed Dec 7, 2012
1 parent 701f488 commit ffa7a91
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/puppet/provider/network_config/interfaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
confine :osfamily => :debian
defaultfor :osfamily => :debian

has_feature :provider_options
has_feature :hotpluggable

def select_file
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/provider/network_config/redhat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
defaultfor :osfamily => :redhat

has_feature :hotpluggable
has_feature :provider_options

SCRIPT_DIRECTORY = "/etc/sysconfig/network-scripts"

Expand Down
14 changes: 9 additions & 5 deletions lib/puppet/type/network_config.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Puppet::Type.newtype(:network_config) do
@doc = "Manage non-volatile network configuration information"

feature :provider_options, <<-EOD
The provider can accept a hash of arbitrary options. The semantics of
these options will depend on the provider.
EOD

feature :hotpluggable, 'The system can hotplug interfaces'

feature :reconfigurable, <<-EOD
Expand Down Expand Up @@ -60,11 +65,10 @@
defaultto :false
end

# Many network configurations can take arbitrary parameters, so instead of
# trying to list every single possible property, we accept a hash of
# properties and let providers do specific mapping of type properties to
# on-disk state.
newproperty(:options) do
# `:options` provides an arbitray passthrough for provider properties, so
# that provider specific behavior doesn't clutter up the main type but still
# allows for more powerful actions to be taken.
newproperty(:options, :required_features => :provider_options) do
desc "Provider specific options to be passed to the provider"

def is_to_s(hash = @is)
Expand Down
7 changes: 7 additions & 0 deletions spec/unit/type/network_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
describe "reconfigurable" do
it { described_class.provider_feature(:reconfigurable).should_not be_nil }
end

describe "provider_options" do
it { described_class.provider_feature(:provider_options).should_not be_nil }
end
end

describe "when validating the attribute" do
Expand Down Expand Up @@ -59,6 +63,9 @@
end

describe "options" do
it "should require the :has_options feature" do
described_class.propertybyname(:options).required_features.should be_include :provider_options
end
it "should be a descendant of the KeyValue property" do
pending "on conversion to specific type"
described_class.propertybyname(:options).ancestors.should be_include(Puppet::Property::Ensure)
Expand Down

0 comments on commit ffa7a91

Please sign in to comment.