示例#1
0
    def _set_property(self, id, value, c_type, nisyscfg_type):
        if c_type == ctypes.c_char_p:
            value = c_string_encode(value)
        elif issubclass(c_type, nisyscfg.enums.BaseEnum):
            value = ctypes.c_int(value)
        else:
            value = c_type(value)

        error_code = self._library.SetResourceProperty(self._handle, id, value)
        nisyscfg.errors.handle_error(self, error_code)
示例#2
0
    def rename(self,
               new_name,
               overwrite_conflict=False,
               update_dependencies=False):
        """
        Changes the display name of a resource.

        new_name - The user-specified new name for the resource.

        overwrite_conflict - Allows resource name changes to occur if there are
        any naming conflicts. If this value is True, the resource name change
        occurs even if another resource with the same name already exists. If
        this value is False (default), this function raises if another resource
        with the same name already exists. If this value is True and you choose
        a name that is already assigned to an existing resource, this function
        also changes the name of the existing resource.

        update_dependencies - Updates dependencies (for example: a task or
        channel) if the resource being renamed has them. Dependencies will be
        updated to refer to the new name by default. Select FALSE if you do not
        want to update these dependencies.
        Note: If overwrite_conflict is True and an existing resource was also
        renamed due to a conflict, the dependencies for that resource will not
        be updated. This option only affects the dependencies for the resource
        you are currently renaming.

        Returns HardwareResource whose name was overwritten. This will be None
        if no other resource was overwritten.

        Raises an nisyscfg.errors.LibraryError exception in the event of an
        error.
        """
        name_already_existed = ctypes.c_int()
        overwritten_resource_handle = nisyscfg.types.ResourceHandle()
        error_code = self._library.RenameResource(
            self._handle, c_string_encode(new_name), overwrite_conflict,
            update_dependencies, ctypes.pointer(name_already_existed),
            ctypes.pointer(overwritten_resource_handle))
        nisyscfg.errors.handle_error(self, error_code)

        # TODO(tkrebes): Ensure lifetime of HardwareResource does not exceed the
        # session.
        overwritten_resource = (
            overwritten_resource_handle.value
            and HardwareResource(overwritten_resource_handle, self._library))

        # Do not return the bool 'name_already_existed' since it is equivalent
        # to 'overwritten_syscfg_resource == None'.
        return overwritten_resource
示例#3
0
    def find_hardware(self,
                      filter=None,
                      mode=nisyscfg.enums.FilterMode.MATCH_VALUES_ALL,
                      expert_names=''):
        """
        Returns an iterator of hardware in a specified system.

        filter - Specifies a filter you can use to limit the results to hardware
        matching specific properties. The default is no filter.

        mode - The enumerated list of filter modes.
        ==================== ===================================================
        Mode                 Description
        -------------------- ---------------------------------------------------
        MATCH_VALUES_ALL     (default) includes all of the properties specified
                             in the input filter.
        MATCH_VALUES_ANY     includes any of the properties specified in the
                             input filter.
        MATCH_VALUES_NONE    includes none of the properties specified in the
                             input filter.
        ALL_PROPERTIES_EXIST includes all of the properties specified in the
                             input filter, regardless of the value of each
                             property.
        ==================== ===================================================

        expert_names - This is a case-insensitive comma-separated string
        specifying which experts to query. If None or empty-string, all
        supported experts are queried.

        Raises an nisyscfg.errors.LibraryError exception in the event of an
        error.
        """
        if filter is None:

            class DummyFilter(object):
                _handle = None

            filter = DummyFilter()
        resource_handle = nisyscfg.types.EnumResourceHandle()
        if isinstance(expert_names, list):
            expert_names = ','.join(expert_names)
        error_code = self._library.FindHardware(
            self._session, mode, filter._handle, c_string_encode(expert_names),
            ctypes.pointer(resource_handle))
        nisyscfg.errors.handle_error(self, error_code)
        iter = HardwareResourceIterator(self._session, resource_handle,
                                        self._library)
        self._children.append(iter)
        return iter
示例#4
0
 def __init__(self,
              target=None,
              username=None,
              password=None,
              language=nisyscfg.enums.Locale.DEFAULT,
              force_property_refresh=True,
              timeout=60000):
     self._children = []
     self._session = nisyscfg.types.SessionHandle()
     self._library = nisyscfg._library_singleton.get()
     self._property_bag = nisyscfg.properties.PropertyBag(
         setter=self._set_property,
         getter=self._get_property,
     )
     error_code = self._library.InitializeSession(
         c_string_encode(target),
         c_string_encode(username),
         c_string_encode(password),
         language,
         force_property_refresh,
         timeout,
         None,  # expert_enum_handle
         ctypes.pointer(self._session))
     nisyscfg.errors.handle_error(self, error_code)
示例#5
0
    def get_system_experts(self, expert_names=''):
        """
        Returns the experts available on the system.

        expert_names - This is a case-insensitive comma-separated string
        specifying which experts to query. If None or empty string, all
        supported experts are queried.

        Raises an nisyscfg.errors.LibraryError exception in the event of an
        error.
        """
        expert_handle = nisyscfg.types.EnumExpertHandle()
        if isinstance(expert_names, list):
            expert_names = ','.join(expert_names)
        error_code = self._library.GetSystemExperts(
            self._session, c_string_encode(expert_names),
            ctypes.pointer(expert_handle))
        nisyscfg.errors.handle_error(self, error_code)
        iter = ExpertInfoIterator(expert_handle, self._library)
        self._children.append(iter)
        return iter
示例#6
0
    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)