@@ -111,6 +111,7 @@ class PxeServerAgent(object):
111
111
NGINX_TERMINAL_PROXY_CONF_PATH = "/etc/nginx/conf.d/terminal/"
112
112
NOVNC_INSTALL_PATH = BAREMETAL_LIB_PATH + "noVNC/"
113
113
NOVNC_TOKEN_PATH = NOVNC_INSTALL_PATH + "tokens/"
114
+ ARM_GRUB_CFG = TFTPBOOT_PATH + "grub.cfg"
114
115
115
116
NMAP_BROADCAST_DHCP_DISCOVER_PATH = "/usr/share/nmap/scripts/broadcast-dhcp-discover.nse"
116
117
@@ -223,7 +224,10 @@ def init(self, req):
223
224
dhcp_conf = """interface={DHCP_INTERFACE}
224
225
port=0
225
226
bind-interfaces
226
- dhcp-boot=pxelinux.0
227
+ dhcp-match=x86PC, option:client-arch, 0 #LEGACLY x86
228
+ dhcp-match=AARCH64_EFI, option:client-arch, 11 #EFI AARCH64
229
+ dhcp-boot=tag:x86PC,pxelinux.0
230
+ dhcp-boot=tag:AARCH64_EFI,grubaa64.efi
227
231
enable-tftp
228
232
tftp-root={TFTPBOOT_PATH}
229
233
log-facility={DNSMASQ_LOG_PATH}
@@ -265,7 +269,7 @@ def init(self, req):
265
269
listen_ipv6=YES
266
270
pam_service_name=vsftpd
267
271
userlist_enable=YES
268
- tcp_wrappers=YES
272
+ # tcp_wrappers=YES
269
273
xferlog_enable=YES
270
274
xferlog_std_format=YES
271
275
xferlog_file={VSFTPD_LOG_PATH}
@@ -278,13 +282,24 @@ def init(self, req):
278
282
pxelinux_cfg = """default zstack_baremetal
279
283
prompt 0
280
284
label zstack_baremetal
281
- kernel zstack/vmlinuz
285
+ kernel zstack/x86_64/ vmlinuz
282
286
ipappend 2
283
- append initrd=zstack/initrd.img devfs=nomount ksdevice=bootif ks=ftp://{PXESERVER_DHCP_NIC_IP}/ks/inspector_ks.cfg vnc
287
+ append initrd=zstack/x86_64/ initrd.img devfs=nomount ksdevice=bootif ks=ftp://{PXESERVER_DHCP_NIC_IP}/ks/inspector_ks.cfg vnc
284
288
""" .format (PXESERVER_DHCP_NIC_IP = pxeserver_dhcp_nic_ip )
285
289
with open (self .PXELINUX_DEFAULT_CFG , 'w' ) as f :
286
290
f .write (pxelinux_cfg )
287
291
292
+ #init grub.cfg for arm
293
+ grub_cfg = """set timeout=10
294
+ menuentry 'ZStack Get Hardware Info' {
295
+ linux zstack/aarch64/vmlinuz ip=dhcp inst.repo=ftp://%s/zstack-dvd inst.ks=ftp://%s/ks/inspector_ks.cfg \
296
+ console=tty0 console=ttyS0,115200n8 rd.debug rd.udev.debug systemd.log_level=debug
297
+ initrd zstack/aarch64/initrd.img
298
+ }
299
+ """ % (pxeserver_dhcp_nic_ip , pxeserver_dhcp_nic_ip )
300
+ with open (self .ARM_GRUB_CFG , 'w' ) as f :
301
+ f .write (grub_cfg )
302
+
288
303
# init inspector_ks.cfg
289
304
ks_tmpl_path = os .path .join (os .path .dirname (os .path .realpath (__file__ )), 'ks_tmpl' )
290
305
with open ("%s/inspector_ks_tmpl" % ks_tmpl_path , 'r' ) as fr :
@@ -366,10 +381,10 @@ def ping(self, req):
366
381
367
382
# DETECT ROGUE DHCP SERVER
368
383
cmd = json_object .loads (req [http .REQUEST_BODY ])
369
- if platform . machine () == "x86_64" :
370
- ret , output = bash_ro ("nmap -sU -p67 --script broadcast-dhcp-discover -e %s | grep 'Server Identifier'" % cmd .dhcpInterface )
371
- if ret == 0 :
372
- raise PxeServerError ("rogue dhcp server[IP:%s] detected" % output .strip ().split (' ' )[- 1 ])
384
+ mac = self . _get_mac_address ( cmd . dhcpInterface )
385
+ ret , output = bash_ro ("nmap -sU -p67 --script broadcast-dhcp-discover --script-args broadcast-dhcp-discover.mac=%s - e %s | grep 'Server Identifier'" % ( mac , cmd .dhcpInterface ) )
386
+ if ret == 0 :
387
+ raise PxeServerError ("rogue dhcp server[IP:%s] detected" % output .strip ().split (' ' )[- 1 ])
373
388
374
389
# make sure pxeserver is running if it's Enabled
375
390
if cmd .enabled :
@@ -468,6 +483,23 @@ def _create_pxelinux_cfg(self, cmd):
468
483
with open (pxe_cfg_file , 'w' ) as f :
469
484
f .write (pxelinux_cfg )
470
485
486
+ # init grub.cfg-MAC for arm
487
+ pxe_cfg_file_arm = os .path .join (self .TFTPBOOT_PATH , "grub.cfg-01-" + cmd .pxeNicMac )
488
+ pxeserver_dhcp_nic_ip = self ._get_ip_address (cmd .dhcpInterface ).strip ()
489
+ grub_cfg = """set default="0"
490
+ set timeout=10
491
+ menuentry 'ZStack Baremetal' {{
492
+ linux {IMAGEUUID}/vmlinuz ip=dhcp inst.repo=ftp://{PXESERVER_DHCP_NIC_IP}/{IMAGEUUID}/ inst.ks=ftp://{PXESERVER_DHCP_NIC_IP}/ks/{KS_CFG_NAME} \
493
+ console=tty0 console=ttyS0,115200n8 rd.debug rd.udev.debug systemd.log_level=debug
494
+ initrd {IMAGEUUID}/initrd.img
495
+ }}
496
+ """ .format (IMAGEUUID = cmd .imageUuid ,
497
+ PXESERVER_DHCP_NIC_IP = pxeserver_dhcp_nic_ip ,
498
+ KS_CFG_NAME = ks_cfg_name
499
+ )
500
+ with open (pxe_cfg_file_arm , 'w' ) as f :
501
+ f .write (grub_cfg )
502
+
471
503
def _create_preconfiguration_file (self , cmd ):
472
504
# in case user didn't seleted a preconfiguration template etc.
473
505
cmd .preconfigurationContent = cmd .preconfigurationContent if cmd .preconfigurationContent != "" else """
@@ -969,12 +1001,18 @@ def delete_bm_configs(self, req):
969
1001
bash_r ("rm -f %s/*" % self .NGINX_TERMINAL_PROXY_CONF_PATH )
970
1002
if os .path .exists (self .NOVNC_TOKEN_PATH ):
971
1003
bash_r ("rm -f %s/*" % self .NOVNC_TOKEN_PATH )
1004
+ if os .path .exists (self .TFTPBOOT_PATH ):
1005
+ bash_r ("rm -f %s/grub.cfg*" % self .TFTPBOOT_PATH )
972
1006
else :
973
1007
mac_as_name = cmd .pxeNicMac .replace (":" , "-" )
974
1008
pxe_cfg_file = os .path .join (self .PXELINUX_CFG_PATH , "01-" + mac_as_name )
975
1009
if os .path .exists (pxe_cfg_file ):
976
1010
os .remove (pxe_cfg_file )
977
1011
1012
+ arm_pxe_cfg_file = os .path .join (self .TFTPBOOT_PATH , "grub.cfg-01-" + mac_as_name )
1013
+ if os .path .exists (arm_pxe_cfg_file ):
1014
+ os .remove (arm_pxe_cfg_file )
1015
+
978
1016
ks_cfg_file = os .path .join (self .KS_CFG_PATH , mac_as_name )
979
1017
if os .path .exists (ks_cfg_file ):
980
1018
os .remove (ks_cfg_file )
@@ -1098,7 +1136,10 @@ def download_imagestore(self, req):
1098
1136
# SUSE
1099
1137
ret5 = bash_r ("cp %s %s" % (os .path .join (mount_path , "boot/*/loader/linux" ), os .path .join (vmlinuz_path , "vmlinuz" )))
1100
1138
ret6 = bash_r ("cp %s %s" % (os .path .join (mount_path , "boot/*/loader/initrd" ), os .path .join (vmlinuz_path , "initrd.img" )))
1101
- if (ret1 != 0 or ret2 != 0 ) and (ret3 != 0 or ret4 != 0 ) and (ret5 != 0 or ret6 != 0 ):
1139
+ # ns10
1140
+ ret7 = bash_r ("cp %s %s" % (os .path .join (mount_path , "images/pxeboot/vmlinuz" ), os .path .join (vmlinuz_path , "vmlinuz" )))
1141
+ ret8 = bash_r ("cp %s %s" % (os .path .join (mount_path , "images/pxeboot/initrd.img" ), os .path .join (vmlinuz_path , "initrd.img" )))
1142
+ if (ret1 != 0 or ret2 != 0 ) and (ret3 != 0 or ret4 != 0 ) and (ret5 != 0 or ret6 != 0 ) and (ret7 != 0 or ret8 != 0 ):
1102
1143
raise PxeServerError ("failed to copy vmlinuz and initrd.img from image[uuid:%s] to baremetal tftp server" % cmd .imageUuid )
1103
1144
1104
1145
logger .info ("successfully downloaded image[uuid:%s] and mounted it" % cmd .imageUuid )
0 commit comments