Пример #1
0
    def set_top_talkers_interval(self, interval):
        """
        set_top_talkers_interval(auth, interval) -> None

        Set the Top Talkers collection period.

        Parameters:
        interval (integer) - Interval in hours (must be 24 or 48)

        Exceptions:
        set_top_talkers_intervalFault - Interval must be 24 or 48 hours
        """
        if interval != 24 and interval != 48:
            raise ServiceError, 'Top Talkers interval must be 24 or 48 hours'

        # convert collection period to snapshot interval (24->300, 48->600)
        interval = interval / 24 * 300

        code, msg = Mgmt.set(
            ('/rbt/sport/netflow/config/top_talkers/snapshot_interval',
             'duration_sec', interval)
            )

        if code != 0:
            raise ServiceError, msg
Пример #2
0
    def __set_banner(self, node_list, motd):
        """Helper function for setting motd/login banner"""
        nodes_to_set = [(x, 'string', motd) for x in node_list]
        code, msg = Mgmt.set(*nodes_to_set)

        if code != 0:
            raise ServiceError, msg
Пример #3
0
    def __set_user_password(self, username, password):
        # XXX/jshilkaitis: lame, should be an action on the mgmtd side

        # XXX/jshilkaitis: why doesn't the framework do validation?

        valid_password = common.lc_password_validate(password)

        if not valid_password:
            # XXX/jshilkaitis: hardcode the reason for now, since we know
            # length is the only criterion, but that may not be true in the
            # future.
            raise ServiceError, 'Password must contain at least 6 characters'

        use_sha512 = Mgmt.get_value('/rbt/support/config/sha_password/enable')

        if use_sha512:
            crypted_password = common.sha_encrypt_password(False, password)
        else:
            crypted_password = common.ltc_encrypt_password(password)

        password_node_name = '/auth/passwd/user/%s/password' % username

        code, msg = Mgmt.set((password_node_name, 'string', crypted_password))

        if code != 0:
            raise ServiceError, msg
Пример #4
0
    def set_bool_node_value(node_name,value):
        """Sets value of a bool node to true/false 

        takes two arguments:
            node_name -> name of the node to be set
            value     -> value the 'node_name' needs to be set to
        returns:
            (return code, error message)
            in case of an error it returns a non-zero error code 
            and error message otherwise it returns zero for success
            and an empty error message.
        """

	import Mgmt
        code, msg = Mgmt.set((node_name,'bool', value))
        return code,msg
Пример #5
0
    def set_snmp_community_string(self, community_string):
        """
        set_snmp_community_string(auth, community_string) -> None

        Set the SNMP community string.

        Parameters:
        community_string (string) - SNMP community string to be set

        Exceptions: None
        """
        code, msg = Mgmt.set(
            ('/snmp/access/rocommunity', 'string', community_string))

        if code != 0:
            raise ServiceError, msg
Пример #6
0
    def set_logging_level(self, level):
        """
        set_logging_level(auth, level) -> None

        Set the minimum logging level.

        Parameters:
        level (string) - logging level to set

        Exceptions: None
        """
        level = level.lower()

        code, msg = Mgmt.set(('/logging/syslog/action/file/\/var\/log\/messages/selector/0/priority', 'string', level))

        if code != 0:
            raise ServiceError, msg
Пример #7
0
    def set_node_value(node_name, node_type, node_value):
        """Sets value of node_name  of type node_type
           to node_value

        takes 3 arguments:
            node_name  -> name of the node to be set
            node_value -> value the 'node_name' needs to be set to
            node_type  -> type of 'node_name'
        returns:
            (return code, error message)
            in case of an error it returns a non-zero error code 
            and error message otherwise it returns zero for success
            and an empty error message.
        """

	import Mgmt
        code, msg = Mgmt.set((node_name, node_type, node_value))
        return code,msg
Пример #8
0
    def enable_netflow(self, enable):
        """
        enable_netflow(auth, enable) -> None

        Turn NetFlow support on or off.

        Parameters:
        enable (bool) - true to enable NetFlow, false to disable NetFlow

        Exceptions:
        enable_netflow - Top Talkers must be disabled before NetFlow can be disabled
        """
        code, msg = Mgmt.set(
            ('/rbt/sport/netflow/config/enable', 'bool', enable)
            )

        if code != 0:
            raise ServiceError, msg
Пример #9
0
    def enable_top_talkers(self, enable):
        """
        enable_top_talkers(auth, enable) -> None

        Turn Top Talkers on or off.

        Parameters:
        enable (bool) - true to enable Top Talkers, false to disable Top Talkers

        Exceptions:
        enable_top_talkersFault - NetFlow must be enabled before Top Talkers can be enabled
        """
        code, msg = Mgmt.set(
            ('/rbt/sport/netflow/config/top_talkers/enable', 'bool', enable)
            )

        if code != 0:
            raise ServiceError, msg
Пример #10
0
    def __set_alarm_threshold(self, alarm, rising_or_falling,
                              error_or_clear, val):
        alarm = alarm.lower()
        rising_or_falling = rising_or_falling.lower()
        error_or_clear = error_or_clear.lower()

        self.__assert_alarm_exists(alarm)

        node_name = '/stats/config/alarm/%s/%s/%s_threshold' % \
                    (alarm, rising_or_falling, error_or_clear)

        # should never fail because we ensure that the alarm exists
        node_type = Mgmt.query(node_name)[0][1]

        code, msg = Mgmt.set((node_name, node_type, val))

        if code != 0:
            raise ServiceError, msg
Пример #11
0
    def set_snmp_password(self, username, password, auth_protocol):
        """
        set_snmp_password(auth, username, password, auth_protocol) -> None

        Configure a SNMP user.

        Parameters:
        username - username of user to configure
        password - user's new password
        auth_protocol - protocol used to encrypt the password

        Exceptions:
        set_snmp_passwordFault - password must contain at least 8 characters
        set_snmp_passwordFault - XXX/BUG 47861/48172 for bad auth_protocol value
        """
        # XXX/jshilkaitis: lame, should be an action on the mgmtd side

        # 8 is USM_LENGTH_P_MIN from net-snmp
        if len(password) < 8:
            raise ServiceError, "password must contain at least 8 characters"

        auth_protocol = auth_protocol.upper()

        code, msg, bindings = Mgmt.action(
            '/snmp/usm/actions/generate_auth_key',
            ('password', 'string', password),
            ('hash_function', 'string', auth_protocol)
            )

        if code != 0:
            raise ServiceError, msg

        auth_key = bindings['auth_key']

        snmp_user_pfx = '/snmp/usm/users/%s' % username
        code, msg = Mgmt.set(
            (snmp_user_pfx, 'string', username),
            (snmp_user_pfx + '/auth_key', 'string', auth_key),
            (snmp_user_pfx + '/hash_function', 'string', auth_protocol)
            )

        if code != 0:
            raise ServiceError, msg
Пример #12
0
    def enable_rsp(self, enable):
        """
        enable_rsp(auth, enable) -> None

        Turn RSP on and off.

        Parameters:
        enable (bool) - true to turn on RSP, false to turn off RSP

        Exceptions:
        enable_rspFault - RSP not supported
        enable_rspFault - RSP not installed
        enable_rspFault - installed RSP release is not supported
        enable_rspFault - RSP not fully shut down
        """
        code, msg = Mgmt.set(
            ('/rbt/rsp2/config/enable', 'bool', enable)
            )

        if code != 0:
            raise ServiceError, msg
Пример #13
0
    def enable_alarm(self, alarm, enable):
        """
        enable_alarm(auth, alarm, enable) -> None

        Turn an alarm on or off.

        Parameters:
        alarm (string) - name of the alarm to change
        enable (bool) - true to enable alarm, false to disable alarm

        Exceptions:
        enable_alarmFault - Alarm does not exist
        """
        alarm = alarm.lower()

        self.__assert_alarm_exists(alarm)

        code, msg = Mgmt.set(
            ('/stats/config/alarm/%s/enable' % alarm, 'bool', enable))

        if code != 0:
            raise ServiceError, msg
Пример #14
0
    def set_snmp_password_preencrypted(self, username, digest, auth_protocol):
        """
        set_snmp_password_preencrypted(auth, username, digest, auth_protocol) -> None

        Configure a SNMP user using a pre-encrypted password.

        Parameters:
        username - username of user to configure
        digest - user's pre-encrypted password
        auth_protocol - protocol used to encrypt the password

        Exceptions:
        set_snmp_passwordFault - XXX/BUG 47861/48172 for bad auth_protocol value
        """
        snmp_user_pfx = '/snmp/usm/users/%s' % username
        code, msg = Mgmt.set(
            (snmp_user_pfx, 'string', username),
            (snmp_user_pfx + '/auth_key', 'string', digest),
            (snmp_user_pfx + '/hash_function', 'string', auth_protocol)
            )

        if code != 0:
            raise ServiceError, msg