yahoo-eng-team team mailing list archive
-
yahoo-eng-team team
-
Mailing list archive
-
Message #57782
[Bug 1633514] [NEW] Unable to upload volume data to image on Unified SDK
Public bug reported:
This feature is available and works on old SDK (Cinder), but does not on
Unified SDK. The image service have an "upload_image" method (on unified
SDK) but I cannot get the data to upload it, as the data is stored as a
volume in the block store service, and the only way to download it is
through glance - which is what I am trying to achieve. Here follows some
code sample:
---------------
UNIFIED SDK
---------------
from openstack import connection
import glanceclient.v2.client as glance_client
from keystoneclient.auth.identity import v3
from keystoneauth1 import session
import cinderclient.v3.client as cinder_client
import sys
import os
import time
import getopt
import json
import subprocess
def get_connection_to_services(auth_url, username, password, user_domain_name, project_name, project_domain_name):
conn = connection.Connection(
auth_url=auth_url,
project_name=project_name,
project_domain_name=project_domain_name,
username=username,
user_domain_name=user_domain_name,
password=password)
return conn
inputfile = 'credentials.json'
with open(inputfile) as json_file:
json_string = json_file.read()
json_obj = json.loads(json_string)
username = json_obj["username"]
password = json_obj["password"]
auth_url_sdk = json_obj["auth_url_sdk"]
user_domain_name = json_obj["user_domain_name"]
project_domain_name = json_obj["project_domain_name"]
project_name = json_obj["project_name"]
conn = get_connection_to_services(
auth_url=auth_url_sdk,
project_name=project_name,
project_domain_name=project_domain_name,
username=username,
user_domain_name=user_domain_name,
password=password)
compute_service = conn.compute
network_service = conn.network
image_service = conn.image
block_service = conn.block_store
# id of desired volume to upload to glance.
id = 'e5b40f95-0e24-46d0-a405-6759b4167f97'
# type of volume: openstack.block_store.v2.volume.Volume
volume = block_service.get_volume(id)
#cinder volume url
data = 'http://10.32.135.74:8776/v2/8136b8ab6da346ed8c342022a91aa975/volumes/e5b40f95-0e24-46d0-a405-6759b4167f97'
# this throws an error
image_service.upload_image('bare', 'raw', volume)
# instead of volume, if we use data, it upload the url string bytes
image_service.upload_image('bare', 'raw', data)
------------
Cinder SDK
------------
def get_session(auth_url, username, password, user_domain_name, project_name, project_domain_name):
auth = v3.Password(
auth_url=auth_url,
username=username,
password=password,
user_domain_name=user_domain_name,
project_name=project_name,
project_domain_name=project_domain_name)
return session.Session(auth=auth)
old_session = get_session(
auth_url_sdk,
username,
password,
user_domain_name,
project_name,
project_domain_name)
cinder = cinder_client.Client(session=old_session)
# type of volume2 = cinderclient.v3.volumes.Volume
volume2 = cinder.volumes.get(id)
body = {'force': 'false','image_name': 'volume2', 'container_format': 'bare', 'disk_format': 'raw'}
# works like a charm :D
volume2.upload_to_image(**body)
** Affects: python-openstacksdk
Importance: Undecided
Status: New
** Tags: cinder image-upload volumes
** Project changed: nova => cinder
** Project changed: cinder => python-openstacksdk
--
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to OpenStack Compute (nova).
https://bugs.launchpad.net/bugs/1633514
Title:
Unable to upload volume data to image on Unified SDK
Status in OpenStack SDK:
New
Bug description:
This feature is available and works on old SDK (Cinder), but does not
on Unified SDK. The image service have an "upload_image" method (on
unified SDK) but I cannot get the data to upload it, as the data is
stored as a volume in the block store service, and the only way to
download it is through glance - which is what I am trying to achieve.
Here follows some code sample:
---------------
UNIFIED SDK
---------------
from openstack import connection
import glanceclient.v2.client as glance_client
from keystoneclient.auth.identity import v3
from keystoneauth1 import session
import cinderclient.v3.client as cinder_client
import sys
import os
import time
import getopt
import json
import subprocess
def get_connection_to_services(auth_url, username, password, user_domain_name, project_name, project_domain_name):
conn = connection.Connection(
auth_url=auth_url,
project_name=project_name,
project_domain_name=project_domain_name,
username=username,
user_domain_name=user_domain_name,
password=password)
return conn
inputfile = 'credentials.json'
with open(inputfile) as json_file:
json_string = json_file.read()
json_obj = json.loads(json_string)
username = json_obj["username"]
password = json_obj["password"]
auth_url_sdk = json_obj["auth_url_sdk"]
user_domain_name = json_obj["user_domain_name"]
project_domain_name = json_obj["project_domain_name"]
project_name = json_obj["project_name"]
conn = get_connection_to_services(
auth_url=auth_url_sdk,
project_name=project_name,
project_domain_name=project_domain_name,
username=username,
user_domain_name=user_domain_name,
password=password)
compute_service = conn.compute
network_service = conn.network
image_service = conn.image
block_service = conn.block_store
# id of desired volume to upload to glance.
id = 'e5b40f95-0e24-46d0-a405-6759b4167f97'
# type of volume: openstack.block_store.v2.volume.Volume
volume = block_service.get_volume(id)
#cinder volume url
data = 'http://10.32.135.74:8776/v2/8136b8ab6da346ed8c342022a91aa975/volumes/e5b40f95-0e24-46d0-a405-6759b4167f97'
# this throws an error
image_service.upload_image('bare', 'raw', volume)
# instead of volume, if we use data, it upload the url string bytes
image_service.upload_image('bare', 'raw', data)
------------
Cinder SDK
------------
def get_session(auth_url, username, password, user_domain_name, project_name, project_domain_name):
auth = v3.Password(
auth_url=auth_url,
username=username,
password=password,
user_domain_name=user_domain_name,
project_name=project_name,
project_domain_name=project_domain_name)
return session.Session(auth=auth)
old_session = get_session(
auth_url_sdk,
username,
password,
user_domain_name,
project_name,
project_domain_name)
cinder = cinder_client.Client(session=old_session)
# type of volume2 = cinderclient.v3.volumes.Volume
volume2 = cinder.volumes.get(id)
body = {'force': 'false','image_name': 'volume2', 'container_format': 'bare', 'disk_format': 'raw'}
# works like a charm :D
volume2.upload_to_image(**body)
To manage notifications about this bug go to:
https://bugs.launchpad.net/python-openstacksdk/+bug/1633514/+subscriptions