Exemple #1
0
 def test_string_to_byte_array(self):
     self.assertEqual(
         avahi.string_to_byte_array('abc'),
         [dbus.Byte(97), dbus.Byte(98), dbus.Byte(99)])
     self.assertIsInstance(
         avahi.string_to_byte_array('abc')[0],
         dbus.Byte)
     self.assertEqual(
         avahi.string_to_byte_array(b'\x01\xff'),
         [dbus.Byte(0x01), dbus.Byte(0xff)])
     self.assertEqual(
         avahi.string_to_byte_array(u'\u00e1'),
         [dbus.Byte(0xc3), dbus.Byte(0xa1)])
    def publish(self, cname):
        """ Push the cname into the avahi stack
            copied from https://gist.github.com/gdamjan/3168336
        """
        bus = dbus.SystemBus()
        server = dbus.Interface(
            bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER),
            avahi.DBUS_INTERFACE_SERVER
        )
        group = dbus.Interface(
            bus.get_object(avahi.DBUS_NAME, server.EntryGroupNew()),
            avahi.DBUS_INTERFACE_ENTRY_GROUP
        )

        cname = self.encode(cname)
        rdata = self.encode_rdata(server.GetHostNameFqdn())
        rdata = avahi.string_to_byte_array(rdata)

        group.AddRecord(
            avahi.IF_UNSPEC,
            avahi.PROTO_UNSPEC,
            dbus.UInt32(0),
            cname,
            Settings.CLASS_IN,
            Settings.TYPE_CNAME,
            Settings.TTL,
            rdata
        )
        group.Commit()
Exemple #3
0
 def publish_cname(self, cname):
     cname = self.encode_cname(cname)
     rdata = self.encode_rdata(self.server.GetHostNameFqdn())
     rdata = avahi.string_to_byte_array(rdata)
     self.group.AddRecord(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC,
                          dbus.UInt32(0), cname, CLASS_IN, TYPE_CNAME, TTL,
                          rdata)
def publish_cname(cname):
    bus = dbus.SystemBus()
    server = dbus.Interface(bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER),
            avahi.DBUS_INTERFACE_SERVER)
    group = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.EntryGroupNew()),
            avahi.DBUS_INTERFACE_ENTRY_GROUP)

    cname = cname + '.local'
    cname = encode_cname(cname)
    rdata = encode_rdata(server.GetHostNameFqdn())
    rdata = avahi.string_to_byte_array(rdata)

    group.AddRecord(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0),
        cname, CLASS_IN, TYPE_CNAME, TTL, rdata)
    group.Commit()
Exemple #5
0
def publish_cname(cname):
    bus = dbus.SystemBus()
    server = dbus.Interface(bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER),
            avahi.DBUS_INTERFACE_SERVER)
    group = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.EntryGroupNew()),
            avahi.DBUS_INTERFACE_ENTRY_GROUP)
 
    if not u'.' in cname:
        cname = cname + '.local'
    cname = encode_cname(cname)
    rdata = encode_rdata(server.GetHostNameFqdn())
    rdata = avahi.string_to_byte_array(rdata)
 
    group.AddRecord(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0),
        cname, CLASS_IN, TYPE_CNAME, TTL, rdata)
    group.Commit()
    def publish(self, cname):
        """ Push the cname into the avahi stack
            copied from https://gist.github.com/gdamjan/3168336
        """
        bus = dbus.SystemBus()
        server = dbus.Interface(
            bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER),
            avahi.DBUS_INTERFACE_SERVER)
        group = dbus.Interface(
            bus.get_object(avahi.DBUS_NAME, server.EntryGroupNew()),
            avahi.DBUS_INTERFACE_ENTRY_GROUP)

        cname = self.encode(cname)
        rdata = self.encode_rdata(server.GetHostNameFqdn())
        rdata = avahi.string_to_byte_array(rdata)

        group.AddRecord(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0),
                        cname, Settings.CLASS_IN, Settings.TYPE_CNAME,
                        Settings.TTL, rdata)
        group.Commit()
Exemple #7
0
    def avahi(self):

        self.execute("systemctl restart avahi-daemon")

        if self.cnames:

            bus = dbus.SystemBus()
            server = dbus.Interface(
                bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER),
                avahi.DBUS_INTERFACE_SERVER)
            group = dbus.Interface(
                bus.get_object(avahi.DBUS_NAME, server.EntryGroupNew()),
                avahi.DBUS_INTERFACE_ENTRY_GROUP)

            for cname in self.cnames:
                group.AddRecord(
                    avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0),
                    self.encode_cname(cname), self.CLASS_IN, self.TYPE_CNAME,
                    self.TTL,
                    avahi.string_to_byte_array(
                        self.encode_rdata(server.GetHostNameFqdn())))

            group.Commit()