Skip to content

Commit

Permalink
Revert "Revert "#87 - support simple windows folder sharing""
Browse files Browse the repository at this point in the history
This reverts commit 2aa2981.
  • Loading branch information
btm committed Aug 27, 2014
1 parent 54e083e commit 6c15186
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 5 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The following cookbooks provided by Opscode are required as noted:
Attributes
----------
* `node['windows']['allow_pending_reboots']` - used to configure the `WindowsRebootHandler` (via the `windows::reboot_handler` recipe) to act on pending reboots. default is true (ie act on pending reboots). The value of this attribute only has an effect if the `windows::reboot_handler` is in a node's run list.
* `node['windows']['allow_reboot_on_failure']` - used to register the `WindowsRebootHandler` (via the `windows::reboot_handler` recipe) as an exception handler too to act on reboots not only at the end of successful Chef runs, but even at the end of failed runs. default is false (ie reboot only after successful runs). The value of this attribute only has an effect if the `windows::reboot_handler` is in a node's run list.


Resource/Provider
Expand Down Expand Up @@ -115,6 +116,7 @@ servermanagercmd -query
#### Providers
- **Chef::Provider::WindowsFeature::DISM**: Uses Deployment Image Servicing and Management (DISM) to manage roles/features.
- **Chef::Provider::WindowsFeature::ServerManagerCmd**: Uses Server Manager to manage roles/features.
- **Chef::Provider::WindowsFeaturePowershell**: Uses Powershell to manage roles/features. (see [COOK-3714](https://tickets.opscode.com/browse/COOK-3714)

#### Examples
Enable the node as a DHCP Server
Expand Down Expand Up @@ -562,7 +564,7 @@ end
Exception/Report Handlers
-------------------------
### WindowsRebootHandler
Required reboots are a necessary evil of configuring and managing Windows nodes. This report handler (ie fires at the end of successful Chef runs) acts on requested (Chef initiated) or pending (as determined by the OS per configuration action we performed) reboots. The `allow_pending_reboots` initialization argument should be set to false if you do not want the handler to automatically reboot a node if it has been determined a reboot is pending. Reboots can still be requested explicitly via the `windows_reboot` LWRP.
Required reboots are a necessary evil of configuring and managing Windows nodes. This report handler (ie fires at the end of Chef runs) acts on requested (Chef initiated) or pending (as determined by the OS per configuration action we performed) reboots. The `allow_pending_reboots` initialization argument should be set to false if you do not want the handler to automatically reboot a node if it has been determined a reboot is pending. Reboots can still be requested explicitly via the `windows_reboot` LWRP.
### Initialization Arguments
- `allow_pending_reboots`: indicator on whether the handler should act on a the Window's 'pending reboot' state. default is true
Expand Down Expand Up @@ -637,6 +639,8 @@ override_attributes(
This will still allow a reboot to be explicitly requested via the `windows_reboot` LWRP.
By default, the handler will only be registered as a report handler, meaning that it will only fire at the end of successful Chef runs. If the run fails, pending or requested reboots will be ignored. This can lead to a situation where some package was installed and notified a reboot request via the `windows_reboot` LWRP, and then the run fails for some unrelated reason, and the reboot request gets dropped because the resource that notified the reboot request will already be up-to-date at the next run and will not request a reboot again, and thus the requested reboot will never be performed. To change this behavior and register the handler as an exception handler that fires at the end of failed runs too, override `node['windows']['allow_reboot_on_failure']` and set the value to true.
License & Authors
-----------------
Expand Down
1 change: 1 addition & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
#

default['windows']['allow_pending_reboots'] = true
default['windows']['allow_reboot_on_failure'] = false
default['windows']['rubyzipversion'] = nil
default['windows']['reboot_timeout'] = 60
16 changes: 14 additions & 2 deletions libraries/matchers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
if defined?(ChefSpec)
ChefSpec::Runner.define_runner_method :windows_package
ChefSpec::Runner.define_runner_method :windows_feature
ChefSpec::Runner.define_runner_method :windows_task
ChefSpec::Runner.define_runner_method :windows_path
ChefSpec::Runner.define_runner_method :windows_batch
ChefSpec::Runner.define_runner_method :windows_pagefile
ChefSpec::Runner.define_runner_method :windows_zipfile
ChefSpec::Runner.define_runner_method :windows_shortcut
ChefSpec::Runner.define_runner_method :windows_auto_run
ChefSpec::Runner.define_runner_method :windows_printer
ChefSpec::Runner.define_runner_method :windows_printer_port
ChefSpec::Runner.define_runner_method :windows_reboot

#
# Assert that a +windows_package+ resource exists in the Chef run with the
Expand Down Expand Up @@ -444,7 +456,7 @@ def cancel_windows_reboot(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:windows_reboot, :cancel, resource_name)
end

def create_windows_shortcut(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:windows_shortcut, :create, resource_name)
def create_windows_share(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:windows_share, :create, resource_name)
end
end
2 changes: 1 addition & 1 deletion libraries/windows_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module Helper
# returns windows friendly version of the provided path,
# ensures backslashes are used everywhere
def win_friendly_path(path)
path.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR) if path
path.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR || '\\') if path
end

# account for Window's wacky File System Redirector
Expand Down
1 change: 1 addition & 0 deletions providers/auto_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
use_inline_resources if defined?(use_inline_resources)

action :create do
windows_registry 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run' do
Expand Down
1 change: 1 addition & 0 deletions providers/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
use_inline_resources if defined?(use_inline_resources)

require 'tempfile'
require 'chef/resource/execute'
Expand Down
1 change: 1 addition & 0 deletions providers/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
use_inline_resources if defined?(use_inline_resources)

action :add do
env "path" do
Expand Down
1 change: 1 addition & 0 deletions providers/printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
use_inline_resources if defined?(use_inline_resources)

# Support whyrun
def whyrun_supported?
Expand Down
1 change: 1 addition & 0 deletions providers/printer_port.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
use_inline_resources if defined?(use_inline_resources)

# Support whyrun
def whyrun_supported?
Expand Down
56 changes: 56 additions & 0 deletions providers/share.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#
# Author:: Venkat Naidu (naiduvenkat@gmail.com)
# Cookbook Name:: windows
# Provider:: share
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


require 'chef/mixin/shell_out'

include Chef::Mixin::ShellOut
include Windows::Helper

def load_current_resource
@current_resource = Chef::Resource::WindowsShare.new(@new_resource.name)
@current_resource.name(@new_resource.name)
@current_resource.user(@new_resource.user)
@current_resource.path(@new_resource.path)
@current_resource.access(@new_resource.access)

@current_resource
end

action :create do
cmd = "net share " + @current_resource.name + "=" + @current_resource.path + " /GRANT:" + @current_resource.user + ",#{access_type_template}"
shell_out!(cmd)
@new_resource.updated_by_last_action(true)
Chef::Log.info("Share created")
end

def access_type_template
case access_type
when :read
"READ"
when :change
"CHANGE"
when :full
"FULL"
else
end
end

def access_type
@current_resource.access
end
2 changes: 1 addition & 1 deletion recipes/reboot_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
chef_handler 'WindowsRebootHandler' do
source "#{node['chef_handler']['handler_path']}/windows_reboot_handler.rb"
arguments node['windows']['allow_pending_reboots']
supports :report => true, :exception => false
supports :report => true, :exception => node['windows']['allow_reboot_on_failure']
action :enable
end
23 changes: 23 additions & 0 deletions resources/share.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
uthor:: Venkat Naidu (<naiduvenkat@gmail.com>)
# Cookbook Name:: windows
# Resource:: share
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

actions :create, :delete
attribute :name, :kind_of => String, :name_attribute => true
attribute :path, :kind_of => String
attribute :access, :kind_of => Symbol, :default => :read, :equal_to => [:read, :chage, :full]
attribute :user, :kind_of => String

0 comments on commit 6c15186

Please sign in to comment.