def do_capacity(self, line):
        "capacity [tablename] {read_units} {write_units}"
        table, line = self.get_table_params(line)
        args = self.getargs(line)

        read_units = int(args[0])
        write_units = int(args[1])

        desc = table.describe()
        prov = desc['Table']['ProvisionedThroughput']

        current_read, current_write = prov['ReadCapacityUnits'], prov['WriteCapacityUnits']
        if read_units < current_read or write_units < current_write:
            print "%s: updating capacity to %d read units, %d write units" % (table.table_name, read_units, write_units)
            print ""
            if not table.update(throughput={'read': read_units, 'write': write_units}):
                print "update failed"
            else:
                self.do_refresh(table.table_name)

        else:
            print "%s: current capacity is %d read units, %d write units" % (table.table_name, current_read, current_write)
            # we can only double the current value at each call
            while current_read < read_units or current_write < write_units:
                if (read_units - current_read) > current_read:
                    current_read *= 2
                else:
                    current_read = read_units

                if (write_units - current_write) > current_write:
                    current_write *= 2
                else:
                    current_write = write_units

                print "%s: updating capacity to %d read units, %d write units" % (table.table_name, current_read, current_write)
                if not table.update({'read': current_read, 'write': current_write}):
                    print ""
                    print "update failed"
                    print ""
                    break
                else:
                    print ""
                    self.do_refresh(table.table_name)
                    print ""
def do_capacity ( self , line ) : table , line = self . get_table_params ( line ) args = self . getargs ( line ) read_units = int ( args [ 0 ] ) write_units = int ( args [ 1 ] ) desc = table . describe ( ) prov = desc [ 'Table' ] [ 'ProvisionedThroughput' ] current_read , current_write = prov [ 'ReadCapacityUnits' ] , prov [ 'WriteCapacityUnits' ] if read_units < current_read or write_units < current_write : print "%s: updating capacity to %d read units, %d write units" % ( table . table_name , read_units , write_units ) print "" if not table . update ( throughput = { 'read' : read_units , 'write' : write_units } ) : print "update failed" else : self . do_refresh ( table . table_name ) else : print "%s: current capacity is %d read units, %d write units" % ( table . table_name , current_read , current_write ) while current_read < read_units or current_write < write_units : if ( read_units - current_read ) > current_read : current_read *= 2 else : current_read = read_units if ( write_units - current_write ) > current_write : current_write *= 2 else : current_write = write_units print "%s: updating capacity to %d read units, %d write units" % ( table . table_name , current_read , current_write ) if not table . update ( { 'read' : current_read , 'write' : current_write } ) : print "" print "update failed" print "" break else : print "" self . do_refresh ( table . table_name ) print ""
capacity [tablename] {read_units} {write_units}