This repository has been archived by the owner on Oct 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MGMT-1318 - add annotations to BMH CRs that include data from bm-inve… (
#12) * MGMT-1318 - add annotations to BMH CRs that include data from bm-inventory (IPs etc')
- Loading branch information
1 parent
9e1c697
commit cdc5fb8
Showing
15 changed files
with
1,169 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#This dockerfile require an openshift installer binary in CWD | ||
FROM alpine:latest | ||
RUN mkdir /root/oc | ||
COPY ./oc /root/oc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import re | ||
import base64 | ||
import yaml | ||
import json | ||
|
||
|
||
BMH_CR_FILE_PATTERN = 'openshift-cluster-api_hosts' | ||
|
||
|
||
def is_bmh_cr_file(path): | ||
if BMH_CR_FILE_PATTERN in path: | ||
return True | ||
return False | ||
|
||
|
||
def get_bmh_dict_from_file(file_data): | ||
source_string = file_data['contents']['source'] | ||
base64_string = re.split("base64,", source_string)[1] | ||
decoded_string = base64.b64decode(base64_string).decode() | ||
return yaml.safe_load(decoded_string) | ||
|
||
|
||
def set_new_bmh_dict_in_file(file_data, bmh_dict): | ||
decoded_string = yaml.dump(bmh_dict) | ||
base64_string = base64.b64encode(decoded_string.encode()) | ||
source_string = 'data:text/plain;charset=utf-8;' + 'base64,' + base64_string.decode() | ||
file_data['contents']['source'] = source_string | ||
|
||
|
||
def is_master_bmh(bmh_dict): | ||
if "-master-" in bmh_dict['metadata']['name']: | ||
return True | ||
return False | ||
|
||
|
||
def update_credentials_name(bmh_dict): | ||
bmh_dict['spec']['bmc']['credentialsName'] = '' | ||
|
||
|
||
def set_baremtal_annotation_in_bmh_dict(bmh_dict, annot_dict): | ||
bmh_dict['metadata']['annotations'] = annot_dict | ||
|
||
|
||
def find_available_inventory_host(hosts_list, is_master): | ||
role = 'master' if is_master else 'worker' | ||
for host in hosts_list: | ||
if host.is_role(role): | ||
return host | ||
return None | ||
|
||
|
||
def prepare_bmh_annotation_dict(status_dict, hosts_list, is_master): | ||
inventory_host = find_available_inventory_host(hosts_list, is_master) | ||
if inventory_host is None: | ||
return None | ||
|
||
annot_dict = dict.copy(status_dict) | ||
nics = inventory_host.get_inventory_host_nics_data() | ||
cpu = inventory_host.get_inventory_host_cpu_data() | ||
storage = inventory_host.get_inventory_host_storage_data() | ||
ram = inventory_host.get_inventory_host_memory() | ||
hostname = inventory_host.get_inventory_host_name() | ||
system_vendor = inventory_host.get_inventory_host_system_vendor() | ||
hardware = {'nics': nics, 'cpu': cpu, 'storage': storage, 'ramMebibytes': ram, 'hostname': hostname, 'systemVendor': system_vendor} | ||
annot_dict['hardware'] = hardware | ||
hosts_list.remove(inventory_host) | ||
return {'baremetalhost.metal3.io/status': json.dumps(annot_dict)} | ||
|
||
|
||
def update_bmh_cr_file(file_data, hosts_list): | ||
bmh_dict = get_bmh_dict_from_file(file_data) | ||
annot_dict = prepare_bmh_annotation_dict(bmh_dict['status'], hosts_list, is_master_bmh(bmh_dict)) | ||
if annot_dict is not None: | ||
# [TODO] - make sure that Kiren fix to openshift-installer is working before removing this fix in 4.6 | ||
# update_credentials_name(bmh_dict) | ||
set_baremtal_annotation_in_bmh_dict(bmh_dict, annot_dict) | ||
set_new_bmh_dict_in_file(file_data, bmh_dict) |
Oops, something went wrong.