underpost 2.8.816 → 2.8.818
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/deploy.js +336 -195
- package/cli.md +1 -1
- package/docker-compose.yml +1 -1
- package/manifests/deployment/dd-template-development/deployment.yaml +2 -2
- package/manifests/maas/device-scan.sh +43 -0
- package/manifests/maas/maas-setup.sh +0 -19
- package/manifests/maas/nat-iptables.sh +21 -0
- package/package.json +1 -1
- package/src/cli/baremetal.js +1 -0
- package/src/index.js +1 -1
package/README.md
CHANGED
package/bin/deploy.js
CHANGED
|
@@ -69,7 +69,9 @@ const keyboardSteps = [
|
|
|
69
69
|
`sudo dpkg-reconfigure --frontend noninteractive keyboard-configuration`,
|
|
70
70
|
`sudo systemctl restart keyboard-setup.service`,
|
|
71
71
|
];
|
|
72
|
-
|
|
72
|
+
|
|
73
|
+
const kernelLibVersion = `6.8.0-41-generic`;
|
|
74
|
+
|
|
73
75
|
const installSteps = [
|
|
74
76
|
`cat <<EOF | tee /etc/apt/sources.list
|
|
75
77
|
deb http://ports.ubuntu.com/ubuntu-ports noble main restricted universe multiverse
|
|
@@ -79,7 +81,11 @@ EOF`,
|
|
|
79
81
|
|
|
80
82
|
`apt update -qq`,
|
|
81
83
|
`apt -y full-upgrade`,
|
|
82
|
-
`apt install -y xinput x11-xkb-utils usbutils`,
|
|
84
|
+
`apt install -y build-essential xinput x11-xkb-utils usbutils`,
|
|
85
|
+
'apt install -y linux-image-generic',
|
|
86
|
+
`apt install -y linux-modules-${kernelLibVersion} linux-modules-extra-${kernelLibVersion}`,
|
|
87
|
+
|
|
88
|
+
`depmod -a ${kernelLibVersion}`,
|
|
83
89
|
// `apt install -y cloud-init=25.1.2-0ubuntu0~24.04.1`,
|
|
84
90
|
`apt install -y cloud-init systemd-sysv openssh-server sudo locales udev util-linux systemd-sysv iproute2 netplan.io ca-certificates curl wget chrony`,
|
|
85
91
|
`ln -sf /lib/systemd/systemd /sbin/init`,
|
|
@@ -89,19 +95,40 @@ EOF`,
|
|
|
89
95
|
`DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata kmod keyboard-configuration console-setup iputils-ping`,
|
|
90
96
|
];
|
|
91
97
|
|
|
98
|
+
const bootCmdSteps = [
|
|
99
|
+
`/underpost/dns.sh`,
|
|
100
|
+
`/underpost/host.sh`,
|
|
101
|
+
// `/underpost/date.sh`,
|
|
102
|
+
`/underpost/keys_import.sh`,
|
|
103
|
+
`/underpost/mac.sh`,
|
|
104
|
+
`cat /underpost/mac`,
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
const cloudInitReset = `sudo cloud-init clean --logs --seed --configs all --machine-id
|
|
108
|
+
sudo rm -rf /var/lib/cloud/*`;
|
|
109
|
+
|
|
110
|
+
const cloudConfigCmdRunFactory = (steps = []) =>
|
|
111
|
+
steps
|
|
112
|
+
.map(
|
|
113
|
+
(step, i, a) =>
|
|
114
|
+
' - echo "\\$(date) | ' + (i + 1) + '/' + a.length + ' - ' + step.split('\n')[0] + '"' + `\n` + ` - ${step}`,
|
|
115
|
+
)
|
|
116
|
+
.join('\n');
|
|
117
|
+
|
|
92
118
|
const cloudConfigFactory = (
|
|
93
|
-
{
|
|
119
|
+
{ controlServerIp, architecture, host, nfsHostPath, commissioningDeviceIp, update, gatewayip, auth },
|
|
94
120
|
{ consumer_key, consumer_secret, token_key, token_secret },
|
|
121
|
+
path = '/etc/cloud/cloud.cfg.d/90_maas.cfg',
|
|
95
122
|
) => [
|
|
96
123
|
// Configure cloud-init for MAAS
|
|
97
|
-
`cat <<EOF_MAAS_CFG >
|
|
124
|
+
`cat <<EOF_MAAS_CFG > ${path}
|
|
98
125
|
#cloud-config
|
|
99
126
|
|
|
100
127
|
hostname: ${host}
|
|
101
128
|
# fqdn: server01.midominio.cl
|
|
102
129
|
# prefer_fqdn_over_hostname: true
|
|
103
|
-
# metadata_url: http://${
|
|
104
|
-
# metadata_url: http://${
|
|
130
|
+
# metadata_url: http://${controlServerIp}:5240/MAAS/metadata
|
|
131
|
+
# metadata_url: http://${controlServerIp}:5248/MAAS/metadata
|
|
105
132
|
|
|
106
133
|
# Check:
|
|
107
134
|
# /MAAS/metadata/latest/enlist-preseed/?op=get_enlist_preseed
|
|
@@ -112,9 +139,9 @@ hostname: ${host}
|
|
|
112
139
|
datasource_list: [ MAAS ]
|
|
113
140
|
datasource:
|
|
114
141
|
MAAS:
|
|
115
|
-
metadata_url: http://${
|
|
142
|
+
metadata_url: http://${controlServerIp}:5240/MAAS/metadata/
|
|
116
143
|
${
|
|
117
|
-
|
|
144
|
+
!auth
|
|
118
145
|
? ''
|
|
119
146
|
: `consumer_key: ${consumer_key}
|
|
120
147
|
consumer_secret: ${consumer_secret}
|
|
@@ -142,18 +169,15 @@ users:
|
|
|
142
169
|
|
|
143
170
|
# check timedatectl on host
|
|
144
171
|
# timezone: America/Santiago
|
|
145
|
-
|
|
172
|
+
timezone: ${timezone}
|
|
146
173
|
|
|
147
174
|
ntp:
|
|
148
175
|
enabled: true
|
|
149
176
|
servers:
|
|
150
177
|
- ${process.env.MAAS_NTP_SERVER}
|
|
151
178
|
ntp_client: chrony
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
# packages:
|
|
155
|
-
# - chrony
|
|
156
|
-
# service_name: chrony
|
|
179
|
+
config:
|
|
180
|
+
confpath: ${chronyConfPath}
|
|
157
181
|
|
|
158
182
|
# ssh:
|
|
159
183
|
# allow-pw: false
|
|
@@ -167,36 +191,40 @@ packages:
|
|
|
167
191
|
- git
|
|
168
192
|
- htop
|
|
169
193
|
- snapd
|
|
194
|
+
- chrony
|
|
170
195
|
resize_rootfs: false
|
|
171
196
|
growpart:
|
|
172
|
-
mode:
|
|
197
|
+
mode: false
|
|
173
198
|
network:
|
|
174
199
|
version: 2
|
|
175
200
|
ethernets:
|
|
176
201
|
${process.env.RPI4_INTERFACE_NAME}:
|
|
177
|
-
|
|
202
|
+
match:
|
|
203
|
+
macaddress: "${process.env.RPI4_MAC_ADDRESS}"
|
|
204
|
+
mtu: 1500
|
|
205
|
+
set-name: ${process.env.RPI4_INTERFACE_NAME}
|
|
206
|
+
dhcp4: false
|
|
178
207
|
addresses:
|
|
179
|
-
- ${
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
208
|
+
- ${commissioningDeviceIp}/24
|
|
209
|
+
gateway4: ${gatewayip}
|
|
210
|
+
nameservers:
|
|
211
|
+
addresses:
|
|
212
|
+
- ${process.env.MAAS_DNS}
|
|
183
213
|
|
|
184
|
-
# chpasswd:
|
|
185
|
-
# expire: false
|
|
186
|
-
# users:
|
|
187
|
-
# - {name: root, password: changeme, type: text}
|
|
188
214
|
|
|
189
|
-
final_message: "
|
|
215
|
+
final_message: "====== Cloud init finished ======"
|
|
190
216
|
|
|
191
217
|
# power_state:
|
|
192
218
|
# mode: reboot
|
|
193
219
|
# message: Rebooting after initial setup
|
|
194
220
|
# timeout: 30
|
|
195
221
|
# condition: True
|
|
222
|
+
|
|
196
223
|
bootcmd:
|
|
197
224
|
- echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
|
|
198
225
|
- echo "Init bootcmd"
|
|
199
226
|
- echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
|
|
227
|
+
${cloudConfigCmdRunFactory(bootCmdSteps)}
|
|
200
228
|
runcmd:
|
|
201
229
|
- echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
|
|
202
230
|
- echo "Init runcmd"
|
|
@@ -212,61 +240,37 @@ preserve_hostname: false
|
|
|
212
240
|
# The modules that run in the 'init' stage
|
|
213
241
|
cloud_init_modules:
|
|
214
242
|
- migrator
|
|
215
|
-
- seed_random
|
|
216
243
|
- bootcmd
|
|
217
244
|
- write-files
|
|
218
245
|
- growpart
|
|
219
246
|
- resizefs
|
|
220
|
-
- disk_setup
|
|
221
|
-
- mounts
|
|
222
247
|
- set_hostname
|
|
223
|
-
- update_hostname
|
|
224
248
|
- update_etc_hosts
|
|
225
|
-
- ca-certs
|
|
226
249
|
- rsyslog
|
|
227
250
|
- users-groups
|
|
228
251
|
- ssh
|
|
229
252
|
|
|
230
|
-
# The modules that run in the 'config' stage
|
|
231
253
|
cloud_config_modules:
|
|
232
|
-
|
|
233
|
-
# this can be used by upstart jobs for 'start on cloud-config'.
|
|
234
|
-
- emit_upstart
|
|
235
|
-
- snap_config
|
|
236
|
-
- ssh-import-id
|
|
254
|
+
- mounts
|
|
237
255
|
- locale
|
|
238
256
|
- set-passwords
|
|
239
|
-
-
|
|
240
|
-
- apt-pipelining
|
|
241
|
-
- apt-configure
|
|
242
|
-
- ntp
|
|
257
|
+
- package-update-upgrade-install
|
|
243
258
|
- timezone
|
|
244
|
-
- disable-ec2-metadata
|
|
245
259
|
- runcmd
|
|
246
|
-
-
|
|
260
|
+
- ssh-import-id
|
|
261
|
+
- ntp
|
|
247
262
|
|
|
248
|
-
# The modules that run in the 'final' stage
|
|
249
263
|
cloud_final_modules:
|
|
250
|
-
- snappy
|
|
251
|
-
- package-update-upgrade-install
|
|
252
|
-
# - fan
|
|
253
|
-
# - landscape
|
|
254
|
-
# - lxd
|
|
255
|
-
# - puppet
|
|
256
|
-
- chef
|
|
257
|
-
- salt-minion
|
|
258
|
-
- mcollective
|
|
259
264
|
- rightscale_userdata
|
|
260
|
-
- scripts-vendor
|
|
261
265
|
- scripts-per-once
|
|
262
266
|
- scripts-per-boot
|
|
263
267
|
- scripts-per-instance
|
|
264
268
|
- scripts-user
|
|
265
269
|
- ssh-authkey-fingerprints
|
|
266
270
|
- keys-to-console
|
|
267
|
-
|
|
271
|
+
- phone-home
|
|
268
272
|
- final-message
|
|
269
|
-
|
|
273
|
+
|
|
270
274
|
EOF_MAAS_CFG`,
|
|
271
275
|
];
|
|
272
276
|
|
|
@@ -285,7 +289,9 @@ EOF_OUTER`;
|
|
|
285
289
|
shellExec(cmd);
|
|
286
290
|
};
|
|
287
291
|
|
|
288
|
-
const chronySetUp = (path) => {
|
|
292
|
+
const chronySetUp = (path, alias = 'chrony') => {
|
|
293
|
+
// use alias = 'chronyd' for RHEL
|
|
294
|
+
// use alias = 'chrony' for Ubuntu
|
|
289
295
|
return [
|
|
290
296
|
`echo '
|
|
291
297
|
# Use public servers from the pool.ntp.org project.
|
|
@@ -328,25 +334,25 @@ logdir /var/log/chrony
|
|
|
328
334
|
# Select which information is logged.
|
|
329
335
|
#log measurements statistics tracking
|
|
330
336
|
' > ${path} `,
|
|
331
|
-
`
|
|
337
|
+
`systemctl stop ${alias}`,
|
|
338
|
+
|
|
339
|
+
`${alias}d -q 'server ntp.ubuntu.com iburst'`,
|
|
332
340
|
|
|
333
341
|
// `chronyd -q 'server 0.europe.pool.ntp.org iburst'`,
|
|
334
|
-
`chronyd -q 'server ntp.ubuntu.com iburst'`,
|
|
335
342
|
|
|
336
|
-
`sudo systemctl enable --now
|
|
337
|
-
`sudo systemctl restart
|
|
338
|
-
`sudo systemctl status
|
|
343
|
+
`sudo systemctl enable --now ${alias}`,
|
|
344
|
+
`sudo systemctl restart ${alias}`,
|
|
345
|
+
`sudo systemctl status ${alias}`,
|
|
339
346
|
|
|
340
347
|
`chronyc sources`,
|
|
341
348
|
`chronyc tracking`,
|
|
342
|
-
// sudo firewall-cmd --add-service=ntp --permanent
|
|
343
|
-
// sudo firewall-cmd --reload
|
|
344
349
|
|
|
345
350
|
`chronyc sourcestats -v`,
|
|
351
|
+
`timedatectl status`,
|
|
346
352
|
];
|
|
347
353
|
};
|
|
348
354
|
|
|
349
|
-
const installUbuntuUnderpostTools = (nfsHostPath) => {
|
|
355
|
+
const installUbuntuUnderpostTools = ({ nfsHostPath, host }) => {
|
|
350
356
|
fs.mkdirSync(`${nfsHostPath}/underpost`, { recursive: true });
|
|
351
357
|
|
|
352
358
|
logger.info('Build', `${nfsHostPath}/underpost/date.sh`);
|
|
@@ -358,6 +364,36 @@ ${chronySetUp(chronyConfPath).join('\n')}
|
|
|
358
364
|
'utf8',
|
|
359
365
|
);
|
|
360
366
|
|
|
367
|
+
logger.info('Build', `${nfsHostPath}/underpost/host.sh`);
|
|
368
|
+
fs.writeFileSync(
|
|
369
|
+
`${nfsHostPath}/underpost/host.sh`,
|
|
370
|
+
`echo -e "127.0.0.1 localhost\n127.0.1.1 ${host}" | tee -a /etc/hosts`,
|
|
371
|
+
'utf8',
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
logger.info('Build', `${nfsHostPath}/underpost/keys_current.sh`);
|
|
375
|
+
fs.writeFileSync(
|
|
376
|
+
`${nfsHostPath}/underpost/keys_current.sh`,
|
|
377
|
+
`cat /etc/cloud/cloud.cfg.d/90_maas.cfg | grep -C 5 'metadata'`,
|
|
378
|
+
'utf8',
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
logger.info('Build', `${nfsHostPath}/underpost/keys_remove.sh`);
|
|
382
|
+
fs.writeFileSync(
|
|
383
|
+
`${nfsHostPath}/underpost/keys_remove.sh`,
|
|
384
|
+
`cp -a /underpost/90_maas_no_keys.cfg /etc/cloud/cloud.cfg.d/90_maas.cfg
|
|
385
|
+
/underpost/keys_current.sh`,
|
|
386
|
+
'utf8',
|
|
387
|
+
);
|
|
388
|
+
|
|
389
|
+
logger.info('Build', `${nfsHostPath}/underpost/keys_import.sh`);
|
|
390
|
+
fs.writeFileSync(
|
|
391
|
+
`${nfsHostPath}/underpost/keys_import.sh`,
|
|
392
|
+
`cp -a /underpost/90_maas_keys.cfg /etc/cloud/cloud.cfg.d/90_maas.cfg
|
|
393
|
+
/underpost/keys_current.sh`,
|
|
394
|
+
'utf8',
|
|
395
|
+
);
|
|
396
|
+
|
|
361
397
|
logger.info('Build', `${nfsHostPath}/underpost/keyboard.sh`);
|
|
362
398
|
fs.writeFileSync(
|
|
363
399
|
`${nfsHostPath}/underpost/keyboard.sh`,
|
|
@@ -376,6 +412,24 @@ ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf`,
|
|
|
376
412
|
'utf8',
|
|
377
413
|
);
|
|
378
414
|
|
|
415
|
+
logger.info('Build', `${nfsHostPath}/underpost/start.sh`);
|
|
416
|
+
fs.writeFileSync(
|
|
417
|
+
`${nfsHostPath}/underpost/start.sh`,
|
|
418
|
+
`#!/bin/bash
|
|
419
|
+
set -x
|
|
420
|
+
sudo cloud-init --all-stages
|
|
421
|
+
`,
|
|
422
|
+
'utf8',
|
|
423
|
+
);
|
|
424
|
+
|
|
425
|
+
logger.info('Build', `${nfsHostPath}/underpost/reset.sh`);
|
|
426
|
+
fs.writeFileSync(
|
|
427
|
+
`${nfsHostPath}/underpost/reset.sh`,
|
|
428
|
+
`${cloudInitReset}
|
|
429
|
+
${bootCmdSteps.join('\n')}`,
|
|
430
|
+
'utf8',
|
|
431
|
+
);
|
|
432
|
+
|
|
379
433
|
logger.info('Build', `${nfsHostPath}/underpost/help.sh`);
|
|
380
434
|
fs.writeFileSync(
|
|
381
435
|
`${nfsHostPath}/underpost/help.sh`,
|
|
@@ -402,6 +456,24 @@ cut -d: -f1 /etc/passwd
|
|
|
402
456
|
'utf8',
|
|
403
457
|
);
|
|
404
458
|
|
|
459
|
+
logger.info('Build', `${nfsHostPath}/underpost/shutdown.sh`);
|
|
460
|
+
fs.writeFileSync(
|
|
461
|
+
`${nfsHostPath}/underpost/shutdown.sh`,
|
|
462
|
+
`cp -a /underpost/90_maas_no_keys.cfg /etc/cloud/cloud.cfg.d/90_maas.cfg
|
|
463
|
+
sudo shutdown -h now`,
|
|
464
|
+
'utf8',
|
|
465
|
+
);
|
|
466
|
+
|
|
467
|
+
logger.info('Build', `${nfsHostPath}/underpost/mac.sh`);
|
|
468
|
+
fs.writeFileSync(
|
|
469
|
+
`${nfsHostPath}/underpost/mac.sh`,
|
|
470
|
+
`echo "$(cat /sys/class/net/${process.env.RPI4_INTERFACE_NAME}/address)" > /underpost/mac`,
|
|
471
|
+
'utf8',
|
|
472
|
+
);
|
|
473
|
+
|
|
474
|
+
logger.info('Build', `${nfsHostPath}/underpost/device_scan.sh`);
|
|
475
|
+
fs.copySync(`./manifests/maas/device-scan.sh`, `${nfsHostPath}/underpost/device_scan.sh`);
|
|
476
|
+
|
|
405
477
|
logger.info('Build', `${nfsHostPath}/underpost/config-path.sh`);
|
|
406
478
|
fs.writeFileSync(`${nfsHostPath}/underpost/config-path.sh`, `echo "/etc/cloud/cloud.cfg.d/90_maas.cfg"`, 'utf8');
|
|
407
479
|
|
|
@@ -417,7 +489,17 @@ cut -d: -f1 /etc/passwd
|
|
|
417
489
|
`chmod +x /underpost/dns.sh`,
|
|
418
490
|
`chmod +x /underpost/help.sh`,
|
|
419
491
|
`chmod +x /underpost/config-path.sh`,
|
|
492
|
+
`chmod +x /underpost/host.sh`,
|
|
493
|
+
`chmod +x /underpost/keys_current.sh`,
|
|
494
|
+
`chmod +x /underpost/keys_import.sh`,
|
|
495
|
+
`chmod +x /underpost/keys_remove.sh`,
|
|
420
496
|
`chmod +x /underpost/test.sh`,
|
|
497
|
+
`chmod +x /underpost/start.sh`,
|
|
498
|
+
`chmod +x /underpost/reset.sh`,
|
|
499
|
+
`chmod +x /underpost/shutdown.sh`,
|
|
500
|
+
`chmod +x /underpost/device_scan.sh`,
|
|
501
|
+
`chmod +x /underpost/mac.sh`,
|
|
502
|
+
chronySetUp(chronyConfPath)[0],
|
|
421
503
|
`sudo chmod 700 ~/.ssh/`,
|
|
422
504
|
`sudo chmod 600 ~/.ssh/authorized_keys`,
|
|
423
505
|
`sudo chmod 644 ~/.ssh/known_hosts`,
|
|
@@ -428,7 +510,15 @@ cut -d: -f1 /etc/passwd
|
|
|
428
510
|
]);
|
|
429
511
|
};
|
|
430
512
|
|
|
431
|
-
const updateVirtualRoot = async ({
|
|
513
|
+
const updateVirtualRoot = async ({
|
|
514
|
+
controlServerIp,
|
|
515
|
+
architecture,
|
|
516
|
+
host,
|
|
517
|
+
nfsHostPath,
|
|
518
|
+
commissioningDeviceIp,
|
|
519
|
+
update,
|
|
520
|
+
gatewayip,
|
|
521
|
+
}) => {
|
|
432
522
|
// <consumer_key>:<consumer_token>:<secret>
|
|
433
523
|
// <consumer_key>:<consumer_secret>:<token_key>:<token_secret>
|
|
434
524
|
// maas apikey --with-names --username ${process.env.MAAS_ADMIN_USERNAME}
|
|
@@ -461,8 +551,7 @@ const updateVirtualRoot = async ({ IP_ADDRESS, architecture, host, nfsHostPath,
|
|
|
461
551
|
// --reboot
|
|
462
552
|
if (process.argv.includes('reset'))
|
|
463
553
|
shellExec(`sudo chroot ${nfsHostPath} /usr/bin/qemu-aarch64-static /bin/bash <<'EOF'
|
|
464
|
-
|
|
465
|
-
sudo rm -rf /var/lib/cloud/*
|
|
554
|
+
${cloudInitReset}
|
|
466
555
|
EOF`);
|
|
467
556
|
|
|
468
557
|
if (fs.existsSync(`${nfsHostPath}/var/log/`)) {
|
|
@@ -495,11 +584,50 @@ EOF`);
|
|
|
495
584
|
runSteps(
|
|
496
585
|
nfsHostPath,
|
|
497
586
|
cloudConfigFactory(
|
|
498
|
-
{
|
|
587
|
+
{
|
|
588
|
+
auth: true,
|
|
589
|
+
controlServerIp,
|
|
590
|
+
architecture,
|
|
591
|
+
host,
|
|
592
|
+
nfsHostPath,
|
|
593
|
+
commissioningDeviceIp,
|
|
594
|
+
update,
|
|
595
|
+
gatewayip,
|
|
596
|
+
},
|
|
597
|
+
{ consumer_key, consumer_secret, token_key, token_secret },
|
|
598
|
+
'/underpost/90_maas_keys.cfg',
|
|
599
|
+
),
|
|
600
|
+
);
|
|
601
|
+
|
|
602
|
+
runSteps(
|
|
603
|
+
nfsHostPath,
|
|
604
|
+
cloudConfigFactory(
|
|
605
|
+
{
|
|
606
|
+
auth: false,
|
|
607
|
+
controlServerIp,
|
|
608
|
+
architecture,
|
|
609
|
+
host,
|
|
610
|
+
nfsHostPath,
|
|
611
|
+
commissioningDeviceIp,
|
|
612
|
+
update,
|
|
613
|
+
gatewayip,
|
|
614
|
+
},
|
|
499
615
|
{ consumer_key, consumer_secret, token_key, token_secret },
|
|
616
|
+
'/underpost/90_maas_no_keys.cfg',
|
|
500
617
|
),
|
|
501
618
|
);
|
|
502
|
-
|
|
619
|
+
|
|
620
|
+
if (process.argv.includes('auth')) {
|
|
621
|
+
shellExec(`cp ${nfsHostPath}/underpost/90_maas_keys.cfg ${nfsHostPath}/etc/cloud/cloud.cfg.d/90_maas.cfg`);
|
|
622
|
+
} else {
|
|
623
|
+
shellExec(`cp ${nfsHostPath}/underpost/90_maas_no_keys.cfg ${nfsHostPath}/etc/cloud/cloud.cfg.d/90_maas.cfg`);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
installUbuntuUnderpostTools({ nfsHostPath, host });
|
|
627
|
+
|
|
628
|
+
shellExec(`./manifests/maas/nat-iptables.sh`, { silent: true });
|
|
629
|
+
|
|
630
|
+
shellExec(`cat ${nfsHostPath}/etc/cloud/cloud.cfg.d/90_maas.cfg`);
|
|
503
631
|
};
|
|
504
632
|
|
|
505
633
|
try {
|
|
@@ -1679,41 +1807,60 @@ EOF`);
|
|
|
1679
1807
|
}
|
|
1680
1808
|
|
|
1681
1809
|
case 'maas': {
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
);
|
|
1685
|
-
dotenv.config({ path: `${getUnderpostRootPath()}/.env`, override: true });
|
|
1686
|
-
const IP_ADDRESS = getLocalIPv4Address();
|
|
1687
|
-
const serverip = IP_ADDRESS;
|
|
1810
|
+
dotenv.config({ path: `/home/dd/engine/engine-private/conf/dd-cron/.env.production`, override: true });
|
|
1811
|
+
const controlServerIp = getLocalIPv4Address();
|
|
1688
1812
|
const tftpRoot = process.argv.includes('v3.0')
|
|
1689
1813
|
? `/var/snap/maas/common/maas/boot-resources/snapshot-20250720-162718`
|
|
1690
1814
|
: process.env.TFTP_ROOT;
|
|
1691
|
-
const
|
|
1815
|
+
const commissioningDeviceIp = process.env.RPI4_IP;
|
|
1692
1816
|
const netmask = process.env.NETMASK;
|
|
1693
1817
|
const gatewayip = process.env.GATEWAY_IP;
|
|
1818
|
+
let commissioningMac = '00:00:00:00:00:00';
|
|
1694
1819
|
|
|
1695
|
-
const
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
}
|
|
1820
|
+
const removeMachines = () => {
|
|
1821
|
+
for (const machine of machines) {
|
|
1822
|
+
shellExec(`maas ${process.env.MAAS_ADMIN_USERNAME} machine delete ${machine.system_id}`);
|
|
1823
|
+
}
|
|
1824
|
+
machines = [];
|
|
1825
|
+
};
|
|
1826
|
+
|
|
1827
|
+
const clearDiscoveries = () => {
|
|
1828
|
+
shellExec(`maas ${process.env.MAAS_ADMIN_USERNAME} discoveries clear all=true`);
|
|
1829
|
+
if (process.argv.includes('force')) {
|
|
1830
|
+
shellExec(`maas ${process.env.MAAS_ADMIN_USERNAME} discoveries scan force=true`);
|
|
1831
|
+
}
|
|
1832
|
+
};
|
|
1833
|
+
|
|
1834
|
+
const macMonitor = async (nfsServerRootPath) => {
|
|
1835
|
+
if (fs.existsSync(`${nfsServerRootPath}/underpost/mac`)) {
|
|
1836
|
+
commissioningMac = fs.readFileSync(`${nfsServerRootPath}/underpost/mac`, 'utf8').trim();
|
|
1837
|
+
logger.info('Commissioning MAC', commissioningMac);
|
|
1838
|
+
return;
|
|
1839
|
+
}
|
|
1840
|
+
await timer(1000);
|
|
1841
|
+
await macMonitor(nfsServerRootPath);
|
|
1842
|
+
};
|
|
1701
1843
|
|
|
1702
1844
|
let resources;
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1845
|
+
if (!process.argv.includes('machines'))
|
|
1846
|
+
try {
|
|
1847
|
+
resources = JSON.parse(
|
|
1848
|
+
shellExec(`maas ${process.env.MAAS_ADMIN_USERNAME} boot-resources read`, {
|
|
1849
|
+
silent: true,
|
|
1850
|
+
stdout: true,
|
|
1851
|
+
}),
|
|
1852
|
+
).map((o) => ({
|
|
1853
|
+
id: o.id,
|
|
1854
|
+
name: o.name,
|
|
1855
|
+
architecture: o.architecture,
|
|
1856
|
+
}));
|
|
1857
|
+
if (process.argv.includes('images')) {
|
|
1858
|
+
console.table(resources);
|
|
1859
|
+
process.exit(0);
|
|
1860
|
+
}
|
|
1861
|
+
} catch (error) {
|
|
1862
|
+
logger.error(error);
|
|
1863
|
+
}
|
|
1717
1864
|
|
|
1718
1865
|
let machines;
|
|
1719
1866
|
try {
|
|
@@ -1722,23 +1869,21 @@ EOF`);
|
|
|
1722
1869
|
stdout: true,
|
|
1723
1870
|
silent: true,
|
|
1724
1871
|
}),
|
|
1725
|
-
).map((m) =>
|
|
1872
|
+
).map((m) => ({
|
|
1873
|
+
system_id: m.interface_set[0].system_id,
|
|
1874
|
+
mac_address: m.interface_set[0].mac_address,
|
|
1875
|
+
hostname: m.hostname,
|
|
1876
|
+
status_name: m.status_name,
|
|
1877
|
+
}));
|
|
1878
|
+
if (process.argv.includes('machines')) {
|
|
1879
|
+
console.table(machines);
|
|
1880
|
+
process.exit(0);
|
|
1881
|
+
}
|
|
1726
1882
|
} catch (error) {
|
|
1727
1883
|
logger.error(error);
|
|
1728
1884
|
}
|
|
1729
1885
|
|
|
1730
|
-
if (process.argv.includes('
|
|
1731
|
-
shellExec(`maas ${process.env.MAAS_ADMIN_USERNAME} boot-sources read`);
|
|
1732
|
-
shellExec(`maas ${process.env.MAAS_ADMIN_USERNAME} commissioning-scripts read`);
|
|
1733
|
-
// shellExec(`maas ${process.env.MAAS_ADMIN_USERNAME} boot-source-selections read 60`);
|
|
1734
|
-
logger.info('Resources');
|
|
1735
|
-
console.table(resources);
|
|
1736
|
-
logger.info('Machines');
|
|
1737
|
-
console.table(machines);
|
|
1738
|
-
process.exit(0);
|
|
1739
|
-
}
|
|
1740
|
-
|
|
1741
|
-
if (process.argv.includes('config')) {
|
|
1886
|
+
if (process.argv.includes('journald')) {
|
|
1742
1887
|
shellExec(`sudo sed -i 's/^#Storage=auto/Storage=volatile/' /etc/systemd/journald.conf`);
|
|
1743
1888
|
shellExec(`sudo systemctl daemon-reload`);
|
|
1744
1889
|
shellExec(`sudo systemctl restart systemd-journald`);
|
|
@@ -1775,14 +1920,8 @@ EOF`);
|
|
|
1775
1920
|
// - Disable DNSSEC validation to No (Disable DNSSEC; useful when upstream DNS is misconfigured)
|
|
1776
1921
|
|
|
1777
1922
|
if (process.argv.includes('clear')) {
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
}
|
|
1781
|
-
// machines = [];
|
|
1782
|
-
shellExec(`maas ${process.env.MAAS_ADMIN_USERNAME} discoveries clear all=true`);
|
|
1783
|
-
if (process.argv.includes('force')) {
|
|
1784
|
-
shellExec(`maas ${process.env.MAAS_ADMIN_USERNAME} discoveries scan force=true`);
|
|
1785
|
-
}
|
|
1923
|
+
removeMachines();
|
|
1924
|
+
clearDiscoveries();
|
|
1786
1925
|
process.exit(0);
|
|
1787
1926
|
}
|
|
1788
1927
|
if (process.argv.includes('grub-arm64')) {
|
|
@@ -1803,37 +1942,13 @@ EOF`);
|
|
|
1803
1942
|
pbcopy(cmd);
|
|
1804
1943
|
process.exit(0);
|
|
1805
1944
|
}
|
|
1806
|
-
if (process.argv.includes('reset')) {
|
|
1807
|
-
// shellExec(
|
|
1808
|
-
// `maas init region+rack --database-uri "postgres://$DB_PG_MAAS_USER:$DB_PG_MAAS_PASS@$DB_PG_MAAS_HOST/$DB_PG_MAAS_NAME"` +
|
|
1809
|
-
// ` --maas-url http://${IP_ADDRESS}:5240/MAAS`,
|
|
1810
|
-
// );
|
|
1811
|
-
const cmd =
|
|
1812
|
-
`maas init region+rack --database-uri "postgres://${process.env.DB_PG_MAAS_USER}:${process.env.DB_PG_MAAS_PASS}@${process.env.DB_PG_MAAS_HOST}/${process.env.DB_PG_MAAS_NAME}"` +
|
|
1813
|
-
` --maas-url http://${IP_ADDRESS}:5240/MAAS`;
|
|
1814
|
-
pbcopy(cmd);
|
|
1815
|
-
process.exit(0);
|
|
1816
|
-
}
|
|
1817
|
-
|
|
1818
|
-
if (process.argv.includes('restart')) {
|
|
1819
|
-
shellExec(`sudo snap restart maas.pebble`);
|
|
1820
|
-
let secs = 0;
|
|
1821
|
-
while (
|
|
1822
|
-
!(
|
|
1823
|
-
shellExec(`maas status`, { silent: true, disableLog: true, stdout: true })
|
|
1824
|
-
.split(' ')
|
|
1825
|
-
.filter((l) => l.match('inactive')).length === 1
|
|
1826
|
-
)
|
|
1827
|
-
) {
|
|
1828
|
-
await timer(1000);
|
|
1829
|
-
console.log(`Waiting... (${++secs}s)`);
|
|
1830
|
-
}
|
|
1831
|
-
process.exit(0);
|
|
1832
|
-
}
|
|
1833
1945
|
|
|
1834
1946
|
// shellExec(`MAAS_ADMIN_USERNAME=${process.env.MAAS_ADMIN_USERNAME}`);
|
|
1835
1947
|
// shellExec(`MAAS_ADMIN_EMAIL=${process.env.MAAS_ADMIN_EMAIL}`);
|
|
1836
1948
|
// shellExec(`maas createadmin --username $MAAS_ADMIN_USERNAME --email $MAAS_ADMIN_EMAIL`);
|
|
1949
|
+
// shellExec(`maas ${process.env.MAAS_ADMIN_USERNAME} boot-sources read`);
|
|
1950
|
+
// shellExec(`maas ${process.env.MAAS_ADMIN_USERNAME} commissioning-scripts read`);
|
|
1951
|
+
// shellExec(`maas ${process.env.MAAS_ADMIN_USERNAME} boot-source-selections read 60`);
|
|
1837
1952
|
|
|
1838
1953
|
// MaaS admin CLI:
|
|
1839
1954
|
// maas login <maas-admin-username> http://localhost:5240/MAAS
|
|
@@ -2022,15 +2137,16 @@ EOF`);
|
|
|
2022
2137
|
];
|
|
2023
2138
|
const cmd = [
|
|
2024
2139
|
`console=serial0,115200`,
|
|
2140
|
+
// `console=ttyAMA0,115200`,
|
|
2025
2141
|
`console=tty1`,
|
|
2026
2142
|
// `initrd=-1`,
|
|
2027
2143
|
// `net.ifnames=0`,
|
|
2028
2144
|
// `dwc_otg.lpm_enable=0`,
|
|
2029
2145
|
// `elevator=deadline`,
|
|
2030
2146
|
`root=/dev/nfs`,
|
|
2031
|
-
`nfsroot=${
|
|
2032
|
-
// `nfsroot=${
|
|
2033
|
-
`ip=${
|
|
2147
|
+
`nfsroot=${controlServerIp}:${process.env.NFS_EXPORT_PATH}/rpi4mb,${mountOptions}`,
|
|
2148
|
+
// `nfsroot=${controlServerIp}:${process.env.NFS_EXPORT_PATH}/rpi4mb`,
|
|
2149
|
+
`ip=${commissioningDeviceIp}:${controlServerIp}:${gatewayip}:${netmask}:${nfsHost}:${interfaceName}:static`,
|
|
2034
2150
|
`rootfstype=nfs`,
|
|
2035
2151
|
`rw`,
|
|
2036
2152
|
`rootwait`,
|
|
@@ -2045,6 +2161,12 @@ EOF`);
|
|
|
2045
2161
|
// 'ip=dfcp',
|
|
2046
2162
|
// 'autoinstall',
|
|
2047
2163
|
// 'rd.break',
|
|
2164
|
+
|
|
2165
|
+
// Disable services that not apply over nfs
|
|
2166
|
+
`systemd.mask=systemd-network-generator.service`,
|
|
2167
|
+
`systemd.mask=systemd-networkd.service`,
|
|
2168
|
+
`systemd.mask=systemd-fsck-root.service`,
|
|
2169
|
+
`systemd.mask=systemd-udev-trigger.service`,
|
|
2048
2170
|
];
|
|
2049
2171
|
|
|
2050
2172
|
// TODO: use autoinstall cloud-config-url=http://<MAAS_IP>:5240/MAAS/metadata/latest
|
|
@@ -2083,30 +2205,58 @@ EOF`);
|
|
|
2083
2205
|
|
|
2084
2206
|
nfsConnectStr = cmd.join(' ');
|
|
2085
2207
|
bootConf = `[all]
|
|
2086
|
-
MAC_ADDRESS=00:00:00:00:00:00
|
|
2087
|
-
MAC_ADDRESS_OTP=0,1
|
|
2088
2208
|
BOOT_UART=0
|
|
2089
2209
|
WAKE_ON_GPIO=1
|
|
2090
2210
|
POWER_OFF_ON_HALT=0
|
|
2091
2211
|
ENABLE_SELF_UPDATE=1
|
|
2092
2212
|
DISABLE_HDMI=0
|
|
2093
|
-
TFTP_IP=${serverip}
|
|
2094
|
-
TFTP_PREFIX=1
|
|
2095
|
-
TFTP_PREFIX_STR=${tftpSubDir.slice(1)}/
|
|
2096
2213
|
NET_INSTALL_ENABLED=1
|
|
2097
2214
|
DHCP_TIMEOUT=45000
|
|
2098
2215
|
DHCP_REQ_TIMEOUT=4000
|
|
2099
2216
|
TFTP_FILE_TIMEOUT=30000
|
|
2100
|
-
BOOT_ORDER=0x21
|
|
2101
|
-
|
|
2102
|
-
|
|
2217
|
+
BOOT_ORDER=0x21
|
|
2218
|
+
|
|
2219
|
+
# ─────────────────────────────────────────────────────────────
|
|
2220
|
+
# TFTP configuration
|
|
2221
|
+
# ─────────────────────────────────────────────────────────────
|
|
2222
|
+
|
|
2223
|
+
# Custom TFTP prefix string (e.g., based on MAC address, no colons)
|
|
2224
|
+
#TFTP_PREFIX_STR=AA-BB-CC-DD-EE-FF/
|
|
2225
|
+
|
|
2226
|
+
# Optional PXE Option43 override (leave commented if unused)
|
|
2227
|
+
#PXE_OPTION43="Raspberry Pi Boot"
|
|
2228
|
+
|
|
2229
|
+
# DHCP client GUID (Option 97); 0x34695052 is the FourCC for Raspberry Pi 4
|
|
2230
|
+
#DHCP_OPTION97=0x34695052
|
|
2231
|
+
|
|
2232
|
+
TFTP_IP=${controlServerIp}
|
|
2233
|
+
TFTP_PREFIX=1
|
|
2234
|
+
TFTP_PREFIX_STR=${tftpSubDir.slice(1)}/
|
|
2235
|
+
|
|
2236
|
+
# ─────────────────────────────────────────────────────────────
|
|
2237
|
+
# Manually override Ethernet MAC address
|
|
2238
|
+
# ─────────────────────────────────────────────────────────────
|
|
2239
|
+
|
|
2240
|
+
MAC_ADDRESS=${process.env.RPI4_MAC_ADDRESS}
|
|
2241
|
+
|
|
2242
|
+
# OTP MAC address override
|
|
2243
|
+
#MAC_ADDRESS_OTP=0,1
|
|
2244
|
+
|
|
2245
|
+
# ─────────────────────────────────────────────────────────────
|
|
2246
|
+
# Static IP configuration (bypasses DHCP completely)
|
|
2247
|
+
# ─────────────────────────────────────────────────────────────
|
|
2248
|
+
CLIENT_IP=${commissioningDeviceIp}
|
|
2249
|
+
SUBNET=255.255.255.0
|
|
2250
|
+
GATEWAY=192.168.1.1
|
|
2251
|
+
|
|
2252
|
+
`;
|
|
2103
2253
|
break;
|
|
2104
2254
|
|
|
2105
2255
|
default:
|
|
2106
2256
|
break;
|
|
2107
2257
|
}
|
|
2108
|
-
shellExec(`sudo chmod 755 ${process.env.NFS_EXPORT_PATH}/${nfsHost}`);
|
|
2109
2258
|
|
|
2259
|
+
shellExec(`sudo chmod 755 ${process.env.NFS_EXPORT_PATH}/${nfsHost}`);
|
|
2110
2260
|
shellExec(`sudo rm -rf ${tftpRoot}${tftpSubDir}`);
|
|
2111
2261
|
shellExec(`sudo cp -a ${firmwarePath} ${tftpRoot}${tftpSubDir}`);
|
|
2112
2262
|
shellExec(`mkdir -p ${tftpRoot}${tftpSubDir}/pxe`);
|
|
@@ -2142,7 +2292,7 @@ BOOT_ORDER=0x21`;
|
|
|
2142
2292
|
set default=0
|
|
2143
2293
|
|
|
2144
2294
|
menuentry '${menuentryStr}' {
|
|
2145
|
-
set root=(tftp,${
|
|
2295
|
+
set root=(tftp,${controlServerIp})
|
|
2146
2296
|
linux ${tftpSubDir}/pxe/vmlinuz-efi ${nfsConnectStr}
|
|
2147
2297
|
initrd ${tftpSubDir}/pxe/initrd.img
|
|
2148
2298
|
boot
|
|
@@ -2173,19 +2323,12 @@ BOOT_ORDER=0x21`;
|
|
|
2173
2323
|
nfsServerRootPath,
|
|
2174
2324
|
nfsConnectStr,
|
|
2175
2325
|
});
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
// for (const machine of machines) {
|
|
2183
|
-
// // shellExec(`maas ${process.env.MAAS_ADMIN_USERNAME} machine delete ${machine.system_id}`);
|
|
2184
|
-
// shellExec(`maas ${process.env.MAAS_ADMIN_USERNAME} machine commission ${machine.system_id}`, {
|
|
2185
|
-
// silent: true,
|
|
2186
|
-
// });
|
|
2187
|
-
// }
|
|
2188
|
-
// machines = [];
|
|
2326
|
+
shellExec(`sudo chown -R root:root ${tftpRoot}`);
|
|
2327
|
+
shellExec(`sudo sudo chmod 755 ${tftpRoot}`);
|
|
2328
|
+
|
|
2329
|
+
logger.info('Waiting for MAC assignment...');
|
|
2330
|
+
fs.removeSync(`${nfsServerRootPath}/underpost/mac`);
|
|
2331
|
+
await macMonitor(nfsServerRootPath);
|
|
2189
2332
|
|
|
2190
2333
|
const monitor = async () => {
|
|
2191
2334
|
// discoveries Query observed discoveries.
|
|
@@ -2196,8 +2339,6 @@ BOOT_ORDER=0x21`;
|
|
|
2196
2339
|
silent: true,
|
|
2197
2340
|
stdout: true,
|
|
2198
2341
|
}),
|
|
2199
|
-
).filter(
|
|
2200
|
-
(o) => o.ip !== IP_ADDRESS && o.ip !== gatewayip && !machines.find((_o) => _o.mac_address === o.mac_address),
|
|
2201
2342
|
);
|
|
2202
2343
|
|
|
2203
2344
|
// {
|
|
@@ -2218,12 +2359,14 @@ BOOT_ORDER=0x21`;
|
|
|
2218
2359
|
// "resource_uri": "/MAAS/api/2.0/discovery/MTkyLjE2OC4xLjE4OSwwMDowMDowMDowMDowMDowMA==/"
|
|
2219
2360
|
// },
|
|
2220
2361
|
|
|
2362
|
+
console.log(discoveries.map((d) => d.ip).join(' | '));
|
|
2363
|
+
|
|
2221
2364
|
for (const discovery of discoveries) {
|
|
2222
2365
|
const machine = {
|
|
2223
2366
|
architecture: architecture.match('amd') ? 'amd64/generic' : 'arm64/generic',
|
|
2224
2367
|
mac_address: discovery.mac_address,
|
|
2225
2368
|
hostname: discovery.hostname ?? discovery.mac_organization ?? discovery.domain ?? `generic-host-${s4()}`,
|
|
2226
|
-
// discovery.ip.match(
|
|
2369
|
+
// discovery.ip.match(commissioningDeviceIp)
|
|
2227
2370
|
// ? nfsHost
|
|
2228
2371
|
// : `unknown-${s4()}`,
|
|
2229
2372
|
// description: '',
|
|
@@ -2231,11 +2374,14 @@ BOOT_ORDER=0x21`;
|
|
|
2231
2374
|
power_type: 'manual', // manual
|
|
2232
2375
|
// power_parameters_power_address: discovery.ip,
|
|
2233
2376
|
mac_addresses: discovery.mac_address,
|
|
2377
|
+
ip: discovery.ip,
|
|
2234
2378
|
};
|
|
2235
2379
|
machine.hostname = machine.hostname.replaceAll(' ', '').replaceAll('.', '');
|
|
2236
2380
|
|
|
2237
|
-
if (machine.
|
|
2381
|
+
if (machine.mac_addresses === commissioningMac)
|
|
2238
2382
|
try {
|
|
2383
|
+
machine.hostname = nfsHost;
|
|
2384
|
+
machine.mac_address = commissioningMac;
|
|
2239
2385
|
let newMachine = shellExec(
|
|
2240
2386
|
`maas ${process.env.MAAS_ADMIN_USERNAME} machines create ${Object.keys(machine)
|
|
2241
2387
|
.map((k) => `${k}="${machine[k]}"`)
|
|
@@ -2245,31 +2391,27 @@ BOOT_ORDER=0x21`;
|
|
|
2245
2391
|
stdout: true,
|
|
2246
2392
|
},
|
|
2247
2393
|
);
|
|
2248
|
-
newMachine =
|
|
2394
|
+
newMachine = { discovery, machine: JSON.parse(newMachine) };
|
|
2249
2395
|
machines.push(newMachine);
|
|
2250
2396
|
console.log(newMachine);
|
|
2251
2397
|
// commissioning_scripts=90-verify-user.sh
|
|
2252
2398
|
shellExec(
|
|
2253
|
-
`maas ${process.env.MAAS_ADMIN_USERNAME} machine commission ${newMachine.system_id} enable_ssh=1 skip_bmc_config=1 skip_networking=1 skip_storage=1`,
|
|
2399
|
+
`maas ${process.env.MAAS_ADMIN_USERNAME} machine commission ${newMachine.machine.boot_interface.system_id} enable_ssh=1 skip_bmc_config=1 skip_networking=1 skip_storage=1`,
|
|
2254
2400
|
{
|
|
2255
2401
|
silent: true,
|
|
2256
2402
|
},
|
|
2257
2403
|
);
|
|
2258
2404
|
} catch (error) {
|
|
2259
2405
|
logger.error(error, error.stack);
|
|
2406
|
+
} finally {
|
|
2407
|
+
process.exit(0);
|
|
2260
2408
|
}
|
|
2261
2409
|
}
|
|
2262
|
-
// if (discoveries.length > 0) {
|
|
2263
|
-
// shellExec(
|
|
2264
|
-
// `maas ${process.env.MAAS_ADMIN_USERNAME} machines read | jq '.[] | {system_id: .interface_set[0].system_id, hostname, status_name, mac_address: .interface_set[0].mac_address}'`,
|
|
2265
|
-
// );
|
|
2266
|
-
// }
|
|
2267
2410
|
await timer(1000);
|
|
2268
2411
|
monitor();
|
|
2269
2412
|
};
|
|
2270
|
-
//
|
|
2271
|
-
|
|
2272
|
-
shellExec(`node bin/deploy maas clear`);
|
|
2413
|
+
// clearDiscoveries();
|
|
2414
|
+
removeMachines();
|
|
2273
2415
|
monitor();
|
|
2274
2416
|
break;
|
|
2275
2417
|
}
|
|
@@ -2351,18 +2493,18 @@ udp-port = 32766
|
|
|
2351
2493
|
}
|
|
2352
2494
|
case 'update-virtual-root': {
|
|
2353
2495
|
dotenv.config({ path: `${getUnderpostRootPath()}/.env`, override: true });
|
|
2354
|
-
const
|
|
2496
|
+
const controlServerIp = getLocalIPv4Address();
|
|
2355
2497
|
const architecture = process.argv[3];
|
|
2356
2498
|
const host = process.argv[4];
|
|
2357
2499
|
const nfsHostPath = `${process.env.NFS_EXPORT_PATH}/${host}`;
|
|
2358
|
-
const
|
|
2500
|
+
const commissioningDeviceIp = process.env.RPI4_IP;
|
|
2359
2501
|
const gatewayip = process.env.GATEWAY_IP;
|
|
2360
2502
|
await updateVirtualRoot({
|
|
2361
|
-
|
|
2503
|
+
controlServerIp,
|
|
2362
2504
|
architecture,
|
|
2363
2505
|
host,
|
|
2364
2506
|
nfsHostPath,
|
|
2365
|
-
|
|
2507
|
+
commissioningDeviceIp,
|
|
2366
2508
|
update: true,
|
|
2367
2509
|
gatewayip,
|
|
2368
2510
|
});
|
|
@@ -2370,7 +2512,7 @@ udp-port = 32766
|
|
|
2370
2512
|
}
|
|
2371
2513
|
case 'open-virtual-root': {
|
|
2372
2514
|
dotenv.config({ path: `${getUnderpostRootPath()}/.env`, override: true });
|
|
2373
|
-
const
|
|
2515
|
+
const controlServerIp = getLocalIPv4Address();
|
|
2374
2516
|
const architecture = process.argv[3];
|
|
2375
2517
|
const host = process.argv[4];
|
|
2376
2518
|
const nfsHostPath = `${process.env.NFS_EXPORT_PATH}/${host}`;
|
|
@@ -2392,7 +2534,6 @@ udp-port = 32766
|
|
|
2392
2534
|
shellExec(`sudo mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc`);
|
|
2393
2535
|
|
|
2394
2536
|
if (process.argv.includes('build')) {
|
|
2395
|
-
// shellExec(`depmod -a`);
|
|
2396
2537
|
shellExec(`mkdir -p ${nfsHostPath}`);
|
|
2397
2538
|
let cmd;
|
|
2398
2539
|
switch (host) {
|
|
@@ -2445,14 +2586,14 @@ EOF`);
|
|
|
2445
2586
|
if (process.argv.includes('build')) {
|
|
2446
2587
|
switch (host) {
|
|
2447
2588
|
case 'rpi4mb':
|
|
2448
|
-
const
|
|
2589
|
+
const commissioningDeviceIp = process.env.RPI4_IP;
|
|
2449
2590
|
|
|
2450
2591
|
await updateVirtualRoot({
|
|
2451
|
-
|
|
2592
|
+
controlServerIp,
|
|
2452
2593
|
architecture,
|
|
2453
2594
|
host,
|
|
2454
2595
|
nfsHostPath,
|
|
2455
|
-
|
|
2596
|
+
commissioningDeviceIp,
|
|
2456
2597
|
gatewayip,
|
|
2457
2598
|
});
|
|
2458
2599
|
|
|
@@ -2503,10 +2644,10 @@ EOF`);
|
|
|
2503
2644
|
|
|
2504
2645
|
case 'create-ports': {
|
|
2505
2646
|
const cmd = [];
|
|
2506
|
-
const
|
|
2647
|
+
const commissioningDeviceIp = getLocalIPv4Address();
|
|
2507
2648
|
for (const port of ['5240']) {
|
|
2508
2649
|
const name = 'maas';
|
|
2509
|
-
cmd.push(`${name}:${port}-${port}:${
|
|
2650
|
+
cmd.push(`${name}:${port}-${port}:${commissioningDeviceIp}`);
|
|
2510
2651
|
}
|
|
2511
2652
|
pbcopy(`node engine-private/r create-port ${cmd}`);
|
|
2512
2653
|
break;
|
package/cli.md
CHANGED
package/docker-compose.yml
CHANGED
|
@@ -17,7 +17,7 @@ spec:
|
|
|
17
17
|
spec:
|
|
18
18
|
containers:
|
|
19
19
|
- name: dd-template-development-blue
|
|
20
|
-
image: localhost/rockylinux9-underpost:v2.8.
|
|
20
|
+
image: localhost/rockylinux9-underpost:v2.8.818
|
|
21
21
|
# resources:
|
|
22
22
|
# requests:
|
|
23
23
|
# memory: "124Ki"
|
|
@@ -100,7 +100,7 @@ spec:
|
|
|
100
100
|
spec:
|
|
101
101
|
containers:
|
|
102
102
|
- name: dd-template-development-green
|
|
103
|
-
image: localhost/rockylinux9-underpost:v2.8.
|
|
103
|
+
image: localhost/rockylinux9-underpost:v2.8.818
|
|
104
104
|
# resources:
|
|
105
105
|
# requests:
|
|
106
106
|
# memory: "124Ki"
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
for iface_path in /sys/class/net/*; do
|
|
4
|
+
name=$(basename "$iface_path")
|
|
5
|
+
mac=$(< "$iface_path/address")
|
|
6
|
+
ip=$(ip -4 addr show dev "$name" \
|
|
7
|
+
| grep -oP '(?<=inet\s)\d+(\.\d+){3}' || echo "—")
|
|
8
|
+
operstate=$(< "$iface_path/operstate")
|
|
9
|
+
mtu=$(< "$iface_path/mtu")
|
|
10
|
+
|
|
11
|
+
# Driver: módulo kernel que maneja esta interfaz
|
|
12
|
+
if [ -L "$iface_path/device/driver" ]; then
|
|
13
|
+
driver=$(basename "$(readlink -f "$iface_path/device/driver")")
|
|
14
|
+
else
|
|
15
|
+
driver="—"
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
# Vendor:Device ID PCI
|
|
19
|
+
pci_dev="$iface_path/device"
|
|
20
|
+
if [ -f "$pci_dev/vendor" ] && [ -f "$pci_dev/device" ]; then
|
|
21
|
+
vendor_id=$(< "$pci_dev/vendor")
|
|
22
|
+
device_id=$(< "$pci_dev/device")
|
|
23
|
+
# pasamos de 0x8086 a 8086, etc.
|
|
24
|
+
vendor_id=${vendor_id#0x}
|
|
25
|
+
device_id=${device_id#0x}
|
|
26
|
+
pci="${vendor_id}:${device_id}"
|
|
27
|
+
else
|
|
28
|
+
pci="—"
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
# Link Speed: lectura directa de /sys/class/net/<iface>/speed
|
|
32
|
+
speed=$(cat "$iface_path/speed" 2>/dev/null || echo "—")
|
|
33
|
+
|
|
34
|
+
echo "Interface: $name"
|
|
35
|
+
echo " MAC: $mac"
|
|
36
|
+
echo " IPv4: $ip"
|
|
37
|
+
echo " Estado: $operstate"
|
|
38
|
+
echo " MTU: $mtu"
|
|
39
|
+
echo " Driver: $driver"
|
|
40
|
+
echo " PCI Vendor:Device ID: $pci"
|
|
41
|
+
echo " Link Speed: ${speed}Mb/s"
|
|
42
|
+
echo
|
|
43
|
+
done
|
|
@@ -9,25 +9,6 @@ sudo snap install maas
|
|
|
9
9
|
INTERFACE=$(ip route | grep default | awk '{print $5}')
|
|
10
10
|
IP_ADDRESS=$(ip -4 addr show dev "$INTERFACE" | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
|
|
11
11
|
|
|
12
|
-
# Disable firewalld
|
|
13
|
-
sudo systemctl disable --now iptables
|
|
14
|
-
sudo systemctl disable --now ufw
|
|
15
|
-
sudo systemctl disable --now firewalld
|
|
16
|
-
|
|
17
|
-
# Enable IP forwarding and configure NAT
|
|
18
|
-
echo "net.ipv4.ip_forward = 1" | sudo tee -a /etc/sysctl.conf
|
|
19
|
-
echo "net.ipv6.conf.all.forwarding = 1" | sudo tee -a /etc/sysctl.conf
|
|
20
|
-
sudo sysctl -p
|
|
21
|
-
|
|
22
|
-
# Accept all traffic
|
|
23
|
-
sudo iptables -P INPUT ACCEPT
|
|
24
|
-
sudo iptables -P FORWARD ACCEPT
|
|
25
|
-
sudo iptables -P OUTPUT ACCEPT
|
|
26
|
-
|
|
27
|
-
# List iptables rules
|
|
28
|
-
sudo iptables -L -n
|
|
29
|
-
sysctl net.ipv4.ip_forward
|
|
30
|
-
|
|
31
12
|
cd /home/dd/engine
|
|
32
13
|
|
|
33
14
|
# Load secrets
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
# Disable firewalld
|
|
5
|
+
sudo systemctl disable --now iptables
|
|
6
|
+
sudo systemctl disable --now ufw
|
|
7
|
+
sudo systemctl disable --now firewalld
|
|
8
|
+
|
|
9
|
+
# Enable IP forwarding and configure NAT
|
|
10
|
+
echo "net.ipv4.ip_forward = 1" | sudo tee -a /etc/sysctl.conf
|
|
11
|
+
echo "net.ipv6.conf.all.forwarding = 1" | sudo tee -a /etc/sysctl.conf
|
|
12
|
+
sudo sysctl -p
|
|
13
|
+
|
|
14
|
+
# Accept all traffic
|
|
15
|
+
sudo iptables -P INPUT ACCEPT
|
|
16
|
+
sudo iptables -P FORWARD ACCEPT
|
|
17
|
+
sudo iptables -P OUTPUT ACCEPT
|
|
18
|
+
|
|
19
|
+
# List iptables rules
|
|
20
|
+
sudo iptables -L -n
|
|
21
|
+
sysctl net.ipv4.ip_forward
|
package/package.json
CHANGED
package/src/cli/baremetal.js
CHANGED
|
@@ -66,6 +66,7 @@ maas login "$MAAS_ADMIN_USERNAME" "http://localhost:5240/MAAS/" "$APIKEY"`);
|
|
|
66
66
|
if (options.controlServerInstall === true) {
|
|
67
67
|
shellExec(`chmod +x ${underpostRoot}/manifests/maas/maas-setup.sh`);
|
|
68
68
|
shellExec(`${underpostRoot}/manifests/maas/maas-setup.sh`);
|
|
69
|
+
shellExec(`${underpostRoot}/manifests/maas/nat-iptables.sh`);
|
|
69
70
|
}
|
|
70
71
|
if (options.controlServerInit === true) {
|
|
71
72
|
shellExec(`node ${underpostRoot}/bin/deploy maas reset`);
|