forked from sous-chefs/consul
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sous-chefs#215 consul_ui resource and readme
- Loading branch information
Showing
2 changed files
with
110 additions
and
0 deletions.
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
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,82 @@ | ||
require 'poise' | ||
|
||
module ConsulCookbook | ||
module Resource | ||
# Resource for managing the Consul web UI installation. | ||
class ConsulUI < Chef::Resource | ||
include Poise | ||
provides(:consul_ui) | ||
default_action(:install) | ||
|
||
# @!attribute version | ||
# @return [String] | ||
attribute(:version, kind_of: String, required: true) | ||
|
||
# @!attribute install_path | ||
# @return [String] | ||
attribute(:install_path, kind_of: String, default: '/srv') | ||
|
||
# @!attribute owner | ||
# @return [String] | ||
attribute(:owner, kind_of: String, default: 'consul') | ||
|
||
# @!attribute group | ||
# @return [String] | ||
attribute(:group, kind_of: String, default: 'consul') | ||
|
||
# @!attribute binary_url | ||
# @return [String] | ||
attribute(:binary_url, kind_of: String, default: "https://dl.bintray.com/mitchellh/consul/%{filename}.zip") | ||
|
||
# @!attribute source_url | ||
# @return [String] | ||
attribute(:source_url, kind_of: String) | ||
|
||
def default_environment | ||
{ GOMAXPROCS: [node['cpu']['total'], 2].max.to_s, PATH: '/usr/local/bin:/usr/bin:/bin' } | ||
end | ||
|
||
def binary_checksum | ||
node['consul']['checksums'].fetch(binary_filename) | ||
end | ||
|
||
def binary_filename | ||
[version, 'web_ui'].join('_') | ||
end | ||
|
||
end | ||
end | ||
|
||
module Provider | ||
# Provider for managing the Consul web UI installation. | ||
class ConsulUI < Chef::Provider | ||
include Poise | ||
provides(:consul_ui) | ||
|
||
def action_install | ||
notifying_block do | ||
artifact = libartifact_file "consul-ui-#{new_resource.version}" do | ||
artifact_name new_resource.name | ||
artifact_version new_resource.version | ||
owner new_resource.owner | ||
group new_resource.group | ||
install_path new_resource.install_path | ||
remote_url new_resource.binary_url % { filename: new_resource.binary_filename } | ||
remote_checksum new_resource.binary_checksum | ||
end | ||
end | ||
end | ||
|
||
def action_uninstall | ||
notifying_block do | ||
artifact = libartifact_file "consul-ui-#{new_resource.version}" do | ||
action :delete | ||
artifact_name new_resource.name | ||
artifact_version new_resource.version | ||
install_path new_resource.install_path | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |