Class: CEPH::User

Inherits:
Radosgw show all
Defined in:
lib/ceph/user.rb

Instance Attribute Summary

Attributes inherited from Radosgw

#ipaddress, #uid, #user_password, #username

Instance Method Summary collapse

Methods inherited from Radosgw

#initialize

Constructor Details

This class inherits a constructor from CEPH::Radosgw

Instance Method Details

#create(uid, display_name) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ceph/user.rb', line 32

def create(uid, display_name)
  ceph_user_json = ""
  ceph_user_json = execution("sudo radosgw-admin user create --uid='#{uid}'  --display-name='#{display_name}'")
  begin
    ceph_user_hash = JSON.parse(ceph_user_json)
    secret_hash = {"access_key" => "#{ceph_user_hash['keys'][0]['access_key']}", "secret_key" => "#{ceph_user_hash['keys'][0]['secret_key']}" }
    secret_hash
  rescue JSON::ParserError => e
  return ceph_user_json
  end
end

#execution(command) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ceph/user.rb', line 3

def execution(command)
  radosgw_json =
  begin
    Net::SSH.start( @ipaddress, @username, :password => @user_password ) do|ssh|
      radosgw_json = ssh.exec!(command)
    end
  rescue Timeout::Error
    return "Timed out Error"
  rescue Errno::EHOSTUNREACH
    return "Host unreachable Error"
  rescue Errno::ECONNREFUSED
    return "Connection refused Error"
  rescue Net::SSH::AuthenticationFailed
    return "Authentication failure Error"
  end
  return radosgw_json
end

#exists(uid) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/ceph/user.rb', line 21

def exists(uid)
  ceph_user_json = ""
  ceph_user_json = execution("sudo radosgw-admin user info --uid='#{uid}'")
  begin
    JSON.parse(ceph_user_json)
    return true
  rescue JSON::ParserError => e
  return false
  end
end

#usage(uid) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ceph/user.rb', line 44

def usage(uid)
  user_usage_json = ""
  if exists(uid)
    user_usage_json = execution("sudo radosgw-admin user stats --uid='#{uid}'")

    if user_usage_json.include? "ERROR: can't read user header: (2) No such file or directory"
      usage_hash = {"total_objects" => "0", "total_bytes" => "0", "last_update" => "#{Time.now}" }
    else
      begin
        user_usage_hash = JSON.parse(user_usage_json)
        usage_hash = {"total_objects" => "#{user_usage_hash['stats']['total_entries']}", "total_bytes" => "#{user_usage_hash['stats']['total_bytes_rounded']}", "last_update" => "#{user_usage_hash['last_stats_update']}" }
        usage_hash
      rescue JSON::ParserError => e
      return user_usage_json
      end
    end
  else
    return "could not fetch user info: no user info saved"
  end
end