Skip to content

Commit 99c66be

Browse files
Updating cloud-init config files and base image
Signed-off-by: Adarsh Agrawal <[email protected]>
1 parent 393bb25 commit 99c66be

File tree

9 files changed

+59
-135
lines changed

9 files changed

+59
-135
lines changed

base-image/Containerfile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,3 @@ RUN dnf -y install cloud-init && \
44
ln -s ../cloud-init.target /usr/lib/systemd/system/default.target.wants && \
55
rm -rf /var/{cache,log} /var/lib/{dnf,rhsm}
66
COPY usr/ /usr/
7-
8-
COPY base_config.sh /usr/bin/
9-
COPY base_config.service /etc/systemd/system
10-
11-
RUN systemctl unmask base_config.service
12-
RUN systemctl enable base_config.service

base-image/README.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ There are three distros of bootc image available to use. CentOS, Fedora and RHEL
99

1010
**Note:**
1111
- You need Red Hat account to get the credentials to pull the image.
12-
- Need to build the image on RHEL machine where subsciption activated.
12+
- Need to build the image on RHEL machine where subscription activated.
1313

1414
- CentOS and Fedora bootc images are available in Open Source, you can consume from their quay registry. If you want to use the CentOS/Fedora, ensure to replace the `FROM` image in [Containerfile](Containerfile)
1515
- [CentOS](https://quay.io/repository/centos-bootc/centos-bootc) - i.e. `quay.io/centos-bootc/centos-bootc:stream10`
@@ -22,16 +22,6 @@ RUN dnf -y install cloud-init && \
2222
rm -rf /var/{cache,log} /var/lib/{dnf,rhsm}
2323
COPY usr/ /usr/
2424
```
25-
Install cloud-init to configure AI image and PIM partition's network and user
26-
27-
```Dockerfile
28-
COPY base_config.sh /usr/bin/
29-
COPY base_config.service /etc/systemd/system
30-
31-
RUN systemctl unmask base_config.service
32-
RUN systemctl enable base_config.service
33-
```
34-
systemd service to setup pimconfig like copying cloud init config and pim config files to respective directory
3525

3626
## Build
3727

base-image/base_config.service

Lines changed: 0 additions & 15 deletions
This file was deleted.

base-image/base_config.sh

Lines changed: 0 additions & 27 deletions
This file was deleted.

cli/cloud-init-iso/templates/99_custom_network.cfg

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
ethernets:
3+
env{{ config["partition"]["network"]["slot_num"] }}:
4+
dhcp4: false
5+
addresses:
6+
- {{ config["partition"]["network"]["ip"]["address"] }}/{{ config["partition"]["network"]["ip"]["prefix-length"] }}
7+
gateway4: {{ config["partition"]["network"]["ip"]["gateway"] }}
8+
nameservers:
9+
addresses:
10+
- {{ config["partition"]["network"]["ip"]["nameserver"] }}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#cloud-config
2+
users:
3+
- name: {{ config["ssh"]["user-name"] }}
4+
sudo: ['ALL=(ALL) NOPASSWD:ALL']
5+
lock_passwd: true
6+
groups: sudo
7+
shell: /bin/bash
8+
ssh_authorized_keys:
9+
- {{ config["ssh"]["pub-key"] }}
10+
11+
write_files:
12+
- path: /etc/pim/pim_config.json
13+
content: |
14+
{{ config["ai"]["config-json"] }}
15+
owner: root:root
16+
permissions: '0644'
17+
- path: /etc/pim/auth.json
18+
content: |
19+
{{ config["ai"]["auth-json"] }}
20+
owner: root:root
21+
permissions: '0644'
22+
- path: /etc/pim/env.conf
23+
content: |
24+
REGISTRY_AUTH_FILE=/etc/pim/auth.json
25+
owner: root:root
26+
permissions: '0644'

cli/utils/iso_util.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,44 @@ def generate_cloud_init_iso_config(config, slot_num, config_dir):
2929
file_loader = FileSystemLoader(f'{common.getclidir()}/cloud-init-iso/templates')
3030
env = Environment(loader=file_loader)
3131

32-
network_config_template = env.get_template('99_custom_network.cfg')
32+
network_config_template = env.get_template('network-config')
3333
network_config_output = network_config_template.render(config=config)
3434

35-
common.create_dir(config_dir)
36-
3735
pim_config_json = config["ai"]["config-json"] if config["ai"]["config-json"] != "" else "{}"
3836
pim_config_json = json.loads(pim_config_json)
3937

4038
# 'workloadImage' is being used inside the bootstrap iso to write the bootc image into disk, in case of modification of this field name, needs same modification in bootstrap.iso too.
4139
pim_config_json["workloadImage"] = get_workload_image(config)
40+
config["ai"]["config-json"] = json.dumps(pim_config_json, separators=(',', ':'))
41+
42+
auth_json = config["ai"]["auth-json"]
43+
if auth_json == "":
44+
auth_json = "{}"
45+
else:
46+
auth_data = json.loads(auth_json)
47+
auth_json = json.dumps(auth_data, separators=(',', ':'))
48+
config["ai"]["auth-json"] = auth_json
4249

43-
pim_config_file = open(config_dir + "/pim_config.json", "w")
44-
pim_config_file.write(json.dumps(pim_config_json))
50+
user_data_template = env.get_template('user-data')
51+
user_data_output = user_data_template.render(config=config)
52+
53+
common.create_dir(config_dir)
4554

46-
network_config_file = open(
47-
config_dir + "/99_custom_network.cfg", "w")
55+
network_config_file = open(config_dir + "/network-config", "w")
4856
network_config_file.write(network_config_output)
57+
58+
user_data_file = open(config_dir + "/user-data", "w")
59+
user_data_file.write(user_data_output)
4960

50-
auth_json = "{}" if config["ai"]["auth-json"] == "" else config["ai"]["auth-json"]
51-
auth_config_file = open(config_dir + "/auth.json", "w")
52-
auth_config_file.write(auth_json)
61+
open(config_dir+"/meta-data", "w")
62+
5363
logger.debug("Generated config files for the cloud-init ISO")
5464

5565

5666
def generate_cloud_init_iso_file(iso_dir, config, config_dir):
5767
logger.debug("Generating cloud-init ISO file")
5868
cloud_init_image_name = get_cloud_init_iso(config)
59-
generate_cmd = f"mkisofs -l -o {iso_dir}/{cloud_init_image_name} {config_dir}"
69+
generate_cmd = f"mkisofs -l -volid cidata -joliet -o {iso_dir}/{cloud_init_image_name} -rock {config_dir}"
6070

6171
try:
6272
subprocess.run(generate_cmd.split(), check=True, capture_output=True)

cli/utils/monitor_util.py

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,7 @@
99
logger = common.get_logger("monitor")
1010

1111

12-
def monitor_pim_boot(config):
13-
# Re-run scenario: If lpar is in 2nd boot stage, check base_config service logs
14-
logger.debug("PIM boot: Checking base_config.service")
15-
try:
16-
ssh_client = common.ssh_to_partition(config)
17-
18-
base_config_svc_exists = "ls /etc/systemd/system/base_config.service"
19-
_, stdout, _ = ssh_client.exec_command(
20-
base_config_svc_exists, get_pty=True)
21-
if stdout.channel.recv_exit_status() == 0:
22-
logger.debug("base_config.service exists")
23-
24-
logger.debug("Checking base_config.service logs")
25-
base_cfg_svc_cmd = "sudo journalctl -u base_config.service -f 2>&1 | awk '{print} /base_config.sh run successfully/ {print \"Match found: \" $0; exit 0}'"
26-
_, stdout, _ = ssh_client.exec_command(
27-
base_cfg_svc_cmd, get_pty=True)
28-
while True:
29-
out = stdout.readline()
30-
logger.debug(out)
31-
if stdout.channel.exit_status_ready():
32-
if stdout.channel.recv_exit_status() == 0:
33-
logger.debug(
34-
"Found 'base_config.sh run successfully' message")
35-
ssh_client.close()
36-
return
37-
if "base_config.service: Failed with result 'exit-code'" in out:
38-
ssh_client.close()
39-
logger.error(f"failed to start AI application. error: {out}")
40-
raise Exception(f"failed to start AI application. error: {out}")
41-
else:
42-
ssh_client.close()
43-
logger.error(
44-
"failed to find '/etc/systemd/system/base_config.service', please check console for more possible errors")
45-
raise Exception(
46-
"failed to find '/etc/systemd/system/base_config.service', please check console for more possible errors")
47-
except Exception as e:
48-
logger.error(f"failed to monitor PIM boot, error: {e}")
49-
raise Exception(f"failed to monitor PIM boot, error: {e}")
50-
51-
5212
def monitor_pim(config):
53-
monitor_pim_boot(config)
5413
logger.info("Partition booted with PIM image")
5514

5615
# No need to validate the AI application deployed via PIM flow if 'ai.validation.request' set to no, can complete the workflow
@@ -113,7 +72,7 @@ def monitor_bootstrap_boot(config):
11372
raise Exception(f"failed to detect bootc based PIM AI image install completion signature. error: {out}")
11473
else:
11574
logger.debug(
116-
"Could not find 'getcontainer.service', will look for 'base_config.service' in PIM boot since it could be a re-run and bootstrap might have already finished")
75+
"Could not find 'getcontainer.service' in PIM boot since it could be a re-run and bootstrap might have already finished")
11776
ssh_client.close()
11877
except Exception as e:
11978
logger.error(f"failed to monitor bootstrap boot, error: {e}")

0 commit comments

Comments
 (0)