experiment with downloading images

Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2017-01-31 10:59:24 -05:00
parent d034c3ecc4
commit 5f49d35322
4 changed files with 65 additions and 2 deletions

1
.gitignore vendored
View File

@ -57,3 +57,4 @@ ChangeLog
# Files created by releasenotes build
releasenotes/build
/clouds.yaml
/*.dat

View File

@ -20,9 +20,11 @@ import pprint
import sys
import os_client_config
import progressbar
import shade
import yaml
from aerostat import download
from aerostat import resolver
@ -39,8 +41,9 @@ def main():
tasks = []
for server in cloud.list_servers():
tasks.extend(res.server(server))
# for server in cloud.list_servers():
# tasks.extend(res.server(server))
tasks.extend(res.server(cloud.get_server('dev1')))
playbook = [
{'hosts': 'localhost',
@ -51,6 +54,11 @@ def main():
print(yaml.dump(playbook, default_flow_style=False, explicit_start=True))
print('downloading snapshot')
image = cloud.get_image('dev1-sn1')
with download.ProgressBarDownloader('dev1-sn1.dat', image.size) as out:
cloud.download_image('dev1-sn1', output_file=out)
# for volume in dev1.volumes:
# vol = cloud.get_volume(volume.id)
# pprint.pprint(vol)

53
aerostat/download.py Normal file
View File

@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
# Copyright 2010-2011 OpenStack Foundation
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import progressbar
class ProgressBarDownloader:
def __init__(self, output_path, max_value):
self.output_path = output_path
self.max_value = max_value
self.bar = None
self.fd = None
self.amt_read = 0
def __enter__(self):
self.bar = progressbar.ProgressBar(
widgets=[
progressbar.Percentage(),
progressbar.Bar(),
progressbar.FileTransferSpeed(),
' ',
progressbar.ETA(),
],
max_value=self.max_value,
)
self.fd = open(self.output_path, 'wb')
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.fd.close()
self.bar.finish()
return False
def write(self, block):
if block:
self.fd.write(block)
self.amt_read += len(block)
self.bar.update(self.amt_read)

View File

@ -7,3 +7,4 @@ cliff>=2.3.0
shade>=1.12.0
os-client-config>=1.22.0
PyYAML>=3.10.0
progressbar2>=3.12.0