forked from oshercc/coreos_installation_iso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_process.py
47 lines (34 loc) · 1.41 KB
/
install_process.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import subprocess
import random
import os
import boto3
from botocore.exceptions import NoCredentialsError
import logging
def upload_to_aws(local_file, bucket, s3_file):
aws_access_key_id = os.environ.get("aws_access_key_id", "accessKey1")
aws_secret_access_key = os.environ.get("aws_secret_access_key", "verySecretKey1")
endpoint_url = os.environ.get("S3_ENDPOINT_URL", None)
if not endpoint_url:
raise Exception("No S3 endpoind passed")
s3 = boto3.client(
's3',
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
endpoint_url=endpoint_url
)
try:
s3.upload_file(local_file, bucket, s3_file, ExtraArgs={'ACL': 'public-read'})
print("Upload Successful")
return True
except NoCredentialsError:
print("Credentials not available")
return False
if not os.environ.get('IGNITION_CONFIG'):
raise Exception("ignition file not passed")
with open('ignition.config', 'w') as f:
f.write(os.environ['IGNITION_CONFIG'])
image_name = os.environ.get("IMAGE_NAME", "coreos_install{}.img".format(random.getrandbits(30)))
command = "./coreos-installer iso embed -c ignition.config -o {} {} -f".format(image_name, os.environ.get("COREOS_IMAGE"))
subprocess.check_output(command, shell=True)
bucket_name = os.environ.get('S3_BUCKET', 'test')
uploaded = upload_to_aws(image_name, bucket_name, image_name)