Class: Chef::Util::Windows::NetUse
- Inherits:
-
Chef::Util::Windows
- Object
- Chef::Util::Windows
- Chef::Util::Windows::NetUse
- Defined in:
- lib/chef/util/windows/net_use.rb
Instance Method Summary collapse
- #add(args) ⇒ Object
- #delete ⇒ Object
- #device ⇒ Object
- #from_use_info_struct(ui2_hash) ⇒ Object
- #get_info ⇒ Object
-
#initialize(localname) ⇒ NetUse
constructor
A new instance of NetUse.
- #to_ui2_struct(use_info) ⇒ Object
- #use_name ⇒ Object
Constructor Details
#initialize(localname) ⇒ NetUse
Returns a new instance of NetUse.
27 28 29 |
# File 'lib/chef/util/windows/net_use.rb', line 27 def initialize(localname) @use_name = localname end |
Instance Method Details
#add(args) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/chef/util/windows/net_use.rb', line 38 def add(args) if args.class == String remote = args args = {} args[:remote] = remote end args[:local] ||= use_name ui2_hash = to_ui2_struct(args) begin Chef::ReservedNames::Win32::Net.net_use_add_l2(nil, ui2_hash) rescue Chef::Exceptions::Win32APIError => e raise ArgumentError, e end end |
#delete ⇒ Object
72 73 74 75 76 |
# File 'lib/chef/util/windows/net_use.rb', line 72 def delete Chef::ReservedNames::Win32::Net.net_use_del(nil, use_name, :use_noforce) rescue Chef::Exceptions::Win32APIError => e raise ArgumentError, e end |
#device ⇒ Object
68 69 70 |
# File 'lib/chef/util/windows/net_use.rb', line 68 def device get_info[:remote] end |
#from_use_info_struct(ui2_hash) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/chef/util/windows/net_use.rb', line 54 def from_use_info_struct(ui2_hash) ui2_hash.inject({}) do |memo, (k, v)| memo[k.to_s.sub("ui2_", "").to_sym] = v memo end end |
#get_info ⇒ Object
61 62 63 64 65 66 |
# File 'lib/chef/util/windows/net_use.rb', line 61 def get_info ui2 = Chef::ReservedNames::Win32::Net.net_use_get_info_l2(nil, use_name) from_use_info_struct(ui2) rescue Chef::Exceptions::Win32APIError => e raise ArgumentError, e end |
#to_ui2_struct(use_info) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/chef/util/windows/net_use.rb', line 31 def to_ui2_struct(use_info) use_info.inject({}) do |memo, (k, v)| memo["ui2_#{k}".to_sym] = v memo end end |
#use_name ⇒ Object
78 79 80 |
# File 'lib/chef/util/windows/net_use.rb', line 78 def use_name @use_name end |