def _audit_nfvi_volume(): """ Audit NFVI Volume """ global _nfvi_volumes_to_audit, _nfvi_volumes_outstanding while True: timer_id = (yield) DLOG.verbose("Audit volume called, timer_id=%s." % timer_id) for volume_uuid in _nfvi_volumes_outstanding.keys(): volume_table = tables.tables_get_volume_table() volume = volume_table.get(volume_uuid, None) if volume is None: del _nfvi_volumes_outstanding[volume_uuid] for volume_uuid in _nfvi_volumes_to_audit.keys(): if 4 <= len(_nfvi_volumes_outstanding): break DLOG.verbose("Auditing volume %s." % volume_uuid) nfvi.nfvi_get_volume(volume_uuid, _audit_nfvi_volume_callback(volume_uuid)) _nfvi_volumes_outstanding[volume_uuid] \ = _nfvi_volumes_to_audit[volume_uuid] del _nfvi_volumes_to_audit[volume_uuid]
def _volume_delete_callback(self, volume_uuid, callback): """ Volume Delete Callback """ response = (yield) DLOG.verbose("Volume-Delete callback response=%s." % response) if response['completed']: volume_table = tables.tables_get_volume_table() volume = volume_table.get(volume_uuid, None) if volume is not None: if volume.is_deleted(): del volume_table[volume_uuid] callback(response['completed'], volume_uuid)
def vim_volume_api_get_volumes(connection, msg): """ Handle Get-Volumes API request """ DLOG.verbose("Get volume, all=%s." % msg.get_all) volume_table = tables.tables_get_volume_table() for volume in volume_table.itervalues(): response = rpc.APIResponseGetVolume() response.uuid = volume.uuid response.name = volume.name response.description = volume.description response.size_gb = volume.size_gb response.bootable = volume.bootable response.encrypted = volume.encrypted response.avail_status = volume.avail_status response.action = volume.action connection.send(response.serialize()) DLOG.verbose("Sent response=%s" % response) connection.close()
def _volume_update_callback(self, volume_uuid, callback): """ Volume Update Callback """ response = (yield) DLOG.verbose("Volume-Update callback response=%s." % response) if response['completed']: nfvi_volume = response['result-data'] volume_table = tables.tables_get_volume_table() volume = volume_table.get(nfvi_volume.uuid, None) if volume is not None: volume = objects.Volume(nfvi_volume) volume_table[nfvi_volume.uuid] = volume volume.nfvi_volume_update(nfvi_volume) callback(response['completed'], volume_uuid, nfvi_volume.name, nfvi_volume.description, nfvi_volume.size_gb, nfvi_volume.bootable, nfvi_volume.encrypted, nfvi_volume.avail_status, nfvi_volume.action) else: callback(response['completed'], volume_uuid, None, None, None, None, None, None, None)
def vim_volume_api_get_volume(connection, msg): """ Handle Get-Volume API request """ DLOG.verbose("Get volume, filter_by_uuid=%s." % msg.filter_by_uuid) volume_table = tables.tables_get_volume_table() response = rpc.APIResponseGetVolume() volume = volume_table.get(msg.filter_by_uuid, None) if volume is not None: response.uuid = volume.uuid response.name = volume.name response.description = volume.description response.size_gb = volume.size_gb response.bootable = volume.bootable response.encrypted = volume.encrypted response.avail_status = volume.avail_status response.action = volume.action else: response.result = rpc.RPC_MSG_RESULT.NOT_FOUND connection.send(response.serialize()) DLOG.verbose("Sent response=%s" % response) connection.close()
def _audit_nfvi_volume_callback(volume_uuid): """ Audit Volumes """ global _nfvi_volumes_outstanding response = (yield) DLOG.verbose("Audit-Volume callback, response=%s." % response) if volume_uuid in _nfvi_volumes_outstanding: del _nfvi_volumes_outstanding[volume_uuid] if response['completed']: nfvi_volume = response['result-data'] volume_table = tables.tables_get_volume_table() volume = volume_table.get(nfvi_volume.uuid, None) if volume is None: volume = objects.Volume(nfvi_volume) volume_table[volume.uuid] = volume volume.nfvi_volume_update(nfvi_volume) else: DLOG.error("Audit-Volume callback, not completed, response=%s." % response)
def _audit_nfvi_volumes_callback(timer_id): """ Audit Volumes """ global _main_audit_inprogress global _added_volumes, _deletable_volumes, _nfvi_volumes_paging global _nfvi_volumes_to_audit, _nfvi_volumes_outstanding response = (yield) DLOG.verbose("Audit-Volumes callback, response=%s." % response) if response['completed']: if response['page-request-id'] == _nfvi_volumes_paging.page_request_id: volume_table = tables.tables_get_volume_table() if _added_volumes is None: _added_volumes = list() if _deletable_volumes is None: _deletable_volumes = list(volume_table) for volume_uuid, volume_name in response['result-data']: volume = volume_table.get(volume_uuid, None) if volume is not None: if volume.uuid in _deletable_volumes: _deletable_volumes.remove(volume.uuid) if volume_uuid not in _nfvi_volumes_to_audit: _nfvi_volumes_to_audit[volume_uuid] = volume_name _added_volumes.append(volume_uuid) if _nfvi_volumes_paging.done: for volume_uuid in _deletable_volumes: volume = volume_table[volume_uuid] volume.nfvi_volume_deleted() if volume.is_deleted(): del volume_table[volume_uuid] if volume_uuid in _nfvi_volumes_to_audit: del _nfvi_volumes_to_audit[volume_uuid] if volume_uuid in _nfvi_volumes_outstanding: del _nfvi_volumes_outstanding[volume_uuid] for volume_uuid in _nfvi_volumes_to_audit: if volume_uuid not in _added_volumes: volume = volume_table.get(volume_uuid, None) if volume is None: del _nfvi_volumes_to_audit[volume_uuid] if volume_uuid in _nfvi_volumes_outstanding: del _nfvi_volumes_outstanding[volume_uuid] _added_volumes[:] = [] _deletable_volumes = list(volume_table) _nfvi_volumes_paging.first_page() else: DLOG.error("Audit-Volumes callback, page-request-id mismatch, " "responses=%s, page-request-id=%s." % (response, _nfvi_volumes_paging.page_request_id)) volume_table = tables.tables_get_volume_table() if _added_volumes is None: _added_volumes = list() else: _added_volumes[:] = [] _deletable_volumes = list(volume_table) _nfvi_volumes_paging.first_page() else: DLOG.error("Audit-Volumes callback, not completed, responses=%s." % response) volume_table = tables.tables_get_volume_table() if _added_volumes is None: _added_volumes = list() else: _added_volumes[:] = [] _deletable_volumes = list(volume_table) _nfvi_volumes_paging.first_page() _nfvi_volumes_paging.set_page_request_id() _main_audit_inprogress = False timers.timers_reschedule_timer(timer_id, 2) # 2 seconds later