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
Fixes #3089 : add a rudder-stdlib library for rudder's best practises #15
Merged
jooooooon
merged 3 commits into
Normation:master
from
ncharles:ust_3087/dev/3089_initiate_rudder_stdlib
Jan 4, 2013
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
##################################################################################### | ||
# Copyright 2012 Normation SAS | ||
##################################################################################### | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, Version 3. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
##################################################################################### | ||
# | ||
# Rudder Promise Body and Bundle Library | ||
# | ||
# This library includes standardized bundles and bodies to be used as part of the | ||
# "best practices" in the Techniques writing | ||
# | ||
|
||
################################################## | ||
# classes body | ||
################################################## | ||
|
||
# | ||
# Automatically defines classes bases on a given prefix | ||
# The classes are defined based on the romises outcome | ||
# | ||
body classes rudder_common_classes(prefix) | ||
{ | ||
promise_kept => { "${prefix}_kept" }; | ||
promise_repaired => { "${prefix}_repaired" }; | ||
repair_failed => { "${prefix}_failed" , "${prefix}_error" }; | ||
repair_denied => { "${prefix}_denied" , "${prefix}_error" }; | ||
repair_timeout => { "${prefix}_timeout", "${prefix}_error" }; | ||
} | ||
|
||
|
||
################################################ | ||
# Reporting bundles | ||
################################################ | ||
|
||
# | ||
# Create and send a report to the server | ||
# This bundle takes 6 parameters : | ||
# technique_name : the name of the technique, human readable | ||
# status : the status of the Component, among the following values | ||
# result_success | ||
# result_error | ||
# result_repaired | ||
# log_repaired (for logging only) | ||
# log_warn (for logging only) | ||
# log_info (for logging only) | ||
# log_debug (for logging only) | ||
# log_trace (for logging only) | ||
# identifier : the identifier of the current Rule and Directive | ||
# component_name : the name of the component within the Technique | ||
# component_key : the value of the component reference variable (or None if undefined) | ||
# message : An explanation message understandable by a human | ||
# | ||
bundle agent rudder_common_report(technique_name, status, identifier, component_name, component_key, message) | ||
{ | ||
reports: | ||
linux|!linux:: | ||
"@@${technique_name}@@${status}@@${identifier}@@${component_name}@@${component_key}@@$(g.execRun)##$(g.uuid)@#${message}"; | ||
} | ||
|
||
|
||
# | ||
# Automatically create reports based on existing classes starting by | ||
# class_prefix (as defined by the body classes rudder_common_classes) | ||
# Takes 6 parameters | ||
# technique_name : the name of the technique, human readable | ||
# class_prefix : the prefix of a set of classes to reporting on (suffixes with "kept", "repaired" or "error") | ||
# identifier : the identifier of the current Rule and Directive | ||
# component_name : the name of the component within the Technique | ||
# component_key : the value of the component reference variable (None if it does not exists) | ||
# message_prefix : The begining of an explanation message understandable by a human | ||
# | ||
bundle agent rudder_common_reports_generic(technique_name, class_prefix, identifier, component_name, component_key, message_prefix) | ||
{ | ||
methods: | ||
"success" | ||
usebundle => rudder_common_report(technique_name, "result_success", identifier, component_name, component_key, "${message_prefix} was correct"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure that the variables here (technique_name, class_prefix, etc) need to have ${} around them. Same on the 2 below. |
||
ifvarclass => "${class_prefix}_kept.!${class_prefix}_repaired.!${class_prefix}_error"; | ||
|
||
"repaired" | ||
usebundle => rudder_common_report(technique_name, "result_repaired", identifier, component_name, component_key, "${message_prefix} was repaired"), | ||
ifvarclass => "${class_prefix}_repaired.!${class_prefix}_error"; | ||
|
||
"error" | ||
usebundle => rudder_common_report(technique_name, "result_error", identifier, component_name, component_key, "${message_prefix} could not be repaired"), | ||
ifvarclass => "${class_prefix}_error"; | ||
} |
98 changes: 98 additions & 0 deletions
98
initial-promises/rootServerInitialPromises/cfengine-nova/common/rudder_stdlib.cf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
##################################################################################### | ||
# Copyright 2012 Normation SAS | ||
##################################################################################### | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, Version 3. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
##################################################################################### | ||
# | ||
# Rudder Promise Body and Bundle Library | ||
# | ||
# This library includes standardized bundles and bodies to be used as part of the | ||
# "best practices" in the Techniques writing | ||
# | ||
|
||
################################################## | ||
# classes body | ||
################################################## | ||
|
||
# | ||
# Automatically defines classes bases on a given prefix | ||
# The classes are defined based on the romises outcome | ||
# | ||
body classes rudder_common_classes(prefix) | ||
{ | ||
promise_kept => { "${prefix}_kept" }; | ||
promise_repaired => { "${prefix}_repaired" }; | ||
repair_failed => { "${prefix}_failed" , "${prefix}_error" }; | ||
repair_denied => { "${prefix}_denied" , "${prefix}_error" }; | ||
repair_timeout => { "${prefix}_timeout", "${prefix}_error" }; | ||
} | ||
|
||
|
||
################################################ | ||
# Reporting bundles | ||
################################################ | ||
|
||
# | ||
# Create and send a report to the server | ||
# This bundle takes 6 parameters : | ||
# technique_name : the name of the technique, human readable | ||
# status : the status of the Component, among the following values | ||
# result_success | ||
# result_error | ||
# result_repaired | ||
# log_repaired (for logging only) | ||
# log_warn (for logging only) | ||
# log_info (for logging only) | ||
# log_debug (for logging only) | ||
# log_trace (for logging only) | ||
# identifier : the identifier of the current Rule and Directive | ||
# component_name : the name of the component within the Technique | ||
# component_key : the value of the component reference variable (or None if undefined) | ||
# message : An explanation message understandable by a human | ||
# | ||
bundle agent rudder_common_report(technique_name, status, identifier, component_name, component_key, message) | ||
{ | ||
reports: | ||
linux|!linux:: | ||
"@@${technique_name}@@${status}@@${identifier}@@${component_name}@@${component_key}@@$(g.execRun)##$(g.uuid)@#${message}"; | ||
} | ||
|
||
|
||
# | ||
# Automatically create reports based on existing classes starting by | ||
# class_prefix (as defined by the body classes rudder_common_classes) | ||
# Takes 6 parameters | ||
# technique_name : the name of the technique, human readable | ||
# class_prefix : the prefix of a set of classes to reporting on (suffixes with "kept", "repaired" or "error") | ||
# identifier : the identifier of the current Rule and Directive | ||
# component_name : the name of the component within the Technique | ||
# component_key : the value of the component reference variable (None if it does not exists) | ||
# message_prefix : The begining of an explanation message understandable by a human | ||
# | ||
bundle agent rudder_common_reports_generic(technique_name, class_prefix, identifier, component_name, component_key, message_prefix) | ||
{ | ||
methods: | ||
"success" | ||
usebundle => rudder_common_report(technique_name, "result_success", identifier, component_name, component_key, "${message_prefix} was correct"), | ||
ifvarclass => "${class_prefix}_kept.!${class_prefix}_repaired.!${class_prefix}_error"; | ||
|
||
"repaired" | ||
usebundle => rudder_common_report(technique_name, "result_repaired", identifier, component_name, component_key, "${message_prefix} was repaired"), | ||
ifvarclass => "${class_prefix}_repaired.!${class_prefix}_error"; | ||
|
||
"error" | ||
usebundle => rudder_common_report(technique_name, "result_error", identifier, component_name, component_key, "${message_prefix} could not be repaired"), | ||
ifvarclass => "${class_prefix}_error"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
##################################################################################### | ||
# Copyright 2012 Normation SAS | ||
##################################################################################### | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, Version 3. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
##################################################################################### | ||
# | ||
# Rudder Promise Body and Bundle Library | ||
# | ||
# This library includes standardized bundles and bodies to be used as part of the | ||
# "best practices" in the Techniques writing | ||
# | ||
|
||
################################################## | ||
# classes body | ||
################################################## | ||
|
||
# | ||
# Automatically defines classes bases on a given prefix | ||
# The classes are defined based on the romises outcome | ||
# | ||
body classes rudder_common_classes(prefix) | ||
{ | ||
promise_kept => { "${prefix}_kept" }; | ||
promise_repaired => { "${prefix}_repaired" }; | ||
repair_failed => { "${prefix}_failed" , "${prefix}_error" }; | ||
repair_denied => { "${prefix}_denied" , "${prefix}_error" }; | ||
repair_timeout => { "${prefix}_timeout", "${prefix}_error" }; | ||
} | ||
|
||
|
||
################################################ | ||
# Reporting bundles | ||
################################################ | ||
|
||
# | ||
# Create and send a report to the server | ||
# This bundle takes 6 parameters : | ||
# technique_name : the name of the technique, human readable | ||
# status : the status of the Component, among the following values | ||
# result_success | ||
# result_error | ||
# result_repaired | ||
# log_repaired (for logging only) | ||
# log_warn (for logging only) | ||
# log_info (for logging only) | ||
# log_debug (for logging only) | ||
# log_trace (for logging only) | ||
# identifier : the identifier of the current Rule and Directive | ||
# component_name : the name of the component within the Technique | ||
# component_key : the value of the component reference variable (or None if undefined) | ||
# message : An explanation message understandable by a human | ||
# | ||
bundle agent rudder_common_report(technique_name, status, identifier, component_name, component_key, message) | ||
{ | ||
reports: | ||
linux|!linux:: | ||
"@@${technique_name}@@${status}@@${identifier}@@${component_name}@@${component_key}@@$(g.execRun)##$(g.uuid)@#${message}"; | ||
} | ||
|
||
|
||
# | ||
# Automatically create reports based on existing classes starting by | ||
# class_prefix (as defined by the body classes rudder_common_classes) | ||
# Takes 6 parameters | ||
# technique_name : the name of the technique, human readable | ||
# class_prefix : the prefix of a set of classes to reporting on (suffixes with "kept", "repaired" or "error") | ||
# identifier : the identifier of the current Rule and Directive | ||
# component_name : the name of the component within the Technique | ||
# component_key : the value of the component reference variable (None if it does not exists) | ||
# message_prefix : The begining of an explanation message understandable by a human | ||
# | ||
bundle agent rudder_common_reports_generic(technique_name, class_prefix, identifier, component_name, component_key, message_prefix) | ||
{ | ||
methods: | ||
"success" | ||
usebundle => rudder_common_report("${technique_name}", "result_success", "${identifier}", "${component_name}", "${component_key}", "${message_prefix} was correct"), | ||
ifvarclass => "${class_prefix}_kept.!${class_prefix}_repaired.!${class_prefix}_error"; | ||
|
||
"repaired" | ||
usebundle => rudder_common_report("${technique_name}", "result_repaired", "${identifier}", "${component_name}", "${component_key}", "${message_prefix} was repaired"), | ||
ifvarclass => "${class_prefix}_repaired.!${class_prefix}_error"; | ||
|
||
"error" | ||
usebundle => rudder_common_report("${technique_name}", "result_error", "${identifier}", "${component_name}", "${component_key}", "${message_prefix} could not be repaired"), | ||
ifvarclass => "${class_prefix}_error"; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a detail, but our convention says use${} not $ (), and g.execRun and g.uuid are therefore not up to date with it.