summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2017-12-15 16:11:53 -0800
committerTim Smith <tsmith@chef.io>2017-12-18 18:10:08 -0800
commita0e844d3b7d47047ca14b8d306db071975000717 (patch)
tree73fe7c16bdd88bd89410197a5042497e513b0857 /lib/chef
parentf61f8bb75fcc0ba934b688c34f8d018bfcb3ca81 (diff)
downloadchef-a0e844d3b7d47047ca14b8d306db071975000717.tar.gz
Modernize the ifconfig resource
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/provider/ifconfig.rb18
-rw-r--r--lib/chef/resource/ifconfig.rb172
2 files changed, 29 insertions, 161 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..351590a339 100644
--- a/lib/chef/resource/ifconfig.rb
+++ b/lib/chef/resource/ifconfig.rb
@@ -21,163 +21,37 @@ 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
+ resource_name :ifconfig
identity_attr :device
-
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
+ 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