def add_host(mac, name=None, ip=None, ddns=False, group=None,
        supersede_host=False):
    '''
    Add a host object for the given mac.

    CLI Example:

    .. code-block:: bash

        salt dhcp-server omapi.add_host ab:ab:ab:ab:ab:ab name=host1

    Add ddns-hostname and a fixed-ip statements:

    .. code-block:: bash

        salt dhcp-server omapi.add_host ab:ab:ab:ab:ab:ab name=host1 ip=10.1.1.1 ddns=true
    '''
    statements = ''
    o = _conn()
    msg = omapi.OmapiMessage.open(b'host')
    msg.message.append((b'create', struct.pack(b'!I', 1)))
    msg.message.append((b'exclusive', struct.pack(b'!I', 1)))
    msg.obj.append((b'hardware-address', omapi.pack_mac(mac)))
    msg.obj.append((b'hardware-type', struct.pack(b'!I', 1)))
    if ip:
        msg.obj.append((b'ip-address', omapi.pack_ip(ip)))
    if name:
        msg.obj.append((b'name', salt.utils.stringutils.to_bytes(name)))
    if group:
        msg.obj.append((b'group', salt.utils.stringutils.to_bytes(group)))
    if supersede_host:
        statements += 'option host-name "{0}"; '.format(name)
    if ddns and name:
        statements += 'ddns-hostname "{0}"; '.format(name)
    if statements:
        msg.obj.append((b'statements', salt.utils.stringutils.to_bytes(statements)))
    response = o.query_server(msg)
    if response.opcode != omapi.OMAPI_OP_UPDATE:
        return False
    return True
def add_host ( mac , name = None , ip = None , ddns = False , group = None , supersede_host = False ) : statements = '' o = _conn ( ) msg = omapi . OmapiMessage . open ( b'host' ) msg . message . append ( ( b'create' , struct . pack ( b'!I' , 1 ) ) ) msg . message . append ( ( b'exclusive' , struct . pack ( b'!I' , 1 ) ) ) msg . obj . append ( ( b'hardware-address' , omapi . pack_mac ( mac ) ) ) msg . obj . append ( ( b'hardware-type' , struct . pack ( b'!I' , 1 ) ) ) if ip : msg . obj . append ( ( b'ip-address' , omapi . pack_ip ( ip ) ) ) if name : msg . obj . append ( ( b'name' , salt . utils . stringutils . to_bytes ( name ) ) ) if group : msg . obj . append ( ( b'group' , salt . utils . stringutils . to_bytes ( group ) ) ) if supersede_host : statements += 'option host-name "{0}"; ' . format ( name ) if ddns and name : statements += 'ddns-hostname "{0}"; ' . format ( name ) if statements : msg . obj . append ( ( b'statements' , salt . utils . stringutils . to_bytes ( statements ) ) ) response = o . query_server ( msg ) if response . opcode != omapi . OMAPI_OP_UPDATE : return False return True
Add a host object for the given mac.

    CLI Example:

    .. code-block:: bash

        salt dhcp-server omapi.add_host ab:ab:ab:ab:ab:ab name=host1

    Add ddns-hostname and a fixed-ip statements:

    .. code-block:: bash

        salt dhcp-server omapi.add_host ab:ab:ab:ab:ab:ab name=host1 ip=10.1.1.1 ddns=true