os_image.share(ctx.obj['os_cloud'], image, dest)
+@click.command()
+@click.argument('image')
+@click.argument('name', nargs=-1, required=True)
+@click.option(
+ '--disk-format', type=str, default='qcow2',
+ help='Disk format of image. (default: qcow2)')
+@click.pass_context
+def upload(ctx, image, name, disk_format):
+ """Share image with another tenant."""
+ name = ' '.join(name)
+ os_image.upload(ctx.obj['os_cloud'], image, name, disk_format)
+
+
image.add_command(cleanup)
image.add_command(list)
image.add_command(share)
+image.add_command(upload)
@openstack.group()
from datetime import datetime
from datetime import timedelta
import logging
+import re
import subprocess
import sys
+import tempfile
import shade
+from six.moves import urllib
log = logging.getLogger(__name__)
log.info('Sharing to {}.'.format(cloud))
_share_to_cloud(os_cloud, image_id, _get_token(cloud))
_accept_shared_image(cloud, image_id)
+
+
+def upload(os_cloud, image, name, disk_format='qcow2'):
+ """Upload image to openstack."""
+ log.info('Uploading image {} with name "{}".'.format(image, name))
+ cloud = shade.openstack_cloud(cloud=os_cloud)
+
+ if re.match(r'^http[s]?://', image):
+ tmp = tempfile.NamedTemporaryFile(suffix='.img')
+ log.info('URL provided downloading image locally to {}.'.format(tmp.name))
+ urllib.request.urlretrieve(image, tmp.name) # nosec
+ image = tmp.name
+
+ try:
+ cloud.create_image(name, image, disk_format=disk_format, wait=True)
+ except FileNotFoundError as e:
+ log.info(str(e))
+ sys.exit(1)
+
+ log.info('Upload complete.')