Last active
January 18, 2021 12:27
-
-
Save dtantsur/7e614963d48cd929ef39fa60c0b34a3d to your computer and use it in GitHub Desktop.
Ramdisk deployment with a configdrive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://gist.github.com/dtantsur/7e614963d48cd929ef39fa60c0b34a3d | |
import os | |
import sys | |
import openstack | |
try: | |
node_id = sys.argv[1] | |
ip = sys.argv[2] | |
except IndexError: | |
sys.exit( | |
f"Usage: {sys.argv[0]} <node ID> <IP address> [<kernel> <initramfs>]") | |
try: | |
kernel = sys.argv[3] | |
initramfs = sys.argv[4] | |
except IndexError: | |
kernel = "file:///httpboot/ramdisk.kernel" | |
initramfs = "file:///httpboot/ramdisk.initramfs" | |
# Using environment variables for connection parameters | |
conn = openstack.connect().baremetal | |
node = conn.get_node(node_id) | |
port = next(conn.ports(node=node_id)) | |
meta_data = { | |
"public_keys": { | |
"0": open(os.path.expanduser("~/.ssh/id_ed25519.pub"), "rt").read(), | |
} | |
} | |
network_data = { | |
"links": [ | |
{ | |
"id": f"port-{port.id}", | |
"type": "phy", | |
"ethernet_mac_address": port.address, | |
} | |
], | |
"networks": [ | |
{ | |
"id": "network0", | |
"type": "ipv4", | |
"link": f"port-{port.id}", | |
"ip_address": ip, | |
"netmask": "255.255.255.0", | |
"network_id": "network0", | |
"routes": [] | |
} | |
], | |
"services": [] | |
} | |
conn.update_node( | |
node, | |
boot_interface="redfish-virtual-media", | |
deploy_interface="ramdisk", | |
instance_info={"kernel": kernel, | |
"ramdisk": initramfs, | |
"image_source": initramfs}, | |
) | |
conn.set_node_provision_state( | |
node, 'active', | |
config_drive={'meta_data': meta_data, 'network_data': network_data}, | |
wait=True, timeout=300, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment