コード例 #1
0
ファイル: node.py プロジェクト: m4h3/smc-python
    def diagnostic(self, filter_enabled=False):
        """ 
        Provide a list of diagnostic options to enable
        
        Get all diagnostic/debug settings::
            
            engine = Engine('myfw')
            for node in engine:
                for diag in node.diagnostic():
                    print diag
                    
        Add filter_enabled=True argument to see only enabled settings

        :param boolean filter_enabled: returns all enabled diagnostics
        :return: list of dict items with diagnostic info; key 'diagnostics'
        :raises: :py:class:`smc.api.exceptions.NodeCommandFailed`
        """
        params = {'filter_enabled': filter_enabled}
        try:
            result = prepared_request(NodeCommandFailed,
                                      href=self._link('diagnostic'),
                                      params=params).read()
            return [(Diagnostic(**diagnostic))
                    for diagnostic in result.json.get('diagnostics')]
        except ResourceNotFound:
            raise NodeCommandFailed(
                'Diagnostic not supported on this node type: {}'.format(
                    self.type))
コード例 #2
0
ファイル: node.py プロジェクト: m4h3/smc-python
    def time_sync(self):
        """ 
        Send a time sync command to this node.

        :return: None
        :raises: :py:class:`smc.api.exceptions.NodeCommandFailed`
        """
        try:
            prepared_request(NodeCommandFailed,
                             href=self._link('time_sync')).update()
        except ResourceNotFound:
            raise NodeCommandFailed(
                'Time sync not supported on this node type: {}'.format(
                    self.type))
コード例 #3
0
ファイル: node.py プロジェクト: ad1rie1/smc-python
 def appliance_info(self):
     """
     .. versionadded:: 0.5.7
         Requires SMC version >= 6.3
     
     Retrieve appliance info for this engine.
     
     :raises NodeCommandFailed: Appliance info not supported on
         this node
     :rtype: ApplianceInfo
     """
     if 'appliance_info' in self.data:
         return ApplianceInfo(**self.data['appliance_info'])
     raise NodeCommandFailed(
         'Appliance information is not available on this engine')
コード例 #4
0
ファイル: node.py プロジェクト: m4h3/smc-python
    def initial_contact(self,
                        enable_ssh=True,
                        time_zone=None,
                        keyboard=None,
                        install_on_server=None,
                        filename=None):
        """ 
        Allows to save the initial contact for for the specified node
 
        :param boolean enable_ssh: flag to know if we allow the ssh daemon on the 
               specified node
        :param str time_zone: optional time zone to set on the specified node 
        :param str keyboard: optional keyboard to set on the specified node
        :param boolean install_on_server: optional flag to know if the generated configuration 
               needs to be installed on SMC Install server (POS is needed)
        :param str filename: filename to save initial_contact to
        :return: str initial contact text information
        :raises: :py:class:`smc.api.exceptions.NodeCommandFailed` 
        """
        try:
            result = prepared_request(href=self._link('initial_contact'),
                                      params={
                                          'enable_ssh': enable_ssh
                                      }).create()
            if result.content:
                if filename:
                    try:
                        save_to_file(filename, result.content)
                    except IOError as e:
                        raise NodeCommandFailed(
                            "Error occurred when attempting to "
                            "save initial contact to file: {}".format(e))
            return result.content
        except ResourceNotFound:
            raise NodeCommandFailed(
                'Initial contact not supported on this node type')
コード例 #5
0
ファイル: node.py プロジェクト: m4h3/smc-python
    def ssh(self, enable=True, comment=None):
        """
        Enable or disable SSH

        :param boolean enable: enable or disable SSH daemon
        :param str comment: optional comment for audit
        :return: None
        :raises: :py:class:`smc.api.exceptions.NodeCommandFailed`
        """
        params = {'enable': enable, 'comment': comment}
        try:
            prepared_request(NodeCommandFailed,
                             href=self._link('ssh'),
                             params=params).update()
        except ResourceNotFound:
            raise NodeCommandFailed(
                'SSH not supported on this node type: {}'.format(self.type))
コード例 #6
0
ファイル: node.py プロジェクト: m4h3/smc-python
    def reset_user_db(self, comment=None):
        """ 
        Executes a Send Reset LDAP User DB Request operation on this
        node.

        :param str comment: comment to audit
        :return: None
        :raises: :py:class:`smc.api.exceptions.NodeCommandFailed`
        """
        params = {'comment': comment}
        try:
            prepared_request(NodeCommandFailed,
                             href=self._link('reset_user_db'),
                             params=params).update()
        except ResourceNotFound:
            raise NodeCommandFailed(
                'Reset userdb not supported on this node type')
コード例 #7
0
ファイル: node.py プロジェクト: Forcepoint/fp-NGFW-SMC-python
    def initial_contact(
        self,
        enable_ssh=True,
        time_zone=None,
        keyboard=None,
        install_on_server=None,
        filename=None,
        as_base64=False,
    ):
        """
        Allows to save the initial contact for for the specified node

        :param bool enable_ssh: flag to know if we allow the ssh daemon on the
               specified node
        :param str time_zone: optional time zone to set on the specified node
        :param str keyboard: optional keyboard to set on the specified node
        :param bool install_on_server: optional flag to know if the generated
            configuration needs to be installed on SMC Install server
            (POS is needed)
        :param str filename: filename to save initial_contact to
        :param bool as_base64: return the initial config in base 64 format. Useful
            for cloud based engine deployments as userdata
        :raises NodeCommandFailed: IOError handling initial configuration data
        :return: initial contact text information
        :rtype: str
        """
        result = self.make_request(
            NodeCommandFailed,
            method="create",
            raw_result=True,
            resource="initial_contact",
            params={"enable_ssh": enable_ssh},
        )

        if result.content:
            if as_base64:
                result.content = b64encode(result.content)

            if filename:
                try:
                    save_to_file(filename, result.content)
                except IOError as e:
                    raise NodeCommandFailed(
                        "Error occurred when attempting to save initial "
                        "contact to file: {}".format(e))
        return result.content
コード例 #8
0
ファイル: node.py プロジェクト: m4h3/smc-python
    def change_ssh_pwd(self, pwd=None, comment=None):
        """
        Executes a change SSH password operation on the specified node 

        :param str pwd: changed password value
        :param str comment: optional comment for audit log
        :return: None
        :raises: :py:class:`smc.api.exceptions.NodeCommandFailed`
        """
        params = {'comment': comment}
        try:
            prepared_request(NodeCommandFailed,
                             href=self._link('change_ssh_pwd'),
                             params=params,
                             json={
                                 'value': pwd
                             }).update()
        except ResourceNotFound:
            raise NodeCommandFailed(
                'Change SSH pwd not supported on this node type: {}'.format(
                    self.type))