Class: VCAP::Quota::RepQuota

Inherits:
Command
  • Object
show all
Defined in:
lib/vcap/quota.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Command

#execute, #run

Constructor Details

#initializeRepQuota

Returns a new instance of RepQuota.



96
97
98
# File 'lib/vcap/quota.rb', line 96

def initialize
  @report_users = true
end

Instance Attribute Details

#filesystemObject

Returns the value of attribute filesystem.



94
95
96
# File 'lib/vcap/quota.rb', line 94

def filesystem
  @filesystem
end

#ids_onlyObject

Returns the value of attribute ids_only.



93
94
95
# File 'lib/vcap/quota.rb', line 93

def ids_only
  @ids_only
end

#report_groupsObject

Returns the value of attribute report_groups.



91
92
93
# File 'lib/vcap/quota.rb', line 91

def report_groups
  @report_groups
end

#report_usersObject

Returns the value of attribute report_users.



92
93
94
# File 'lib/vcap/quota.rb', line 92

def report_users
  @report_users
end

Instance Method Details

#build_commandObject



105
106
107
108
109
110
111
112
113
# File 'lib/vcap/quota.rb', line 105

def build_command
  cmd = ['repquota', '-p'] # -p reports grace as 0 when unset
  cmd << '-u' if self.report_users
  cmd << '-g' if self.report_groups
  cmd << '-n' if self.ids_only
  cmd << self.filesystem
  cmd = cmd.flatten.join(' ')
  cmd
end

#parse_result(result) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/vcap/quota.rb', line 115

def parse_result(result)
  if result[0] == 0
    quota_info = {}
    result[1].lines.each do |line|
      next unless line.match(/[^\s]+\s+[+-]+\s+\d+/)
      fields = line.split(/\s+/)
      if self.ids_only
        match = fields[0].match(/^#(\d+)$/)
        uid = match[1].to_i
      else
        uid = fields[0]
      end
      quota_info[uid] = {
        :usage => {
          :block => fields[2].to_i,
          :inode => fields[6].to_i
        },
        :quotas => {
          :block => {
            :soft => fields[3].to_i,
            :hard => fields[4].to_i,
          },
          :inode => {
            :soft => fields[7].to_i,
            :hard => fields[8].to_i,
          },
        }
      }
    end
    [true, quota_info]
  else
    [false, result]
  end
end

#validateObject



100
101
102
103
# File 'lib/vcap/quota.rb', line 100

def validate
  assert_at_least_one_of(:report_groups, :report_users)
  assert_at_least_one_of(:filesystem)
end