experiment with downloading images
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
d034c3ecc4
commit
5f49d35322
|
@ -57,3 +57,4 @@ ChangeLog
|
||||||
# Files created by releasenotes build
|
# Files created by releasenotes build
|
||||||
releasenotes/build
|
releasenotes/build
|
||||||
/clouds.yaml
|
/clouds.yaml
|
||||||
|
/*.dat
|
||||||
|
|
|
@ -20,9 +20,11 @@ import pprint
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import os_client_config
|
import os_client_config
|
||||||
|
import progressbar
|
||||||
import shade
|
import shade
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from aerostat import download
|
||||||
from aerostat import resolver
|
from aerostat import resolver
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,8 +41,9 @@ def main():
|
||||||
|
|
||||||
tasks = []
|
tasks = []
|
||||||
|
|
||||||
for server in cloud.list_servers():
|
# for server in cloud.list_servers():
|
||||||
tasks.extend(res.server(server))
|
# tasks.extend(res.server(server))
|
||||||
|
tasks.extend(res.server(cloud.get_server('dev1')))
|
||||||
|
|
||||||
playbook = [
|
playbook = [
|
||||||
{'hosts': 'localhost',
|
{'hosts': 'localhost',
|
||||||
|
@ -51,6 +54,11 @@ def main():
|
||||||
|
|
||||||
print(yaml.dump(playbook, default_flow_style=False, explicit_start=True))
|
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:
|
# for volume in dev1.volumes:
|
||||||
# vol = cloud.get_volume(volume.id)
|
# vol = cloud.get_volume(volume.id)
|
||||||
# pprint.pprint(vol)
|
# pprint.pprint(vol)
|
||||||
|
|
|
@ -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)
|
|
@ -7,3 +7,4 @@ cliff>=2.3.0
|
||||||
shade>=1.12.0
|
shade>=1.12.0
|
||||||
os-client-config>=1.22.0
|
os-client-config>=1.22.0
|
||||||
PyYAML>=3.10.0
|
PyYAML>=3.10.0
|
||||||
|
progressbar2>=3.12.0
|
||||||
|
|
Loading…
Reference in New Issue