summaryrefslogtreecommitdiffstats
path: root/loaders/zpxe.rexx
blob: b187b2e224b53080c8a216258e8e5756d1f8c912 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/* zPXE: REXX PXE Client for System z
 
zPXE is a PXE client used with Cobbler.  It must be run under
z/VM.  zPXE uses TFTP to first download a list of profiles,
then a specific kernel, initial RAMdisk, and PARM file.  These
files are then punched to start the install process.
 
zPXE does not require a writeable 191 A disk.  Files are
downloaded to a temporary disk (VDISK).
 
zPXE can also IPL a DASD disk by default.  You can specify the
default dasd in ZPXE CONF, as well as the hostname of the Cobbler
server.
---
 
Copyright 2006-2009, Red Hat, Inc
Brad Hinson <bhinson@redhat.com>
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301  USA
*/
 
 
/* Defaults */
 
server = ''                           /* define server in ZPXE CONF */
iplDisk = 100                   /* overridden by value in ZPXE CONF */
profilelist = PROFILE LIST T    /* VDISK will be defined as T later */
profiledetail = PROFILE DETAIL T
zpxeparm = ZPXE PARM T
zpxeconf = ZPXE CONF T
config = ZPXE CONF
 
/* For translating strings to lowercase */
upper = xrange('A', 'Z')
lower = xrange('a', 'z')
 
/* Useful settings normally found in PROFILE EXEC */
'cp set run on'
'cp set pf11 retrieve forward'
'cp set pf12 retrieve'
 
/* Check for config file */
if lines(config) > 0 then do
  inputline = linein(config)    /* first line is server hostname/IP */
  parse var inputline . server .
  inputline = linein(config)     /* second line is DASD disk to IPL */
  parse var inputline . iplDisk .
end
 
/* Define temporary disk (VDISK) to store files */
'detach ffff'                             /* detach ffff if present */
'define vfb-512 as ffff blk 100000' /* 512 byte block size =~ 50 MB */
queue '1'
queue 'tmpdsk'
'format ffff t'                     /* format VDISK as file mode t */
 
/* Link TCPMAINT disk for access to TFTP */
'link tcpmaint 592 592 rr'
'access 592 e'
 
/* Query user ID.  This is used later to determine:
     1. Whether a user-specific PXE profile exists.
     2. Whether user is disconnected. If so, IPL the default disk.
*/
'pipe cp query' userid() '| var user'
parse value user with id . dsc .
userid = translate(id, lower, upper)
 
/* Check whether a user-specific PXE profile exists.
   If so, proceed with this.  Otherwise, continue and
   show the system-wide profile menu.
*/
call GetTFTP '/s390x/s_'userid 'profile.detail.t'
 
if lines(profiledetail) > 0 then do
 
  /* Get user PARM and CONF containing network info */
  call GetTFTP '/s390x/s_'userid'_parm' 'zpxe.parm.t'
  call GetTFTP '/s390x/s_'userid'_conf' 'zpxe.conf.t'
 
  vmfclear                                          /* clear screen */
  call CheckServer                             /* print server name */
  say 'Profile 'userid' found'
  say ''
 
  bootRc = ParseSystemRecord()        /* parse file for boot action */
  if bootRc = 0 then
    'cp ipl' iplDisk                           /* boot default DASD */
  else do
    call DownloadBinaries             /* download kernel and initrd */
    say 'Starting install...'
    say ''
    call PunchFiles                 /* punch files to begin install */
    exit
    end /* if bootRc = 0 */
 
end /* if user-specific profile found */
 
 
/* Download initial profile list */
call GetTFTP '/s390x/profile_list' 'profile.list.t'
 
vmfclear                                            /* clear screen */
call CheckServer                               /* print server name */
 
say 'zPXE MENU'                                        /* show menu */
say '---------'
 
count = 0
do while lines(profilelist) > 0     /* display one profile per line */
  count = count + 1
  inputline = linein(profilelist)
  parse var inputline profile.count
  say count'. 'profile.count
end
 
if (count = 0) then
  say '** Error connecting to server: no profiles found **'
 
count = count + 1
say count'. Exit to CMS shell [IPL CMS]'
say ''
say ''
say 'Enter Choice -->'
say 'or press <Enter> to boot from disk [DASD 'iplDisk']'
 
/* Check if user is disconnected, indicating
   logon by XAUTOLOG.  In this case, IPL the
   default disk.
*/
if (dsc = 'DSC') then do                    /* user is disconnected */
  say 'User disconnected.  Booting from DASD 'iplDisk'...'
  'cp ipl' iplDisk
  end
else do                            /* user is interactive -> prompt */
  parse upper pull answer .
  select
    when (answer = count)
    then do
      say 'Exiting to CMS shell...'
      exit
      end
    when (answer = '')                            /* IPL by default */
    then do
      say 'Booting from DASD 'iplDisk'...'
      'cp ipl' iplDisk
      end
    when (answer < 0) | (answer > count)         /* invalid respone */
    then do
      say 'Invalid choice, exiting to CMS shell.'
      exit
    end
    when (answer > 0) & (answer < count)          /* valid response */
    then do
      call GetTFTP '/s390x/p_'profile.answer 'profile.detail.t'
 
      /* get profile-based PARM and CONF files */
      call GetTFTP '/s390x/p_'profile.answer'_parm' 'zpxe.parm.t'
      call GetTFTP '/s390x/p_'profile.answer'_conf' 'zpxe.conf.t'
 
      vmfclear                                      /* clear screen */
      say 'Using profile 'answer' ['profile.answer']'
      say ''
      call DownloadBinaries           /* download kernel and initrd */
 
      say 'Starting install...'
      say ''
 
      call PunchFiles
 
    end /* valid answer */
    otherwise
      say 'Invalid choice, exiting to CMS shell.'
      exit
  end /* Select */
end
exit
 
 
/* Procedure CheckServer
   Print error message if server is not defined.  Otherwise
   show server name
*/
CheckServer:
 
  if server = '' then
    say '** Error: No host defined in ZPXE.CONF **'
  else say 'Connected to server 'server
  say ''
 
return 0 /* CheckServer */
 
 
/* Procedure GetTFTP
   Use CMS TFTP client to download files
     path: remote file location
     filename: local file name
     transfermode [optional]: 'ascii' or 'octet'
*/
GetTFTP:
 
  parse arg path filename transfermode
 
  if transfermode <> '' then
    queue 'mode' transfermode
  queue 'get 'path filename
  queue 'quit'
 
  'set cmstype ht'                          /* suppress tftp output */
  tftp server
  'set cmstype rt'
 
return 0 /* GetTFTP */
 
 
/* Procedure DownloadBinaries
   Download kernel and initial RAMdisk.  Convert both
   to fixed record length 80.
*/
DownloadBinaries:
 
  inputline = linein(profiledetail)         /* first line is kernel */
  parse var inputline kernelpath
  say 'Downloading kernel ['kernelpath']...'
  call GetTFTP kernelpath 'kernel.img.t' octet
 
  inputline = linein(profiledetail)        /* second line is initrd */
  parse var inputline initrdpath
  say 'Downloading initrd ['initrdpath']...'
  call GetTFTP initrdpath 'initrd.img.t' octet
 
  inputline = linein(profiledetail)  /* third line is ks kernel arg */
  parse var inputline ksline
  call lineout zpxeparm, ksline       /* add ks line to end of parm */
  call lineout zpxeparm                               /* close file */
 
  /* convert to fixed record length */
  'pipe < KERNEL IMG T | fblock 80 00 | > KERNEL IMG T'
  'pipe < INITRD IMG T | fblock 80 00 | > INITRD IMG T'
 
return 0 /* DownloadBinaries */
 
 
/* Procedure PunchFiles
   Punch the kernel, initial RAMdisk, and PARM file.
   Then IPL to start the install process.
*/
PunchFiles:
 
  'spool punch *'
  'close reader'
  'purge reader all'                       /* clear reader contents */
  'punch kernel img t (noh'                         /* punch kernel */
  'punch zpxe parm t (noh'                       /* punch PARM file */
  'punch initrd img t (noh'                         /* punch initrd */
  'change reader all keep'                  /* keep files in reader */
  'ipl 00c clear'                                 /* IPL the reader */
 
return 0 /* PunchFiles */
 
 
/* Procedure ParseSystemRecord
   Open system record file to look for local boot flag.
   Return 0 if local flag found (guest will IPL default DASD).
   Return 1 otherwise (guest will download kernel/initrd and install).
*/
ParseSystemRecord:
 
  inputline = linein(profiledetail)               /* get first line */
  parse var inputline systemaction .
  call lineout profiledetail                          /* close file */
 
  if systemaction = 'local' then
    return 0
  else
    return 1
 
/* End ParseSystemRecord */