Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

prep work before moving to other repo

  • Loading branch information...
commit 9627bc678f2d7e40dd10cd98b2a05e595d9a8e64 1 parent f286eeb
CloudEdge Solutions authored
View
206 change-image/dell/openstack_manager/lib/barclamp_install.rb
@@ -0,0 +1,206 @@
+# Copyright 2011, Dell
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Author: RobHirschfeld
+#
+
+namespace :barclamp do
+
+ MODEL_SOURCE = File.join 'lib', 'barclamp_model'
+ MODEL_SUBSTRING_BASE = '==BC-MODEL=='
+ MODEL_SUBSTRING_CAMEL = '==^BC-MODEL=='
+ MODEL_TARGET = File.join '..', 'barclamps'
+ BASE_PATH = File.join '/opt', 'dell'
+ BARCLAMP_PATH = File.join BASE_PATH, 'chef'
+ CROWBAR_PATH = File.join BASE_PATH, 'openstack_manager'
+ BIN_PATH = File.join BASE_PATH, 'bin'
+
+ def bc_cloner(item, bc, entity, source, target, replace)
+ files = []
+ puts "cloner #{item}, #{bc}, #{entity}, #{source}, #{target}, #{replace}."
+ new_item = (replace ? bc_replacer(item, bc, entity) : item)
+ new_file = File.join target, new_item
+ new_source = File.join(source, item)
+ if File.directory? new_source
+ puts "\tcreating directory #{new_file}."
+ FileUtils.mkdir new_file
+ clone = Dir.entries(new_source).find_all { |e| !e.start_with? '.'}
+ clone.each do |recurse|
+ files += bc_cloner(recurse, bc, entity, new_source, new_file, replace)
+ end
+ else
+ #need to inject into the file
+ unless replace
+ puts "\t\tcopying file #{new_file}."
+ FileUtils.cp new_source, new_file
+ else
+ puts "\t\tcreating file #{new_file}."
+ t = File.open(new_file, 'w')
+ File.open(new_source, 'r') do |f|
+ s = f.read
+ t.write(bc_replacer(s, bc, entity))
+ end
+ t.close
+ files << new_file
+ end
+ end
+ return files
+ end
+
+ def bc_replacer(item, bc, entity)
+ item = item.gsub(MODEL_SUBSTRING_BASE, bc)
+ item = item.gsub(MODEL_SUBSTRING_CAMEL, bc.capitalize)
+ item = item.gsub('Copyright 2011, Dell', "Copyright #{Time.now.year}, #{entity}")
+ return item
+ end
+
+ # this is used by the install-chef installer script becaues rake is not ready yet
+ def shell_install(path, parts)
+ version = File.join path, 'crowbar.yml'
+ barclamp = YAML.load_file(version)
+ bc_install_layout_0 bc, path, barclamp, parts
+ end
+
+ #merges localizations from config into the matching translation files
+ def merge_i18n(barclamp)
+ locales = barclamp['locale_additions']
+ locales.each do |key, value|
+ #translation file (can be multiple)
+ f = File.join CROWBAR_PATH, 'config', 'locales', "#{key}.yml"
+ if File.exist? f
+ puts "merging tranlation for #{f}"
+ master = YAML.load_file f
+ master = merge_tree(key, value, master)
+ File.open( f, 'w' ) do |out|
+ YAML.dump( master, out )
+ end
+ else
+ puts "WARNING: Did not attempt tranlation merge for #{f} because file was not found."
+ end
+ end
+ end
+
+ def merge_nav(barclamp, installing)
+ unless barclamp['nav'].nil?
+ # get raw file
+ nav_file = File.join 'config', 'navigation.rb' #assume that we're in the app dir
+ nav = []
+ File.open(nav_file, 'r') do |f|
+ nav << f.eachline { |line| nav.push line }
+ end
+ add = barclamp['nav']['add']
+ # we only write the updated file if we are adding to it
+ unless add.nil?
+ File.open( nav_file, 'w') do |out|
+ nav.each do |line|
+ # remove the old menu item (works for install or uninstall)
+ out.puts line unless line.lstrip.starts_with? "secondary.item :#{key}"
+ # if you are installing, add the item under the barclamp menu.
+ if installing and line.lstrip.starts_with? "primary.item :barclamps"
+ add.each do |key, value|
+ out.puts "secondary.item :#{key}, t('nav.#{key}'), #{value}" unless value.nil?
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+
+ def merge_tree(key, value, target)
+ if target.key? key
+ if target[key].class == Hash
+ value.each do |k, v|
+ #puts "recursing into tree at #{key} for #{k}"
+ target[key] = merge_tree(k, v, target[key])
+ end
+ else
+ #puts "replaced key #{key} value #{value}"
+ target[key] = value
+ end
+ else
+ #puts "added key #{key} value #{value}"
+ target[key] = value
+ end
+ return target
+ end
+
+ def bc_remove_layout_1(bc, path, barclamp)
+ filelist = File.join path, 'filelist.yml'
+ end
+
+ def bc_install_layout_1_app(bc, path, barclamp)
+
+ #TODO - add a roll back so there are NOT partial results if a step fails
+ files = []
+
+ puts "Installing barclamp #{bc} from #{path}"
+
+ #merge i18n information (least invasive operations first)
+ merge_i18n barclamp
+ merge_nav barclamp
+
+ #copy the rails parts (required for render BEFORE import into chef)
+ dirs = Dir.entries(path)
+ files += bc_cloner('app', bc, nil, path, CROWBAR_PATH, false) if dirs.include? 'app'
+ files += bc_cloner('public', bc, nil, path, CROWBAR_PATH, false) if dirs.include? 'public'
+ files += bc_cloner('command_line', bc, nil, path, BIN_PATH, false) if dirs.include? 'command_line'
+ puts "\tcopied app & command line files"
+
+ # copy all the files to the target
+ files += bc_cloner('chef', bc, nil, path, BASE_PATH, false)
+ puts "\tcopied over chef parts from #{path} to #{BARCLAMP_PATH}"
+
+ filelist = File.join path, 'filelist.yml'
+ File.open( filelist, 'w' ) do |out|
+ YAML.dump( {"files" => files }, out )
+ end
+
+ if File.directory?(File.join('/etc', 'redhat-release'))
+ system "service httpd reload"
+ else
+ system "service apache2 reload"
+ end
+ puts "\trestarted the web server"
+
+ puts "Barclamp #{bc} (format v1) added to Crowbar Framework. Review #{filelist} for files created."
+
+ def bc_install_layout_1_chef(bc, path, barclamp)
+
+ #upload the cookbooks
+ FileUtils.cd File.join BARCLAMP_PATH, 'cookbooks'
+ knife_cookbook = "knife cookbook upload -o . #{bc}"
+ system knife_cookbook
+ puts "\texecuted: #{knife_cookbook}"
+
+ #upload the databags
+ FileUtils.cd File.join BARCLAMP_PATH, 'data_bags', 'crowbar'
+ knife_databag = "knife data bag from file crowbar bc-template-#{bc}.json"
+ system knife_databag
+ puts "\texecuted: #{knife_databag}"
+
+ #upload the roles
+ roles = Dir.entries(File.join(path, 'chef', 'roles')).find_all { |r| r.end_with?(".rb") }
+ FileUtils.cd File.join BARCLAMP_PATH, 'roles'
+ roles.each do |role|
+ knife_role = "knife role from file #{role}"
+ system knife_role
+ puts "\texecuted: #{knife_role}"
+ end
+
+ puts "Barclamp #{bc} (format v1) Chef Components Uploaded."
+
+ end
+
+end
View
26 change-image/dell/openstack_manager/lib/barclamp_model/README.txt
@@ -0,0 +1,26 @@
+Welcome to a Barclamp for the Crowbar Framework project
+=======================================================
+_Copyright 2011, Dell_
+
+The code and documentation is distributed under the Apache 2 license (http://www.apache.org/licenses/LICENSE-2.0.html). Contributions back to the source are encouraged.
+
+The Crowbar Framework (https://github.com/dellcloudedge/crowbar) was developed by the Dell CloudEdge Solutions Team (http://dell.com/openstack) as a OpenStack installer (http://OpenStack.org) but has evolved as a much broader function tool.
+A Barclamp is a module component that implements functionality for Crowbar. Core barclamps operate the essential functions of the Crowbar deployment mechanics while other barclamps extend the system for specific applications.
+
+* This functonality of this barclamp DOES NOT stand alone, the Crowbar Framework is required *
+
+About this ==^BC-MODEL==
+-------------------------------------
+
+Information for this barclamp is maintained on the Crowbar Framework Wiki: https://github.com/dellcloudedge/crowbar/wiki
+
+
+
+
+Legals
+-------------------------------------
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
View
2  change-image/dell/openstack_manager/lib/barclamp_model/crowbar.yml
@@ -22,7 +22,7 @@ barclamp:
version: 0
crowbar:
- layout: 0
+ layout: 1
nav:
add:
View
181 change-image/dell/openstack_manager/lib/tasks/barclamp.rake
@@ -17,14 +17,7 @@
namespace :barclamp do
- MODEL_SOURCE = File.join 'lib', 'barclamp_model'
- MODEL_SUBSTRING_BASE = '==BC-MODEL=='
- MODEL_SUBSTRING_CAMEL = '==^BC-MODEL=='
- MODEL_TARGET = File.join '..', 'barclamps'
- BASE_PATH = File.join '/opt', 'dell'
- BARCLAMP_PATH = File.join BASE_PATH, 'chef'
- CROWBAR_PATH = File.join BASE_PATH, 'openstack_manager'
- BIN_PATH = File.join BASE_PATH, 'bin'
+ require File.join '..', 'barclamp_install'
desc "Create a new barclamp"
task :create, :name, :entity, :target, :needs=>[] do |t, args|
@@ -52,48 +45,10 @@ namespace :barclamp do
puts "Barclamp #{bc} created in #{target}. Review #{filelist} for files created."
end
- def bc_cloner(item, bc, entity, source, target, replace)
- files = []
- puts "cloner #{item}, #{bc}, #{entity}, #{source}, #{target}, #{replace}."
- new_item = (replace ? bc_replacer(item, bc, entity) : item)
- new_file = File.join target, new_item
- new_source = File.join(source, item)
- if File.directory? new_source
- puts "\tcreating directory #{new_file}."
- FileUtils.mkdir new_file
- clone = Dir.entries(new_source).find_all { |e| !e.start_with? '.'}
- clone.each do |recurse|
- files += bc_cloner(recurse, bc, entity, new_source, new_file, replace)
- end
- else
- #need to inject into the file
- unless replace
- puts "\t\tcopying file #{new_file}."
- FileUtils.cp new_source, new_file
- else
- puts "\t\tcreating file #{new_file}."
- t = File.open(new_file, 'w')
- File.open(new_source, 'r') do |f|
- s = f.read
- t.write(bc_replacer(s, bc, entity))
- end
- t.close
- files << new_file
- end
- end
- return files
- end
-
- def bc_replacer(item, bc, entity)
- item = item.gsub(MODEL_SUBSTRING_BASE, bc)
- item = item.gsub(MODEL_SUBSTRING_CAMEL, bc.capitalize)
- item = item.gsub('Copyright 2011, Dell', "Copyright #{Time.now.year}, #{entity}")
- return item
- end
-
desc "Install a barclamp into an active system"
- task :install, [:path] do |t, args|
- path = args.path || "."
+ task :install, [:bc, :path] do |t, args|
+ args.with_defaults(:path => '/opt/dell/barclamps')
+ path = File.join args.path, args.bc
version = File.join path, 'crowbar.yml'
unless File.exist? version
puts "ERROR: could not install barclamp - failed to find required #{version} file"
@@ -115,6 +70,7 @@ namespace :barclamp do
desc "Install a barclamp into an active system"
task :bootstrap, [:path] do |t, args|
+ args.with_defaults(:path => '/opt/dell/barclamps')
path = args.path
puts "Boostrapping starting in #{path}."
clone = Dir.entries(path).find_all { |e| !e.start_with? '.'}
@@ -132,7 +88,7 @@ namespace :barclamp do
desc "Install a barclamp into an active system"
task :install, [:path] do |t, args|
- path = args.path || "."
+ path = args.path || "/opt."
version = File.join path, 'crowbar.yml'
unless File.exist? version
puts "ERROR: could not install barclamp - failed to find required #{version} file"
@@ -141,8 +97,9 @@ namespace :barclamp do
bc = barclamp["barclamp"]["name"].chomp.strip
case barclamp["crowbar"]["layout"].to_i
- when 0
- bc_install_layout_0 bc, path, barclamp
+ when 1
+ bc_install_layout_1_app bc, path, barclamp
+ bc_install_layout_1_chef bc, path, barclamp
else
puts "ERROR: could not install barclamp #{bc} because #{barclamp["barclamp"]["crowbar_layout"]} is unknown layout."
end
@@ -152,124 +109,4 @@ namespace :barclamp do
end
end
- #merges localizations from config into the matching translation files
- def merge_i18n(barclamp)
- locales = barclamp['locale_additions']
- locales.each do |key, value|
- #translation file (can be multiple)
- f = File.join CROWBAR_PATH, 'config', 'locales', "#{key}.yml"
- if File.exist? f
- puts "merging tranlation for #{f}"
- master = YAML.load_file f
- master = merge_tree(key, value, master)
- File.open( f, 'w' ) do |out|
- YAML.dump( master, out )
- end
- else
- puts "WARNING: Did not attempt tranlation merge for #{f} because file was not found."
- end
- end
- end
-
- def merge_nav(barclamp)
- unless barclamp['nav'].nil?
- # get raw file
- nav_file = File.join 'config', 'navigation.rb' #assume that we're in the app dir
- nav = []
- File.open(nav_file, 'r') do |f|
- nav << f.eachline { |line| nav.push line }
- end
- add = barclamp['nav']['add']
- unless add.nil?
- File.open( nav_file, 'w') do |out|
- nav.each do |line|
- out.puts line
- if line.starts_with? "primary.item :barclamps"
- add.each do |key, value|
- out.puts "secondary.item :#{key}, t('nav.#{key}'), #{value}" unless value.nil?
- end
- end
- end
- end
- end
- end
- end
-
- def merge_tree(key, value, target)
- if target.key? key
- if target[key].class == Hash
- value.each do |k, v|
- #puts "recursing into tree at #{key} for #{k}"
- target[key] = merge_tree(k, v, target[key])
- end
- else
- #puts "replaced key #{key} value #{value}"
- target[key] = value
- end
- else
- #puts "added key #{key} value #{value}"
- target[key] = value
- end
- return target
- end
-
- def bc_install_layout_0(bc, path, barclamp)
-
- #TODO - add a roll back so there are NOT partial results if a step fails
- files = []
-
- puts "Installing barclamp #{bc} from #{path}"
-
- #merge i18n information (least invasive operations first)
- merge_i18n barclamp
-
- #copy the rails parts (required for render BEFORE import into chef)
- dirs = Dir.entries(path)
- files += bc_cloner('app', bc, nil, path, CROWBAR_PATH, false) if dirs.include? 'app'
- files += bc_cloner('public', bc, nil, path, CROWBAR_PATH, false) if dirs.include? 'public'
- files += bc_cloner('command_line', bc, nil, path, BIN_PATH, false) if dirs.include? 'command_line'
- puts "\tcopied app & command line files"
-
- # copy all the files to the target
- files += bc_cloner('chef', bc, nil, path, BASE_PATH, false)
- puts "\tcopied over chef parts from #{path} to #{BARCLAMP_PATH}"
-
- #upload the cookbooks
- FileUtils.cd File.join BARCLAMP_PATH, 'cookbooks'
- knife_cookbook = "knife cookbook upload -o . #{bc}"
- system knife_cookbook
- puts "\texecuted: #{knife_cookbook}"
-
- #upload the databags
- FileUtils.cd File.join BARCLAMP_PATH, 'data_bags', 'crowbar'
- knife_databag = "knife data bag from file crowbar bc-template-#{bc}.json"
- system knife_databag
- puts "\texecuted: #{knife_databag}"
-
- #upload the roles
- roles = Dir.entries(File.join(path, 'chef', 'roles')).find_all { |r| r.end_with?(".rb") }
- FileUtils.cd File.join BARCLAMP_PATH, 'roles'
- roles.each do |role|
- knife_role = "knife role from file #{role}"
- system knife_role
- puts "\texecuted: #{knife_role}"
- end
-
- if File.directory?(File.join('/etc', 'redhat-release'))
- system "service httpd reload"
- else
- system "service apache2 reload"
- end
- puts "\trestarted the web server"
-
- filelist = File.join path, 'filelist.yml'
- File.open( filelist, 'w' ) do |out|
- YAML.dump( {"files" => files }, out )
- end
-
- merge_nav barclamp
-
- puts "Barclamp #{bc} (format v1) installed. Review #{filelist} for files created."
-
- end
end
View
58 change-image/dell/openstack_manager/lib/validate_bags.rb
@@ -0,0 +1,58 @@
+#!/usr/bin/ruby
+# Copyright 2011, Dell
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#
+
+require File.join(File.dirname(__FILE__), 'validate_data_bag' )
+
+def verify_bags(base_dir)
+ err = false
+ Dir.chdir(base_dir) { |d|
+ Dir["*/*.json"].each { |bag|
+ schema = find_schema_for_file(bag)
+ puts "validating #{bag} against #{schema}"
+ begin
+ rc = validate(schema,bag)
+ rescue Exception => e
+ rc = -1
+ end
+ err = true if rc != 0
+ }
+ }
+ err
+end
+
+
+def find_schema_for_file(f)
+ dir = File.dirname(f)
+ base = File.basename(f,'.json')
+ components = base.split("-")
+ cnt = components.length
+ # trim sections of file name (-) to try to find schema
+ check_name =""
+ begin
+ check_name = "#{dir}/#{components[0..cnt].join('-')}.schema"
+ break if File.exists?(check_name)
+ cnt = cnt - 1
+ end while cnt >0
+ check_name
+end
+
+
+
+if __FILE__ == $0
+ base_dir = ARGV[0].nil? ? "/opt/dell/chef/data_bags" : ARGV[0]
+ puts "Using #{base_dir}"
+ err = verify_bags( base_dir)
+ exit -3 if err
+ exit 0
+end
View
80 change-image/dell/openstack_manager/lib/validate_data_bag.rb
@@ -0,0 +1,80 @@
+#!/usr/bin/ruby
+# Copyright 2011, Dell
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+require 'kwalify'
+require 'uri'
+
+require '/opt/dell/openstack_manager/app/models/crowbar_validator.rb'
+
+def validate(schema_filename, config_filename)
+ ## validate schema definition
+ metavalidator = Kwalify::MetaValidator.instance
+ parser = Kwalify::Yaml::Parser.new(metavalidator)
+ document = parser.parse_file(schema_filename)
+
+ rc = 0
+
+ # show errors
+ for e in parser.errors
+ rc = -1
+ puts "#{schema_filename}: #{e.linenum}:#{e.column} [#{e.path}] #{e.message}"
+ end if parser.errors && !parser.errors.empty?
+
+ ## Validate the config file
+ validator = CrowbarValidator.new(schema_filename)
+ parser = Kwalify::Yaml::Parser.new(validator)
+ document = parser.parse_file(config_filename)
+
+ ## show errors
+ for e in parser.errors
+ rc = -2 if rc == 0
+ puts "#{config_filename}: #{e.linenum}:#{e.column} [#{e.path}] #{e.message}"
+ end if parser.errors && !parser.errors.empty?
+
+ rc
+end
+
+if __FILE__ == $0
+
+if ARGV.size != 2
+ puts "Must specify two files\n"
+ puts "Usage: validate_data_bag <schema file> <data file>\n"
+ exit -3
+end
+
+if !File.exists?(ARGV[0])
+ puts "#{ARGV[0]} must exist\n"
+ puts "Usage: validate_data_bag <schema file> <data file>\n"
+ exit -4
+end
+
+if !File.exists?(ARGV[1])
+ puts "#{ARGV[1]} must exist\n"
+ puts "Usage: validate_data_bag <schema file> <data file>\n"
+ exit -5
+end
+
+rc = -1
+begin
+ rc = validate(ARGV[0], ARGV[1])
+rescue Exception => e
+ puts "Failed with exception: #{e.message}"
+end
+
+exit rc
+
+end
View
21 ubuntu-10.10-extra/install-chef.sh
@@ -175,8 +175,25 @@ knifeloop() {
}
# MODULAR approach: Install barclamps using rake (only uses ones that conform to new layout)
-cd /opt/dell/openstack_manager
-rake barclamp:bootstrap["/opt/dell/barclamps"]
+cd /opt/dell/barclamps
+for i in *; do
+ [[ -d $i ]] || continue
+ if [ -e $i/crowbar.yml ]; then
+ # MODULAR FORMAT copy to right location (installed by rake barclamp:install)
+ ruby /opt/dell/openstack_manager/lib/tasks/barclamps.rb
+ else
+ echo "copy LEGACY format $i"
+ cd "$i"
+ # LEGACY COPY (picked up in install-chef.sh)
+ ( cd chef; cp -r * /opt/dell/chef )
+ ( cd app; cp -r * /opt/dell/openstack_manager/app )
+ ( cd config; cp -r * /opt/dell/openstack_manager/config )
+ ( cd command_line; cp * /opt/dell/bin )
+ ( cd public ; cp -r * /opt/dell/openstack_manager/public )
+ cd ..
+ fi
+done
+
# LEGACY BARCLAMP INSTALLER (this should go away when all the barclamps are converted)
cd /opt/dell/chef/cookbooks
Please sign in to comment.
Something went wrong with that request. Please try again.