Skip to content

Instantly share code, notes, and snippets.

@MACscr
Last active December 19, 2015 21:00
Show Gist options
  • Save MACscr/d89fb627d8cede20c378 to your computer and use it in GitHub Desktop.
Save MACscr/d89fb627d8cede20c378 to your computer and use it in GitHub Desktop.
create default pxe menus for each cluster host
#!/usr/bin/php -q
<?php
// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
function foreman_api($request) {
$username = 'apiuser';
$password = '##########';
$server = 'puppet';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => "https://$server/api/v2/$request",
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_USERPWD => $username . ":" . $password,
));
$response = curl_exec($curl);
curl_close($curl);
// put entire response into an array
return json_decode($response, true);
}
function get_hosts($group, $verbose = false) {
$hostgroup_hosts = foreman_api("hostgroups/$group/hosts");
return $hostgroup_hosts['results'];
}
$storage = get_hosts(3,true);
$kvm_hosts = get_hosts(4,true);
$cluster = array_merge($storage,$kvm_hosts);
foreach ($cluster as $host) {
$host_short = array_shift((explode(".",$host['name'])));
$hostname = $host['name'];
$mac = str_replace(':','-',$host['mac']);
$pxe_template = "
DEFAULT menu
PROMPT 1
MENU TITLE PXE Menu
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT proxmox_iscsi
LABEL proxmox_iscsi
MENU LABEL Proxmox ISCSI Boot
KERNEL boot/iscsi-vmlinuz
APPEND initrd=boot/$host_short-iscsi-initrd.img BOOTIF=$mac INTERFACE=auto IP=dhcp HOSTNAME=$hostname ISCSI_INITIATOR=iqn.2015-012.gluster:storage:$host_short-client ISCSI_TARGET_NAME=iqn.2015-012.gluster:storage:$host_short ISCSI_USERNAME=####### ISCSI_PASSWORD=########## ISCSI_TARGET_IP=192.168.0.17 ISCSI_TARGET_PORT=3260 root=UUID=6251cd48-3299-4134-b3f5-da9fedeb78e0 rw
LABEL proxmox_iscsi_single
MENU LABEL Proxmox ISCSI Boot - Single User Mode
KERNEL boot/iscsi-vmlinuz
APPEND initrd=boot/$host_short-iscsi-initrd.img BOOTIF=$mac INTERFACE=auto IP=dhcp HOSTNAME=$hostname ISCSI_INITIATOR=iqn.2015-012.gluster:storage:$host_short-client ISCSI_TARGET_NAME=iqn.2015-012.gluster:storage:$host_short ISCSI_USERNAME=######## ISCSI_PASSWORD=######## ISCSI_TARGET_IP=192.168.0.17 ISCSI_TARGET_PORT=3260 root=UUID=6251cd48-3299-4134-b3f5-da9fedeb78e0 rw init=/bin/bash
";
$file = "/var/lib/lxc/puppet/rootfs/srv/tftp/pxelinux.cfg/01-$mac";
file_put_contents($file, $pxe_template);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment