@@ -111,6 +111,7 @@ class PxeServerAgent(object):
111111 NGINX_TERMINAL_PROXY_CONF_PATH = "/etc/nginx/conf.d/terminal/"
112112 NOVNC_INSTALL_PATH = BAREMETAL_LIB_PATH + "noVNC/"
113113 NOVNC_TOKEN_PATH = NOVNC_INSTALL_PATH + "tokens/"
114+ ARM_GRUB_CFG = TFTPBOOT_PATH + "grub.cfg"
114115
115116 NMAP_BROADCAST_DHCP_DISCOVER_PATH = "/usr/share/nmap/scripts/broadcast-dhcp-discover.nse"
116117
@@ -223,7 +224,10 @@ def init(self, req):
223224 dhcp_conf = """interface={DHCP_INTERFACE}
224225port=0
225226bind-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
227231enable-tftp
228232tftp-root={TFTPBOOT_PATH}
229233log-facility={DNSMASQ_LOG_PATH}
@@ -265,7 +269,7 @@ def init(self, req):
265269listen_ipv6=YES
266270pam_service_name=vsftpd
267271userlist_enable=YES
268- tcp_wrappers=YES
272+ # tcp_wrappers=YES
269273xferlog_enable=YES
270274xferlog_std_format=YES
271275xferlog_file={VSFTPD_LOG_PATH}
@@ -278,13 +282,24 @@ def init(self, req):
278282 pxelinux_cfg = """default zstack_baremetal
279283prompt 0
280284label zstack_baremetal
281- kernel zstack/vmlinuz
285+ kernel zstack/x86_64/ vmlinuz
282286ipappend 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
284288""" .format (PXESERVER_DHCP_NIC_IP = pxeserver_dhcp_nic_ip )
285289 with open (self .PXELINUX_DEFAULT_CFG , 'w' ) as f :
286290 f .write (pxelinux_cfg )
287291
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+
288303 # init inspector_ks.cfg
289304 ks_tmpl_path = os .path .join (os .path .dirname (os .path .realpath (__file__ )), 'ks_tmpl' )
290305 with open ("%s/inspector_ks_tmpl" % ks_tmpl_path , 'r' ) as fr :
@@ -366,10 +381,10 @@ def ping(self, req):
366381
367382 # DETECT ROGUE DHCP SERVER
368383 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 ])
373388
374389 # make sure pxeserver is running if it's Enabled
375390 if cmd .enabled :
@@ -468,6 +483,23 @@ def _create_pxelinux_cfg(self, cmd):
468483 with open (pxe_cfg_file , 'w' ) as f :
469484 f .write (pxelinux_cfg )
470485
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+
471503 def _create_preconfiguration_file (self , cmd ):
472504 # in case user didn't seleted a preconfiguration template etc.
473505 cmd .preconfigurationContent = cmd .preconfigurationContent if cmd .preconfigurationContent != "" else """
@@ -969,12 +1001,18 @@ def delete_bm_configs(self, req):
9691001 bash_r ("rm -f %s/*" % self .NGINX_TERMINAL_PROXY_CONF_PATH )
9701002 if os .path .exists (self .NOVNC_TOKEN_PATH ):
9711003 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 )
9721006 else :
9731007 mac_as_name = cmd .pxeNicMac .replace (":" , "-" )
9741008 pxe_cfg_file = os .path .join (self .PXELINUX_CFG_PATH , "01-" + mac_as_name )
9751009 if os .path .exists (pxe_cfg_file ):
9761010 os .remove (pxe_cfg_file )
9771011
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+
9781016 ks_cfg_file = os .path .join (self .KS_CFG_PATH , mac_as_name )
9791017 if os .path .exists (ks_cfg_file ):
9801018 os .remove (ks_cfg_file )
@@ -1098,7 +1136,10 @@ def download_imagestore(self, req):
10981136 # SUSE
10991137 ret5 = bash_r ("cp %s %s" % (os .path .join (mount_path , "boot/*/loader/linux" ), os .path .join (vmlinuz_path , "vmlinuz" )))
11001138 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 ):
11021143 raise PxeServerError ("failed to copy vmlinuz and initrd.img from image[uuid:%s] to baremetal tftp server" % cmd .imageUuid )
11031144
11041145 logger .info ("successfully downloaded image[uuid:%s] and mounted it" % cmd .imageUuid )
0 commit comments