From nobody Tue Oct 29 13:24:53 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Xd9wP5VPsz5bSg6; Tue, 29 Oct 2024 13:24:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Xd9wP4hhNz4CNK; Tue, 29 Oct 2024 13:24:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730208293; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=CycGij8Y8VzqNfoftdfNDu9+S+Q0LMvXLTIBtBrYSMU=; b=heGG3lw/o/fNLrAeAQxWuvtBsDLWRz/U8waATEa9ZkCciPmluoBGQmg4QDb+wo4fWkBCtv yZWNUTcGqNnyB/HQAubI5h+Ct8ewrR8pMEbBlqrTxnb8gNBAdsVAxRDSc7pf9z07/Pvs8o kqeAtoTeS6oRjHKJAUN2LYqSgDQbUqySjNBrCS3covOHTfGTG1NyOr6rgeQ5Si1X54YogL U/Potf647gqgv0lWASUq9gOa10rL6g9ycckgDQKehho9YoNRui/Px/bMwutItPgvK02Gha 0/Drwwrlv4l3NzwxdXOKLO/K2xKDrloq8H4YBJOjrC67cQIe3eKqS9vJJ/c7LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730208293; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=CycGij8Y8VzqNfoftdfNDu9+S+Q0LMvXLTIBtBrYSMU=; b=NS6OogKp+RPEMBgEqb0K8+Uu9/u8fUVGbeH09hg42111KrHCRkdGOOlbMChIT0FYoqModU c4b4GpMM8Y1YFpW8jmtoHCMdWPyksxA8DekG71otwR8rz+7l6tseaT74bYKhg05/aEYTh0 tQZRNUQn/TyTfz6ysRaGsF2kAohLPrHrXz7gflIQeVveB0o83Ynn8HjoiEslRuEb4auxDx BsUFtA3WsQ/Q+gWT9pt84jj6RPToUv+no0nv8CQO6Jiali7iztHL5e3G8zLDMMVsLyr8SK VbR8y+I59v6MjOIy+XYIXhHEN0i6c00y4heuj9wQMDwX5aRShQNJxtWlSQ9tfw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730208293; a=rsa-sha256; cv=none; b=epIf64wtm0BPrUj/xX6CLoAYz9emxdvPcuoiDXGrIkNb7WqQxZIpWFyaI7ggpA7o8Y4ZNh iJxMNBdl+EtNXcr6SxblQU1//UivfhB+YWKOJUS6MdyUuLYijD6q3EKAvNb7th1OTtWJ3O 0H9efN1sAMNqbS0VyY+lT0j7DC1hSJXAn5lQBoNPvtAKSOBozqYelc/B+/M0xxUheB7OVO aLaiSH31Cm0UZMT1AVkEDjfWVqL495lYjGpE1IhB8ZKpaPQdncrF096TkjiO7gcW2yOimy RHiVVLeiZQrOx8+dzb8XzTD3SG9yYo8akBT5ZAzfTehHAmHp+OoyLcDH4ct2ig== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Xd9wP4BjtzQKW; Tue, 29 Oct 2024 13:24:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49TDOr50017554; Tue, 29 Oct 2024 13:24:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49TDOrqu017551; Tue, 29 Oct 2024 13:24:53 GMT (envelope-from git) Date: Tue, 29 Oct 2024 13:24:53 GMT Message-Id: <202410291324.49TDOrqu017551@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: 2775b9b0bcc2 - main - nuageinit: add support for OpenStack network config List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2775b9b0bcc278dd4183b57784953c26a3fcdc89 Auto-Submitted: auto-generated The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=2775b9b0bcc278dd4183b57784953c26a3fcdc89 commit 2775b9b0bcc278dd4183b57784953c26a3fcdc89 Author: Baptiste Daroussin AuthorDate: 2024-10-29 13:17:39 +0000 Commit: Baptiste Daroussin CommitDate: 2024-10-29 13:23:47 +0000 nuageinit: add support for OpenStack network config Add naive support for openstack network config. if no config driver have been found, try to detect that we are running a VM on openstack via the smbios information, use the first iface available and temporary activate dhcp on it, to be able to fetch the necessary informations for cloudinit. While here make the rc script execute after devmatch, some ethernet device might be attached via devmatch and may be needed for cloudinit. Tested on OVHCloud Public Cloud. MFC after: 3 weeks Sponsored by: OVHCloud --- libexec/rc/rc.d/nuageinit | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/libexec/rc/rc.d/nuageinit b/libexec/rc/rc.d/nuageinit index a44761ea1d9e..54e5b1fbec07 100755 --- a/libexec/rc/rc.d/nuageinit +++ b/libexec/rc/rc.d/nuageinit @@ -2,7 +2,7 @@ # # PROVIDE: nuageinit -# REQUIRE: mountcritlocal zfs +# REQUIRE: mountcritlocal zfs devmatch # BEFORE: NETWORKING # KEYWORD: firstboot @@ -14,6 +14,18 @@ start_cmd="nuageinit_start" stop_cmd=":" rcvar="nuageinit_enable" +fetch_openstack() +{ + cd /media/nuageinit/openstack/latest + for file in meta_data.json network_data.json user_data; do + fetch http://169.254.169.254/openstack/latest/$file || : + done + if [ -f user_data ]; then + chmod 755 user_data + fi + cd - +} + nuageinit_start() { local citype @@ -34,13 +46,28 @@ nuageinit_start() fi unset drive done - if [ -z "$drive" ]; then - # try to detect networked based instance - err 1 "Impossible to find a cloud init provider" + if [ -n "$drive" ]; then + mkdir -p /media/nuageinit + fs=$(fstyp $drive 2> /dev/null) + mount -t $fs $drive /media/nuageinit + else + product=$(kenv smbios.system.product) + case "$product" in + OpenStack*) + mkdir -p /media/nuageinit/openstack/latest + ifaces=$(ifconfig -l ether) + set -- $ifaces + dhclient -p /tmp/ephemeraldhcp.pid $1 + fetch_openstack + pkill -F /tmp/ephemeraldhcp.pid + citype=config-2 + ;; + *) + # try to detect networked based instance + err 1 "Impossible to find a cloud init provider" + ;; + esac fi - mkdir -p /media/nuageinit - fs=$(fstyp $drive 2> /dev/null) - mount -t $fs $drive /media/nuageinit # according to the specification, the content is either # in the openstack or ec2 directory case "$citype" in @@ -59,8 +86,10 @@ nuageinit_start() esac if [ -n "$drive" ]; then umount /media/nuageinit + rmdir /media/nuageinit + else + rm -rf /media/nuageinit fi - rmdir /media/nuageinit } load_rc_config $name