Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cloudstack provider support for Flatcar #1064

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

. /usr/share/oem/bin/cloudstack-dhcp

DHCP_SERVER=$(get_dhcp_ip)
USERDATA_URL="http://${DHCP_SERVER}/latest/user-data"

block-until-url "${USERDATA_URL}"
coreos-cloudinit --from-url="${USERDATA_URL}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

get_dhcp_ip() {
local leases_dir="/run/systemd/netif/leases"
local found=0
while true; do
for leasefile in $(find "${leases_dir}" -type f -size +1c); do
dhcp_server_ip=$(cat $leasefile | awk -F= '/SERVER_ADDRESS/ { print $2 }')
if [[ -n "${dhcp_server_ip}" ]]; then
metadata_url="http://${dhcp_server_ip}/latest/meta-data/"
if curl --fail -s "${metadata_url}" >/dev/null; then
echo $dhcp_server_ip
found=1
break
fi
fi
done
[[ $found -eq 0 ]] || break
sleep .5
done
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

. /usr/share/oem/bin/cloudstack-dhcp

DHCP_SERVER=$(get_dhcp_ip)
KEY_URL="http://${DHCP_SERVER}/latest/meta-data/public-keys"

block-until-url "${KEY_URL}"
curl --fail -s "${KEY_URL}" | update-ssh-keys -a cloudstack
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

ENV=$1

if [[ -z "$ENV" ]]; then
echo "usage: $0 /etc/environment" >&2
exit 1
fi

# Make sure that the file is writable
touch $ENV
if [[ $? -ne 0 ]]; then
echo "$0: unable to modify ${ENV}" >&2
exit 1
fi

sed -i -e '/^COREOS_PUBLIC_IPV4=/d' \
-e '/^COREOS_PRIVATE_IPV4=/d' \
"${ENV}"

. /usr/share/oem/bin/cloudstack-dhcp

DHCP_SERVER=$(get_dhcp_ip)
METADATA_URL="http://${DHCP_SERVER}/latest/meta-data/"

block-until-url "${METADATA_URL}"

PUBLIC_IP=$(curl --fail -s "${METADATA_URL}public-ipv4")
echo COREOS_PUBLIC_IPV4=${PUBLIC_IP} >> $ENV

PRIVATE_IP=$(curl --fail -s "${METADATA_URL}local-ipv4")
echo COREOS_PRIVATE_IPV4=${PRIVATE_IP} >> $ENV
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#cloud-config

coreos:
units:
- name: cloudstack-ssh-key.service
command: restart
runtime: yes
content: |
[Unit]
Description=Sets SSH key from metadata

[Service]
Type=oneshot
StandardOutput=journal+console
ExecStart=/usr/share/oem/bin/cloudstack-ssh-key
- name: cloudstack-cloudinit.service
command: restart
runtime: yes
content: |
[Unit]
Description=Cloudinit from CloudStack-style metadata
Requires=flatcar-setup-environment.service
After=flatcar-setup-environment.service

[Service]
Type=oneshot
EnvironmentFile=/etc/environment
ExecStart=/usr/share/oem/bin/cloudstack-coreos-cloudinit
oem:
id: cloudstack
name: CloudStack
version-id: 0.0.4
home-url: http://cloudstack.apache.org/
bug-report-url: https://github.com/coreos/coreos-overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Flatcar GRUB settings

set oem_id="cloudstack"
9 changes: 9 additions & 0 deletions images/capi/ansible/roles/providers/tasks/cloudstack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
owner: root
group: root
mode: 0644
when: ansible_os_family != "Flatcar"

# For Flatcar, copy the cloudstack support files into the oem partition
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this comment could probably be left out, the block is self-explanatory.

- name: Copy Cloudstack support files into the oem partition
copy:
src: files/flatcar-oem-cloudstack/
dest: /usr/share/oem/
mode: preserve
when: ansible_os_family == "Flatcar"

- name: Run dracut cmd to regenerate initramfs with all drivers - needed when converting to different hypervisor templates
shell: dracut --force --no-hostonly
Expand Down