#!/usr/bin/env ruby

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

def usage
    puts <<USAGE
== Synopsis

oo-set-quota: Sets the quota for a gear.

== Usage

oo-set-quota -c <UUID> -b <BLOCKS> -i <INODES>

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

USAGE
end

opts = GetoptLong.new(
    ['--uuid'  , '-c', GetoptLong::REQUIRED_ARGUMENT],
    ['--blocks', '-b', GetoptLong::REQUIRED_ARGUMENT],
    ['--inodes', '-i', 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']
blocks = args['--blocks']
inodes = args['--inodes']

# modification to at least one parameter (blocks or inodes) must be requested
if !uuid or (!blocks and !inodes)
  usage
  exit -100
end

begin
  OpenShift::Node.set_quota(uuid, blocks, inodes)
rescue Exception => e
  $stderr.puts(e.message)
  exit -1
else
  exit 0
end
