Skip to content

Commit

Permalink
Create node with sepcific name.
Browse files Browse the repository at this point in the history
Signed-off-by: Zheng Xiao Mei <[email protected]>
  • Loading branch information
zhengxiaomei123 authored and bjhuangr committed Jun 14, 2024
1 parent e7d99cb commit e26d871
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 14 deletions.
43 changes: 36 additions & 7 deletions z_infra_provisioning/cloud_infra_center/ocp_upi/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,43 @@
# Security groups names
os_sg_master: "{{ infra_id.stdout_lines[0] }}-master"
os_sg_worker: "{{ infra_id.stdout_lines[0] }}-worker"
# Server names
# Ignition files
os_bootstrap_ignition: "{{ infra_id.stdout_lines[0] }}-bootstrap-ignition.json"

- name: 'Bootstrap server names with prefix'
ansible.builtin.set_fact:
os_bootstrap_server_name: "{{ bootstrap_name_prefix }}"
when:
- bootstrap_name_prefix is defined

- name: 'Bootstrap server names without prefix'
ansible.builtin.set_fact:
os_bootstrap_server_name: "{{ infra_id.stdout_lines[0] }}-bootstrap"
when:
- bootstrap_name_prefix is not defined

- name: 'Master server names with prefix'
ansible.builtin.set_fact:
os_cp_server_name: "{{ master_name_prefix }}"
os_cp_server_group_name: "{{ master_name_prefix }}"
when:
- master_name_prefix is defined

- name: 'Master server names without prefix'
ansible.builtin.set_fact:
os_cp_server_name: "{{ infra_id.stdout_lines[0] }}-master"
os_cp_server_group_name: "{{ infra_id.stdout_lines[0] }}-master"
when:
- master_name_prefix is not defined

- name: 'Worker server names without prefix'
ansible.builtin.set_fact:
os_compute_server_name: "{{ infra_id.stdout_lines[0] }}-worker"
# Ignition files
os_bootstrap_ignition: "{{ infra_id.stdout_lines[0] }}-bootstrap-ignition.json"
# BFV volume names
os_bootstrap_bfv_name: "{{ infra_id.stdout_lines[0] }}-bootstrap-boot"
os_master_bfv_name: "{{ infra_id.stdout_lines[0] }}-master-boot"
os_worker_bfv_name: "{{ infra_id.stdout_lines[0] }}-worker-boot"
when:
- worker_name_prefix is not defined

- name: 'Worker server names without prefix'
ansible.builtin.set_fact:
os_compute_server_name: "{{ worker_name_prefix }}"
when:
- worker_name_prefix is defined
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,8 @@ all:
os_dns_domain: '<external-dns-ip-addr>'
cluster_name: '<cluster-name>'
base_domain: '<cluster-base-domain>'
bootstrap_name_prefix: ''
master_name_prefix: ''
worker_name_prefix: ''
pullsecret: '<pull-secret>'
sshkey: '<ssh-key>'
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
register: glance_token

- name: Generate bootstrap ignition shim
ansible.builtin.script: tools/generate-bootstrap-ignitionshim.py {{ image_url.stdout_lines[0] }} {{ glance_token.stdout }} {{ infra_id.stdout_lines[0] }}
ansible.builtin.script: tools/generate-bootstrap-ignitionshim.py {{ image_url.stdout_lines[0] }} {{ glance_token.stdout }} {{ infra_id.stdout_lines[0] }} {{ bootstrap_name_prefix }}
args:
executable: python3

- name: Generate master ignition
ansible.builtin.script: tools/generate-master-ignition.sh {{ infra_id.stdout_lines[0] }} {{ os_control_nodes_number }}
ansible.builtin.script: tools/generate-master-ignition.sh {{ infra_id.stdout_lines[0] }} {{ os_control_nodes_number }} {{ master_name_prefix }}

- name: Generate worker ignition
ansible.builtin.script: tools/generate-worker-ignition.sh {{ infra_id.stdout_lines[0] }} {{ os_compute_nodes_number }}
ansible.builtin.script: tools/generate-worker-ignition.sh {{ infra_id.stdout_lines[0] }} {{ os_compute_nodes_number }} {{ worker_name_prefix }}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@
}
})

name_prefix = sys.argv[4]
if name_prefix:
name_prefix_byte = name_prefix.encode()
bootstrap_hostname = base64.standard_b64encode(name_prefix_byte).decode().strip()
files.update(
{
"storage": {
"files": {
"path": "/etc/hostname",
"mode": 420,
"contents": {
"source": "data:text/plain;charset=utf-8;base64," + bootstrap_hostname
}
}
}
})
infra_id = sys.argv[3]
if infra_id:
with open(infra_id+'-bootstrap-ignition.json', 'a') as f:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@

infra_id=$1
master_end=$(($2 - 1))
name_prefix=$3

for index in $( seq 0 $master_end); do
MASTER_HOSTNAME="$infra_id-master-$index\n"
if [ -n "$name_prefix" ]; then
MASTER_HOSTNAME="$name_prefix-$index\n"
IGNITION_NAME="$name_prefix-$index"
else
MASTER_HOSTNAME="$infra_id-master-$index\n"
IGNITION_NAME="$infra_id-master-$index"
fi
python -c "import base64, json, sys
ignition = json.load(sys.stdin)
storage = ignition.get('storage', {})
files = storage.get('files', [])
files.append({'path': '/etc/hostname', 'mode': 420, 'contents': {'source': 'data:text/plain;charset=utf-8;base64,' + base64.standard_b64encode(b'$MASTER_HOSTNAME').decode().strip()},'filesystem': 'root'})
storage['files'] = files
ignition['storage'] = storage
json.dump(ignition, sys.stdout)" < master.ign > "$infra_id-master-$index-ignition.json"
json.dump(ignition, sys.stdout)" < master.ign > "$IGNITION_NAME-ignition.json"
done
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@
# =================================================================
infra_id=$1
worker_end=$(($2 - 1))
name_prefix=$3

for index in $( seq 0 $worker_end); do
WORKER_HOSTNAME="$infra_id-worker-$index\n"
if [ -n "$name_prefix" ]; then
WORKER_HOSTNAME="$name_prefix-$index\n"
IGNITION_NAME="$name_prefix-$index"
else
WORKER_HOSTNAME="$infra_id-worker-$index\n"
IGNITION_NAME="$infra_id-worker-$index"
fi
python -c "import base64, json, sys
ignition = json.load(sys.stdin)
storage = ignition.get('storage', {})
files = storage.get('files', [])
files.append({'path': '/etc/hostname', 'mode': 420, 'contents': {'source': 'data:text/plain;charset=utf-8;base64,' + base64.standard_b64encode(b'$WORKER_HOSTNAME').decode().strip()},'filesystem': 'root'})
storage['files'] = files
ignition['storage'] = storage
json.dump(ignition, sys.stdout)" < worker.ign > "$infra_id-worker-$index-ignition.json"
json.dump(ignition, sys.stdout)" < worker.ign > "$IGNITION_NAME-ignition.json"
done

0 comments on commit e26d871

Please sign in to comment.