mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Bug 8208 - bare metal provisioning
Work with PING
This commit is contained in:
parent
ab643851c5
commit
5819e8fee0
@ -10,5 +10,4 @@ public class PrepareLinMinPxeServerAnswer extends Answer {
|
|||||||
public PrepareLinMinPxeServerAnswer(PrepareLinMinPxeServerCommand cmd, String details) {
|
public PrepareLinMinPxeServerAnswer(PrepareLinMinPxeServerCommand cmd, String details) {
|
||||||
super(cmd, false, details);
|
super(cmd, false, details);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,62 +2,9 @@ package com.cloud.agent.api.baremetal;
|
|||||||
|
|
||||||
import com.cloud.agent.api.Command;
|
import com.cloud.agent.api.Command;
|
||||||
|
|
||||||
public class PrepareLinMinPxeServerCommand extends Command {
|
public class PrepareLinMinPxeServerCommand extends PreparePxeServerCommand {
|
||||||
String ip;
|
|
||||||
String mac;
|
|
||||||
String netMask;
|
|
||||||
String gateway;
|
|
||||||
String dns;
|
|
||||||
String template;
|
|
||||||
String vmName;
|
|
||||||
String hostName;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean executeInSequence() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PrepareLinMinPxeServerCommand(String ip, String mac, String netMask, String gateway, String dns, String template, String vmName, String hostName) {
|
public PrepareLinMinPxeServerCommand(String ip, String mac, String netMask, String gateway, String dns, String template, String vmName, String hostName) {
|
||||||
this.ip = ip;
|
super(ip, mac, netMask, gateway, dns, template, vmName, hostName);
|
||||||
this.mac = mac;
|
|
||||||
this.netMask = netMask;
|
|
||||||
this.gateway = gateway;
|
|
||||||
this.dns = dns;
|
|
||||||
this.template = template;
|
|
||||||
this.vmName = vmName;
|
|
||||||
this.hostName = hostName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIp() {
|
|
||||||
return ip;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMac() {
|
|
||||||
return mac;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNetMask() {
|
|
||||||
return netMask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getGateWay() {
|
|
||||||
return gateway;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDns() {
|
|
||||||
return dns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTemplate() {
|
|
||||||
return template;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVmName() {
|
|
||||||
return vmName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHostName() {
|
|
||||||
return hostName;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,13 @@
|
|||||||
|
package com.cloud.agent.api.baremetal;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.Answer;
|
||||||
|
|
||||||
|
public class PreparePxeServerAnswer extends Answer {
|
||||||
|
public PreparePxeServerAnswer(PreparePxeServerCommand cmd) {
|
||||||
|
super(cmd, true, "SUCCESS");
|
||||||
|
}
|
||||||
|
|
||||||
|
public PreparePxeServerAnswer(PreparePxeServerCommand cmd, String details) {
|
||||||
|
super(cmd, false, details);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,64 @@
|
|||||||
|
package com.cloud.agent.api.baremetal;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.Command;
|
||||||
|
|
||||||
|
public class PreparePxeServerCommand extends Command {
|
||||||
|
|
||||||
|
String ip;
|
||||||
|
String mac;
|
||||||
|
String netMask;
|
||||||
|
String gateway;
|
||||||
|
String dns;
|
||||||
|
String template;
|
||||||
|
String vmName;
|
||||||
|
String hostName;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean executeInSequence() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PreparePxeServerCommand(String ip, String mac, String netMask, String gateway, String dns, String template, String vmName, String hostName) {
|
||||||
|
this.ip = ip;
|
||||||
|
this.mac = mac;
|
||||||
|
this.netMask = netMask;
|
||||||
|
this.gateway = gateway;
|
||||||
|
this.dns = dns;
|
||||||
|
this.template = template;
|
||||||
|
this.vmName = vmName;
|
||||||
|
this.hostName = hostName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIp() {
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMac() {
|
||||||
|
return mac;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNetMask() {
|
||||||
|
return netMask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGateWay() {
|
||||||
|
return gateway;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDns() {
|
||||||
|
return dns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTemplate() {
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVmName() {
|
||||||
|
return vmName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHostName() {
|
||||||
|
return hostName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -213,5 +213,10 @@ public class ApiConstants {
|
|||||||
public static final String PRIVATE_NETMASK = "privatenetmask";
|
public static final String PRIVATE_NETMASK = "privatenetmask";
|
||||||
public static final String PRIVATE_NETWORK_ID = "privatenetworkid";
|
public static final String PRIVATE_NETWORK_ID = "privatenetworkid";
|
||||||
public static final String USE_EXTERNAL_DHCP = "useexternaldhcp";
|
public static final String USE_EXTERNAL_DHCP = "useexternaldhcp";
|
||||||
|
public static final String PING_STORAGE_SERVER_IP = "pingstorageserverip";
|
||||||
|
public static final String PING_DIR = "pingdir";
|
||||||
|
public static final String TFTP_DIR = "tftpdir";
|
||||||
|
public static final String PING_CIFS_USERNAME = "pingcifsusername";
|
||||||
|
public static final String PING_CIFS_PASSWORD = "pingcifspassword";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -212,6 +212,7 @@
|
|||||||
<fileset dir="${scripts.dir}">
|
<fileset dir="${scripts.dir}">
|
||||||
<include name="**/*"/>
|
<include name="**/*"/>
|
||||||
<exclude name="**/fsimage.so"/>
|
<exclude name="**/fsimage.so"/>
|
||||||
|
<exclude name="**/ping.tar.bz2"/>
|
||||||
<exclude name="**/vhd-util"/>
|
<exclude name="**/vhd-util"/>
|
||||||
<exclude name="**/.*" />
|
<exclude name="**/.*" />
|
||||||
</fileset>
|
</fileset>
|
||||||
@ -222,6 +223,7 @@
|
|||||||
<copy todir="${scripts.target.dir}">
|
<copy todir="${scripts.target.dir}">
|
||||||
<fileset dir="${scripts.dir}">
|
<fileset dir="${scripts.dir}">
|
||||||
<include name="**/fsimage.so"/>
|
<include name="**/fsimage.so"/>
|
||||||
|
<include name="**/ping.tar.bz2"/>
|
||||||
<include name="**/vhd-util"/>
|
<include name="**/vhd-util"/>
|
||||||
</fileset>
|
</fileset>
|
||||||
</copy>
|
</copy>
|
||||||
|
|||||||
@ -10,8 +10,8 @@ usage = '''dhcpd_edithosts.py mac ip hostname dns gateway nextserver'''
|
|||||||
conf_path = "/etc/dhcpd.conf"
|
conf_path = "/etc/dhcpd.conf"
|
||||||
file_lock = "/etc/dhcpd.conf_locked"
|
file_lock = "/etc/dhcpd.conf_locked"
|
||||||
sleep_max = 20
|
sleep_max = 20
|
||||||
host_entry = 'host %s { hardware ethernet %s; fixed-address %s; option domain-name-servers %s; option domain-name "%s"; option routers %s; default-lease-time infinite; max-lease-time infinite; min-lease-time infinite;}'
|
host_entry = 'host %s { hardware ethernet %s; fixed-address %s; option domain-name-servers %s; option domain-name "%s"; option routers %s; default-lease-time infinite; max-lease-time infinite; min-lease-time infinite; filename "pxelinux.0";}'
|
||||||
host_entry1 = 'host %s { hardware ethernet %s; fixed-address %s; option domain-name-servers %s; option domain-name "%s"; option routers %s; default-lease-time infinite; max-lease-time infinite; min-lease-time infinite; next-server %s;}'
|
host_entry1 = 'host %s { hardware ethernet %s; fixed-address %s; option domain-name-servers %s; option domain-name "%s"; option routers %s; default-lease-time infinite; max-lease-time infinite; min-lease-time infinite; next-server %s; filename "pxelinux.0";}'
|
||||||
def lock():
|
def lock():
|
||||||
if exists(file_lock):
|
if exists(file_lock):
|
||||||
count = 0
|
count = 0
|
||||||
@ -95,6 +95,12 @@ if __name__ == "__main__":
|
|||||||
gateway = sys.argv[5]
|
gateway = sys.argv[5]
|
||||||
next_server = sys.argv[6]
|
next_server = sys.argv[6]
|
||||||
|
|
||||||
|
if exists(conf_path) == False:
|
||||||
|
conf_path = "/etc/dhcp/dhcpd.conf"
|
||||||
|
if exists(conf_path) == False:
|
||||||
|
print "Cannot find dhcpd.conf"
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
ret = insert_host_entry(mac, ip, hostname, dns, gateway, next_server)
|
ret = insert_host_entry(mac, ip, hostname, dns, gateway, next_server)
|
||||||
sys.exit(ret)
|
sys.exit(ret)
|
||||||
|
|
||||||
|
|||||||
BIN
scripts/network/ping/ping.tar.bz2
Normal file
BIN
scripts/network/ping/ping.tar.bz2
Normal file
Binary file not shown.
64
scripts/network/ping/prepare_ping.sh
Normal file
64
scripts/network/ping/prepare_ping.sh
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# usage prepare_ping.sh subnet tftp_dir
|
||||||
|
|
||||||
|
dhcpd_conf=
|
||||||
|
subnet=$1
|
||||||
|
tftp_dir=$2
|
||||||
|
|
||||||
|
exit_with_error() {
|
||||||
|
echo $1
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
exit_if_fail() {
|
||||||
|
[ $? -ne 0 ] && exit_with_error "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
config_dhcpd() {
|
||||||
|
echo "$*" >> $dhcpd_conf
|
||||||
|
[ $? -ne 0 ] && exit_with_error "echo $* failed"
|
||||||
|
}
|
||||||
|
|
||||||
|
[ $# -ne 2 ] && exit_with_error "Usage:prepare_ping.sh subnet tftp_dir"
|
||||||
|
|
||||||
|
if [ -f "/etc/dhcp/dhcpd.conf" ]; then
|
||||||
|
dhcpd_conf="/etc/dhcp/dhcpd.conf"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ x"$dhcpd_conf" == "x" ] && [ -f "/etc/dhcpd.conf" ]; then
|
||||||
|
dhcpd_conf="/etc/dhcpd.conf"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ x"$dhcpd_conf" == "x" ]; then
|
||||||
|
exit_with_error "Cannot find dhcpd.conf"
|
||||||
|
fi
|
||||||
|
|
||||||
|
signature=`head -n 1 $dhcpd_conf`
|
||||||
|
if [ x"$signature" != x"# CloudStack" ]; then
|
||||||
|
# prepare dhcpd
|
||||||
|
cp $dhcpd_conf /etc/dhcpd.conf.bak -f
|
||||||
|
exit_if_fail "Cannot back dhcpd.conf"
|
||||||
|
echo "# CloudStack" > $dhcpd_conf
|
||||||
|
echo "# This is produced by CloudStack" >> $dhcpd_conf
|
||||||
|
config_dhcpd ddns-update-style interim\;
|
||||||
|
config_dhcpd subnet $subnet netmask 255.255.255.0 {}
|
||||||
|
config_dhcpd allow booting\;
|
||||||
|
config_dhcpd allow bootp\;
|
||||||
|
fi
|
||||||
|
|
||||||
|
# prepare tftp
|
||||||
|
pushd $tftp_dir $>/dev/null
|
||||||
|
[ -f ping.tar.bz2 ] || exit_with_error "Cannot find ping.tar.bz2 at $tftp_dir"
|
||||||
|
tar xjf ping.tar.bz2
|
||||||
|
exit_if_fail "tar xjf ping.tar.bz2 failed"
|
||||||
|
#rm ping.tar.bz2 -f
|
||||||
|
#exit_if_fail "rm ping.tar.bz2 failed"
|
||||||
|
if [ ! -d pxelinux.cfg ]; then
|
||||||
|
mkdir pxelinux.cfg
|
||||||
|
exit_if_fail "Cannot create pxelinux.cfg"
|
||||||
|
fi
|
||||||
|
popd
|
||||||
|
|
||||||
|
service dhcpd restart
|
||||||
|
exit_if_fail "service dhcpd restart failed"
|
||||||
|
exit 0
|
||||||
58
scripts/network/ping/prepare_tftp_bootfile.py
Normal file
58
scripts/network/ping/prepare_tftp_bootfile.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# Usage: prepare_tftp_bootfile.py tftp_dir mac cifs_server share directory image_to_restore cifs_username cifs_password
|
||||||
|
import os, sys
|
||||||
|
from sys import exit
|
||||||
|
from os import makedirs
|
||||||
|
from os.path import exists, join
|
||||||
|
|
||||||
|
template = '''DEFAULT default
|
||||||
|
PROMPT 1
|
||||||
|
TIMEOUT 26
|
||||||
|
DISPLAY boot.msg
|
||||||
|
LABEL default
|
||||||
|
KERNEL kernel
|
||||||
|
APPEND vga=normal devfs=nomount pxe ramdisk_size=66000 load_ramdisk=1 init=/linuxrc prompt_ramdisk=0 initrd=initrd.gz root=/dev/ram0 rw noapic nolapic lba combined_mode=libata ide0=noprobe nomce pci=nomsi irqpoll quiet Server="%s" Share="%s" Directory="%s" Image_To_Restore="%s" After_Completion="Reboot" CIFS_Preferred="Y" Zsplit_Preferred="Y" AUTO="Y" User="%s" Passwd="%s" Extend_Parts_Whenever_Possible="N" Replace_BIOS="N"
|
||||||
|
'''
|
||||||
|
|
||||||
|
tftp_dir = ''
|
||||||
|
mac = ''
|
||||||
|
cifs_server = ''
|
||||||
|
share = ''
|
||||||
|
directory = ''
|
||||||
|
image_to_restore = ''
|
||||||
|
cifs_username = ''
|
||||||
|
cifs_password = ''
|
||||||
|
|
||||||
|
def prepare_boot_file():
|
||||||
|
try:
|
||||||
|
pxelinux = join(tftp_dir, "pxelinux.cfg")
|
||||||
|
if exists(pxelinux) == False:
|
||||||
|
makedirs(pxelinux)
|
||||||
|
|
||||||
|
cfg_name = "01-" + mac.replace(':','-')
|
||||||
|
cfg_path = join(pxelinux, cfg_name)
|
||||||
|
f = open(cfg_path, "w")
|
||||||
|
stuff = template % (cifs_server, share, directory, image_to_restore, cifs_username, cifs_password)
|
||||||
|
f.write(stuff)
|
||||||
|
f.close()
|
||||||
|
return 0
|
||||||
|
except IOError, e:
|
||||||
|
print e
|
||||||
|
return 1
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) < 9:
|
||||||
|
print "Usage: prepare_tftp_bootfile.py tftp_dir mac cifs_server share directory image_to_restor cifs_username cifs_password"
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
tftp_dir = sys.argv[1]
|
||||||
|
mac = sys.argv[2]
|
||||||
|
cifs_server = sys.argv[3]
|
||||||
|
share = sys.argv[4]
|
||||||
|
directory = sys.argv[5]
|
||||||
|
image_to_restore = sys.argv[6]
|
||||||
|
cifs_username = sys.argv[7]
|
||||||
|
cifs_password = sys.argv[8]
|
||||||
|
|
||||||
|
ret = prepare_boot_file()
|
||||||
|
exit(ret)
|
||||||
Loading…
x
Reference in New Issue
Block a user