lib/kiwi_config.rb in machinery-tool-1.17.0 vs lib/kiwi_config.rb in machinery-tool-1.18.0

- old
+ new

@@ -1,6 +1,6 @@ -# Copyright (c) 2013-2015 SUSE LLC +# Copyright (c) 2013-2016 SUSE LLC # # This program is free software; you can redistribute it and/or # modify it under the terms of version 3 of the GNU General Public License as # published by the Free Software Foundation. # @@ -14,11 +14,11 @@ # # To contact SUSE about this file by physical or electronic mail, # you may find current contact information at www.suse.com class KiwiConfig < Exporter - attr_accessor :xml, :sh + attr_accessor :xml_text, :sh attr_accessor :name def initialize(system_description, options = {}) @name = "kiwi" @system_description = system_description @@ -39,12 +39,12 @@ inject_users_and_groups(output_location) inject_extracted_files(output_location) @sh << "baseCleanMount\n" @sh << "exit 0\n" - File.write(File.join(output_location, "config.xml") , @xml.to_xml) - File.write(File.join(output_location, "config.sh") , @sh) + File.write(File.join(output_location, "config.xml"), xml_text) + File.write(File.join(output_location, "config.sh"), @sh) FileUtils.cp( File.join(Machinery::ROOT, "export_helpers/kiwi_export_readme.md"), File.join(output_location, "README.md") ) @@ -190,45 +190,45 @@ suseSetupProduct suseImportBuildKey suseConfig EOF - builder = Nokogiri::XML::Builder.new do |xml| - xml.image(schemaversion: "5.8", name: @system_description.name) do - xml.description(type: "system") do - xml.author "Machinery" - xml.contact "" - xml.specification "Description of system '#{@system_description.name}' exported by Machinery" - end + xml = Builder::XmlMarkup.new(indent: 2) + xml.instruct! :xml + xml.image(schemaversion: "5.8", name: @system_description.name) do + xml.description(type: "system") do + xml.author "Machinery" + xml.contact "" + xml.specification "Description of system '#{@system_description.name}' exported by Machinery" + end - xml.preferences do - xml.packagemanager "zypper" - xml.version "0.0.1" - xml.type_( - image: "vmx", - filesystem: "ext3", - installiso: "true", - boot: @system_description.os.kiwi_boot, - format: "qcow2", bootloader: @system_description.os.kiwi_bootloader - ) - end + xml.preferences do + xml.packagemanager "zypper" + xml.version "0.0.1" + xml.type( + image: "vmx", + filesystem: "ext3", + installiso: "true", + boot: @system_description.os.kiwi_boot, + format: "qcow2", bootloader: @system_description.os.kiwi_bootloader + ) + end - xml.users(group: "root") do - xml.user(password: "$1$wYJUgpM5$RXMMeASDc035eX.NbYWFl0", - home: "/root", name: "root") - end + xml.users(group: "root") do + xml.user(password: "$1$wYJUgpM5$RXMMeASDc035eX.NbYWFl0", + home: "/root", name: "root") + end - apply_repositories(xml) - apply_packages(xml) - apply_services - end + apply_repositories(xml) + apply_packages(xml) + apply_services end pre_process_config - @xml = builder.doc + @xml_text = xml.target! end def apply_packages(xml) filter = YAML.load_file( File.join(Machinery::ROOT, "filters", "filter-packages-for-build.yaml") @@ -292,49 +292,51 @@ def apply_services if @system_description["services"] init_system = @system_description["services"].init_system case init_system - when "sysvinit" - @system_description["services"].each do |service| + when "sysvinit" + @system_description["services"].each do |service| + @sh << if service.state == "on" - @sh << "chkconfig #{service.name} on\n" + "chkconfig #{service.name} on\n" else - @sh << "chkconfig #{service.name} off\n" + "chkconfig #{service.name} off\n" end + end + when "systemd" + # possible systemd service states: + # http://www.freedesktop.org/software/systemd/man/systemctl.html#Unit%20File%20Commands + @system_description["services"].each do |service| + case service.state + when "enabled" + @sh << "systemctl enable #{service.name}\n" + when "disabled" + @sh << "systemctl disable #{service.name}\n" + when "masked" + @sh << "systemctl mask #{service.name}\n" + when "static" + # Don't do anything because the unit is not meant to be + # enabled/disabled manually. + when "linked" + # Don't do anything because linking doesn't mean enabling + # nor disabling. + when "enabled-runtime" + when "linked-runtime" + when "masked-runtime" + # Don't do anything because these states are not supposed + # to be permanent. + else + raise Machinery::Errors::ExportFailed.new( + "The systemd unit state #{service.state} is unknown." + ) end - - when "systemd" - # possible systemd service states: - # http://www.freedesktop.org/software/systemd/man/systemctl.html#Unit%20File%20Commands - @system_description["services"].each do |service| - case service.state - when "enabled" - @sh << "systemctl enable #{service.name}\n" - when "disabled" - @sh << "systemctl disable #{service.name}\n" - when "masked" - @sh << "systemctl mask #{service.name}\n" - when "static" - # Don't do anything because the unit is not meant to be - # enabled/disabled manually. - when "linked" - # Don't do anything because linking doesn't mean enabling - # nor disabling. - when "enabled-runtime" - when "linked-runtime" - when "masked-runtime" - # Don't do anything because these states are not supposed - # to be permanent. - else - raise Machinery::Errors::ExportFailed.new( - "The systemd unit state #{service.state} is unknown." - ) - end - end - - else - raise "Unsupported init system: #{init_system.inspect}." + end + else + Machinery::Ui.warn( + "Warning: Containers do not have an init system, so the default service" \ + " configuration provided by the packages will be used for the image." + ) end end end def enable_dhcp(output_location)