#!/usr/bin/env ruby

require 'rubygems'
require 'openshift-origin-node'
require 'optparse'

def usage
    puts <<USAGE
== Synopsis

oo-get-quota: Gets the quota for a gear.

== Usage

oo-get-quota -c <UUID>

Options:
-h|--help:
   Prints this message

USAGE
end

opts = GetoptLong.new(
    ['--uuid', '-c', GetoptLong::REQUIRED_ARGUMENT],
    ['--help', '-?', GetoptLong::NO_ARGUMENT]
)

args = {}
begin
    opts.each{ |k,v| args[k]=v }
rescue GetoptLong::Error => e
    usage
    exit -100
end

if args["--help"]
  usage
  exit -1
end

uuid = args['--uuid']

unless uuid
  usage
  exit -100
end


begin
  quota_info = OpenShift::Node.get_quota(uuid)
  filesystem, quota, quota_soft, quota_hard, inodes, inodes_soft, inodes_hard = quota_info
  puts "Quota information for uuid: #{uuid}"
  puts "Filesystem: #{filesystem}"
  puts "Blocks used: #{quota}"
  puts "Soft limit for blocks: #{quota_soft}"
  puts "Hard limit for blocks: #{quota_hard}"
  puts "Inodes used: #{inodes}"
  puts "Soft limit for inodes: #{inodes_soft}"
  puts "Hard limit for inodes: #{inodes_hard}"
rescue Exception => e
  $stderr.puts(e.message)
  exit -1
else
  exit 0
end
