* Added first cut of migration for os_type on instances table
* Track os_type when taking snapshots
This commit is contained in:
@@ -34,7 +34,7 @@ instances_os_type = Column('os_type',
|
||||
String(length=255, convert_unicode=False,
|
||||
assert_unicode=None, unicode_error=None,
|
||||
_warn_on_bytestring=False),
|
||||
nullable=True)
|
||||
nullable=False)
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
@@ -43,3 +43,5 @@ def upgrade(migrate_engine):
|
||||
meta.bind = migrate_engine
|
||||
|
||||
instances.create_column(instances_os_type)
|
||||
|
||||
|
||||
|
||||
@@ -303,7 +303,7 @@ class VMHelper(HelperBase):
|
||||
return template_vm_ref, template_vdi_uuids
|
||||
|
||||
@classmethod
|
||||
def upload_image(cls, session, instance_id, vdi_uuids, image_id):
|
||||
def upload_image(cls, session, instance, vdi_uuids, image_id):
|
||||
""" Requests that the Glance plugin bundle the specified VDIs and
|
||||
push them into Glance using the specified human-friendly name.
|
||||
"""
|
||||
@@ -312,15 +312,18 @@ class VMHelper(HelperBase):
|
||||
logging.debug(_("Asking xapi to upload %(vdi_uuids)s as"
|
||||
" ID %(image_id)s") % locals())
|
||||
|
||||
# TODO(dubs): os_type is currently defaulting to linux, we actually
|
||||
# want to make this a NOT NULL column and require it to be specified.
|
||||
params = {'vdi_uuids': vdi_uuids,
|
||||
'image_id': image_id,
|
||||
'glance_host': FLAGS.glance_host,
|
||||
'glance_port': FLAGS.glance_port,
|
||||
'sr_path': get_sr_path(session)}
|
||||
'sr_path': get_sr_path(session),
|
||||
'os_type': instance.get('os_type', 'linux')}
|
||||
|
||||
kwargs = {'params': pickle.dumps(params)}
|
||||
task = session.async_call_plugin('glance', 'upload_vhd', kwargs)
|
||||
session.wait_for_task(instance_id, task)
|
||||
session.wait_for_task(instance.id, task)
|
||||
|
||||
@classmethod
|
||||
def fetch_image(cls, session, instance_id, image, user, project,
|
||||
|
||||
@@ -238,11 +238,11 @@ class VMOps(object):
|
||||
try:
|
||||
# call plugin to ship snapshot off to glance
|
||||
VMHelper.upload_image(
|
||||
self._session, instance.id, template_vdi_uuids, image_id)
|
||||
self._session, instance, template_vdi_uuids, image_id)
|
||||
finally:
|
||||
self._destroy(instance, template_vm_ref, shutdown=False,
|
||||
destroy_kernel_ramdisk=False)
|
||||
|
||||
|
||||
logging.debug(_("Finished snapshot and upload for VM %s"), instance)
|
||||
|
||||
def reboot(self, instance):
|
||||
|
||||
@@ -191,7 +191,7 @@ def _prepare_staging_area_for_upload(sr_path, staging_path, vdi_uuids):
|
||||
os.link(source, link_name)
|
||||
|
||||
|
||||
def _upload_tarball(staging_path, image_id, glance_host, glance_port):
|
||||
def _upload_tarball(staging_path, image_id, glance_host, glance_port, os_type):
|
||||
"""
|
||||
Create a tarball of the image and then stream that into Glance
|
||||
using chunked-transfer-encoded HTTP.
|
||||
@@ -205,9 +205,10 @@ def _upload_tarball(staging_path, image_id, glance_host, glance_port):
|
||||
headers = {
|
||||
'content-type': 'application/octet-stream',
|
||||
'transfer-encoding': 'chunked',
|
||||
'x-image-meta-is_public': 'True',
|
||||
'x-image-meta-is-public': 'True',
|
||||
'x-image-meta-status': 'queued',
|
||||
'x-image-meta-type': 'vhd'
|
||||
'x-image-meta-type': 'vhd',
|
||||
'x-image-meta-property-os-type': os_type
|
||||
}
|
||||
for header, value in headers.iteritems():
|
||||
conn.putheader(header, value)
|
||||
@@ -330,11 +331,13 @@ def upload_vhd(session, args):
|
||||
glance_host = params["glance_host"]
|
||||
glance_port = params["glance_port"]
|
||||
sr_path = params["sr_path"]
|
||||
os_type = params["os_type"]
|
||||
|
||||
staging_path = _make_staging_area(sr_path)
|
||||
try:
|
||||
_prepare_staging_area_for_upload(sr_path, staging_path, vdi_uuids)
|
||||
_upload_tarball(staging_path, image_id, glance_host, glance_port)
|
||||
_upload_tarball(staging_path, image_id, glance_host, glance_port,
|
||||
os_type)
|
||||
finally:
|
||||
_cleanup_staging_area(staging_path)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user