Skip to content

Commit

Permalink
kvm: warn when setting reservip without an ip
Browse files Browse the repository at this point in the history
  • Loading branch information
karmab committed Apr 13, 2024
1 parent 0a97f7a commit fbf766c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@ kcli create vm -i $img -P nets=['{"name":"default","ip":"192.168.122.250","netma

## ip, dns and host Reservations

If you set *reserveip* to True, a reservation will be made if the corresponding network has dhcp and when the provided IP belongs to the network range.
If you set *reserveip* to True, a reservation will be made if the corresponding network has dhcp and when the provided ip belongs to the network range. Note providing such ip is mandatory.

You can set *reservedns* to True to create a dns entry for the vm in the corresponding network ( only done for the first nic).

Expand Down Expand Up @@ -1544,9 +1544,9 @@ parameters:
|*dns*|None|Dns server|
|*domain*|None|Dns search domain|
|*start*|true||
|*vnc*|false| if set to true, vnc is used for console instead of spice|
|*vnc*|false|if set to true, vnc is used for console instead of spice|
|*cloudinit*|true||
|*reserveip*|false||
|*reserveip*|false|if set to true and an ip was provided, create a dhcp reservation in libvirt network|
|*reservedns*|false||
|*reservehost*|false||
|*keys*|[]|Array of ssh public keys to inject to the vm. Whether the actual content or the public key path|
Expand Down
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ You can also provide network configuration on the command line when creating a s
ip, dns and host Reservations
-----------------------------

If you set *reserveip* to True, a reservation will be made if the corresponding network has dhcp and when the provided IP belongs to the network range.
If you set *reserveip* to True, a reservation will be made if the corresponding network has dhcp and when the provided ip belongs to the network range. Note providing such ip is mandatory.

You can set *reservedns* to True to create a dns entry for the vm in the corresponding network ( only done for the first nic).

Expand Down Expand Up @@ -1662,7 +1662,7 @@ Parameter Default Value Comments
*start* true
*vnc* false if set to true, vnc is used for console instead of spice
*cloudinit* true
*reserveip* false
*reserveip* false if set to true and an ip was provided, create a dhcp reservation in libvirt network
*reservedns* false
*reservehost* false
*keys* [] Array of ssh public keys to inject to the vm. Whether the actual content or the public key path
Expand Down
5 changes: 4 additions & 1 deletion kvirt/providers/kvm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2340,6 +2340,9 @@ def _reserve_ip(self, name, domain, vmxml, nets, force=True, primary=False, netw
reserveip = net.get('reserveip', reserveip)
if not reserveip or ip is None or netname is None:
continue
elif reserveip and ip is None:
warning("Skipping reserveip because no ip was provided")
continue
if netname not in networks:
warning(f"Skipping incorrect network {netname}")
continue
Expand All @@ -2360,7 +2363,7 @@ def _reserve_ip(self, name, domain, vmxml, nets, force=True, primary=False, netw
currentmac = hostentry.get('mac')
if currentip == ip:
if currentname == name and currentmac is not None and currentmac == mac:
warning(f"Skipping reserved ip existing entry for ip {ip} and mac {mac}")
warning(f"Skipping reserved ip as there is an existing entry for ip {ip} and mac {mac}")
return
else:
warning(f"Removing old ip entry for ip {ip} and name {currentname}")
Expand Down

0 comments on commit fbf766c

Please sign in to comment.