summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2017-12-19 09:47:14 +0000
committerGitHub <noreply@github.com>2017-12-19 09:47:14 +0000
commit648c29c223e96545cb36e556f454ca4cf7490bcb (patch)
tree88dff3169b4561bd2fa7be164aba2ce5abd3bb00
parent2a78bd532304dfe3fd297cbe1aefdab95502a192 (diff)
parent7402a236b6128776387e1914d75ece748c0eafa8 (diff)
downloadchef-648c29c223e96545cb36e556f454ca4cf7490bcb.tar.gz
Merge pull request #6684 from chef/ifconfig_resource
Modernize the ifconfig resource
-rw-r--r--lib/chef/provider/ifconfig.rb18
-rw-r--r--lib/chef/resource/ifconfig.rb173
2 files changed, 29 insertions, 162 deletions
diff --git a/lib/chef/provider/ifconfig.rb b/lib/chef/provider/ifconfig.rb
index 5008d7877a..c8da5e255f 100644
--- a/lib/chef/provider/ifconfig.rb
+++ b/lib/chef/provider/ifconfig.rb
@@ -23,20 +23,14 @@ require "chef/resource/file"
require "chef/exceptions"
require "erb"
-# Recipe example:
-#
-# int = {Hash with your network settings...}
-#
-# ifconfig int['ip'] do
-# ignore_failure true
-# device int['dev']
-# mask int['mask']
-# gateway int['gateway']
-# mtu int['mtu']
-# end
-
class Chef
class Provider
+ # use the ifconfig resource to manage interfaces on *nix systems
+ #
+ # @example set a static ip on eth1
+ # ifconfig '33.33.33.80' do
+ # device 'eth1'
+ # end
class Ifconfig < Chef::Provider
provides :ifconfig
diff --git a/lib/chef/resource/ifconfig.rb b/lib/chef/resource/ifconfig.rb
index 3673311348..e9ef47d95b 100644
--- a/lib/chef/resource/ifconfig.rb
+++ b/lib/chef/resource/ifconfig.rb
@@ -21,163 +21,36 @@ require "chef/resource"
class Chef
class Resource
+ # use the ifconfig resource to manage interfaces on *nix systems
+ #
+ # @example set a static ip on eth1
+ # ifconfig '33.33.33.80' do
+ # device 'eth1'
+ # end
class Ifconfig < Chef::Resource
-
- identity_attr :device
+ resource_name :ifconfig
state_attrs :inet_addr, :mask
default_action :add
allowed_actions :add, :delete, :enable, :disable
- def initialize(name, run_context = nil)
- super
- @target = name
- @hwaddr = nil
- @mask = nil
- @inet_addr = nil
- @bcast = nil
- @mtu = nil
- @metric = nil
- @device = nil
- @onboot = nil
- @network = nil
- @bootproto = nil
- @onparent = nil
- @ethtool_opts = nil
- @bonding_opts = nil
- @master = nil
- @slave = nil
- end
-
- def target(arg = nil)
- set_or_return(
- :target,
- arg,
- :kind_of => String
- )
- end
-
- def device(arg = nil)
- set_or_return(
- :device,
- arg,
- :kind_of => String
- )
- end
-
- def hwaddr(arg = nil)
- set_or_return(
- :hwaddr,
- arg,
- :kind_of => String
- )
- end
-
- def inet_addr(arg = nil)
- set_or_return(
- :inet_addr,
- arg,
- :kind_of => String
- )
- end
-
- def bcast(arg = nil)
- set_or_return(
- :bcast,
- arg,
- :kind_of => String
- )
- end
-
- def mask(arg = nil)
- set_or_return(
- :mask,
- arg,
- :kind_of => String
- )
- end
-
- def mtu(arg = nil)
- set_or_return(
- :mtu,
- arg,
- :kind_of => String
- )
- end
-
- def metric(arg = nil)
- set_or_return(
- :metric,
- arg,
- :kind_of => String
- )
- end
-
- def onboot(arg = nil)
- set_or_return(
- :onboot,
- arg,
- :kind_of => String
- )
- end
-
- def network(arg = nil)
- set_or_return(
- :network,
- arg,
- :kind_of => String
- )
- end
-
- def bootproto(arg = nil)
- set_or_return(
- :bootproto,
- arg,
- :kind_of => String
- )
- end
-
- def onparent(arg = nil)
- set_or_return(
- :onparent,
- arg,
- :kind_of => String
- )
- end
-
- def ethtool_opts(arg = nil)
- set_or_return(
- :ethtool_opts,
- arg,
- :kind_of => String
- )
- end
-
- def bonding_opts(arg = nil)
- set_or_return(
- :bonding_opts,
- arg,
- :kind_of => String
- )
- end
-
- def master(arg = nil)
- set_or_return(
- :master,
- arg,
- :kind_of => String
- )
- end
-
- def slave(arg = nil)
- set_or_return(
- :slave,
- arg,
- :kind_of => String
- )
- end
+ property :target, String, name_property: true
+ property :hwaddr, String
+ property :mask, String
+ property :inet_addr, String
+ property :bcast, String
+ property :mtu, String
+ property :metric, String
+ property :device, String, identity: true
+ property :onboot, String
+ property :network, String
+ property :bootproto, String
+ property :onparent, String
+ property :ethtool_opts, String
+ property :bonding_opts, String
+ property :master, String
+ property :slave, String
end
-
end
end