Skip to content

Commit

Permalink
Merge pull request #105 from majormoses/master
Browse files Browse the repository at this point in the history
created a new resource to install:
  • Loading branch information
bdangit committed May 7, 2016
2 parents e313c46 + fcd1cc5 commit 122db89
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [unreleased]

## 4.2.0
* Added influxdb\_install resource (contributed by @majormoses)

## 4.1.0
* Updated attributes to support Influxdb 0.10.0
* Set default resource actions (:create is default)
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ influxdb_database 'my_db' do
end
```

### influxdb\_install
This resource sets up or removes the appropriate repositories and installs/removes the appropriate packages

```ruby
influxdb_install 'influxdb' do
arch_type 'amd64' # if undefined will auto detect
include_repository true # default
influxdb_key 'https://repos.influxdata.com/influxdb.key' # default
action :install # default
end
```

```ruby
influxdb_install 'influxdb' do
action :remove
end
```

### influxdb\_user
This resources configures a user to interact with InfluxDB databases.

Expand Down
17 changes: 17 additions & 0 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module InfluxdbCookbook
# helper functions to be used in resources
module Helpers
def determine_arch_type(new_resource, node)
if new_resource.arch_type
new_resource.arch_type.to_s
else
case node['kernel']['machine']
when /64/
'amd64'
when /386/
'i386'
end
end
end
end
end
8 changes: 8 additions & 0 deletions libraries/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,12 @@ def create_influxdb_config(config)
def delete_influxdb_config(config)
ChefSpec::Matchers::ResourceMatcher.new(:influxdb_config, :delete, config)
end

def install_influxdb_install(package)
ChefSpec::Matchers::ResourceMatcher.new(:influxdb_install, :install, package)
end

def remove_influxdb_install(package)
ChefSpec::Matchers::ResourceMatcher.new(:influxdb_install, :remove, package)
end
end
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
maintainer_email '[email protected]'
license 'MIT'
description 'InfluxDB, a timeseries database'
version '4.1.0'
version '4.2.0'

# For CLI client
# https://github.com/redguide/nodejs
Expand Down
22 changes: 2 additions & 20 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,8 @@
compile_time false if respond_to?(:compile_time)
end

if platform_family? 'rhel'
yum_repository 'influxdb' do
description 'InfluxDB Repository - RHEL \$releasever'
baseurl node['influxdb']['upstream_repository']
gpgkey 'https://repos.influxdata.com/influxdb.key'
end
else
package 'apt-transport-https'

apt_repository 'influxdb' do
uri node['influxdb']['upstream_repository']
distribution node['lsb']['codename']
components ['stable']
arch 'amd64'
key 'https://repos.influxdata.com/influxdb.key'
end
end

package 'influxdb' do
version node['influxdb']['version']
influxdb_install 'influxdb' do
action [:install]
end

influxdb_config node['influxdb']['config_file_path'] do
Expand Down
65 changes: 65 additions & 0 deletions resources/install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# resources/install.rb

# Resource for InfluxDB install

property :arch_type, kind_of: String
property :include_repository, kind_of: [TrueClass, FalseClass], default: true
property :influxdb_key, kind_of: String, default: 'https://repos.influxdata.com/influxdb.key'
default_action :install

include InfluxdbCookbook::Helpers

action :install do
if node.platform_family? 'rhel'
yum_repository 'influxdb' do
description 'InfluxDB Repository - RHEL \$releasever'
baseurl node['influxdb']['upstream_repository']
gpgkey influxdb_key
only_if { include_repository }
end
elsif node.platform_family? 'debian'
# see if we should auto detect
unless new_resource.arch_type
new_resource.arch_type determine_arch_type(new_resource, node)
end

package 'apt-transport-https' do
action :install
end

apt_repository 'influxdb' do
uri node['influxdb']['upstream_repository']
distribution node['lsb']['codename']
components ['stable']
arch_type new_resource.arch_type
key influxdb_key
only_if { include_repository }
end
else
Chef::Log.warn "I do not support your platform: #{node.platform_family}"
end

package 'influxdb' do
version node['influxdb']['version']
end
end

action :remove do
if node.platform_family? 'rhel'
yum_repository 'influxdb' do
action :delete
only_if { include_repository }
end
elsif node.platform_family? 'debian'
apt_repository 'influxdb' do
action :delete
only_if { include_repository }
end
else
Chef.Log.warn "I do not support your platform: #{node.platform_family}"
end

package 'influxdb' do
action :remove
end
end

0 comments on commit 122db89

Please sign in to comment.