Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
AllCops:
Exclude:
- 'Vagrantfile'
2 changes: 1 addition & 1 deletion Berksfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source "https://supermarket.chef.io"
source 'https://supermarket.chef.io'

metadata
4 changes: 2 additions & 2 deletions Thorfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ require 'bundler/setup'
require 'berkshelf/thor'

begin
require "kitchen/thor_tasks"
require 'kitchen/thor_tasks'
Kitchen::ThorTasks.new
rescue LoadError
puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV["CI"]
puts '>>>>> Kitchen gem not loaded, omitting tasks' unless ENV['CI']
end
9 changes: 4 additions & 5 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
#
# $ vagrant plugin install vagrant-omnibus
#
if Vagrant.has_plugin?("vagrant-omnibus")
if Vagrant.has_plugin?('vagrant-omnibus')
config.omnibus.chef_version = 'latest'
end

Expand All @@ -27,7 +27,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# config.vm.box_url doesn't need to be specified.
config.vm.box = 'chef/ubuntu-14.04'


# Assign this VM to a host-only network IP, allowing you to access it
# via the IP. Host-only networks can talk to the host machine as well as
# any other machines on the same network, but cannot be accessed (through this
Expand Down Expand Up @@ -79,12 +78,12 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
mysql: {
server_root_password: 'rootpass',
server_debian_password: 'debpass',
server_repl_password: 'replpass'
}
server_repl_password: 'replpass',
},
}

chef.run_list = [
'recipe[cloudstack::default]'
'recipe[cloudstack::default]',
]
end
end
2 changes: 1 addition & 1 deletion libraries/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def init_config_database
def dbconf_exist?
# test if db.properties as been modified from default installation file. if password encrypted, then we step there to not break anything.
Chef::Log.debug 'Checking to see if database config db.properties as been configured'
conf_exist = Mixlib::ShellOut.new("cat /etc/cloudstack/management/db.properties |grep \"ENC(\"")
conf_exist = Mixlib::ShellOut.new('cat /etc/cloudstack/management/db.properties |grep "ENC("')
conf_exist.run_command
if conf_exist.exitstatus == 0
return true
Expand Down
16 changes: 7 additions & 9 deletions libraries/global_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,25 @@

module Cloudstack
module GlobalSetting

# Support whyrun
def whyrun_supported?
false
end

def load_current_value(name)
require 'cloudstack_ruby_client'
# get CloudStack current value of the Global Setting
client = CloudstackRubyClient::Client.new('http://localhost:8080/client/api/', @current_resource.admin_apikey, @current_resource.admin_secretkey, false)
client.list_configurations(:name => name)['configuration'].first['value']
client.list_configurations(name: name)['configuration'].first['value']
end

def update_setting(name, value)
require 'cloudstack_ruby_client'
client = CloudstackRubyClient::Client.new('http://localhost:8080/client/api/', @current_resource.admin_apikey, @current_resource.admin_secretkey, false)
client.update_configuration({
:name => name,
:value => value
})
client.update_configuration(
name: name,
value: value
)
end

end
end
4 changes: 2 additions & 2 deletions libraries/system_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_template_id
template_id = Mixlib::ShellOut.new(template_cmd)
template_id.run_command
Chef::Log.debug "template id = #{template_id.stdout.chomp}"
return template_id.stdout.chomp
template_id.stdout.chomp
end

# Create or mount secondary storage path
Expand All @@ -46,7 +46,7 @@ def secondary_storage

def download_systemvm_template
# Create database configuration for cloudstack management server that will use and existing database.
#puts "Downloading system template from: #{@current_resource.url}"
# puts "Downloading system template from: #{@current_resource.url}"
Chef::Log.info "Downloading system template for #{@current_resource.hypervisor}, this will take some time..."
download_cmd = "/usr/share/cloudstack-common/scripts/storage/secondary/cloud-install-sys-tmplt -m #{@current_resource.nfs_path} -u #{@current_resource.url} -h #{@current_resource.hypervisor} -F"
download_template = Mixlib::ShellOut.new(download_cmd)
Expand Down
6 changes: 3 additions & 3 deletions providers/api_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ def whyrun_supported?

action :create do
wait_count = 0
until cloudstack_api_is_running? or wait_count == 5 do
until cloudstack_api_is_running? || wait_count == 5 do
cloudstack_api_is_running?
sleep(5)
wait_count +=1
wait_count += 1
if wait_count == 1
Chef::Log.info 'Waiting CloudStack to start'
end
Expand All @@ -54,7 +54,7 @@ def whyrun_supported?

action :reset do
# force generate new API keys
#load_current_resource
# load_current_resource
if cloudstack_is_running?
if @current_resource.username == 'admin'
converge_by('Reseting admin api keys') do
Expand Down
12 changes: 5 additions & 7 deletions providers/global_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
unless @current_resource.admin_apikey.nil?
unless @current_resource.exists
converge_by("Update Global Setting: #{@current_resource.name} to #{@current_resource.value}") do
#test_connection?(@current_resource.admin_apikey, @current_resource.admin_secretkey)
# test_connection?(@current_resource.admin_apikey, @current_resource.admin_secretkey)
update_setting(@current_resource.name, @current_resource.value)
end
end
Expand All @@ -44,7 +44,7 @@ def load_current_resource
require 'cloudstack_ruby_client'
@current_resource = Chef::Resource::CloudstackGlobalSetting.new(@new_resource.name)
@current_resource.name(@new_resource.name)
if $admin_apikey.nil?
if $admin_apikey.nil?
@current_resource.admin_apikey(@new_resource.admin_apikey)
@current_resource.admin_secretkey(@new_resource.admin_secretkey)
else # if it's the first run on the server $admin_apikey will not be empty
Expand All @@ -61,12 +61,10 @@ def load_current_resource
current_value = load_current_value(@current_resource.name)
if current_value.nil?
Chef::Log.error "Global Setting: #{@current_resource.name} not found"
elsif @current_resource.value == current_value
@current_resource.exists = true
else
if @current_resource.value == current_value
@current_resource.exists = true
else
@current_resource.exists = false
end
@current_resource.exists = false
end
end
else
Expand Down
16 changes: 7 additions & 9 deletions providers/setup_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# limitations under the License.
#

#include Chef::Mixin::ShellOut
# include Chef::Mixin::ShellOut
include Cloudstack::Helper
include Cloudstack::Database

Expand Down Expand Up @@ -59,16 +59,14 @@ def load_current_resource

if cloudstack_is_running?
@current_resource.exists = true
else
if dbconf_exist?
if db_exist?(@current_resource.ip, @current_resource.user, @current_resource.password)
@current_resource.exists = true
else
Chef::Log.info 'Database server ready, not database found, creating it...'
@current_resource.exists = false
end
elsif dbconf_exist?
if db_exist?(@current_resource.ip, @current_resource.user, @current_resource.password)
@current_resource.exists = true
else
Chef::Log.info 'Database server ready, not database found, creating it...'
@current_resource.exists = false
end
else
@current_resource.exists = false
end
end
34 changes: 16 additions & 18 deletions providers/system_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# Chef::Log.info 'creating cloudstack database'
unless @current_resource.exists
converge_by("Downloading system template from: #{@current_resource.url}") do
#test_connection?(@current_resource.admin_apikey, @current_resource.admin_secretkey)
# test_connection?(@current_resource.admin_apikey, @current_resource.admin_secretkey)
secondary_storage
download_systemvm_template
end
Expand All @@ -51,24 +51,22 @@ def load_current_resource
# if CloudStack management-server is running, it mean a systemvm template as been downloaded.
if cloudstack_is_running?
@current_resource.exists = true
else
if db_exist?(@current_resource.db_host, @current_resource.db_user, @current_resource.db_password)
if @current_resource.url.nil?
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'")
cmd.run_command
cmd.error!
@current_resource.url(cmd.stdout.chomp)
end
template_id = get_template_id
Chef::Log.debug "looking for template in #{@current_resource.nfs_path}/template/tmpl/1/#{template_id}"
if ::File.exist?("#{@current_resource.nfs_path}/template/tmpl/1/#{template_id}/template.properties")
Chef::Log.debug "template exists in #{@current_resource.nfs_path}/template/tmpl/1/#{template_id}"
@current_resource.exists = true
else
@current_resource.exists = false
end
elsif db_exist?(@current_resource.db_host, @current_resource.db_user, @current_resource.db_password)
if @current_resource.url.nil?
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'")
cmd.run_command
cmd.error!
@current_resource.url(cmd.stdout.chomp)
end
template_id = get_template_id
Chef::Log.debug "looking for template in #{@current_resource.nfs_path}/template/tmpl/1/#{template_id}"
if ::File.exist?("#{@current_resource.nfs_path}/template/tmpl/1/#{template_id}/template.properties")
Chef::Log.debug "template exists in #{@current_resource.nfs_path}/template/tmpl/1/#{template_id}"
@current_resource.exists = true
else
Chef::Log.error 'Database not configured. Cannot retrieve Template URL'
@current_resource.exists = false
end
else
Chef::Log.error 'Database not configured. Cannot retrieve Template URL'
end
end
12 changes: 6 additions & 6 deletions resources/api_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

default_action :create

attribute :username , :name_attribute => true, :kind_of => String
attribute :url , :kind_of => String, :default => 'http://localhost:8080/client/api'
attribute :password , :kind_of => String, :default => 'password'
attribute :admin_apikey , :kind_of => String
attribute :admin_secretkey, :kind_of => String
attribute :ssl , :equal_to => [true, false, 'true', 'false'], :default => false
attribute :username, name_attribute: true, kind_of: String
attribute :url, kind_of: String, default: 'http://localhost:8080/client/api'
attribute :password, kind_of: String, default: 'password'
attribute :admin_apikey, kind_of: String
attribute :admin_secretkey, kind_of: String
attribute :ssl, equal_to: [true, false, 'true', 'false'], default: false

attr_accessor :exists
8 changes: 4 additions & 4 deletions resources/global_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

default_action :update

attribute :name , :name_attribute => true, :kind_of => String
attribute :value , :kind_of => String
attribute :admin_apikey , :kind_of => String
attribute :admin_secretkey , :kind_of => String
attribute :name, name_attribute: true, kind_of: String
attribute :value, kind_of: String
attribute :admin_apikey, kind_of: String
attribute :admin_secretkey, kind_of: String

attr_accessor :exists
14 changes: 7 additions & 7 deletions resources/setup_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

default_action :create

attribute :ip , :name_attribute => true, :kind_of => String
attribute :user , :kind_of => String, :default => 'cloud'
attribute :password , :kind_of => String, :default => 'password'
attribute :root_user , :kind_of => String, :default => 'root'
attribute :root_password , :kind_of => String, :default => 'ilikerandompasswords'
attribute :management_server_key, :kind_of => String, :default => 'password'
attribute :database_key , :kind_of => String, :default => 'password'
attribute :ip, name_attribute: true, kind_of: String
attribute :user, kind_of: String, default: 'cloud'
attribute :password, kind_of: String, default: 'password'
attribute :root_user, kind_of: String, default: 'root'
attribute :root_password, kind_of: String, default: 'ilikerandompasswords'
attribute :management_server_key, kind_of: String, default: 'password'
attribute :database_key, kind_of: String, default: 'password'

attr_accessor :exists
2 changes: 1 addition & 1 deletion resources/setup_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@

bash 'cloudstack-setup-management' do
code "/usr/bin/cloudstack-setup-management #{params}"
not_if { ::File.exists?('/etc/cloudstack/management/tomcat6.conf') || ::File.exists?('/etc/cloudstack/management/server.xml')}
not_if { ::File.exist?('/etc/cloudstack/management/tomcat6.conf') || ::File.exist?('/etc/cloudstack/management/server.xml') }
end
end
14 changes: 7 additions & 7 deletions resources/system_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

default_action :create

attribute :hypervisor , :name_attribute => true, :kind_of => String
attribute :nfs_path , :kind_of => String, :default => '/mnt/secondary'
attribute :nfs_server , :kind_of => String, :default => 'localhost'
attribute :hypervisor, name_attribute: true, kind_of: String
attribute :nfs_path, kind_of: String, default: '/mnt/secondary'
attribute :nfs_server, kind_of: String, default: 'localhost'

# If URL net specify, can retreive template URL from database.
attribute :url , :kind_of => String
attribute :db_user , :kind_of => String, :default => 'cloud' # node['cloudstack']['db']['user']
attribute :db_password , :kind_of => String, :default => 'password' # node['cloudstack']['db']['password']
attribute :db_host , :kind_of => String, :default => 'localhost' # node['cloudstack']['db']['host']
attribute :url, kind_of: String
attribute :db_user, kind_of: String, default: 'cloud' # node['cloudstack']['db']['user']
attribute :db_password, kind_of: String, default: 'password' # node['cloudstack']['db']['password']
attribute :db_host, kind_of: String, default: 'localhost' # node['cloudstack']['db']['host']

attr_accessor :exists
3 changes: 1 addition & 2 deletions spec/recipes/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
it 'does something' do
expect(chef_run).to do_something('...')
end

end

describe 'cloudstack::cloudstack_management' do
Expand All @@ -26,4 +25,4 @@
it 'installs cloudstack-management' do
expect(chef_run).to install_package('cloudstack-management')
end
end
end
2 changes: 0 additions & 2 deletions test/integration/default/serverspec/management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
it { should be_installed }
end


describe user('cloud') do
it { should exist }
end

2 changes: 1 addition & 1 deletion test/integration/default/serverspec/usage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

describe package('cloudstack-usage') do
it { should be_installed }
end
end