Permalink
Browse files

graph generator recipe and lwrp

  • Loading branch information...
1 parent cfdd9c8 commit bc1aae2ab5c69d69b2a550eb63d79a85ac2f830b @webframp committed Apr 18, 2012
Showing with 105 additions and 0 deletions.
  1. +44 −0 providers/dashboard.rb
  2. +52 −0 recipes/graph_generator.rb
  3. +9 −0 resources/dashboard.rb
View
@@ -0,0 +1,44 @@
+require 'yaml'
+
+def load_current_resource
+ node.include_attribute "gdash::gdash"
+ node.include_recipe "gdash::default"
+
+ @dashboard_dir = ::File.join(node.gdash.templatedir,
+ new_resource.category,
+ new_resource.name)
+
+ @dashboard_yaml = ::File.join(@dashboard_dir,"dash.yaml")
+end
+
+action :create do
+
+ directory @dashboard_dir do
+ owner node.gdash.owner
+ group node.gdash.group
+ end
+
+ file @dashboard_yaml do
+ owner node.gdash.owner
+ group node.gdash.group
+ content YAML.dump(:name => new_resource.name,
+ :description => new_resource.description)
+ end
+
+ new_resource.updated_by_last_action(true)
+
+end
+
+action :delete do
+
+ directory @dashboard_dir do
+ action :delete
+ end
+
+ file @dashboard_yaml do
+ action :delete
+ end
+
+ new_resource.updated_by_last_action(true)
+
+end
View
@@ -0,0 +1,52 @@
+#
+# Cookbook Name:: gdash
+# Recipe:: graph_generator
+#
+# Copyright 2012, Sean Escriva <sean.escriva@gmail.com>
+#
+# 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.
+#
+
+include_recipe "gdash::default"
+
+test_dashboards = [
+ {
+ :name => "test",
+ :category => "bob",
+ :description => "bob's testing your uncle"
+ }
+ ]
+
+test_dashboards.each do |dashboard|
+ unless node.gdash.categories.include? dashboard[:category]
+ node.gdash.categories = (node.gdash.categories | [dashboard[:category]] )
+ end
+end
+
+node.gdash.categories.map do |category|
+ directory File.join(node.gdash.templatedir, category) do
+ owner node.gdash.owner
+ group node.gdash.group
+ notifies :restart, resources(:service => "gdash"), :delayed
+ end
+end
+
+test_dashboards.each do |dashboard|
+ Chef::Log.debug "gdash_dashboard: going to create #{dashboard.inspect}"
+
+ gdash_dashboard dashboard[:name] do
+ category dashboard[:category]
+ description dashboard[:description]
+ end
+end
+
View
@@ -0,0 +1,9 @@
+def initialize(*args)
+ super
+ @action = :create
+end
+
+actions :create, :delete
+
+attribute :category, :kind_of => String, :required => true
+attribute :description, :kind_of => String, :required => true

0 comments on commit bc1aae2

Please sign in to comment.