Coder Social home page Coder Social logo

tubbz-alt / compat_resource Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pwnieexpress/compat_resource

0.0 1.0 0.0 151 KB

Cookbook (+ gem) to bring some features from future Chef to earlier versions

Home Page: https://supermarket.chef.io/cookbooks/compat_resource

License: Apache License 2.0

Ruby 100.00%

compat_resource's Introduction

compat_resource cookbook

Build Status Cookbook Version

This cookbook brings the custom resource syntax from Chef 12.5 to earlier Chef 12.X releases.

Converting cookbooks from the old resource model to the new

Boilerplate

  1. Depend on compat_resource
    • Descend resources from ChefCompat::Resource
    • Set resource_name in the class instead of the constructor
  2. Convert Attributes to Properties
    • Rename attribute -> property
    • Move set_or_return -> property
    • Take kind_of/equal_to/regexes and make them types
    • Use true/false/nil instead of TrueClass/FalseClass/NilClass
    • Remove default: nil (it's the default)
  3. Convert Top-Level Providers to Actions
    • Create any resources that don't already exist (for example in multi-provider cases) and descend from the base resource
    • Remove allowed_actions / @actions
    • @action -> default_action
    • Move provides and action :x to the resource
    • Remove use_inline_resources and def whyrun_safe?
    • Move other methods to action_class.class_eval do

Now you have everything in a resource, are using properties, and have gotten rid of a bunch of boilerplate. Of course, this is just getting it moved. Now you can start to really use the new features. And if you're making resources for the first time, congrats--you probably didn't have to do very much of this :)

Advanced Concepts

  1. Resource Inheritance
  2. Resources That Are Different On Each OS?
  3. Coercion: Handling User Input
  4. Lazy Defaults
  5. Using Load Current Resource
  6. Using Converge If Changed
  7. Defaults Are For Creation
  8. Shared types: using a type multiple places

Requirements

Platforms

  • All platforms supported by Chef

Chef

  • Chef 12.0+

Cookbooks

  • none

Usage

To use this cookbook, put depends 'compat_resource' in the metadata.rb of your cookbook. Once this is done, you can use all the new custom resource features to define resources. It Just Works.

For example, if you create resources/myresource.rb, myresource can use property, load_current_value and action (no need to create a provider). If you want to create Resource classes directly, extend from ChefCompat::Resource instead of Chef::Resource. Properties, current value loading, converge_if_changed, and resource_name will all function the same across versions.

Custom Resources?

Curious about how to use custom resources? Here are the 12.5 docs:

##License & Authors

Author: John Keiser ([email protected])

Copyright: 2015, Chef Software, Inc.

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.

compat_resource's People

Contributors

jkeiser avatar tas50 avatar sstelfox avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.