module XenStore::Utils
XenStore::Utils
implements utility methods which are unlikely to be required by users but are used by the rest of the module
Public Class Methods
Convert an error number or symbol to an Errno exception
@param n [Integer, Symbol] An Integer
or symbol
representing the
Errno exception to return.
@return [Exception] The Exception
representing the provided type
of error.
# File lib/xsrb/utils.rb, line 68 def error(n) if n.is_a? Integer @errno_exception_map[n] else Errno.send(n) end end
Get the next request ID to contact XenStore
with.
@return [Integer] The next ID in the sequence.
# File lib/xsrb/utils.rb, line 79 def next_request_id @reqid += 1 # Ensure no larger than uint32_t which is used in xs_wire.h @reqid %= MAX_UINT end
Raise an exception if the provided path is invalid.
@param path [String] The XenStore
path to check. @return [String] The valid path.
# File lib/xsrb/utils.rb, line 99 def valid_path?(path) pathname = Pathname.new path max_len = pathname.absolute? ? 3072 : 2048 if path.length > max_len raise XenStore::Exceptions::InvalidPath, "Path too long: #{path}" end unless @path_regex =~ path raise XenStore::Exceptions::InvalidPath, path.to_s end path end
Check if every member of a list of permissions strings is valid.
@param perms [Array, String] An Array
of XenStore
permissions
specifications
@return [Array] The list of permissions.
# File lib/xsrb/utils.rb, line 133 def valid_permissions?(perms) perms = [perms] if perms.is_a? String perms.each do |perm| unless perm =~ @perms_regex raise XenStore::Exceptions::InvalidPermission, "Invalid permission string: #{perm}" end end end
Raise an exception if the provided XenStore
watch path is invalid.
@param path [String] The XenStore
watch path to check. @return [String] The valid path.
# File lib/xsrb/utils.rb, line 120 def valid_watch_path?(path) if path.starts_with?('@') && (@watch_path_regex !~ path) raise XenStore::Exceptions::InvalidPath, path.to_s end valid_path? path end
Get the XenBus path on this system
@return [String] The path to the XenBus device
# File lib/xsrb/utils.rb, line 146 def xenbus_path default = '/dev/xen/xenbus' host_os = RbConfig::CONFIG['host_os'] case host_os when 'netbsd' '/kern/xen/xenbus' when 'linux' File.readable?('/dev/xen/xenbus') ? '/proc/xen/xenbus' : default when /mswin|windows/i raise NotImplementedError, "OS '#{RbConfig::CONFIG['host_os']}' is not supported" else default end end