Last active
September 23, 2015 09:31
-
-
Save ujuc/e6e913519c82412db8fb to your computer and use it in GitHub Desktop.
Glance image download
This file contains hidden or 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
#!/usr/bin/env python | |
# coding: utf-8 | |
""" | |
Glance Image 리스트를 파일로 만든 다음 스크립트 실행하도록하자. | |
이미지중 필요없는 것들에 대해서는 스크립트 실행 전에 로그에서 삭제하도록한다. | |
""" | |
import sys | |
import subprocess as sub | |
def image_down(id, name): | |
""" | |
ID 와 Nmae을 받아서 이미지를 다운로드 받음 | |
반환 값은 다운이 완료되었을때, 다음으로 넘어가도록 설정함. | |
:param id: Image UUID | |
:param name: Image Name | |
:return: image_down_log | |
""" | |
image_down_log = sub.Popen(['glance', 'image-download', '{}'.format(id), | |
'--file', '{name}-{id}'.format(name=name, id=id[:4])], | |
stdout=sub.PIPE, stderr=sub.PIPE).communicate() | |
return image_down_log | |
if __name__ == "__main__": | |
image_list_file = sys.argv[1] | |
with open(sys.argv[1]) as f: | |
image_list_raw = f.read().split('\n') | |
image_data = image_list_raw[3:-2] | |
image_list = [] | |
for image in image_data: | |
data = image.split('|') | |
dict = { | |
"img_id": data[1].strip(), | |
"img_name": data[2].strip(), | |
"img_status": data[6].strip() | |
} | |
image_list.append(dict) | |
# 이름으로 다운로드함. | |
for image in image_list: | |
if image['img_status'] == "active": | |
print "Start -- down load {name}".format(name=image['img_name']) | |
image_status = image_down(image['img_id'], image['img_name']) | |
print "name: {name}, id: {id}, status: {status}".format( | |
name=image['img_name'], id=image['img_id'], status=image_status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
문제