Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to using the wmi-lite gem #101

Merged
merged 5 commits into from
Aug 4, 2014
Merged

Switch to using the wmi-lite gem #101

merged 5 commits into from
Aug 4, 2014

Conversation

btm
Copy link
Contributor

@btm btm commented Aug 4, 2014

Chef switched from ruby-wmi to wmi-lite recently, have this cookbook do the same.

This replaces #100, and I'm handing this off to @Adamex to finish. I think the only work left is to think about making sure that wmi-lite is installed before the libraries need it if you're running on older versions of Chef that don't come with wmi-lite. Later we should deprecate the windows/libraries/version.rb in favor of `lib/chef/win32/version.rb' in chef.

I've been testing with this recipe to make sure we exercise the libraries, as the default cookbook was happily running for me with just @pieter-lazzro's patch before I did so.

winver = Windows::Version.new

log "server core" do
  message "not on server core"
  not_if { winver.server_core? }
end

hive_name = Registry.get_hive_name("HKLM")

log "hive name" do
  message "HKLM is really #{hive_name}"
end

log "not media center" do
  message "we are not on media center"
  not_if { Registry.value_exists?(AUTO_RUN_KEY, 'Windows Media Center') }
end

Resulting in:

Recipe: win_test::default
  * log[server core] action write[2014-08-04T14:35:52-04:00] INFO: Processing log[server core] action write (win_test::default line 4)
[2014-08-04T14:35:52-04:00] INFO: not on server core


  * log[hive name] action write[2014-08-04T14:35:52-04:00] INFO: Processing log[hive name] action write (win_test::default line 11)
[2014-08-04T14:35:52-04:00] INFO: HKLM is really HKEY_LOCAL_MACHINE


  * log[not media center] action write[2014-08-04T14:35:52-04:00] INFO: Processing log[not media center] action write (win_test::default line 15)
[2014-08-04T14:35:52-04:00] INFO: we are not on media center

@pieter-lazzaro
Copy link
Contributor

Thanks btm. Have just started using chef and ruby and my use case was very simple and don't think I actually hit the code I changed.

@adamedx
Copy link
Contributor

adamedx commented Aug 4, 2014

@danielsdeleo , @btm, @sersut , @juliandunn, can you take a peek? Not sure if this is the best way to try to use chef_gem to satisfy a gem dependency in a library file.

@@ -100,6 +100,7 @@ class Version
0x00000030 => {:ms_const => 'PRODUCT_PROFESSIONAL', :name => 'Professional'},
0x00000045 => {:ms_const => 'PRODUCT_PROFESSIONAL_E', :name => 'Not supported'},
0x00000031 => {:ms_const => 'PRODUCT_PROFESSIONAL_N', :name => 'Professional N'},
0x00000067 => {:ms_const => 'PRODUCT_PROFESSIONAL_WMC', :name => 'Professional with Media Center'},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you're the only other person besides me @btm running Windows Media Center?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It came free with my pro upgrade ¯_(ツ)_/¯

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, its a really nasty undefined method '[]' for nil:NilClass error if your SKU isn't in the constant :(

@danielsdeleo
Copy link

The gem install stuff is ugly, but I don't know how to do it better without some support from Chef, which is something we've thought about but don't have a design for (and that wouldn't help immediate pain anyway). 👍

@adamedx
Copy link
Contributor

adamedx commented Aug 4, 2014

Thanks @btm, @danielsdeleo. Yeah, ideally you could express the gem dependencies in metadata.rb or even in a gemspec-like file. Then gems could be downloaded to a bundle for the cookbook when cookbooks are fetched. Crazy talk.

@adamedx
Copy link
Contributor

adamedx commented Aug 4, 2014

Tested on 11.12.8, 11.14.2, and 10.32.2 successfully.

adamedx pushed a commit that referenced this pull request Aug 4, 2014
@adamedx adamedx merged commit add4bf9 into master Aug 4, 2014
@adamedx adamedx deleted the btm/ruby-wmi branch August 4, 2014 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants