#coding:utf-8

import sunhpc.commands
class Command(sunhpc.commands.set.host.command):
    """
    Set the number of CPUs for a list of hosts.
    
    <arg type='string' name='host' repeat='1'>
    One or more host names.
    </arg>

    <arg type='string' name='cpus'>
    The number of CPUs to assign to each host.
    </arg>

    <param optional='1' type='string' name='cpus'>
    Can be used in place of the cpus argument.
    </param>

    <example cmd='set host cpus compute-0-0 2'>
    Sets the CPU value to 2 for compute-0-0.
    </example>

    <example cmd='set host cpus compute-0-0 compute-0-1 4'>
    Sets the CPU value to 4 for compute-0-0 and compute-0-1.
    </example>

    <example cmd='set host cpus compute-0-0 compute-0-1 cpus=4'>
    Same as above.
    </example>
    """

    def run(self, params, args):
        (args, cpus) = self.fillPositionalArgs(('cpus',))
        
        if not len(args):
            self.abort('must supply host')
        if not cpus:
            self.abort('must supply cpus')
            
        for host in self.getHostnames(args):
            self.db.execute("""update nodes set cpus=%d where
                name='%s'""" % (int(cpus), host))
            
RollName = "base"
