def _nfvi_lock_host_callback(self): """ NFVI Lock Host Callback """ from nfv_vim import directors response = (yield) DLOG.verbose("NFVI Lock Host callback response=%s." % response) if not response['completed']: DLOG.info("Lock of host %s failed, reason=%s." % (response['host_name'], response['reason'])) host_table = tables.tables_get_host_table() host = host_table.get(response['host_name'], None) if host is None: DLOG.verbose("Host %s does not exist." % response['host_name']) return if self._host_operation is None: DLOG.verbose("No host %s operation inprogress." % host.name) return if OPERATION_TYPE.LOCK_HOSTS != self._host_operation.operation_type: DLOG.verbose("Unexpected host %s operation %s, ignoring." % (host.name, self._host_operation.operation_type)) return sw_mgmt_director = directors.get_sw_mgmt_director() sw_mgmt_director.host_lock_failed(host)
def _nfvi_disable_host_services_callback(self): """ NFVI Disable Host Services Callback """ from nfv_vim import directors response = (yield) DLOG.verbose("NFVI Disable Host Services callback response=%s." % response) if not response['completed']: DLOG.info( "Disable of host services on host %s failed, reason=%s." % (response['host_name'], response['reason'])) host_table = tables.tables_get_host_table() host = host_table.get(response['host_name'], None) if host is None: DLOG.verbose("Host %s does not exist." % response['host_name']) return if self._host_operation is None: DLOG.verbose("No host %s operation inprogress." % host.name) return if OPERATION_TYPE.DISABLE_HOST_SERVICES != \ self._host_operation.operation_type: DLOG.verbose("Unexpected host %s operation %s, ignoring." % (host.name, self._host_operation.operation_type)) return sw_mgmt_director = directors.get_sw_mgmt_director() sw_mgmt_director.disable_host_services_failed(host)
def vim_sw_update_api_get_strategy(connection, msg): """ Handle Sw-Update Get Strategy API request """ DLOG.verbose("Get sw-update strategy.") if 'sw-patch' == msg.sw_update_type: sw_update_type = objects.SW_UPDATE_TYPE.SW_PATCH elif 'sw-upgrade' == msg.sw_update_type: sw_update_type = objects.SW_UPDATE_TYPE.SW_UPGRADE else: DLOG.error("Invalid message name: %s" % msg.sw_update_type) sw_update_type = 'unknown' response = rpc.APIResponseGetSwUpdateStrategy() sw_mgmt_director = directors.get_sw_mgmt_director() strategy = sw_mgmt_director.get_sw_update_strategy(sw_update_type) if strategy is None: DLOG.verbose("No sw-update strategy exists.") response.result = rpc.RPC_MSG_RESULT.NOT_FOUND elif msg.uuid is None: response.strategy = strategy.as_json() elif msg.uuid != strategy.uuid: DLOG.info("No sw-update strategy exists matching strategy uuid %s." % msg.uuid) response.result = rpc.RPC_MSG_RESULT.NOT_FOUND else: response.strategy = strategy.as_json() connection.send(response.serialize()) DLOG.verbose("Sent response=%s." % response) connection.close()
def vim_sw_update_api_delete_strategy(connection, msg): """ Handle Sw-Update Delete Strategy API request """ DLOG.info("Delete sw-update strategy, force=%s.", msg.force) if 'sw-patch' == msg.sw_update_type: sw_update_type = objects.SW_UPDATE_TYPE.SW_PATCH elif 'sw-upgrade' == msg.sw_update_type: sw_update_type = objects.SW_UPDATE_TYPE.SW_UPGRADE else: DLOG.error("Invalid message name: %s" % msg.sw_update_type) sw_update_type = 'unknown' sw_mgmt_director = directors.get_sw_mgmt_director() strategy = sw_mgmt_director.get_sw_update_strategy(sw_update_type) if strategy is None: DLOG.info("No sw-update strategy to delete.") response = rpc.APIResponseDeleteSwUpdateStrategy() response.result = rpc.RPC_MSG_RESULT.NOT_FOUND connection.send(response.serialize()) DLOG.verbose("Sent response=%s." % response) connection.close() return _sw_update_strategy_delete_operations[strategy.uuid] = connection sw_mgmt_director.delete_sw_update_strategy( strategy.uuid, msg.force, _vim_sw_update_api_delete_strategy_callback)
def host_state_change_notify(host): """ Notifies the host director that a host has changed state """ from nfv_vim import directors DLOG.info("Host %s state change notification." % host.name) sw_mgmt_director = directors.get_sw_mgmt_director() sw_mgmt_director.host_state_change(host)
def __init__(self, host): from nfv_vim import objects self._host_reference = weakref.ref(host) if objects.HOST_PERSONALITY.WORKER in self._host.personality and \ self._host.is_force_lock(): # When a worker host is being disabled due to a force lock, we # want it to be rebooted. To do this we need to indicate that # the host services disable failed. notify_host_services_task = NotifyHostServicesDisableFailedTaskWork else: notify_host_services_task = NotifyHostServicesDisabledTaskWork task_work_list = list() if host.host_service_configured(objects.HOST_SERVICES.COMPUTE): task_work_list.append( DisableHostServicesTaskWork(self, host, objects.HOST_SERVICES.COMPUTE)) if host.host_service_configured(objects.HOST_SERVICES.GUEST): task_work_list.append( DisableHostServicesTaskWork(self, host, objects.HOST_SERVICES.GUEST)) if host.host_service_configured(objects.HOST_SERVICES.COMPUTE): task_work_list.append( QueryHypervisorTaskWork(self, host, force_pass=True)) task_work_list.append(NotifyInstancesHostDisablingTaskWork(self, host)) if host.host_service_configured(objects.HOST_SERVICES.COMPUTE): task_work_list.append( NotifyHostDisabledTaskWork(self, host, objects.HOST_SERVICES.COMPUTE)) if host.host_service_configured(objects.HOST_SERVICES.NETWORK): task_work_list.append( NotifyHostDisabledTaskWork(self, host, objects.HOST_SERVICES.NETWORK)) task_work_list.append(NotifyInstancesHostDisabledTaskWork(self, host)) if host.host_service_configured(objects.HOST_SERVICES.CONTAINER): # Only disable the container services if the host is being locked # (or is already locked) and we are not running in a single # controller configuration. In a single controller configuration we # keep the container services running. if self._host.is_locking() or self._host.is_locked(): from nfv_vim import directors sw_mgmt_director = directors.get_sw_mgmt_director() if not sw_mgmt_director.single_controller: task_work_list.append( DisableHostServicesTaskWork( self, host, objects.HOST_SERVICES.CONTAINER)) task_work_list.append( notify_host_services_task(self, host, force_pass=True)) if host.host_service_configured(objects.HOST_SERVICES.COMPUTE): task_work_list.append( QueryHypervisorTaskWork(self, host, force_pass=True)) super(DisableHostTask, self).__init__('disable-host_%s' % host.name, task_work_list)
def host_audit(host): """ Notifies the host director that a host audit is inprogress """ from nfv_vim import directors DLOG.verbose( "Notify other directors that a host %s audit is inprogress." % host.name) instance_director = directors.get_instance_director() instance_director.host_audit(host) sw_mgmt_director = directors.get_sw_mgmt_director() sw_mgmt_director.host_audit(host)
def __init__(self, host): from nfv_vim import objects self._host_reference = weakref.ref(host) task_work_list = list() if host.host_service_configured(objects.HOST_SERVICES.CONTAINER): # Only disable the container services if the host is being locked # and we are not running in a single controller configuration. In # a single controller configuration we keep the container services # running. if self._host.is_locking(): from nfv_vim import directors sw_mgmt_director = directors.get_sw_mgmt_director() if not sw_mgmt_director.single_controller: task_work_list.append( DisableHostServicesTaskWork( self, host, objects.HOST_SERVICES.CONTAINER)) task_work_list.append( NotifyHostServicesDisabledTaskWork(self, host, force_pass=True)) super(NotifyDisabledHostTask, self).__init__('notify-disabled-host_%s' % host.name, task_work_list)
def vim_sw_update_api_create_strategy(connection, msg): """ Handle Sw-Update Create Strategy API request """ global _sw_update_strategy_create_operations DLOG.info("Create sw-update strategy.") if 'parallel' == msg.controller_apply_type: controller_apply_type = objects.SW_UPDATE_APPLY_TYPE.PARALLEL elif 'serial' == msg.controller_apply_type: controller_apply_type = objects.SW_UPDATE_APPLY_TYPE.SERIAL else: controller_apply_type = objects.SW_UPDATE_APPLY_TYPE.IGNORE if 'parallel' == msg.storage_apply_type: storage_apply_type = objects.SW_UPDATE_APPLY_TYPE.PARALLEL elif 'serial' == msg.storage_apply_type: storage_apply_type = objects.SW_UPDATE_APPLY_TYPE.SERIAL else: storage_apply_type = objects.SW_UPDATE_APPLY_TYPE.IGNORE if 'parallel' == msg.swift_apply_type: swift_apply_type = objects.SW_UPDATE_APPLY_TYPE.PARALLEL elif 'serial' == msg.swift_apply_type: swift_apply_type = objects.SW_UPDATE_APPLY_TYPE.SERIAL else: swift_apply_type = objects.SW_UPDATE_APPLY_TYPE.IGNORE if 'parallel' == msg.compute_apply_type: compute_apply_type = objects.SW_UPDATE_APPLY_TYPE.PARALLEL elif 'serial' == msg.compute_apply_type: compute_apply_type = objects.SW_UPDATE_APPLY_TYPE.SERIAL else: compute_apply_type = objects.SW_UPDATE_APPLY_TYPE.IGNORE if msg.max_parallel_compute_hosts is not None: max_parallel_compute_hosts = msg.max_parallel_compute_hosts else: max_parallel_compute_hosts = 2 if 'migrate' == msg.default_instance_action: default_instance_action = objects.SW_UPDATE_INSTANCE_ACTION.MIGRATE else: default_instance_action = objects.SW_UPDATE_INSTANCE_ACTION.STOP_START if 'strict' == msg.alarm_restrictions: alarm_restrictions = objects.SW_UPDATE_ALARM_RESTRICTION.STRICT else: alarm_restrictions = objects.SW_UPDATE_ALARM_RESTRICTION.RELAXED sw_mgmt_director = directors.get_sw_mgmt_director() if 'sw-patch' == msg.sw_update_type: uuid, reason = sw_mgmt_director.create_sw_patch_strategy( controller_apply_type, storage_apply_type, swift_apply_type, compute_apply_type, max_parallel_compute_hosts, default_instance_action, alarm_restrictions, _vim_sw_update_api_create_strategy_callback) elif 'sw-upgrade' == msg.sw_update_type: start_upgrade = msg.start_upgrade complete_upgrade = msg.complete_upgrade uuid, reason = sw_mgmt_director.create_sw_upgrade_strategy( storage_apply_type, compute_apply_type, max_parallel_compute_hosts, alarm_restrictions, start_upgrade, complete_upgrade, _vim_sw_update_api_create_strategy_callback) else: DLOG.error("Invalid message name: %s" % msg.sw_update_type) response = rpc.APIResponseCreateSwUpdateStrategy() response.result = rpc.RPC_MSG_RESULT.FAILED connection.send(response.serialize()) DLOG.verbose("Sent response=%s." % response) connection.close() return if uuid is None: response = rpc.APIResponseCreateSwUpdateStrategy() if reason == "strategy already exists": response.result = rpc.RPC_MSG_RESULT.CONFLICT else: response.result = rpc.RPC_MSG_RESULT.FAILED connection.send(response.serialize()) DLOG.verbose("Sent response=%s." % response) connection.close() return _sw_update_strategy_create_operations[uuid] = connection