Class: RightScale::Platform
- Includes:
- RightSupport::Ruby::EasySingleton
- Defined in:
- lib/right_agent/platform.rb,
lib/right_agent/platform/unix/platform.rb,
lib/right_agent/platform/windows/platform.rb,
lib/right_agent/platform/unix/linux/platform.rb,
lib/right_agent/platform/unix/darwin/platform.rb,
lib/right_agent/platform/windows/mingw/platform.rb,
lib/right_agent/platform/windows/mswin/platform.rb
Overview
Windows specific implementation
Defined Under Namespace
Classes: CommandError, Controller, Filesystem, Installer, PlatformHelperBase, Process, Rng, Shell, VolumeManager, Win32Error, WindowsCommon, WindowsSecurity, WindowsSystemInformation
Constant Summary collapse
- FEDORA_REL =
'/etc/fedora-release'
- FEDORA_SIG =
/Fedora release ([0-9]+) \((.*)\)/
Instance Attribute Summary collapse
-
#codename ⇒ Object
readonly
Returns the value of attribute codename.
-
#flavor ⇒ Object
readonly
Returns the value of attribute flavor.
-
#release ⇒ Object
readonly
Returns the value of attribute release.
Instance Method Summary collapse
-
#centos? ⇒ TrueClass|FalseClass
Is this machine running CentOS?.
-
#controller ⇒ Controller
Platform-specific controller object.
-
#darwin? ⇒ TrueClass|FalseClass
Is current platform Darwin?.
-
#dispatch(*args) { ... } ⇒ Object
Call platform specific implementation of method whose symbol is returned by the passed in block.
-
#ec2? ⇒ TrueClass|FalseClass
deprecated
Deprecated.
use right_link cloud libraries instead.
-
#eucalyptus? ⇒ TrueClass|FalseClass
deprecated
Deprecated.
use right_link cloud libraries instead.
-
#execute(command, options = {}) ⇒ String
Blocking call to invoke a command line tool used to perform platform- specific tasks.
-
#family ⇒ Symbol
deprecated
Deprecated.
family is a legacy definition, see genus/species for a more granular definition.
-
#filesystem ⇒ Filesystem
Platform-specific filesystem config object.
-
#genus ⇒ Symbol
Platform genus.
-
#installer ⇒ Installer
Platform-specific installer information object.
-
#linux? ⇒ TrueClass|FalseClass
Is current platform Linux?.
-
#process ⇒ Process
Platform-specific process facilities object.
-
#rackspace? ⇒ TrueClass|FalseClass
deprecated
Deprecated.
use right_link cloud libraries instead.
-
#resolve_cloud_type ⇒ String
deprecated
Deprecated.
leverage the right_link cloud libraries for any cloud- specific behavior because the behavior of all possible clouds is beyond the scope of hard-coded case statements.
-
#rhel? ⇒ TrueClass|FalseClass
Is this machine running RHEL?.
-
#rng ⇒ Rng
Platform-specific RNG object.
-
#shell ⇒ Shell
Platform-specific shell information object.
-
#species ⇒ Symbol
Platform species.
-
#suse? ⇒ TrueClass|FalseClass
Is this machine running Suse?.
-
#ubuntu? ⇒ TrueClass|FalseClass
Is this machine running Ubuntu?.
-
#unix? ⇒ TrueClass|FalseClass
Is current platform in the Unix genus?.
-
#volume_manager ⇒ VolumeManager
Platform-specific volume manager config object.
-
#windows? ⇒ TrueClass|FalseClass
Is current platform Windows?.
-
#windows_common ⇒ WindowsCommon
Platform-specific Windows common.
-
#windows_security ⇒ WindowsSecurity
Platform-specific Windows security.
-
#windows_system_information ⇒ WindowsSystemInformation
Platform-specific Windows system information.
Instance Attribute Details
#codename ⇒ Object (readonly)
Returns the value of attribute codename.
62 63 64 |
# File 'lib/right_agent/platform.rb', line 62 def codename @codename end |
#flavor ⇒ Object (readonly)
Returns the value of attribute flavor.
62 63 64 |
# File 'lib/right_agent/platform.rb', line 62 def flavor @flavor end |
#release ⇒ Object (readonly)
Returns the value of attribute release.
62 63 64 |
# File 'lib/right_agent/platform.rb', line 62 def release @release end |
Instance Method Details
#centos? ⇒ TrueClass|FalseClass
Is this machine running CentOS?
43 44 45 |
# File 'lib/right_agent/platform/unix/linux/platform.rb', line 43 def centos? !!(@flavor =~ /centos/) end |
#controller ⇒ Controller
Returns Platform-specific controller object.
177 178 179 |
# File 'lib/right_agent/platform.rb', line 177 def controller platform_service(:controller) end |
#darwin? ⇒ TrueClass|FalseClass
Is current platform Darwin?
104 105 106 |
# File 'lib/right_agent/platform.rb', line 104 def darwin? species == :darwin end |
#dispatch(*args) { ... } ⇒ Object
Call platform specific implementation of method whose symbol is returned by the passed in block. Arguments are passed through. e.g.
Platform.dispatch(2) { :echo }
will result in ‘echo_linux(2)’ being executed in self if running on linux, ‘echo_windows(2)’ if running on Windows and ‘echo_darwin(2)’ if on Mac OS X. Note that the method is run in the instance of the caller.
164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/right_agent/platform.rb', line 164 def dispatch(*args, &blk) raise 'Platform.dispatch requires a block' unless blk binding = blk.binding.eval('self') meth = blk.call target = dispatch_candidates(meth).detect do |candidate| binding.respond_to?(candidate) end raise "No platform dispatch target found in #{binding.class} for " + "'#{meth.inspect}', tried " + dispatch_candidates(meth).join(', ') unless target binding.send(target, *args) end |
#ec2? ⇒ TrueClass|FalseClass
use right_link cloud libraries instead.
Are we on an EC2 cloud instance?
120 121 122 123 124 |
# File 'lib/right_agent/platform.rb', line 120 def ec2? warn "#{self.class.name}#ec2? is deprecated, use right_link cloud libraries instead.\n#{caller[0,2].join("\n")}" resolve_cloud_type unless @cloud_type @cloud_type == 'ec2' end |
#eucalyptus? ⇒ TrueClass|FalseClass
use right_link cloud libraries instead.
Are we on an Eucalyptus cloud instance?
142 143 144 145 146 |
# File 'lib/right_agent/platform.rb', line 142 def eucalyptus? warn "#{self.class.name}#eucalyptus? is deprecated, use right_link cloud libraries instead.\n#{caller[0,2].join("\n")}" resolve_cloud_type unless @cloud_type @cloud_type == 'eucalyptus' end |
#execute(command, options = {}) ⇒ String
Blocking call to invoke a command line tool used to perform platform- specific tasks.
Also provides a consistent interface for mocking command output during spec testing. Implementations should use this method instead of embedding popen/backtick calls to assist with testing.
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/right_agent/platform.rb', line 225 def execute(command, = {}) = { :raise_on_failure => true }.merge() raise_on_failure = [:raise_on_failure] output_text = '' begin output_text = `#{command}` if !$?.success? && [:raise_on_failure] = [] << "Command failed with exit code = #{$?.exitstatus}:" << "> #{command}" error_output_text = output_text.strip << error_output_text unless error_output_text.empty? e = CommandError.new(.join("\n")) e.command = command e.status = $? e.output_text = output_text raise e end rescue Errno::ENOENT => e if raise_on_failure raise CommandError, "Command failed: #{e.}" end end output_text end |
#family ⇒ Symbol
family is a legacy definition, see genus/species for a more granular definition.
Generic platform family
70 71 72 73 |
# File 'lib/right_agent/platform.rb', line 70 def family warn "#{self.class.name}#family is deprecated, use genus or species instead.\n#{caller[0,2].join("\n")}" (genus == :unix) ? species : genus end |
#filesystem ⇒ Filesystem
Returns Platform-specific filesystem config object.
182 183 184 |
# File 'lib/right_agent/platform.rb', line 182 def filesystem platform_service(:filesystem) end |
#genus ⇒ Symbol
Returns platform genus.
76 77 78 79 |
# File 'lib/right_agent/platform.rb', line 76 def genus resolve_taxonomy unless @genus @genus end |
#installer ⇒ Installer
Returns Platform-specific installer information object.
207 208 209 |
# File 'lib/right_agent/platform.rb', line 207 def installer platform_service(:installer) end |
#linux? ⇒ TrueClass|FalseClass
Is current platform Linux?
97 98 99 |
# File 'lib/right_agent/platform.rb', line 97 def linux? species == :linux end |
#process ⇒ Process
Returns Platform-specific process facilities object.
202 203 204 |
# File 'lib/right_agent/platform.rb', line 202 def process platform_service(:process) end |
#rackspace? ⇒ TrueClass|FalseClass
use right_link cloud libraries instead.
Are we on an Rackspace cloud instance?
131 132 133 134 135 |
# File 'lib/right_agent/platform.rb', line 131 def rackspace? warn "#{self.class.name}#rackspace? is deprecated, use right_link cloud libraries instead.\n#{caller[0,2].join("\n")}" resolve_cloud_type unless @cloud_type @cloud_type == 'rackspace' end |
#resolve_cloud_type ⇒ String
leverage the right_link cloud libraries for any cloud- specific behavior because the behavior of all possible clouds is beyond the scope of hard-coded case statements.
Determines which cloud we’re on by the cheap but simple expedient of reading the RightScale cloud file.
259 260 261 262 263 |
# File 'lib/right_agent/platform.rb', line 259 def resolve_cloud_type cloud_file_path = ::File.join(self.filesystem.right_scale_static_state_dir, 'cloud') @cloud_type = ::File.read(cloud_file_path) rescue nil @cloud_type end |
#rhel? ⇒ TrueClass|FalseClass
Is this machine running RHEL?
57 58 59 |
# File 'lib/right_agent/platform/unix/linux/platform.rb', line 57 def rhel? !!(@flavor =~ /redhatenterpriseserver/) end |
#rng ⇒ Rng
Returns Platform-specific RNG object.
197 198 199 |
# File 'lib/right_agent/platform.rb', line 197 def rng platform_service(:rng) end |
#shell ⇒ Shell
Returns Platform-specific shell information object.
192 193 194 |
# File 'lib/right_agent/platform.rb', line 192 def shell platform_service(:shell) end |
#species ⇒ Symbol
Returns platform species.
82 83 84 85 |
# File 'lib/right_agent/platform.rb', line 82 def species resolve_taxonomy unless @species @species end |
#suse? ⇒ TrueClass|FalseClass
Is this machine running Suse?
50 51 52 |
# File 'lib/right_agent/platform/unix/linux/platform.rb', line 50 def suse? !!(@flavor =~ /suse/) end |
#ubuntu? ⇒ TrueClass|FalseClass
Is this machine running Ubuntu?
36 37 38 |
# File 'lib/right_agent/platform/unix/linux/platform.rb', line 36 def ubuntu? !!(@flavor =~ /ubuntu/) end |
#unix? ⇒ TrueClass|FalseClass
Is current platform in the Unix genus?
90 91 92 |
# File 'lib/right_agent/platform.rb', line 90 def unix? genus == :unix end |
#volume_manager ⇒ VolumeManager
Returns Platform-specific volume manager config object.
187 188 189 |
# File 'lib/right_agent/platform.rb', line 187 def volume_manager platform_service(:volume_manager) end |
#windows? ⇒ TrueClass|FalseClass
Is current platform Windows?
111 112 113 |
# File 'lib/right_agent/platform.rb', line 111 def windows? genus == :windows end |
#windows_common ⇒ WindowsCommon
Returns Platform-specific Windows common.
1769 1770 1771 |
# File 'lib/right_agent/platform/windows/platform.rb', line 1769 def windows_common platform_service(:windows_common) end |
#windows_security ⇒ WindowsSecurity
Returns Platform-specific Windows security.
1774 1775 1776 |
# File 'lib/right_agent/platform/windows/platform.rb', line 1774 def windows_security platform_service(:windows_security) end |
#windows_system_information ⇒ WindowsSystemInformation
Returns Platform-specific Windows system information.
1779 1780 1781 |
# File 'lib/right_agent/platform/windows/platform.rb', line 1779 def windows_system_information platform_service(:windows_system_information) end |