Skip to content

Instantly share code, notes, and snippets.

@dtantsur

dtantsur/ramdisk-deploy.py

Last active Jan 18, 2021
Embed
What would you like to do?
Ramdisk deployment with a configdrive
# 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