Skip to content

Commit

Permalink
Adding Cloudkick cookbook
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhjk committed Apr 23, 2010
1 parent 66bf350 commit 7218d78
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 0 deletions.
34 changes: 34 additions & 0 deletions cloudkick/README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
= DESCRIPTION:

Installs and configures the Cloudkick Agent, and integrates it with Chef.

= REQUIREMENTS:

You must be running a platform supported by the Cloudkick Agent - at this time, that means Ubuntu, CentOS or Red Hat.

= USAGE:

In order for the agent to function, you'll need to have defined your Cloudkick API key and secret. We recommend you do this in a Role, which should also take care of applying the cloudkick::default recipe.

Assuming you name the role 'cloudkick', here is the required json:

{
"name": "cloudkick",
"chef_type": "role",
"json_class": "Chef::Role",
"default_attributes": {

},
"description": "Configures Cloudkick",
"run_list": [
"recipe[cloudkick]"
],
"override_attributes": {
"cloudkick": {
"oauth_key": "YOUR KEY HERE"
"oauth_secret": "YOUR SECRET HERE"
}
}
}

If you want Cloudkick installed everywhere, we recommend you just add the cloudkick attributes to a base role.
30 changes: 30 additions & 0 deletions cloudkick/attributes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Cookbook Name:: cloudkick
# Attribute:: default
#
# Copyright 2010, Opscode, 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.
#

cloudkick_enabled = false

begin
require 'cloudkick'
cloudkick_enabled = true
rescue LoadError => e
end

if cloudkick_enabled
set[:cloudkick][:data] = Chef::CloudkickData.get(self)
end
1 change: 1 addition & 0 deletions cloudkick/files/default/plugins/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is where Cloudkick plugins go!
38 changes: 38 additions & 0 deletions cloudkick/libraries/cloudkick_data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Cookbook Name:: cloudkick
# Library:: cloudkick_data
#
# Copyright 2010, Opscode, 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.
#

class Chef
class CloudkickData
def self.get(node)
ckb = Cloudkick::Base.new(node.cloudkick.oauth_key, node.cloudkick.oauth_secret)
node = ckb.get("nodes", "node:#{node.hostname}").nodes.first
data = {
:agent_state => node.agent_state,
:color => node.color,
:id => node.id,
:ipaddress => node.ipaddress,
:name => node.name,
:provider_id => node.provider_id,
:provider_name => node.provider_name,
:status => node.status,
:tags => node.tags
}
end
end
end
11 changes: 11 additions & 0 deletions cloudkick/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
maintainer "Opscode, Inc."
maintainer_email "[email protected]"
license "Apache 2.0"
description "Installs/Configures the Cloudkick Agent"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
version "0.1.0"

depends "apt"

recipe "cloudkick::default", "Installs and configures Cloudkick"

82 changes: 82 additions & 0 deletions cloudkick/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#
# Cookbook Name:: cloudkick
# Recipe:: default
#
# Copyright 2010, Opscode, 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.
#

case node.platform
when "ubuntu"
include_recipe "apt"

execute "curl http://packages.cloudkick.com/cloudkick.packages.key | apt-key add -" do
not_if "apt-key finger | grep '0B80 27BD B5FB A7F1 8FF3 DC1F 2B5E 7CE0 8EE6 154E'"
end

template "/etc/apt/sources.list.d/cloudkick.com.list" do
mode "0644"
source "cloudkick.com.list.erb"
notifies :run, resources(:execute => "apt-get update"), :immediately
end
when "centos", "redhat"
execute "yum check-update" do
action :nothing
end

template "/etc/yum.repos.d/cloudkick.repo" do
mode "0644"
source "cloudkick.repo.erb"
notifies :run, resources(:execute => "yum check-update"), :immediately
end
end

remote_directory "/usr/lib/cloudkick-agent/plugins" do
source "plugins"
mode "0755"
files_mode "0644"
files_backup 0
recursive true
end

template "/etc/cloudkick.conf" do
mode "0644"
source "cloudkick.conf.erb"
variables({
:cloudkick_tags => node.run_list.roles
})
end

package "cloudkick-agent" do
action :upgrade
end

service "cloudkick-agent" do
action [ :enable, :start ]
subscribes :restart, resources(:template => "/etc/cloudkick.conf")
end

ruby_block "initial cloudkick data load" do
block do
Gem.clear_paths
require 'cloudkick'
node.set[:cloudkick][:data] = Chef::CloudkickData.get(node)
end
action :nothing
end

gem_package "cloudkick" do
notifies :create, resources(:ruby_block => "initial cloudkick data load"), :immediately
end

1 change: 1 addition & 0 deletions cloudkick/templates/default/cloudkick.com.list.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deb http://packages.cloudkick.com/ubuntu <%= node[:lsb][:codename] %> main
5 changes: 5 additions & 0 deletions cloudkick/templates/default/cloudkick.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
oauth_key <%= node.cloudkick.oauth_key %>
oauth_secret <%= node.cloudkick.oauth_secret %>
tags <%= @cloudkick_tags.join(",") %>
name <%= node.hostname %>

0 comments on commit 7218d78

Please sign in to comment.