karmab / kcli

Management tool for virtualization and kubernetes platforms
https://kcli.readthedocs.io/en/latest/
Apache License 2.0
502 stars 138 forks source link

set nic BOOTPROTO with static or none as default #722

Closed BurlyLuo closed 15 hours ago

BurlyLuo commented 5 days ago

issue description: when the cloud-init set the BOOTPROTO=dhcp, there will DHCPDISCOVER and wait the replay. but the bridge is not enable the dhcp feature, the network start will be failed and timeout.

# 1. centos7
kcli create vm -i       centos7 -P memory=4096 -P disks=[50] -P rootpassword=hive -P nets="[{'name':'brnet','ip':'192.168.2.96','netmask':'24','gateway':'192.168.2.1'},{'name':'vppdpdk5'},{'name':'vppdpdk8'},{'name':'vppdpdk9'}]" -P cpupinning=['{"vcpus": "0", "hostcpus": "0"}','{"vcpus": "1", "hostcpus": "1"}','{"vcpus": "2", "hostcpus": "2"}','{"vcpus": 3, "hostcpus": 3}'] -P numcpus=4 -P cmds='[rm -rf /etc/yum.repos.d/* && curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo && yum -y install net-tools pciutils wget lrzsz && wget http://192.168.2.100/kvm/tools/lseth -P /usr/bin/ && chmod +x /usr/bin/lseth]' vm

Sep 25 03:14:55 vm systemd[1]: network.service start operation timed out. Terminating.
Sep 25 03:14:55 vm systemd[1]: Failed to start LSB: Bring up/down networking.
-- Subject: Unit network.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit network.service has failed.
-- 
-- The result is failed.
Sep 25 03:14:55 vm systemd[1]: Unit network.service entered failed state.
Sep 25 03:14:55 vm systemd[1]: network.service failed.
Sep 25 03:15:01 vm dhclient[959]: No DHCPOFFERS received.
Sep 25 03:15:01 vm network[739]: Determining IP information for eth1... failed.
Sep 25 03:16:32 vm systemd[1]: Starting LSB: Bring up/down networking...
-- Subject: Unit network.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit network.service has begun starting up.
Sep 25 03:16:33 vm network[8042]: Bringing up loopback interface:  [  OK  ]
Sep 25 03:16:33 vm network[8042]: Bringing up interface eth0:  [  OK  ]
Sep 25 03:16:33 vm network[8042]: Bringing up interface eth1:
Sep 25 03:16:33 vm dhclient[8247]: DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 4 (xid=0x79d47b09)
Sep 25 03:16:37 vm dhclient[8247]: DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 9 (xid=0x79d47b09)
Sep 25 03:16:46 vm dhclient[8247]: DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 10 (xid=0x79d47b09)
Sep 25 03:16:56 vm dhclient[8247]: DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 13 (xid=0x79d47b09)
Sep 25 03:17:09 vm dhclient[8247]: DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 16 (xid=0x79d47b09)

so can we set the BOOTPROTO as none or static to avoid the block. thanks.

if change the parameter as static and restart the network service, it worked as expected.

[root@vm network-scripts]# cat ifcfg-eth1 
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=static
DEVICE=eth1
ONBOOT=yes
STARTMODE=auto
TYPE=Ethernet
USERCTL=no
[root@vm network-scripts]# 

and the service under running status:

[root@vm network-scripts]# systemctl status network 
● network.service - LSB: Bring up/down networking
   Loaded: loaded (/etc/rc.d/init.d/network; bad; vendor preset: disabled)
   Active: active (exited) since Wed 2024-09-25 03:21:15 UTC; 6min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 8436 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=0/SUCCESS)
karmab commented 15 hours ago

you can change your invocation to prevent cloudinit from setting dhcp for specific interfaces

kcli create vm -i  centos7 -P memory=4096 -P disks=[50] -P rootpassword=hive \
-P nets="[{'name':'brnet','ip':'192.168.2.96','netmask':'24','gateway':'192.168.2.1'},{'name':'vppdpdk5','noconf':'true'},{'name':'vppdpdk8','noconf':'true'},{'name':'vppdpdk9',noconf':'true''}]" \
 -P cpupinning=['{"vcpus": "0", "hostcpus": "0"}','{"vcpus": "1", "hostcpus": "1"}','{"vcpus": "2", "hostcpus": "2"}','{"vcpus": 3, "hostcpus": 3}'] -P numcpus=4 \
 -P cmds='[rm -rf /etc/yum.repos.d/* && curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo && yum -y install net-tools pciutils wget lrzsz && wget http://192.168.2.100/kvm/tools/lseth -P /usr/bin/ && chmod +x /usr/bin/lseth]' vm

side note: you should really use a plan file. Your command line can be rewritten as a plan like this

vm:
 type: vm
 image centos7
 rootpassword: hive
 memory: 4096
 numcpus: 4
 cpupinning:
 - vcpus: 0
    hostcpus: 0
 - vcpus: 1
    hostcpus: 1
 - vcpus: 2
    hostcpus: 2
  - vcpus: 3
     hostcpus: 3
 disks:
 - 50
 nets:
 - name: brnet
    ip: 192.168.2.96
    netmask: 24
    gateway: 192.168.2.1
 - name: vppdpdk5
    noconf: true
 - name: vppdpdk8
    noconf: true
 - name: vppdpdk9,
    noconf: true
 cmds:
 - rm -rf /etc/yum.repos.d/*
 - curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
 - yum -y install net-tools pciutils wget lrzsz
 - wget http://192.168.2.100/kvm/tools/lseth -P /usr/bin
 - chmod +x /usr/bin/lseth vm
BurlyLuo commented 13 hours ago

Okay, thank you