Class: LocalSystem
Overview
Copyright © 2013-2014 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.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, contact SUSE LLC.
To contact SUSE about this file by physical or electronic mail, you may find current contact information at www.suse.com
Class Method Summary collapse
- .os_object ⇒ Object
- .validate_build_compatibility(system_description) ⇒ Object
- .validate_existence_of_package(package) ⇒ Object
- .validate_machinery_compatibility ⇒ Object
Instance Method Summary collapse
-
#read_file(file) ⇒ Object
Reads a file from the System.
- #requires_root? ⇒ Boolean
-
#retrieve_files(filelist, destination) ⇒ Object
Retrieves files specified in filelist from the local system and raises an Machinery::Errors::RsyncFailed exception when it’s not successful.
- #run_command(*args) ⇒ Object
Methods inherited from System
#check_requirement, #create_archive, for, #run_script
Class Method Details
.os_object ⇒ Object
20 21 22 23 24 25 |
# File 'lib/local_system.rb', line 20 def os_object description = SystemDescription.new("localhost") inspector = OsInspector.new inspector.inspect(System.for("localhost"), description) description.os_object end |
.validate_build_compatibility(system_description) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/local_system.rb', line 57 def validate_build_compatibility(system_description) if !os_object.can_build?(system_description.os_object) = "Building '#{system_description.os_object.name}' images is " \ "not supported on this distribution.\n" \ "Check the 'BUILD SUPPORT MATRIX' section in our man page for " \ "further information which build targets are supported." raise(Machinery::Errors::BuildFailed.new()) end end |
.validate_existence_of_package(package) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/local_system.rb', line 27 def validate_existence_of_package(package) begin Cheetah.run("rpm", "-q", package) rescue needed_module = os_object.module_required_by_package(package) if needed_module raise(Machinery::Errors::MissingRequirement.new("You need the package '#{package}' from module '#{needed_module}'. You can install it as follows:\n" \ "If you haven't selected the module '#{needed_module}' before, run `yast2 scc` and choose 'Select Extensions' and activate '#{needed_module}'.\nRun `zypper install #{package}` to install the package.")) else raise(Machinery::Errors::MissingRequirement.new("You need the package '#{package}'. You can install it by running `zypper install #{package}`")) end end end |
.validate_machinery_compatibility ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/local_system.rb', line 41 def validate_machinery_compatibility begin os = os_object rescue Machinery::Errors::SystemDescriptionError os = nil end if !os || !os.can_run_machinery? = "Running Machinery is not supported on this system.\n" \ "Check the 'Installation' section in the README.md for more information " \ "about the requirements." raise(Machinery::Errors::IncompatibleHost.new()) end end |
Instance Method Details
#read_file(file) ⇒ Object
Reads a file from the System. Returns nil if it does not exist.
101 102 103 104 105 106 |
# File 'lib/local_system.rb', line 101 def read_file(file) File.read(file) rescue Errno::ENOENT # File not found, return nil return end |
#requires_root? ⇒ Boolean
69 70 71 |
# File 'lib/local_system.rb', line 69 def requires_root? true end |
#retrieve_files(filelist, destination) ⇒ Object
Retrieves files specified in filelist from the local system and raises an Machinery::Errors::RsyncFailed exception when it’s not successful. Destination is the directory where to put the files.
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/local_system.rb', line 87 def retrieve_files(filelist, destination) begin LoggedCheetah.run("rsync", "--chmod=go-rwx", "--files-from=-", "/", destination, :stdout => :capture, :stdin => filelist.join("\n") ) rescue Cheetah::ExecutionFailed => e raise Machinery::Errors::RsyncFailed.new( "Could not rsync files from localhost. \n" \ "Error: #{e}\n" \ "If you lack read permissions on some files you may want to retry as user root or specify\n" \ "the fully qualified host name instead of localhost in order to connect as root via ssh." ) end end |
#run_command(*args) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/local_system.rb', line 73 def run_command(*args) if args.last.is_a?(Hash) && args.last[:disable_logging] cheetah_class = Cheetah else cheetah_class = LoggedCheetah end with_c_locale do cheetah_class.run(*args) end end |