This repository has been archived by the owner on Sep 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
install_process.py
57 lines (43 loc) · 2.01 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
48
49
50
51
52
53
54
55
56
57
import subprocess
import random
import os
import time
import boto3
from botocore.exceptions import NoCredentialsError
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)
s3_client = 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_client.upload_file(local_file, bucket, s3_file)
s3_client.put_object_tagging(Bucket=bucket, Key=s3_file,
Tagging={'TagSet': [{'Key': 'create_sec_since_epoch', 'Value': str(int(time.time()))}]})
print("Upload Successful")
return True
except NoCredentialsError:
print("Credentials not available")
return False
def main():
if not os.environ.get('IGNITION_CONFIG'):
raise Exception("ignition file not passed")
work_dir = os.environ.get("WORK_DIR")
if not work_dir:
raise Exception("working directory was not defined")
with open(os.path.join(work_dir, '/data/ignition.config'), 'w') as file_desc:
file_desc.write(os.environ['IGNITION_CONFIG'])
image_name = os.path.join(work_dir, os.environ.get("IMAGE_NAME", "coreos_install{}.img".format(random.getrandbits(30))))
s3_name = os.environ.get("IMAGE_NAME", "coreos_install{}.img".format(random.getrandbits(30)))
command = "%s/coreos-installer iso embed -c %s/ignition.config -o %s %s -f" % (work_dir, work_dir, image_name,
os.environ.get("COREOS_IMAGE"))
print("command to executes is:<%s>" % command)
subprocess.check_output(command, shell=True)
bucket_name = os.environ.get('S3_BUCKET', 'test')
upload_to_aws(image_name, bucket_name, s3_name)
if __name__ == "__main__":
main()