def self_test(self, mode=0): """ Verifies that system devices are able to perform basic I/O functions. No other tasks should run on the system while executing the self test because the driver may need exclusive access to some device resources. You do not need to disconnect devices from external equipment because the state of I/O lines are maintained throughout the test. mode - Reserved. This must be 0. Returns a string containing results of any errors that may have occurred during execution. Raises an nisyscfg.errors.LibraryError exception in the event of an error. """ c_detailed_result = ctypes.POINTER(ctypes.c_char)() error_code = self._library.SelfTestHardware( self._handle, mode, ctypes.pointer(c_detailed_result)) if c_detailed_result: detailed_result = c_string_decode( ctypes.cast(c_detailed_result, ctypes.c_char_p).value) error_code_2 = self._library.FreeDetailedString(c_detailed_result) nisyscfg.errors.handle_error(self, error_code) nisyscfg.errors.handle_error(self, error_code_2) return detailed_result
def save_changes(self): """ Writes and saves property changes on a device. Returns tuple (restart_required, detailed_description) restart_required - Specifies whether the changes require a reboot. If True, call restart. detailed_description - A string containing results of any errors that may have occurred during execution. Raises an nisyscfg.errors.LibraryError exception in the event of an error. """ restart_required = ctypes.c_int() c_detailed_description = ctypes.POINTER(ctypes.c_char)() error_code = self._library.SaveResourceChanges( self._handle, restart_required, ctypes.pointer(c_detailed_description)) if c_detailed_description: detailed_description = c_string_decode( ctypes.cast(c_detailed_description, ctypes.c_char_p).value) error_code_2 = self._library.FreeDetailedString( c_detailed_description) nisyscfg.errors.handle_error(self, error_code) nisyscfg.errors.handle_error(self, error_code_2) ReturnData = collections.namedtuple( 'ReturnData', 'restart_required detailed_description') return ReturnData(restart_required.value != 0, detailed_description)
def save_changes(self): """ Saves changes made to systems. Returns tuple (restart_required, result) restart_required - Specifies whether the changes require a reboot. If TRUE, call restart(). result - A string containing results of any errors that may have occurred during execution. Raises an nisyscfg.errors.LibraryError exception in the event of an error. """ restart_required = ctypes.c_int() c_detailed_description = ctypes.POINTER(ctypes.c_char)() error_code = self._library.SaveSystemChanges( self._session, restart_required, ctypes.pointer(c_detailed_description)) if c_detailed_description: detailed_description = c_string_decode( ctypes.cast(c_detailed_description, ctypes.c_char_p).value) error_code_2 = self._library.FreeDetailedString( c_detailed_description) nisyscfg.errors.handle_error(self, error_code) nisyscfg.errors.handle_error(self, error_code_2) return restart_required.value != 0, detailed_description
def __next__(self): if not self._handle: # TODO(tkrebes): raise RuntimeError raise StopIteration() expert_name = nisyscfg.types.simple_string() display_name = nisyscfg.types.simple_string() version = nisyscfg.types.simple_string() error_code = self._library.NextExpertInfo(self._handle, expert_name, display_name, version) if error_code == 1: raise StopIteration() nisyscfg.errors.handle_error(self, error_code) return { 'expert_name': c_string_decode(expert_name.value), 'display_name': c_string_decode(display_name.value), 'version': c_string_decode(version.value), }
def __next__(self): id = nisyscfg.types.simple_string() version = nisyscfg.types.simple_string() title = nisyscfg.types.simple_string() item_type = nisyscfg.types.ctypes.c_long() error_code = self._library.NextComponentInfo(self._handle, id, version, title, ctypes.pointer(item_type), None) if error_code == 1: raise StopIteration() nisyscfg.errors.handle_error(self, error_code) return { 'id': c_string_decode(id.value), 'version': c_string_decode(version.value), 'title': c_string_decode(title.value), 'type': nisyscfg.types.ComponentType(item_type.value), 'details': None, # TODO(tkrebes): Implement }
def delete(self, mode=nisyscfg.enums.DeleteValidationMode. DELETE_IF_NO_DEPENDENCIES_EXIST): """ Permanently removes a hardware resource and its configuration data from the system. Note: Not all devices can be deleted; consult your product documentation. mode - Specifies the conditions under which to delete the specified resource. ================================= ====================================== Mode Description --------------------------------- -------------------------------------- VALIDATE_BUT_DO_NOT_DELETE Verify whether the resource can be deleted and whether it has dependencies. DELETE_IF_NO_DEPENDENCIES_EXIST Delete the resource only if no dependencies exist. These could be tasks or child resources. DELETE_ITEM_AND_ANY_DEPENDENCIES Delete this resource. If any dependencies exist, delete them too. DELETE_ITEM_BUT_KEEP_DEPENDENCIES Delete this resource. If any dependencies exist, leave them in an unusable state. ================================= ====================================== Returns tuple (dependent_items_deleted, detailed_result) dependent_items_deleted - Returns whether resources other than the specified one were deleted. For example, this may happen if the resource is a simulated chassis that contained modules. detailed_result - A string containing results of any errors that may have occurred during execution. Raises an nisyscfg.errors.LibraryError exception in the event of an error. """ dependent_items_deleted = ctypes.c_int() c_detailed_result = ctypes.POINTER(ctypes.c_char)() error_code = self._library.DeleteResource( self._handle, mode, dependent_items_deleted, ctypes.pointer(c_detailed_result)) if c_detailed_result: detailed_result = c_string_decode( ctypes.cast(c_detailed_result, ctypes.c_char_p).value) error_code_2 = self._library.FreeDetailedString(c_detailed_result) nisyscfg.errors.handle_error(self, error_code) nisyscfg.errors.handle_error(self, error_code_2) ReturnData = collections.namedtuple( 'ReturnData', 'dependent_items_deleted detailed_result') return ReturnData(dependent_items_deleted.value != 0, detailed_result)
def _get_status_description(self, status): c_detailed_description = ctypes.POINTER(ctypes.c_char)() error_code = self._library.GetStatusDescription( self._session, status, ctypes.pointer(c_detailed_description)) if c_detailed_description: detailed_description = c_string_decode( ctypes.cast(c_detailed_description, ctypes.c_char_p).value) error_code_2 = self._library.FreeDetailedString( c_detailed_description) nisyscfg.errors.handle_error(self, error_code, is_error_handling=True) nisyscfg.errors.handle_error(self, error_code_2, is_error_handling=True) return detailed_description
def firmware_status(self): """ Returns the status of the firmware upgrade in progress. Returns tuple (percent_complete, status, detailed_result) percent_complete - The status, in percent, of the current step in the firmware upgrade. This parameter returns -1 if there is no firmware update in progress. status - The status of the firmware update. If this output returns FirmwareStatus.READY_PENDING_USER_RESTART, call restart. You can view more information about additional results in the detailed_result output. detailed_result - Results of any errors that may have occurred when this function completed. This output also may return additional information about the value returned from status. Raises an nisyscfg.errors.LibraryError exception in the event of an error. """ percent_complete = ctypes.c_int() firmware_status = ctypes.c_int() c_detailed_result = ctypes.POINTER(ctypes.c_char)() error_code = self._library.CheckFirmwareStatus( self._handle, percent_complete, firmware_status, ctypes.pointer(c_detailed_result)) if c_detailed_result: detailed_result = c_string_decode( ctypes.cast(c_detailed_result, ctypes.c_char_p).value) error_code_2 = self._library.FreeDetailedString(c_detailed_result) nisyscfg.errors.handle_error(self, error_code) nisyscfg.errors.handle_error(self, error_code_2) ReturnData = collections.namedtuple( 'ReturnData', 'percent_complete status detailed_result') return ReturnData( percent_complete.value, nisyscfg.enums.FirmwareStatus(firmware_status.value), detailed_result, )
def _get_indexed_property(self, id, index, c_type): if c_type == ctypes.c_char_p: value = nisyscfg.types.simple_string() value_arg = value elif issubclass(c_type, nisyscfg.enums.BaseEnum): value = ctypes.c_int() value_arg = ctypes.pointer(value) else: value = c_type() value_arg = ctypes.pointer(value) error_code = self._library.GetResourceIndexedProperty( self._handle, id, index, value_arg) nisyscfg.errors.handle_error(self, error_code) if issubclass(c_type, nisyscfg.enums.BaseEnum): return c_type(value.value) return c_string_decode(value.value)
def restart(self, sync_call=True, install_mode=False, flush_dns=False, timeout=90000): """ Reboots a system or network device. sync_call - Waits until the reboot has finished before the function operation is completed, by default. Select FALSE to not wait until the reboot is finished before the function completes its operation. install_mode - Does not reboot the system into install mode by default. To reboot into install mode, select TRUE. The default is FALSE, reboot into normal mode. flush_dns - Does not clear the DNS cache by default. DNS clients temporarily store system hostnames. Flushing the DNS allows you to clear those names from memory. This parameter applies to the local Windows system. timeout - The time, in milliseconds, that the function waits to establish a connection before it returns an error. The default is 90,000 ms (90 s). Returns the new IP address of the rebooted system. This IP address may differ from the previous IP address if the system acquires a different IP address from the DHCP server. Raises an nisyscfg.errors.LibraryError exception in the event of an error. """ new_ip_address = nisyscfg.types.simple_string() error_code = self._library.Restart(self._session, sync_call, install_mode, flush_dns, timeout, new_ip_address) nisyscfg.errors.handle_error(self, error_code) return c_string_decode(new_ip_address.value)
def upgrade_firmware(self, version=None, filepath=None, auto_stop_task=True, force=False, sync_call=True): """ Updates the firmware on the target. version - Specifies the firmware version you want to apply to the target. Use '0' to install the latest available firmware. filepath - Specifies the firmware file you want to upload to the target. Note: Parameters version and filepath are mutually exclusive and you must specify one and only one. auto_stop_task - Specifies to automatically end all tasks running on the target, even if they are incomplete and switch to firmware update mode. The default is True. force - Specifies to overwrite the destination firmware image even if the version is the same as or older than the version of the destination firmware image. If False, the function checks the version of the firmware returned by the expert and, if the returned version is newer than the version you are upgrading, this function returns an error. If the firmware version is the same and this parameter is set to False, the function does not upgrade the firmware and returns success. If True, this function automatically upgrades the firmware, regardless of the version of the destination firmware image. The default is False. sync_call - Specifies whether to wait for the upgrade operation to finish before returning. If False, the upgrade operation may continue running even after this function returns. To check the status, query the firmware_status property. The default is True. Returns tuple (status, detailed_result) status - The status of the firmware update. If this output returns FirmwareStatus.READY_PENDING_USER_RESTART, call restart. You can view more information about additional results in the detailed_result output. detailed_result - Results of any errors that may have occurred when this function completed. This output also may return additional information about the value returned from status. Raises an nisyscfg.errors.LibraryError exception in the event of an error. """ if version and filepath: raise ValueError( "version and filepath are mutually exclusive parameters") firmware_status = ctypes.c_int() c_detailed_result = ctypes.POINTER(ctypes.c_char)() if version: error_code = self._library.UpgradeFirmwareVersion( self._handle, c_string_encode(version), auto_stop_task, force, sync_call, ctypes.pointer(firmware_status), ctypes.pointer(c_detailed_result)) elif filepath: error_code = self._library.UpgradeFirmwareFromFile( self._handle, c_string_encode(filepath), auto_stop_task, force, sync_call, ctypes.pointer(firmware_status), ctypes.pointer(c_detailed_result)) else: raise ValueError( "upgrade_firmware() requires either version or filepath to be specified" ) if c_detailed_result: detailed_result = c_string_decode( ctypes.cast(c_detailed_result, ctypes.c_char_p).value) error_code_2 = self._library.FreeDetailedString(c_detailed_result) nisyscfg.errors.handle_error(self, error_code) nisyscfg.errors.handle_error(self, error_code_2) ReturnData = collections.namedtuple('ReturnData', 'status detailed_result') return ReturnData(nisyscfg.enums.FirmwareStatus(firmware_status.value), detailed_result)