[Kea-users] How to insert properly hosts in Kea PostgreSQL database?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Kea-users] How to insert properly hosts in Kea PostgreSQL database?

Stéphane Klein
Hi,

I have this Kea static configuration:

```
{
  "Dhcp4": {
    "valid-lifetime": 4000,
    "renew-timer": 1000,
    "rebind-timer": 2000,
    "interfaces-config": {
      "interfaces": [ "enp0s8" ]
    },
    "lease-database": {
      "type": "memfile",
      "name": "/var/kea/dhcp4.leases"
    },
    "valid-lifetime": 4000,
    "subnet4": [
      {
        "subnet": "192.168.0.0/24",
        "pools": [
          {
            "pool": "192.168.0.10 - 192.168.0.20"
          }
        ],
        "reservations": [
            {
                "hw-address": "08:00:27:8e:15:8a",
                "ip-address": "192.168.0.11"
            },
            {
                "hw-address": "08:00:27:8e:15:8b",
                "ip-address": "192.168.0.12"
            }
        ]
      }
    ],
    "next-server": "192.168.0.254",
    "boot-file-name": "pxelinux.0"
  },
  "Logging": {
    "loggers": [
      {
        "name": "kea-dhcp4",
        "output_options": [
          {
            "output": "stdout"
          }
        ],
        "severity": "INFO"
      }
    ]
  }
}
```

It works perfectly.

I would like to do the same thing with PostgreSQL backend.

I have initialized my PostgreSQL database with: [dhcpdb_create.pgsql
](
https://github.com/isc-projects/kea/blob/master/src/share/database/scripts/pgsql/dhcpdb_create.pgsql
)

I have this kea configuration file:

```
{
  "Dhcp4": {
    "valid-lifetime": 4000,
    "renew-timer": 1000,
    "rebind-timer": 2000,
    "interfaces-config": {
      "interfaces": [ "enp0s8" ]
    },
    "lease-database": {
      "type": "memfile",
      "name": "/var/kea/dhcp4.leases"
    },
    "valid-lifetime": 4000,
    "hosts-database": {
      "type": "postgresql",
      "name": "kea",
      "user": "kea",
      "password": "password",
      "host": "127.0.0.1"
    },
    "subnet4": [
      {
        "subnet": "192.168.0.0/24",
        "pools": [
          {
            "pool": "192.168.0.10 - 192.168.0.20"
          }
        ]
      }
    ],
    "next-server": "192.168.0.254",
    "boot-file-name": "pxelinux.0"
  },
  "Logging": {
    "loggers": [
      {
        "name": "kea-dhcp4",
        "output_options": [
          {
            "output": "stdout"
          }
        ],
        "severity": "INFO"
      }
    ]
  }
}
```

Next, for now I have inserted this data in database:

```
DELETE FROM lease4;
INSERT INTO lease4 (
  address,
  hwaddr,
  hostname
) VALUES(
  '192.168.0.11'::inet - '0.0.0.0'::inet,
  DECODE(REPLACE('08-00-27-8e-15-8a', '-', ''), 'hex'),
  'blank_machine'
);
INSERT INTO lease4 (
  address,
  hwaddr,
  hostname
) VALUES(
  '192.168.0.12'::inet - '0.0.0.0'::inet,
  DECODE(REPLACE('08-00-27-8e-15-8b', '-', ''), 'hex'),
  'test-dhcp-server'
);
```

but this insert are incomplete.

Do you have example how to insert properly my host in Kea PostgreSQL
database?

Best regards,
Stéphane
--

_______________________________________________
Kea-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/kea-users
Reply | Threaded
Open this post in threaded view
|

Re: [Kea-users] How to insert properly hosts in Kea PostgreSQL database?

Tomek Mrugalski
On 02/27/18 15:38, Stéphane Klein wrote:
> Do you have example how to insert properly my host in Kea PostgreSQL
> database?
Have you read this http://kea.isc.org/wiki/HostReservationsHowTo?

Tomek
_______________________________________________
Kea-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/kea-users
Reply | Threaded
Open this post in threaded view
|

Re: [Kea-users] How to insert properly hosts in Kea PostgreSQL database?

Stéphane Klein


2018-02-27 16:15 GMT+01:00 Tomek Mrugalski <[hidden email]>:
On 02/27/18 15:38, Stéphane Klein wrote:
> Do you have example how to insert properly my host in Kea PostgreSQL
> database?
Have you read this http://kea.isc.org/wiki/HostReservationsHowTo?


Thanks

I have written:

DELETE FROM hosts;

INSERT INTO hosts (
  dhcp_identifier,
  dhcp_identifier_type,
  dhcp4_subnet_id,
  ipv4_address,
  hostname,
  dhcp4_next_server,
  dhcp4_server_hostname,
  dhcp4_boot_file_name
)

VALUES (
  DECODE(REPLACE('08-00-27-8e-15-8a', '-', ''), 'hex'),
    (SELECT type FROM host_identifier_type WHERE name='hw-address'),
  1,
  (SELECT ('192.168.0.11'::inet - '0.0.0.0'::inet)),
  'blank_machine',
  (SELECT ('192.168.0.254'::inet - '0.0.0.0'::inet)),
  'blank_machine',
  'pxelinux.0'
);

INSERT INTO hosts (
  dhcp_identifier,
  dhcp_identifier_type,
  dhcp4_subnet_id,
  ipv4_address,
  hostname,
  dhcp4_next_server,
  dhcp4_server_hostname,
  dhcp4_boot_file_name
)

VALUES (
  DECODE(REPLACE('08-00-27-8e-15-8b', '-', ''), 'hex'),
    (SELECT type FROM host_identifier_type WHERE name='hw-address'),
  1,
  (SELECT ('192.168.0.12'::inet - '0.0.0.0'::inet)),
  'test-dhcp-server',
  (SELECT ('192.168.0.254'::inet - '0.0.0.0'::inet)),
  'test-dhcp-server',
  'pxelinux.0'
);


_______________________________________________
Kea-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/kea-users