Fix whitespace issues in Python files
[demo.git] / vnfs / DAaaS / sample-apps / sample-minio-load-model / build / load-model-from-minio.py
1 #!/usr/bin/env python
2 #
3 # -------------------------------------------------------------------------
4 #   Copyright (c) 2019 Intel Corporation Intellectual Property
5 #
6 #   Licensed under the Apache License, Version 2.0 (the "License");
7 #   you may not use this file except in compliance with the License.
8 #   You may obtain a copy of the License at
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
12 #   Unless required by applicable law or agreed to in writing, software
13 #   distributed under the License is distributed on an "AS IS" BASIS,
14 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #   See the License for the specific language governing permissions and
16 #   limitations under the License.
17 #
18 # -------------------------------------------------------------------------
19 #
20
21 '''Sample Python application to load model from Minio'''
22
23 # python imports
24
25 import json
26 import os
27 import time
28 from minio import Minio
29 from minio.error import ResponseError
30
31
32 client = Minio(os.environ['S3_ENDPOINT'],
33                access_key=os.environ['AWS_ACCESS_KEY_ID'],
34                secret_key=os.environ['AWS_SECRET_ACCESS_KEY'],
35                secure=False)
36
37
38 def load_model(bucket_name, object_name, filepath):
39     try:
40         client.fget_object(bucket_name, object_name, filepath)
41     except ResponseError as err:
42         print(err)
43
44 if __name__ == "__main__":
45     bucket_name = os.environ['MODEL_BUCKET']
46     objects = json.loads(os.environ['MODEL_OBJECTS'])
47     filepath = '/models/'
48     for object_name in objects:
49         print(f"Load model from s3://{bucket_name}/{object_name} to {filepath+object_name}")
50         load_model(bucket_name, object_name, filepath+object_name)
51     time.sleep(300)