From eeda01a7be07c78dac7b6ae5013524d857ceba3b Mon Sep 17 00:00:00 2001 From: Mustapha Lansana Date: Tue, 27 May 2014 22:02:56 -0400 Subject: deploychef: configure chef-solo for deploychef package The deploychef package uses chef-solo to reconfigure an openstack installation by converting services' configuration files to template files. The attributes file defines the constants chef-solo uses to generate configuration files/scripts. The recipe file describes how those files/scripts should be created. The config and .json files are input to chef-solo and describe location of files. Later in this series, the attributes file will be replaced by a dynamically generated attributes file. In addition, the recipe file will change to accommodate changes to deploychef in order to support openstackchef. Signed-off-by: Mustapha Lansana --- .../deploychef/files/attributes.json | 3 + .../deploychef/files/chefsolo_default_attribute.rb | 76 ++++++ .../deploychef/files/chefsolo_default_recipe.rb | 264 +++++++++++++++++++++ .../recipes-support/deploychef/files/config.rb | 29 +++ 4 files changed, 372 insertions(+) create mode 100644 meta-openstack/recipes-support/deploychef/files/attributes.json create mode 100644 meta-openstack/recipes-support/deploychef/files/chefsolo_default_attribute.rb create mode 100644 meta-openstack/recipes-support/deploychef/files/chefsolo_default_recipe.rb create mode 100644 meta-openstack/recipes-support/deploychef/files/config.rb diff --git a/meta-openstack/recipes-support/deploychef/files/attributes.json b/meta-openstack/recipes-support/deploychef/files/attributes.json new file mode 100644 index 0000000..ac077fb --- /dev/null +++ b/meta-openstack/recipes-support/deploychef/files/attributes.json @@ -0,0 +1,3 @@ +{ + "run_list": [ "recipe[openstack::default]" ] +} diff --git a/meta-openstack/recipes-support/deploychef/files/chefsolo_default_attribute.rb b/meta-openstack/recipes-support/deploychef/files/chefsolo_default_attribute.rb new file mode 100644 index 0000000..caf5af2 --- /dev/null +++ b/meta-openstack/recipes-support/deploychef/files/chefsolo_default_attribute.rb @@ -0,0 +1,76 @@ +# +# Copyright (c) 2014 Wind River Systems, Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +# +#These are the default values that chef-solo uses +#to convert our template files into the respective +#configuration and script files we want it to bake. +#Note though that Some of which are overwritten in the recipe file(s) + +default["CHEFROOT_DIR"] ="%DEPLOYCHEF_ROOT_DIR%/" +default["TEMPLATE_DIR"] ="#{node[:CHEFROOT_DIR]}cookbooks/openstack/templates/default/*" +default["ETC_DIR"]= "%SYSCONFDIR%/" +default["POSTINSTS_DIR"] ="#{node[:ETC_DIR]}%POSTINSTS_DIR%/" +default["NOVA_CONF_DIR"]="#{node[:ETC_DIR]}nova/" +default["SWIFT_CONF_DIR"]="#{node[:ETC_DIR]}swift/" +default["CEILOMETER_CONF_DIR"]="#{node[:ETC_DIR]}ceilometer/" +default["NEUTRON_CONF_DIR"]= "#{node[:ETC_DIR]}neutron/" +default["NEUTRON_CORE_PLUGIN"]= "neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2" +default["OPENVSWITCH_CONF_DIR"]= "#{node[:NEUTRON_CONF_DIR]}plugins/openvswitch/" +default["LINUXBRIDGE_CONF_DIR"]= "#{node[:NEUTRON_CONF_DIR]}plugins/linuxbridge/" +default["KEYSTONE_CONF_DIR"]= "#{node[:ETC_DIR]}keystone/" +default["CINDER_CONF_DIR"]= "#{node[:ETC_DIR]}cinder/" +default["GLANCE_CONF_DIR"]= "#{node[:ETC_DIR]}glance/" +default["CEPH_CONF_DIR"]= "#{node[:ETC_DIR]}ceph/" +default["DB_DATADIR"]= "#{node[:ETC_DIR]}postgresql/" +default["HEAT_CONF_DIR"]= "#{node[:ETC_DIR]}heat/" + +default["INITD_DIR"]= "#{node[:ETC_DIR]}init.d/" +default["CONTROLLER_DAEMON"]= "#{node[:INITD_DIR]}nova-api" +default["COMPUTE_DAEMON"]= "#{node[:INITD_DIR]}nova-compute" +default["NODE_TYPE"]="compute" +default["NODE_TYPES"]="compute controller allinone" +default["POSTINSTS_SCRIPT"] = "run-postinsts" +default["PREINSTS_SCRIPT"] = "service-shutdown" +default["AUTH_PROTOCOL"] = "http" +default["PRIVATE_IP"] = "127.0.0.1" + +default["CONTROLLER_IP"] = "%CONTROLLER_IP%" +default["CONTROLLER_HOST"] = "%CONTROLLER_HOST%" +default["COMPUTE_IP"] = "%COMPUTE_IP%" +default["COMPUTE_HOST"] = "%COMPUTE_HOST%" +default["ADMIN_PASSWORD"] = "%ADMIN_PASSWORD%" +default["SERVICE_PASSWORD"] = "%SERVICE_PASSWORD%" +default["SERVICE_TENANT_NAME"] ="%SERVICE_TENANT_NAME%" +default["SERVICE_USER"] ="%SERVICE_USER%" +default["SERVICE_TOKEN"] ="%SERVICE_TOKEN%" +default["DEMO_USER"] ="%DEMO_USER%" +default["DEMO_PASSWORD"] ="%DEMO_PASSWORD%" +default["OS_TENANT_NAME"] ="%OS_TENANT_NAME%" +default["OS_USERNAME"] ="%OS_USERNAME%" +default["OS_PASSWORD"] ="%OS_PASSWORD%" +default["DB_USER"] ="%DB_USER%" +default["DB_PASSWORD"] ="%DB_PASSWORD%" +default["PUBLIC_IP"] ="#{node[:CONTROLLER_IP]}" +default["HOST_NAME"]="#{node[:CONTROLLER_HOSTS]}" +default["PUBLIC_DOMAIN"] ="#{node[:CONTROLLER_IP]}/24" + + diff --git a/meta-openstack/recipes-support/deploychef/files/chefsolo_default_recipe.rb b/meta-openstack/recipes-support/deploychef/files/chefsolo_default_recipe.rb new file mode 100644 index 0000000..3c83b23 --- /dev/null +++ b/meta-openstack/recipes-support/deploychef/files/chefsolo_default_recipe.rb @@ -0,0 +1,264 @@ +# default.rb +# +# Copyright (c) 2014 Wind River Systems, Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +# This is our main recipe that chef-solo bakes to configure our openstack deployment +domain = node['hostname'] +domain += " " + node['platform'] +domain += " " + node['platform_version'] +domain += " " + node['ipaddress'] +log domain do + level:info +end + +#This function enables us to over-ride the hostname and ipaddress +#attributes based on the type of node installation +#we are running on. +def update_node_info() + if File.executable?(node[:CONTROLLER_DAEMON]) and \ + File.executable?(node[:COMPUTE_DAEMON]) + #All in one installation + if node[:ipaddress].length + node.default["CONTROLLER_IP"]=node.default["COMPUTE_IP"]=node[:ipaddress] + end + if node[:hostname].length + node.default["CONTROLLER_HOST"]=node.default["COMPUTE_HOST"]=node[:hostname] + end + node.default["NODE_TYPE"] ="allinone" + elsif File.executable?(node[:CONTROLLER_DAEMON]) + if node[:ipaddress].length + node.default["CONTROLLER_IP"]=node[:ipaddress] + end + if node[:hostname].length + node.default["CONTROLLER_HOST"]=node[:hostname] + end + node.default["NODE_TYPE"] ="controller" + else + if node[:ipaddress].length + node.default["COMPUTE_IP"]=node[:ipaddress] + end + if node[:hostname].length + node.default["COMPUTE_HOST"]=node[:hostname] + end + node.default["NODE_TYPE"] ="compute" + end + + node.default["PUBLIC_IP"]="#{node[:CONTROLLER_IP]}" + node.default["HOST_NAME"]="#{node[:CONTROLLER_HOST]}" + node.default["PUBLIC_DOMAIN"]="#{node[:CONTROLLER_IP]}/24" +end +#This fucntion loops through all the files in the templates +#directory and create configuration or scripts files from the +#templates using the sets of defined attributes +def create_files_from_templates() + #Make it easier to move from development environment to target + output_dir = node[:POSTINSTS_DIR] + template_dir = node[:TEMPLATE_DIR] + #See if output directory exist if not create one + if not File.directory?(output_dir) + execute "Create #{output_dir} directory" do + command "mkdir -p #{output_dir}" + end + end + #Get the list of all template files + files = Dir.glob(template_dir) + #To ensure that the files are executed in increasing order + files = files.sort + for file in files do + #Exclude references to current and parent directory in search + next if File.directory?(file) or file == '.' or file == '..' + script_file = output_dir + File.basename(file) + script_file.gsub!(".erb","") + if File.file?(script_file) + execute "Delete file #{script_file} if present" do + command "rm -rf #{script_file}" + end + end + template script_file do + source File.basename(file) + mode 0755 + owner node[:user] + group node[:user] + end + end +end +#This function moves the generated configuration files for +#the respective modules to the specified module configuration directory +#Overwriting the current configuration file in the process +def replace_config_files(files, configDir, makeNoneExec=true) + #!files.strip + #!configDir.strip + if files and configDir + if not File.directory?(configDir) + execute "Create #{configDir}" do + command "mkdir -p #{configDir}" + end + end + if files.strip.include?(" ") + file_names = files.split + file_names.each do | fileName | + fileName=fileName.strip + if File.file?("#{node[:POSTINSTS_DIR]}#{fileName}") + execute "Move #{fileName} to #{configDir} " do + command "mv #{node[:POSTINSTS_DIR]}#{fileName} #{configDir}#{fileName}" + end + if makeNoneExec + execute "Remove execution mode on #{fileName}" do + command "chmod 0644 #{configDir}#{fileName}" + end + end + end + end + else + #There is only one file in the list + files=files.strip + if File.file?("#{node[:POSTINSTS_DIR]}#{files}") + execute "Move #{files} to #{configDir} " do + command "mv #{node[:POSTINSTS_DIR]}#{files} #{configDir}#{files}" + end + if makeNoneExec + execute "Remove execution mode on #{files}" do + command "chmod 0644 #{configDir}#{files}" + end + end + end + end + end +end + +#Update hostname and ipaddress to be written to configuration files +update_node_info + +#Generate scripts and cofiguration files +create_files_from_templates + +#Move the configuration files to /etc/nova directory +#and make remove execution modifier from the files +novaConfigFiles="nova.conf openrc api-paste.ini deploy.conf" +replace_config_files(novaConfigFiles,"#{node[:NOVA_CONF_DIR]}") +#Move the configuration files to /etc/swift directory +#and remove execution modifier from the files +swiftConfigFiles="test.conf dispersion.conf proxy-server.conf" +if node[:NODE_TYPE] == "compute" + files = swiftConfigFiles.split + files.each do | fileName | + fileName=fileName.strip + fileName ="#{node[:POSTINSTS_DIR]}#{fileName}" + if File.file?(fileName) + execute "Remove file #{fileName}" do + command "rm #{node[:POSTINSTS_DIR]}#{fileName}" + end + end + end +else + replace_config_files(swiftConfigFiles,"#{node[:SWIFT_CONF_DIR]}") +end +#Move the configuration files to /etc/neutron directory +#and remove execution modifier from the files +configFiles="neutron.conf" +replace_config_files(configFiles,"#{node[:NEUTRON_CONF_DIR]}") +configFiles="linuxbridge_conf.ini" +replace_config_files(configFiles,"#{node[:LINUXBRIDGE_CONF_DIR]}") +configFiles="ovs_neutron_plugin.ini" +replace_config_files(configFiles,"#{node[:OPENVSWITCH_CONF_DIR]}") + +configFiles="ceilometer.conf" +replace_config_files(configFiles,"#{node[:CEILOMETER_CONF_DIR]}") + +configFiles="glance-api.conf glance-cache.conf glance-registry.conf" +if node[:NODE_TYPE] == "compute" + files = configFiles.split + files.each do | fileName | + if File.file?("#{node[:POSTINSTS_DIR]}#{fileName}") + execute "Remove file #{fileName}" do + command "rm #{node[:POSTINSTS_DIR]}#{fileName}" + end + end + end +else + replace_config_files(configFiles,"#{node[:GLANCE_CONF_DIR]}") +end + +#Move the postgresql init script and make them executable +configFiles="postgresql-init" +replace_config_files(configFiles, "#{node[:INITD_DIR]}", false) + +configFiles="ceph.conf" +replace_config_files(configFiles, "#{node[:CEPH_CONF_DIR]}") + +configFiles="ceph-setup" +if node[:NODE_TYPE] == "compute" + if File.file?("#{node[:POSTINSTS_DIR]}#{configFiles}") + execute "Remove file #{configFiles}" do + command "rm #{node[:POSTINSTS_DIR]}#{configFiles}" + end + end +else + replace_config_files(configFiles, "#{node[:INITD_DIR]}", false) +end + +configFiles="keystone.conf identity.sh" +if node[:NODE_TYPE] == "compute" + files = configFiles.split + files.each do | fileName | + if File.file?("#{node[:POSTINSTS_DIR]}#{fileName}") + execute "Remove file #{fileName}" do + command "rm #{node[:POSTINSTS_DIR]}#{fileName}" + end + end + end +else + replace_config_files(configFiles, "#{node[:KEYSTONE_CONF_DIR]}") + #Openrc in keystone conf dir is same as that found in nova + execute "Copy openrc to #{node[:KEYSTONE_CONF_DIR]}" do + command "cp #{node[:NOVA_CONF_DIR]}openrc #{node[:KEYSTONE_CONF_DIR]}" + end +end +#cinder configurations +configFiles="api-paste.ini.cinder cinder.conf" +replace_config_files(configFiles, "#{node[:CINDER_CONF_DIR]}") + +fileName="#{node[:CINDER_CONF_DIR]}api-paste.ini.cinder" +if File.file?(fileName) + execute "Rename api-paste.ini.cinder to api-paste.ini" do + command "mv #{node[:CINDER_CONF_DIR]}api-paste.ini.cinder #{node[:CINDER_CONF_DIR]}api-paste.ini" + end +end +#heat configuration +configFiles="heat.conf" +if node[:NODE_TYPE] == "compute" + if File.file?("#{node[:POSTINSTS_DIR]}#{configFiles}") + execute "Remove file #{configFiles}" do + command "rm #{node[:POSTINSTS_DIR]}#{configFiles}" + end + end +else + replace_config_files(configFiles, "#{node[:HEAT_CONF_DIR]}") +end +#Move the hosts file in place +configFiles="hosts" +replace_config_files(configFiles,"#{node[:ETC_DIR]}") + +=begin +service host[:hostname] do + action :restart +endf +=end diff --git a/meta-openstack/recipes-support/deploychef/files/config.rb b/meta-openstack/recipes-support/deploychef/files/config.rb new file mode 100644 index 0000000..bce20f8 --- /dev/null +++ b/meta-openstack/recipes-support/deploychef/files/config.rb @@ -0,0 +1,29 @@ +# config.rb +## Copyright (c) 2014 Wind River Systems, Inc. +## +## Permission is hereby granted, free of charge, to any person obtaining a copy +## of this software and associated documentation files (the "Software"), to deal +## in the Software without restriction, including without limitation the rights +## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +## copies of the Software, and to permit persons to whom the Software is +## furnished to do so, subject to the following conditions: +## +## The above copyright notice and this permission notice shall be included in +## all copies or substantial portions of the Software. +# +## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +## THE SOFTWARE. +## +# +# This configuration file points chef-solo to the location +# our our cookbooks and recipes within those cookbooks +log_level :info +ssl_verify_mode :verify_peer +base_dir Dir.pwd + "/" +file_cache_path base_dir + "cache/" +cookbook_path base_dir + "cookbooks/" -- cgit v1.2.3-54-g00ecf