Class: LocalSystem
Overview
Copyright © 2013-2015 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
Constant Summary collapse
- @@os =
nil
Class Method Summary collapse
- .os ⇒ Object
- .validate_architecture(arch) ⇒ 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, #has_command?, #run_script
Class Method Details
.os ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/local_system.rb', line 22 def os if !@@os description = SystemDescription.new("localhost", SystemDescriptionMemoryStore.new) inspector = OsInspector.new(System.for("localhost"), description) inspector.inspect(nil) @@os = description.os end @@os end |
.validate_architecture(arch) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/local_system.rb', line 68 def validate_architecture(arch) if os.architecture != arch raise(Machinery::Errors::UnsupportedArchitecture.new( "This operation is not supported on architecture '#{os.architecture}'." )) end 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.can_build?(system_description.os) = "Building '#{system_description.os.display_name}' 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
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/local_system.rb', line 32 def validate_existence_of_package(package) begin Cheetah.run("rpm", "-q", package) rescue needed_module = os.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
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/local_system.rb', line 46 def validate_machinery_compatibility if !os.can_run_machinery? supported_oses = Os.supported_host_systems.map { |o| o.canonical_name }. sort.join(", ") = "Running Machinery is not supported on this system.\n" \ "Supported operating systems are: #{supported_oses}" 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.
109 110 111 112 113 114 |
# File 'lib/local_system.rb', line 109 def read_file(file) File.read(file) rescue Errno::ENOENT # File not found, return nil return end |
#requires_root? ⇒ Boolean
77 78 79 |
# File 'lib/local_system.rb', line 77 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.
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/local_system.rb', line 95 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
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/local_system.rb', line 81 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 |