Skip to content

Instantly share code, notes, and snippets.

@ujuc
Last active September 23, 2015 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ujuc/e6e913519c82412db8fb to your computer and use it in GitHub Desktop.
Save ujuc/e6e913519c82412db8fb to your computer and use it in GitHub Desktop.
Glance image download
#!/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)
@ujuc
Copy link
Author

ujuc commented Sep 23, 2015

문제

  1. 하드가 꽉 찼을때에 대한 내용은 없음.
  2. 중복된 내용에 대해서는 없음.
    1. 파일에 대한 내용으로 확인하는 것이 필요함.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment