Class: Fileshare

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/provider/fileshare/wmi/fileshare.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Fileshare

Returns a new instance of Fileshare.



7
8
9
10
# File 'lib/puppet/provider/fileshare/wmi/fileshare.rb', line 7

def initialize(name)
  @wmi_session = WIN32OLE.connect("winmgmts://localhost/root/cimv2")
  @name = name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/puppet/provider/fileshare/wmi/fileshare.rb', line 5

def name
  @name
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/puppet/provider/fileshare/wmi/fileshare.rb', line 5

def path
  @path
end

Instance Method Details

#commentObject



32
33
34
# File 'lib/puppet/provider/fileshare/wmi/fileshare.rb', line 32

def comment
  @wmi_session.get("Win32_Share='#{@name}'").description
end

#comment=(string) ⇒ Object



36
37
38
# File 'lib/puppet/provider/fileshare/wmi/fileshare.rb', line 36

def comment=(string)
  @wmi_session.get("Win32_Share='#{@name}'").setshareinfo(maxcon, string)
end

#createObject



12
13
14
15
16
# File 'lib/puppet/provider/fileshare/wmi/fileshare.rb', line 12

def create
  wmi = WIN32OLE.connect("winmgmts:Win32_Share")
  creation = wmi.create(@path, @name, 0, nil, nil)
  evaluate_success(creation)
end

#daclObject



53
54
55
56
57
58
# File 'lib/puppet/provider/fileshare/wmi/fileshare.rb', line 53

def dacl
  share = @wmi_session.get("Win32_LogicalShareSecuritySetting='#{@name}'")
  share.getsecuritydescriptor(4)
  returns = WIN32OLE::ARGV[0] #Retrospectively receives args from GetSecurityDescriptor
  return returns.DACL
end

#deleteObject



18
19
20
21
# File 'lib/puppet/provider/fileshare/wmi/fileshare.rb', line 18

def delete
  deletion = @wmi_session.get("Win32_Share='#{@name}'").delete
  evaluate_success(deletion)
end

#exists?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
# File 'lib/puppet/provider/fileshare/wmi/fileshare.rb', line 23

def exists?
  begin
    @wmi_session.get("Win32_Share='#{@name}'") #Raises exception if share doesn't exist
    return true
  rescue
    return false
  end
end

#maxconObject



40
41
42
# File 'lib/puppet/provider/fileshare/wmi/fileshare.rb', line 40

def maxcon
  @wmi_session.get("Win32_Share='#{@name}'").maximumallowed
end

#maxcon=(int) ⇒ Object



44
45
46
# File 'lib/puppet/provider/fileshare/wmi/fileshare.rb', line 44

def maxcon=(int)
  @wmi_session.get("Win32_Share='#{@name}'").setshareinfo(int, comment)
end

#sd=(sd) ⇒ Object



48
49
50
51
# File 'lib/puppet/provider/fileshare/wmi/fileshare.rb', line 48

def sd=(sd)
  share = @wmi_session.get("Win32_LogicalShareSecuritySetting='#{@name}'")
  share.setsecuritydescriptor(sd)
end