Class: LeoManager::Client
- Inherits:
-
Object
- Object
- LeoManager::Client
- Defined in:
- lib/leo_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_UPDATE_ACL =
"update-acl %s %s %s"- 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 ==== Args bucket_name
- a bucket name access_key_id
-
access key id ==== Return Result.
-
#compact_resume(node) ⇒ Object
- Execute ‘compact suspend’ ==== Args node
-
a storage node ==== Return Result.
-
#compact_start(node, num_of_targets_or_all, num_of_concurrents = nil) ⇒ Object
- Execute data comaction in a storage node ==== Args node
- a storage node num_of_targets_or_all
- a number of targets - [integer | all] num_of_concurrents
-
a number of concurrents ==== Return Result.
-
#compact_status(node) ⇒ Object
- Execute ‘compact status’ ==== Args node
-
a storage node ==== Return CompactionStatus.
-
#compact_suspend(node) ⇒ Object
- Execute ‘compact suspend’ ==== Args node
-
a storage node ==== Return Result.
-
#create_user(user_id, password = nil) ⇒ Object
- Generate credential of a user ==== Args user_id
- user id password
-
password ==== Return Credential.
-
#delete_bucket(bucket_name, access_key_id) ⇒ Object
- Delete an Bucket in the system ==== Args bucket_name
- a bucket name access_key_id
-
access key id ==== Return Result.
-
#delete_endpoint(endpoint) ⇒ Object
(also: #del_endpoint)
- Remove an endpoint from the system ==== Args endpoint
-
an endpoint ==== Return nil.
-
#delete_user(user_id) ⇒ Object
- Delete a user ==== Args user_id
-
user id ==== Return Result.
-
#detach(node) ⇒ Object
- Leave a node from the storage cluster ==== Args node
-
a storage node ==== Return Result.
-
#disconnect! ⇒ Object
Disconnect to LeoFS Manager explicitly ==== Return Result.
-
#du(node) ⇒ Object
- Retrieve storage status from the storage ==== Args node
-
a storage node ==== 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
Retrieve a user ==== Return Map.
-
#initialize(*servers) ⇒ Client
constructor
APIs ====================================================================== Constructor.
-
#login(user_id, password) ⇒ Object
- Login as specifies user ==== Args user_id
- user id password
-
password ==== Return LoginInfo.
-
#purge(path) ⇒ Object
- Purge a cache in the gateways ==== Args path
-
an object path ==== Return Result.
-
#rebalance ⇒ Object
Execute relocate of objects - “rebalance” in the storage cluster ==== Return Result.
-
#recover_file(path) ⇒ Object
- Recover file ==== Args path
-
an object path ==== Return Result.
-
#recover_node(node) ⇒ Object
- Recover node ==== Args node
-
a storage node ==== Return Result.
-
#recover_ring(node) ⇒ Object
- Recover ring ==== Args node
-
a storage node ==== Return Result.
-
#resume(node) ⇒ Object
- Resume a node in the storage cluster ==== Args node
-
a storage node ==== Return Result.
-
#set_endpoint(endpoint) ⇒ Object
- Insert an endpoint in the system ==== Args endpoint
-
an endpoint ==== Return Result.
-
#start ⇒ Object
Launch LeoFS’s storage cluster ==== Return Result.
-
#status(node = nil) ⇒ Object
- Retrieve LeoFS’s system status from LeoFS Manager ==== Args node
-
Node ==== Return Status.
-
#suspend(node) ⇒ Object
- Suspend a node in the storage cluster ==== Args node
-
a storage node ==== Return Result.
-
#update_acl(bucket, accesskey, acl) ⇒ Object
- Update acl of a bucket ==== Args bucket_name
- a bucket name access_key_id
- access key id acl
-
acl of a bucket ==== Return Result.
-
#update_user_password(user_id, new_password) ⇒ Object
- Update password of a user ==== Args user_id
- user id new_password
-
new password ==== Return Result.
-
#update_user_role(user_id, role) ⇒ Object
- Update role of a user ==== Args user_id
- user id role
-
operation role of a user ==== Return Result.
-
#version ⇒ Object
Retrieve LeoFS’s version from LeoFS Manager ==== Return Version of LeoFS.
-
#whereis(path) ⇒ Object
- Retrieve assigned file information ==== Args path
-
an object path ==== Return Array of AssignedFile.
Constructor Details
#initialize(*servers) ⇒ Client
APIs
Constructor
71 72 73 74 75 76 |
# File 'lib/leo_manager_client.rb', line 71 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
81 82 83 |
# File 'lib/leo_manager_client.rb', line 81 def current_server @current_server end |
#servers ⇒ Object (readonly)
servers to connect
79 80 81 |
# File 'lib/leo_manager_client.rb', line 79 def servers @servers end |
Instance Method Details
#add_bucket(bucket_name, access_key_id) ⇒ Object
Add an Bucket in the system
Args
bucket_name :: a bucket name
access_key_id :: access key id
Return
Result
306 307 308 |
# File 'lib/leo_manager_client.rb', line 306 def add_bucket(bucket_name, access_key_id) Result.new(call(CMD_ADD_BUCKET % [bucket_name, access_key_id])) end |
#compact_resume(node) ⇒ Object
Execute ‘compact suspend’
Args
node :: a storage node
Return
Result
201 202 203 |
# File 'lib/leo_manager_client.rb', line 201 def compact_resume(node) Result.new(call(CMD_COMPACT_RESUME % node)) end |
#compact_start(node, num_of_targets_or_all, num_of_concurrents = nil) ⇒ Object
Execute data comaction in a storage node
Args
node :: a storage node
num_of_targets_or_all :: a number of targets - [integer | all]
num_of_concurrents :: a number of concurrents
Return
Result
177 178 179 180 181 182 183 184 185 |
# File 'lib/leo_manager_client.rb', line 177 def compact_start(node, num_of_targets_or_all, num_of_concurrents=nil) case num_of_targets_or_all.to_s when /^all$/i Result.new(call(CMD_COMPACT_START_ALL % node)) else num_of_concurrents = num_of_concurrents ? Integer(num_of_concurrents) : "" Result.new(call(CMD_COMPACT_START % [node, Integer(num_of_targets_or_all), num_of_concurrents])) end end |
#compact_status(node) ⇒ Object
Execute ‘compact status’
Args
node :: a storage node
Return
CompactionStatus
210 211 212 213 |
# File 'lib/leo_manager_client.rb', line 210 def compact_status(node) compaction = call(CMD_COMPACT_STATUS % node)[:compaction_status] CompactionStatus.new(compaction) end |
#compact_suspend(node) ⇒ Object
Execute ‘compact suspend’
Args
node :: a storage node
Return
Result
192 193 194 |
# File 'lib/leo_manager_client.rb', line 192 def compact_suspend(node) Result.new(call(CMD_COMPACT_SUSPEND % node)) end |
#create_user(user_id, password = nil) ⇒ Object
Generate credential of a user
Args
user_id :: user id
password :: password
Return
Credential
230 231 232 |
# File 'lib/leo_manager_client.rb', line 230 def create_user(user_id, password=nil) Credential.new(call(CMD_CRE_USER % [user_id, password])) end |
#delete_bucket(bucket_name, access_key_id) ⇒ Object
Delete an Bucket in the system
Args
bucket_name :: a bucket name
access_key_id :: access key id
Return
Result
316 317 318 |
# File 'lib/leo_manager_client.rb', line 316 def delete_bucket(bucket_name, access_key_id) Result.new(call(CMD_DELETE_BUCKET % [bucket_name, access_key_id])) end |
#delete_endpoint(endpoint) ⇒ Object Also known as: del_endpoint
Remove an endpoint from the system
Args
endpoint :: an endpoint
Return
nil
287 288 289 |
# File 'lib/leo_manager_client.rb', line 287 def delete_endpoint(endpoint) Result.new(call(CMD_DEL_ENDPOINT % endpoint)) end |
#delete_user(user_id) ⇒ Object
Delete a user
Args
user_id :: user id
Return
Result
261 262 263 |
# File 'lib/leo_manager_client.rb', line 261 def delete_user(user_id) Result.new(call(CMD_DEL_USER % user_id)) end |
#detach(node) ⇒ Object
Leave a node from the storage cluster
Args
node :: a storage node
Return
Result
122 123 124 |
# File 'lib/leo_manager_client.rb', line 122 def detach(node) Result.new(call(CMD_DETACH % node)) end |
#disconnect! ⇒ Object
Disconnect to LeoFS Manager explicitly
Return
Result
370 371 372 |
# File 'lib/leo_manager_client.rb', line 370 def disconnect! disconnect end |
#du(node) ⇒ Object
Retrieve storage status from the storage
Args
node :: a storage node
Return
StorageStat
166 167 168 |
# File 'lib/leo_manager_client.rb', line 166 def du(node) StorageStat.new(call(CMD_DU % node)) end |
#get_buckets ⇒ Object
Retrieve all buckets from the system
Return
Array of Bucket
323 324 325 326 |
# File 'lib/leo_manager_client.rb', line 323 def get_buckets buckets = call(CMD_GET_BUCKETS)[:buckets] buckets.map {|bucket| Bucket.new(bucket) } end |
#get_endpoints ⇒ Object
Retrieve an endpoint in the system
Return
Array of Endpoint
295 296 297 298 |
# File 'lib/leo_manager_client.rb', line 295 def get_endpoints endpoints = call(CMD_GET_ENDPOINTS)[:endpoints] endpoints.map {|endpoint| Endpoint.new(endpoint) } end |
#get_users ⇒ Object
Retrieve a user
Return
Map
268 269 270 271 |
# File 'lib/leo_manager_client.rb', line 268 def get_users users = call(CMD_GET_USERS)[:users] users.map {|account| User.new(account) } end |
#login(user_id, password) ⇒ Object
Login as specifies user
Args
user_id :: user id
password :: password
Return
LoginInfo
106 107 108 |
# File 'lib/leo_manager_client.rb', line 106 def login(user_id, password) LoginInfo.new(call(CMD_LOGIN % [user_id, password])) end |
#purge(path) ⇒ Object
Purge a cache in the gateways
Args
path :: an object path
Return
Result
220 221 222 |
# File 'lib/leo_manager_client.rb', line 220 def purge(path) Result.new(call(CMD_PURGE % path)) end |
#rebalance ⇒ Object
Execute relocate of objects - “rebalance” in the storage cluster
Return
Result
147 148 149 |
# File 'lib/leo_manager_client.rb', line 147 def rebalance Result.new(call(CMD_REBALANCE)) end |
#recover_file(path) ⇒ Object
Recover file
Args
path :: an object path
Return
Result
344 345 346 |
# File 'lib/leo_manager_client.rb', line 344 def recover_file(path) Result.new(call(CMD_RECOVER_FILE % path)) end |
#recover_node(node) ⇒ Object
Recover node
Args
node :: a storage node
Return
Result
353 354 355 |
# File 'lib/leo_manager_client.rb', line 353 def recover_node(node) Result.new(call(CMD_RECOVER_NODE % node)) end |
#recover_ring(node) ⇒ Object
Recover ring
Args
node :: a storage node
Return
Result
362 363 364 365 |
# File 'lib/leo_manager_client.rb', line 362 def recover_ring(node) Result.new(call(CMD_RECOVER_RING % node)) nil end |
#resume(node) ⇒ Object
Resume a node in the storage cluster
Args
node :: a storage node
Return
Result
140 141 142 |
# File 'lib/leo_manager_client.rb', line 140 def resume(node) Result.new(call(CMD_RESUME % node)) end |
#set_endpoint(endpoint) ⇒ Object
Insert an endpoint in the system
Args
endpoint :: an endpoint
Return
Result
278 279 280 |
# File 'lib/leo_manager_client.rb', line 278 def set_endpoint(endpoint) Result.new(call(CMD_SET_ENDPOINT % endpoint)) end |
#start ⇒ Object
Launch LeoFS’s storage cluster
Return
Result
113 114 115 |
# File 'lib/leo_manager_client.rb', line 113 def start Result.new(call(CMD_START)) end |
#status(node = nil) ⇒ Object
Retrieve LeoFS’s system status from LeoFS Manager
Args
node :: Node
Return
Status
96 97 98 |
# File 'lib/leo_manager_client.rb', line 96 def status(node=nil) Status.new(call(CMD_STATUS % node)) end |
#suspend(node) ⇒ Object
Suspend a node in the storage cluster
Args
node :: a storage node
Return
Result
131 132 133 |
# File 'lib/leo_manager_client.rb', line 131 def suspend(node) Result.new(call(CMD_SUSPEND % node)) end |
#update_acl(bucket, accesskey, acl) ⇒ Object
Update acl of a bucket
Args
bucket_name :: a bucket name
access_key_id :: access key id
acl :: acl of a bucket
Return
Result
335 336 337 |
# File 'lib/leo_manager_client.rb', line 335 def update_acl(bucket, accesskey, acl) Result.new(call(CMD_UPDATE_ACL % [bucket, accesskey, acl])) end |
#update_user_password(user_id, new_password) ⇒ Object
Update password of a user
Args
user_id :: user id
new_password :: new password
Return
Result
252 253 254 |
# File 'lib/leo_manager_client.rb', line 252 def update_user_password(user_id, new_password) Result.new(call(CMD_UPD_USER_PASS % [user_id, new_password])) end |
#update_user_role(user_id, role) ⇒ Object
Update role of a user
Args
user_id :: user id
role :: operation role of a user
Return
Result
240 241 242 243 244 |
# File 'lib/leo_manager_client.rb', line 240 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 Result.new(call(CMD_UPD_USER_ROLE % [user_id, role])) end |
#version ⇒ Object
Retrieve LeoFS’s version from LeoFS Manager
Return
Version of LeoFS
86 87 88 89 |
# File 'lib/leo_manager_client.rb', line 86 def version h = call(CMD_VERSION) return h[:result] end |
#whereis(path) ⇒ Object
Retrieve assigned file information
Args
path :: an object path
Return
Array of AssignedFile
156 157 158 159 |
# File 'lib/leo_manager_client.rb', line 156 def whereis(path) assigned_info = call(CMD_WHEREIS % path)[:assigned_info] assigned_info.map {|h| AssignedFile.new(h)} end |