Skip to content

Commit cf45b2c

Browse files
authored
Merge pull request #7 from olivierlemasle/foodcritic
Use best practices from http://www.foodcritic.io
2 parents d3e419d + f44fcb3 commit cf45b2c

File tree

9 files changed

+35
-16
lines changed

9 files changed

+35
-16
lines changed

libraries/api_keys.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ def create_admin_apikeys
3636
# bypass the section if CloudStack is not running.
3737
if @current_resource.admin_apikey or @current_resource.admin_secretkey
3838
# if keys attributes are empty search in Chef environment for other node having API-KEYS.
39-
other_nodes = search(:node, "chef_environment:#{node.chef_environment} AND cloudstack_admin_api_key:* NOT name:#{node.name}")
39+
if Chef::Config[:solo]
40+
Chef::Log.warn('This recipe uses search. Chef Solo does not support search.')
41+
other_nodes = []
42+
else
43+
other_nodes = search(:node, "chef_environment:#{node.chef_environment} AND cloudstack_admin_api_key:* NOT name:#{node.name}")
44+
end
4045
if ! other_nodes.empty?
4146
@current_resource.admin_apikey(other_nodes.first["cloudstack"]["admin"]["api_key"])
4247
@current_resource.admin_secretkey(other_nodes.first["cloudstack"]["admin"]["secret_key"])

libraries/system_template.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@ def get_template_id
3434

3535
# Create or mount secondary storage path
3636
def secondary_storage
37-
unless ::File.exist?(@current_resource.nfs_path)
38-
directory @current_resource.nfs_path do
39-
owner "root"
40-
group "root"
41-
action :create
42-
recursive true
43-
end
37+
directory @current_resource.nfs_path do
38+
owner "root"
39+
group "root"
40+
action :create
41+
recursive true
42+
not_if { ::File.exist?(@current_resource.nfs_path)}
4443
end
4544
end
4645

@@ -55,4 +54,4 @@ def download_systemvm_template
5554
end
5655
end
5756
end
58-
end
57+
end

metadata.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
77
version '4.0.5'
88

9+
source_url 'https://github.com/cloudops/cookbook_cloudstack'
10+
issues_url 'https://github.com/cloudops/cookbook_cloudstack/issues'
11+
912
depends "yum", "> 3.0"
1013
depends "apt", "> 2.0"
1114
depends "mysql", "> 6.0.0"

providers/api_keys.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def whyrun_supported?
3333
true
3434
end
3535

36+
use_inline_resources
37+
3638
#########
3739
# ACTIONS
3840
#########

providers/global_setting.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
include Cloudstack::Helper
2525
include Cloudstack::GlobalSetting
2626

27+
use_inline_resources
28+
2729
#########
2830
# ACTIONS
2931
#########

providers/setup_database.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
include Cloudstack::Helper
2222
include Cloudstack::Database
2323

24+
use_inline_resources
25+
2426
action :create do
2527
#load_current_resource
2628
#Chef::Log.info "creating cloudstack database"

providers/setup_management.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
# execute default cloudstack configuration script
2020
###############################################################################
2121

22+
use_inline_resources
23+
2224
action :run do
2325

2426
bash "cloudstack-setup-management" do
2527
code "/usr/bin/cloudstack-setup-management"
2628
not_if { ::File.exists?("/etc/cloudstack/management/tomcat6.conf") || ::File.exists?("/etc/cloudstack/management/server.xml")}
2729
end
2830

29-
end
31+
end

providers/system_template.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
include Cloudstack::Helper
2323
include Cloudstack::SystemTemplate
2424

25+
use_inline_resources
26+
2527
action :create do
2628
load_current_resource
2729

@@ -53,7 +55,10 @@ def load_current_resource
5355
else
5456
if db_exist?(@current_resource.db_host, @current_resource.db_user, @current_resource.db_password)
5557
if @current_resource.url.nil?
56-
@current_resource.url(`mysql -h #{@current_resource.db_host} --user=#{@current_resource.db_user} --password=#{@current_resource.db_password} --skip-column-names -U cloud -e 'select max(url) from cloud.vm_template where type = \"SYSTEM\" and hypervisor_type = \"#{@current_resource.hypervisor}\" and removed is null'`.chomp)
58+
cmd = Mixlib::ShellOut.new("mysql -h #{@current_resource.db_host} --user=#{@current_resource.db_user} --password=#{@current_resource.db_password} --skip-column-names -U cloud -e 'select max(url) from cloud.vm_template where type = \"SYSTEM\" and hypervisor_type = \"#{@current_resource.hypervisor}\" and removed is null'")
59+
cmd.run_command
60+
cmd.error!
61+
@current_resource.url(cmd.stdout.chomp)
5762
end
5863
template_id = get_template_id
5964
Chef::Log.debug "looking for template in #{@current_resource.nfs_path}/template/tmpl/1/#{template_id}"

recipes/management_server.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@
2929
end
3030
end
3131

32-
if platform?(%w{ubuntu debian})
33-
# tomcat6 package installation automatically start tomcat6 on port 8080.
34-
service 'tomcat6' do
35-
action [:stop, :disable]
36-
end
32+
# tomcat6 package installation automatically start tomcat6 on port 8080.
33+
service 'tomcat6' do
34+
action [:stop, :disable]
35+
only_if { platform?(%w{ubuntu debian}) }
3736
end
3837

3938

0 commit comments

Comments
 (0)