Class: LeoFSManager::Client
- Inherits:
-
Object
- Object
- LeoFSManager::Client
- Defined in:
- lib/leofs_manager_client.rb
Constant Summary collapse
- CMD_VERSION =
"version"
- CMD_LOGIN =
"login %s %s"
- CMD_STATUS =
"status %s"
- CMD_START =
"start"
- CMD_DETACH =
"detach %s"
- CMD_SUSPEND =
"suspend %s"
- CMD_RESUME =
"resume %s"
- CMD_REBALANCE =
"rebalance"
- CMD_WHEREIS =
"whereis %s"
- CMD_DU =
"du %s"
- CMD_COMPACT_START =
"compact start %s %s %s"
- CMD_COMPACT_START_ALL =
"compact start %s all"
- CMD_COMPACT_SUSPEND =
"compact suspend %s"
- CMD_COMPACT_RESUME =
"compact resume %s"
- CMD_COMPACT_STATUS =
"compact status %s"
- CMD_PURGE =
"purge %s"
- CMD_CRE_USER =
"create-user %s %s"
- CMD_UPD_USER_ROLE =
"update-user-role %s %s"
- CMD_UPD_USER_PASS =
"update-user-password %s %s"
- CMD_DEL_USER =
"delete-user %s"
- CMD_GET_USERS =
"get-users"
- CMD_SET_ENDPOINT =
"set-endpoint %s"
- CMD_DEL_ENDPOINT =
"delete-endpoint %s"
- CMD_GET_ENDPOINTS =
"get-endpoints"
- CMD_ADD_BUCKET =
"add-bucket %s %s"
- CMD_DELETE_BUCKET =
"delete-bucket %s %s"
- CMD_GET_BUCKETS =
"get-buckets"
- CMD_RECOVER_FILE =
"recover file %s"
- CMD_RECOVER_NODE =
"recover node %s"
- CMD_RECOVER_RING =
"recover ring %s"
- USER_ROLES =
RoleDef.invert
Instance Attribute Summary collapse
-
#current_server ⇒ Object
readonly
the server currently connected.
-
#servers ⇒ Object
readonly
servers to connect.
Instance Method Summary collapse
-
#add_bucket(bucket_name, access_key_id) ⇒ Object
- Add an Bucket in the system Return
-
nil.
-
#compact_resume(node) ⇒ Object
- Execute ‘compact suspend’ Return
-
nil.
-
#compact_start(node, num_of_targets_or_all, num_of_concurrents = nil) ⇒ Object
- Execute ‘compact start’ Return
-
nil.
-
#compact_status(node) ⇒ Object
- Execute ‘compact status’ Return
-
nil.
-
#compact_suspend(node) ⇒ Object
- Execute ‘compact suspend’ Return
-
nil.
-
#create_user(user_id, password = nil) ⇒ Object
- Generate credential for LeoFS Return
-
Credential.
-
#delete_bucket(bucket_name, access_key_id) ⇒ Object
- Delete an Bucket in the system Return
-
nil.
-
#delete_endpoint(endpoint) ⇒ Object
(also: #del_endpoint)
- Remove an endpoint from the system Return
-
nil.
-
#delete_user(user_id) ⇒ Object
- Delete user Return
-
nil.
-
#detach(node) ⇒ Object
- Leave a node from the storage cluster Return
-
nil.
-
#disconnect! ⇒ Object
- Disconnect to LeoFS Manager explicitly Return
-
nil.
-
#du(node) ⇒ Object
- Retrieve storage status from the storage Return
-
StorageStat.
-
#get_buckets ⇒ Object
- Retrieve all buckets from the system Return
-
Array of Bucket.
-
#get_endpoints ⇒ Object
- Retrieve an endpoint in the system Return
-
Array of Endpoint.
- #get_users ⇒ Object
-
#initialize(*servers) ⇒ Client
constructor
APIs ====================================================================== Constructor.
-
#login(user_id, password) ⇒ Object
- Login as specifies user Return
-
LoginInfo.
-
#purge(path) ⇒ Object
- Purge a cache in gateways Return
-
nil.
-
#rebalance ⇒ Object
- Execute ‘rebalance’ in the storage cluster Return
-
nil.
-
#recover_file(path) ⇒ Object
- Recover file Return
-
nil.
-
#recover_node(node) ⇒ Object
- Recover node Return
-
nil.
-
#recover_ring(node) ⇒ Object
- Recover ring Return
-
nil.
-
#resume(node) ⇒ Object
- Resume a node in the storage cluster Return
-
nil.
-
#set_endpoint(endpoint) ⇒ Object
- Insert an endpoint in the system Return
-
nil.
-
#start ⇒ Object
- Launch LeoFS’s storage cluster Return
-
nil.
-
#status(node = nil) ⇒ Object
- Retrieve LeoFS’s system status from LeoFS Manager Return
-
Status.
-
#suspend(node) ⇒ Object
- Suspend a node in the storage cluster Return
-
nil.
-
#update_user_password(user_id, new_password) ⇒ Object
- Update user password Return
-
nil.
-
#update_user_role(user_id, role) ⇒ Object
- Update user role Return
-
nil.
-
#version ⇒ Object
- Retrieve LeoFS’s version from LeoFS Manager Return
-
Version of LeoFS.
-
#whereis(path) ⇒ Object
- Retrieve assigned file information Return
-
Array of AssignedFile.
Constructor Details
#initialize(*servers) ⇒ Client
APIs
Constructor
70 71 72 73 74 75 |
# File 'lib/leofs_manager_client.rb', line 70 def initialize(*servers) @servers = parse_servers(servers) set_current_server @mutex = Mutex.new connect end |
Instance Attribute Details
#current_server ⇒ Object (readonly)
the server currently connected
80 81 82 |
# File 'lib/leofs_manager_client.rb', line 80 def current_server @current_server end |
#servers ⇒ Object (readonly)
servers to connect
78 79 80 |
# File 'lib/leofs_manager_client.rb', line 78 def servers @servers end |
Instance Method Details
#add_bucket(bucket_name, access_key_id) ⇒ Object
Add an Bucket in the system
- Return
-
nil
271 272 273 274 |
# File 'lib/leofs_manager_client.rb', line 271 def add_bucket(bucket_name, access_key_id) sender(CMD_ADD_BUCKET % [bucket_name, access_key_id]) nil end |
#compact_resume(node) ⇒ Object
Execute ‘compact suspend’
- Return
-
nil
184 185 186 187 |
# File 'lib/leofs_manager_client.rb', line 184 def compact_resume(node) sender(CMD_COMPACT_RESUME % node) nil end |
#compact_start(node, num_of_targets_or_all, num_of_concurrents = nil) ⇒ Object
Execute ‘compact start’
- Return
-
nil
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/leofs_manager_client.rb', line 162 def compact_start(node, num_of_targets_or_all, num_of_concurrents=nil) case num_of_targets_or_all.to_s when /^all$/i sender(CMD_COMPACT_START_ALL % node) else num_of_concurrents = num_of_concurrents ? Integer(num_of_concurrents) : "" sender(CMD_COMPACT_START % [node, Integer(num_of_targets_or_all), num_of_concurrents]) end nil end |
#compact_status(node) ⇒ Object
Execute ‘compact status’
- Return
-
nil
192 193 194 195 |
# File 'lib/leofs_manager_client.rb', line 192 def compact_status(node) compaction = sender(CMD_COMPACT_STATUS % node)[:compaction_status] CompactionStatus.new(compaction) end |
#compact_suspend(node) ⇒ Object
Execute ‘compact suspend’
- Return
-
nil
176 177 178 179 |
# File 'lib/leofs_manager_client.rb', line 176 def compact_suspend(node) sender(CMD_COMPACT_SUSPEND % node) nil end |
#create_user(user_id, password = nil) ⇒ Object
Generate credential for LeoFS
- Return
-
Credential
208 209 210 |
# File 'lib/leofs_manager_client.rb', line 208 def create_user(user_id, password=nil) Credential.new(sender(CMD_CRE_USER % [user_id, password])) end |
#delete_bucket(bucket_name, access_key_id) ⇒ Object
Delete an Bucket in the system
- Return
-
nil
279 280 281 282 |
# File 'lib/leofs_manager_client.rb', line 279 def delete_bucket(bucket_name, access_key_id) sender(CMD_DELETE_BUCKET % [bucket_name, access_key_id]) nil end |
#delete_endpoint(endpoint) ⇒ Object Also known as: del_endpoint
Remove an endpoint from the system
- Return
-
nil
254 255 256 257 |
# File 'lib/leofs_manager_client.rb', line 254 def delete_endpoint(endpoint) sender(CMD_DEL_ENDPOINT % endpoint) nil end |
#delete_user(user_id) ⇒ Object
Delete user
- Return
-
nil
233 234 235 236 |
# File 'lib/leofs_manager_client.rb', line 233 def delete_user(user_id) sender(CMD_DEL_USER % user_id) nil end |
#detach(node) ⇒ Object
Leave a node from the storage cluster
- Return
-
nil
115 116 117 118 |
# File 'lib/leofs_manager_client.rb', line 115 def detach(node) sender(CMD_DETACH % node) nil end |
#disconnect! ⇒ Object
Disconnect to LeoFS Manager explicitly
- Return
-
nil
319 320 321 |
# File 'lib/leofs_manager_client.rb', line 319 def disconnect! disconnect end |
#du(node) ⇒ Object
Retrieve storage status from the storage
- Return
-
StorageStat
155 156 157 |
# File 'lib/leofs_manager_client.rb', line 155 def du(node) StorageStat.new(sender(CMD_DU % node)) end |
#get_buckets ⇒ Object
Retrieve all buckets from the system
- Return
-
Array of Bucket
287 288 289 290 |
# File 'lib/leofs_manager_client.rb', line 287 def get_buckets buckets = sender(CMD_GET_BUCKETS)[:buckets] buckets.map {|bucket| Bucket.new(bucket) } end |
#get_endpoints ⇒ Object
Retrieve an endpoint in the system
- Return
-
Array of Endpoint
263 264 265 266 |
# File 'lib/leofs_manager_client.rb', line 263 def get_endpoints endpoints = sender(CMD_GET_ENDPOINTS)[:endpoints] endpoints.map {|endpoint| Endpoint.new(endpoint) } end |
#get_users ⇒ Object
238 239 240 241 |
# File 'lib/leofs_manager_client.rb', line 238 def get_users users = sender(CMD_GET_USERS)[:users] users.map {|account| User.new(account) } end |
#login(user_id, password) ⇒ Object
Login as specifies user
- Return
-
LoginInfo
100 101 102 |
# File 'lib/leofs_manager_client.rb', line 100 def login(user_id, password) LoginInfo.new(sender(CMD_LOGIN % [user_id, password])) end |
#purge(path) ⇒ Object
Purge a cache in gateways
- Return
-
nil
200 201 202 203 |
# File 'lib/leofs_manager_client.rb', line 200 def purge(path) sender(CMD_PURGE % path) nil end |
#rebalance ⇒ Object
Execute ‘rebalance’ in the storage cluster
- Return
-
nil
139 140 141 142 |
# File 'lib/leofs_manager_client.rb', line 139 def rebalance sender(CMD_REBALANCE) nil end |
#recover_file(path) ⇒ Object
Recover file
- Return
-
nil
295 296 297 298 |
# File 'lib/leofs_manager_client.rb', line 295 def recover_file(path) sender(CMD_RECOVER_FILE % path) nil end |
#recover_node(node) ⇒ Object
Recover node
- Return
-
nil
303 304 305 306 |
# File 'lib/leofs_manager_client.rb', line 303 def recover_node(node) sender(CMD_RECOVER_NODE % node) nil end |
#recover_ring(node) ⇒ Object
Recover ring
- Return
-
nil
311 312 313 314 |
# File 'lib/leofs_manager_client.rb', line 311 def recover_ring(node) sender(CMD_RECOVER_RING % node) nil end |
#resume(node) ⇒ Object
Resume a node in the storage cluster
- Return
-
nil
131 132 133 134 |
# File 'lib/leofs_manager_client.rb', line 131 def resume(node) sender(CMD_RESUME % node) nil end |
#set_endpoint(endpoint) ⇒ Object
Insert an endpoint in the system
- Return
-
nil
246 247 248 249 |
# File 'lib/leofs_manager_client.rb', line 246 def set_endpoint(endpoint) sender(CMD_SET_ENDPOINT % endpoint) nil end |
#start ⇒ Object
Launch LeoFS’s storage cluster
- Return
-
nil
107 108 109 110 |
# File 'lib/leofs_manager_client.rb', line 107 def start sender(CMD_START) nil end |
#status(node = nil) ⇒ Object
Retrieve LeoFS’s system status from LeoFS Manager
- Return
-
Status
93 94 95 |
# File 'lib/leofs_manager_client.rb', line 93 def status(node=nil) Status.new(sender(CMD_STATUS % node)) end |
#suspend(node) ⇒ Object
Suspend a node in the storage cluster
- Return
-
nil
123 124 125 126 |
# File 'lib/leofs_manager_client.rb', line 123 def suspend(node) sender(CMD_SUSPEND % node) nil end |
#update_user_password(user_id, new_password) ⇒ Object
Update user password
- Return
-
nil
225 226 227 228 |
# File 'lib/leofs_manager_client.rb', line 225 def update_user_password(user_id, new_password) sender(CMD_UPD_USER_PASS % [user_id, new_password]) nil end |
#update_user_role(user_id, role) ⇒ Object
Update user role
- Return
-
nil
215 216 217 218 219 220 |
# File 'lib/leofs_manager_client.rb', line 215 def update_user_role(user_id, role) role = role.to_sym if role.is_a? String role = USER_ROLES[role] if role.is_a? Symbol sender(CMD_UPD_USER_ROLE % [user_id, role]) nil end |
#version ⇒ Object
Retrieve LeoFS’s version from LeoFS Manager
- Return
-
Version of LeoFS
85 86 87 88 |
# File 'lib/leofs_manager_client.rb', line 85 def version h = sender(CMD_VERSION) return h[:result] end |
#whereis(path) ⇒ Object
Retrieve assigned file information
- Return
-
Array of AssignedFile
147 148 149 150 |
# File 'lib/leofs_manager_client.rb', line 147 def whereis(path) assigned_info = sender(CMD_WHEREIS % path)[:assigned_info] assigned_info.map {|h| AssignedFile.new(h)} end |