#coding:utf-8

import sunhpc.commands
class Command(sunhpc.commands.list.host.command):
    """
    Lists the interface definitions for hosts. For each host supplied on
    the command line, this command prints the hostname and interface
    definitions for that host.

    <arg optional='1' type='string' name='host' repeat='1'>
    Zero, one or more host names. If no host names are supplied, info about
    all the known hosts is listed.
    </arg>

    <example cmd='list host interface compute-0-0'>
    List network interface info for compute-0-0.
    </example>

    <example cmd='list host interface'>
    List network interface info for all known hosts.
    </example>
    """

    def run(self, params, args):

        self.beginOutput()
        for host in self.getHostnames(args):
            self.db.execute(""" SELECT s.name, n.Device, n.Mac, 
            n.ip, s.netmask, n.Name
            FROM networks n LEFT JOIN subnets s ON n.subnet=s.id 
            INNER JOIN nodes h ON n.node = h.id AND h.name='%s'""" %host)
            for row in self.db.fetchall():
                #
                # if device name matches vlan* then clear
                # fields for printing
                #
                self.addOutput(host, row)
    
        self.endOutput(header=['host', 'subnet', 'iface', 'mac', 'ip', 'netmask', 'name'])

RollName = "base"
