Module: XenStore::Utils
- Defined in:
- lib/xsrb/utils.rb
Overview
XenStore::Utils implements utility methods which are unlikely to be required by users but are used by the rest of the module
Class Method Summary collapse
-
.error(n) ⇒ Exception
Convert an error number or symbol to an Errno exception.
-
.next_request_id ⇒ Integer
Get the next request ID to contact XenStore with.
-
.unix_socket_path ⇒ String
Get the path of the XenStore unix socket.
-
.valid_path?(path) ⇒ String
Raise an exception if the provided path is invalid.
-
.valid_permissions?(perms) ⇒ Array
Check if every member of a list of permissions strings is valid.
-
.valid_watch_path?(path) ⇒ String
Raise an exception if the provided XenStore watch path is invalid.
-
.xenbus_path ⇒ String
Get the XenBus path on this system.
Class Method Details
.error(n) ⇒ Exception
Convert an error number or symbol to an Errno exception
68 69 70 71 72 73 74 |
# 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 |
.next_request_id ⇒ Integer
Get the next request ID to contact XenStore with.
79 80 81 82 83 84 |
# 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 |
.unix_socket_path ⇒ String
Get the path of the XenStore unix socket.
89 90 91 92 93 |
# File 'lib/xsrb/utils.rb', line 89 def unix_socket_path dp = '/var/run/xenstored' ENV['XENSTORED_PATH'] || File.join(ENV['XENSTORED_RUNDIR'] || dp, 'socket') end |
.valid_path?(path) ⇒ String
Raise an exception if the provided path is invalid.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# 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 |
.valid_permissions?(perms) ⇒ Array
Check if every member of a list of permissions strings is valid.
133 134 135 136 137 138 139 140 141 |
# File 'lib/xsrb/utils.rb', line 133 def (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 |
.valid_watch_path?(path) ⇒ String
Raise an exception if the provided XenStore watch path is invalid.
120 121 122 123 124 125 126 |
# 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 |
.xenbus_path ⇒ String
Get the XenBus path on this system
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# 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 |