Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Commit d41b218

Browse files
authored
Merge pull request #9 from troy-bishop/main
Fix the scenario where a custom z/OS image needs to override the parmlib location
2 parents a5195df + b05e241 commit d41b218

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ This set of scripts and automation can be used in conjunction with Wazi Image Bu
3232

3333
This will create the VSI with the required data volumes. You might want to use the VSI serial console: the progress logs are written there by cloud init.
3434

35-
Once compeleted successfully, the following can be observed as output:
35+
Once completed successfully, the following can be observed as output:
3636

3737
- A bootable qcow2 image is uploaded to the IBM Cloud Object Storage bucket
3838
- A VPC block storage device, storing data volumes from the z/OS image, is created

data_mover/data_mover.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
METADATA_FILE = 'image-metadata.json'
3535
DEVMAP_FILE = 'devmap'
36+
ENV_OVERRIDES_FILE = 'env-overrides'
37+
PROPERTIES_JSON_FILE = 'properties.json'
3638
VOLUME_DIRECTORIES = '/volumes/'
3739
BOOT_VOLUME_DIRECTORY = VOLUME_DIRECTORIES+'boot/' # Trailing slashes
3840
DATA_VOLUME_DIRECTORY = VOLUME_DIRECTORIES+'data/' # Trailing slashes
@@ -45,6 +47,30 @@
4547
endpoint_url=COS_ENDPOINT)
4648

4749

50+
def copy_env_overrides_file():
51+
'''
52+
Copy the env-overrides file, if it exists, to the data volume
53+
'''
54+
env_overrides_exists = exists_in_bucket(COS_BUCKET_NAME, ENV_OVERRIDES_FILE)
55+
if env_overrides_exists:
56+
env_overrides_filename = DATA_VOLUME_DIRECTORY + '../env-overrides'
57+
with open(env_overrides_filename, 'wb') as file:
58+
file.write(get_item(COS_BUCKET_NAME, ENV_OVERRIDES_FILE).read())
59+
shutil.copy(env_overrides_filename, DATA_VOLUME_DIRECTORY)
60+
61+
62+
def copy_properties_file():
63+
'''
64+
Copy the properties.json file, if it exists, to the data volume
65+
'''
66+
properties_file_exists = exists_in_bucket(COS_BUCKET_NAME, PROPERTIES_JSON_FILE)
67+
if properties_file_exists:
68+
properties_filename = DATA_VOLUME_DIRECTORY + '../properties.json'
69+
with open(properties_filename, 'wb') as file:
70+
file.write(get_item(COS_BUCKET_NAME, PROPERTIES_JSON_FILE).read())
71+
shutil.copy(properties_filename, DATA_VOLUME_DIRECTORY)
72+
73+
4874
def pull_metadata_file():
4975
'''
5076
Pulls the metadata file from a COS bucket, and returns it.
@@ -65,6 +91,23 @@ def pull_devmap():
6591
os.chown(volume + 'devmap', 999, 999)
6692

6793

94+
def exists_in_bucket(bucket_name, item_name):
95+
'''
96+
Validate that a given item name (file name) exists in the given bucket name.
97+
'''
98+
global bucket_contents
99+
print('Checking if the item \'{1}\' exists in the bucket \'{0}\''.format(bucket_name, item_name))
100+
try:
101+
if item_name in get_bucket_contents(COS_BUCKET_NAME):
102+
return True
103+
else:
104+
return False
105+
except ClientError as ce:
106+
exit('CLIENT ERROR: {0}\n'.format(ce))
107+
except Exception as e:
108+
exit('Unable to retrieve file contents: {0}'.format(e))
109+
110+
68111
def get_item(bucket_name, item_name):
69112
'''
70113
For a given bucket name and item name (file name), return the contents of that file,
@@ -264,6 +307,10 @@ def format_and_mount(volume):
264307
# Define 5 concurrent processes to get the volume files with
265308
p = Pool(10)
266309

310+
# Copy the env-overrides and/or properties.json files, if they exists in the COS bucket
311+
copy_env_overrides_file()
312+
copy_properties_file()
313+
267314
# Pull the metadata file from the COS bucket and get
268315
# the boot volume and data volume names
269316
metadata_file = pull_metadata_file()

my-settings.auto.tfvars-template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ibmcloud_api_key = "Your IBM Cloud API key"
33
cos_instance_name = "Cloud Object Storage-xx"
44
cos_bucket_name = "wazi-custom-image-bucket"
55
cos_bucket_region = "ca-tor"
6+
cos_resource_group = "Default"
67

78
custom_image_name = "wazi-custom-image"
89

0 commit comments

Comments
 (0)