def _audit_nfvi_images_callback(timer_id): """ Audit Images """ global _main_audit_inprogress global _deletable_images, _nfvi_images_paging response = (yield) DLOG.verbose("Audit-Images callback, response=%s." % response) if response['completed']: if response['page-request-id'] == _nfvi_images_paging.page_request_id: image_table = tables.tables_get_image_table() if _deletable_images is None: _deletable_images = list(image_table) for nfvi_image in response['result-data']: image = image_table.get(nfvi_image.uuid, None) if image is None: image = objects.Image(nfvi_image) image_table[nfvi_image.uuid] = image else: if not image.is_deleted(): if nfvi_image.uuid in _deletable_images: _deletable_images.remove(nfvi_image.uuid) image.nfvi_image_update(nfvi_image) if _nfvi_images_paging.done: for image_uuid in _deletable_images: image = image_table.get(image_uuid, None) image.nfvi_image_deleted() if image.is_deleted(): del image_table[image_uuid] _deletable_images = list(image_table) _nfvi_images_paging.first_page() else: DLOG.error("Audit-Images callback, page-request-id mismatch, " "responses=%s, page-request-id=%s." % (response, _nfvi_images_paging.page_request_id)) image_table = tables.tables_get_image_table() _deletable_images = list(image_table) _nfvi_images_paging.first_page() else: DLOG.error("Audit-Images callback, not completed, responses=%s." % response) image_table = tables.tables_get_image_table() _deletable_images = list(image_table) _nfvi_images_paging.first_page() _nfvi_images_paging.set_page_request_id() _main_audit_inprogress = False timers.timers_reschedule_timer(timer_id, 2) # 2 seconds later
def vim_image_api_get_image(connection, msg): """ Handle Get-Image API request """ DLOG.verbose("Get image, filter_by_uuid=%s." % msg.filter_by_uuid) image_table = tables.tables_get_image_table() response = rpc.APIResponseGetImage() image = image_table.get(msg.filter_by_uuid, None) if image is not None: response.uuid = image.uuid response.name = image.name response.description = image.description response.container_format = image.container_format response.disk_format = image.disk_format response.min_disk_size_gb = image.min_disk_size_gb response.min_memory_size_mb = image.min_memory_size_mb response.visibility = image.visibility response.protected = image.protected response.avail_status = image.avail_status response.action = image.action response.properties = json.dumps(image.properties) else: response.result = rpc.RPC_MSG_RESULT.NOT_FOUND connection.send(response.serialize()) DLOG.verbose("Sent response=%s" % response) connection.close()
def _image_delete_callback(self, image_uuid, callback): """ Image Delete Callback """ response = (yield) DLOG.verbose("Image-Delete callback response=%s." % response) if response['completed']: image_table = tables.tables_get_image_table() image = image_table.get(image_uuid, None) if image is not None: if image.is_deleted(): del image_table[image_uuid] callback(response['completed'], image_uuid)
def vim_image_api_get_images(connection, msg): """ Handle Get-Images API request """ DLOG.verbose("Get image, all=%s." % msg.get_all) image_table = tables.tables_get_image_table() for image in image_table.itervalues(): response = rpc.APIResponseGetImage() response.uuid = image.uuid response.name = image.name response.description = image.description response.container_format = image.container_format response.disk_format = image.disk_format response.min_disk_size_gb = image.min_disk_size_gb response.min_memory_size_mb = image.min_memory_size_mb response.visibility = image.visibility response.protected = image.protected response.avail_status = image.avail_status response.action = image.action response.properties = json.dumps(image.properties) connection.send(response.serialize()) DLOG.verbose("Sent response=%s" % response) connection.close()
def _image_update_callback(self, image_uuid, callback): """ Image Update Callback """ response = (yield) DLOG.verbose("Image-Update callback response=%s." % response) if response['completed']: nfvi_image = response['result-data'] image_table = tables.tables_get_image_table() image = image_table.get(nfvi_image.uuid, None) if image is not None: image = objects.Image(nfvi_image) image_table[nfvi_image.uuid] = image image.nfvi_image_update(nfvi_image) callback(response['completed'], image_uuid, nfvi_image.name, nfvi_image.description, nfvi_image.container_format, nfvi_image.disk_format, nfvi_image.min_disk_size_gb, nfvi_image.min_memory_size_mb, nfvi_image.visibility, nfvi_image.protected, nfvi_image.avail_status, nfvi_image.action, nfvi_image.properties) else: callback(response['completed'], image_uuid, None, None, None, None, None, None, None, None, None, None, None)