Table of contents
1.
Introduction 📝 
2.
Syntax
3.
Actions
4.
Properties
5.
Common Resource Functionality
5.1.
Common Properties
5.2.
Notifications
5.3.
Guards
5.3.1.
Properties
6.
Examples
7.
Frequently Asked Question❓
7.1.
What is Chef in DevOps?
7.2.
Is Chef Infra free to use?
7.3.
What is Chef infra used for?
7.4.
What are the resources in chef?
7.5.
In which language is Chef written?
8.
Conclusion ✉️
Last Updated: Mar 27, 2024
Easy

CHEF-RESOURCES -windows_power_management Resource

Author Alok Pandey
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction 📝 

In this blog, we will discuss CHEF-RESOURCES windows_power_management resource. Chef is a corporation that specializes in automation. Since its launch in 2008, they have brought developers and system administrators together with our eponymous product, Chef Infra. Many features make the chef infra unique.

Chef resources
 

The windows power management resource is used to configure the power parameters of a kiosk-style device when you need it to be always-on New in Chef Desktop 1.0.

Syntax

windows_power_management 'name' do
  disk_timeout            Integer
  hibernate_timeout       Integer
  monitor_timeout         Integer
  power_level             String 
  power_scheme_label      String
  standby_timeout         Integer
  action                  Symbol 
end

Actions

The windows_power_management resource contains the following set of actions:

:set
This set the power scheme on a node to ‘balanced’ or ‘ultimate’.

:nothing
This resource block does not act until notified to do so by another resource. When this resource block is notified, it either runs immediately or is delayed to execute at the end of a Chef Infra Client run.

Properties

The windows_power_management resource has the following properties:


power_level

Ruby Type: String | Default Value: balanced

Power is divided into two categories: balanced and ultimate.


disk_timeout

Ruby Type: Integer

The number of minutes to wait before turning off the HD.


monitor_timeout

Ruby Type: Integer

The number of minutes to wait before shutting off the display.


hibernate_timeout

Ruby Type: Integer

The number of minutes to wait before hibernating the system.


standby_timeout

Ruby Type: Integer

The number of minutes to wait before putting the system into standby mode.

 

power_scheme_label

Ruby Type: String

A label name is used to preface your power scheme. To keep it separate, the code mimics the existing power scheme.
 

Common Resource Functionality

Chef resources contain common attributes, notifications, and resource guardians.

Common Properties

There are the following common properties  to every resource:

sensitive

Ruby Type: true, false | Default Value: false

This ensures that sensitive resource data is not logged by Chef Infra Client.

 

retries

Ruby Type: Integer | Default Value: 0

The number of times an exception is caught and the resource is retried.

 

ignore_failure

Ruby Type: false, true, :quiet | Default Value: false

If a resource fails for any reason, continue running the recipe. :quiet This will not display the full stack trace, and the recipe will continue to run if a resource fails.

 

compile_time

Ruby Type: true, false | Default Value: false

Control the phase of the resource's execution on the node. Set to true to allow the resource collection to operate while it is being constructed. Set to false to prevent the Chef Infra Client from running while the node is being configured (the converge phase).
 

retry_delay

Ruby Type: Integer | Default Value: 2

The delay in seconds between retry attempts.
 

Notifications

notifies

Ruby Type: Symbol, 'Chef::Resource[String]'

When a resource's state changes, it can alert another resource to take action. Specify a'resource[name],' the :action that resource should take, and then the :timer for that action. A resource may inform more than one resource; use a notifying statement for each resource to be notified.

A timer specifies when a notice is sent during a Chef Infra Client execution. There are the following timers available:
 

:before

It specifies that the action on a notified resource should be executed before the resource block in which the notification is located is processed.
 

:delayed

Default. This property specifies that a notification should be queued and then executed at the end of a Chef Infra Client run.

:immediate, :immediately

It specifies that a notification should be run immediately, for each resource notified.

The syntax for notifies is:

notifies :action, 'resource[name]', :timer

Guards

During the execution stage of a Chef Infra Client run, the state of a node can be checked using the guard property in the windows power management resource. According to the outcomes of this review, a guard property is utilized to instruct Chef Infra Client whether or not to continue executing a resource. A guard property accepts either a string or a Ruby block value.

A guard property is important for guaranteeing that a resource is idempotent by allowing that resource to test for the intended state as it is being performed and then do nothing if the required state is present.

Properties

There are following properties can be used to define a guard in windows_power_management resource that is checked during the execution phase of a Chef Infra Client run:

only_if

This allows a resource to execute only if the condition returns true.

not_if

This prevents a resource from executing when the condition returns true.

Examples

The following recipes show alternative techniques to using the windows_power_management resource:

Setup a Power Management Policy:

windows_power_management 'Set the Device to a defined power level' do
  power_scheme_label 'Unrestricted'
  power_level 'ultimate'
  monitor_timeout 30
  disk_timeout 0
  standby_timeout 0
  hibernate_timeout 0
  action :set
end

Frequently Asked Question❓

What is Chef in DevOps?

A guide for people new to DevOps With Chef, a DevOps program in your kitchen, becoming an expert in the cloud is much simpler. Chef is an open-source cloud deployment and configuration management tool. Anyone can use it to organize servers in a departmental data center or the cloud.

Is Chef Infra free to use?

Chef Infra is open-source so you can use it for free.

What is Chef infra used for?

A powerful automation platform called Chef Infra turns infrastructure into code. Whatever the size of your network, Chef Infra automates the configuration, deployment, and management of infrastructure across it, whether you're operating in the cloud, on-premises, or a hybrid environment.

What are the resources in chef?

Chef resources are an example of an operating system component in their ideal state. It is a declaration of configuration policy that explains the desired state of a node to be reached by resource providers using the existing configuration.

In which language is Chef written?

Chef is written in ruby and erlang programming language.

Conclusion ✉️

In this article, we have extensively discussed the CHEF- RESOURCES -windows_power_management Resource. If you would like to learn more, check out our articles on
 


Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. 

Enroll in our courses and refer to the mock test and problems available.

Take a look at the interview experiences and interview bundle for placement preparations.

Happy Coding!

Live masterclass