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
72 73 74 75 76 77 78 |
# File 'lib/local_system.rb', line 72 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
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/local_system.rb', line 61 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' by running `#{$0} build --help` 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 56 57 58 59 |
# File 'lib/local_system.rb', line 46 def validate_machinery_compatibility return if !Machinery::Config.new.perform_support_check || os.can_run_machinery? supported_oses = Os.supported_host_systems.map { |o| o.canonical_name }.sort.join(", ") = <<EOF You are running Machinery on a platform we do not explicitly support and test. It still could work very well. If you run into issues or would like to provide us feedback, you are welcome to file an issue at https://github.com/SUSE/machinery/issues/new or write an email to [email protected]. Oficially supported operating systems are: '#{supported_oses}' To disable this message in the machinery configuration use 'machinery config perform-support-check=false' EOF Machinery::Ui.warn end |
Instance Method Details
#read_file(file) ⇒ Object
Reads a file from the System. Returns nil if it does not exist.
121 122 123 124 125 126 |
# File 'lib/local_system.rb', line 121 def read_file(file) File.read(file) rescue Errno::ENOENT # File not found, return nil return end |
#requires_root? ⇒ Boolean
81 82 83 |
# File 'lib/local_system.rb', line 81 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.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/local_system.rb', line 99 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
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/local_system.rb', line 85 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 |