(self, *key_vals)
Set variable via SNMP

        Args:
            variable : variable to set via SNMP.
            value    : value to set on the given variable.
Set variable via SNMP
Set variable via SNMP
def _set(self, *key_vals):
        """Set variable via SNMP

        Args:
            variable : variable to set via SNMP.
            value    : value to set on the given variable.

        """
        if (self.dry):
            # Convert to the corresponding net-snmp command
            for key, val in key_vals:
                # SNMP OID
                if (isinstance(key, tuple)):
                    key = ".".join([str(x) for x in key])
                else:
                    key += ".0"  # scalar values must have a .0 suffix
                # Translate values
                # TODO: Fix s400LOFrequency.0, which is not writable due to
                # being a Counter64 object.
                if ("s400ModulationStandard" in key):
                    if (val in standard_snmp_table):
                        val = standard_snmp_table[val]
                if ("s400Modcod" in key):
                    if (val in modcod_snmp_table):
                        val = modcod_snmp_table[val]
                if ("RowStatus" in key):
                    if (val in snmp_row_status_table):
                        val = snmp_row_status_table[val]
                if (val in ["disable", "enable"]):
                    val = int(val == "enable")
                if (val in ["disabled", "enabled"]):
                    val = int(val == "enabled")
                if (val in ["vertical", "horizontal"]):
                    val = int(val == "horizontal")
                # Value type
                if isinstance(val, str):
                    val_type = "s"
                elif (("LBandFrequency" in key)
                      or ("SymbolRate" in key and "SymbolRateAuto" not in key)
                      or ("s400MpePid1Pid" in key)):
                    val_type = "u"
                else:
                    val_type = "i"
                print("> snmpset -v 2c -c private {}:{} {}::{} {} {}".format(
                    self.address, self.port, self.mib, key, val_type, val))
            return

        obj_types = []
        for key, val in key_vals:
            if isinstance(key, tuple):
                obj = ObjectType(
                    ObjectIdentity(self.mib, key[0],
                                   key[1]).addMibSource(self.mib_dir), val)
            else:
                obj = ObjectType(
                    ObjectIdentity(self.mib, key,
                                   0).addMibSource(self.mib_dir), val)
            obj_types.append(obj)

        errorIndication, errorStatus, errorIndex, varBinds = next(
            setCmd(self.engine, CommunityData('private'),
                   UdpTransportTarget((self.address, self.port), timeout=10.0),
                   ContextData(), *obj_types))

        if errorIndication:
            logger.error(errorIndication)
        elif errorStatus:
            logger.error(
                '%s at %s' %
                (errorStatus.prettyPrint(),
                 errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
        else:
            for varBind in varBinds:
                logger.debug(' = '.join([x.prettyPrint() for x in varBind]))
def _set ( self , * key_vals ) : if ( self . dry ) : # Convert to the corresponding net-snmp command for key , val in key_vals : # SNMP OID if ( isinstance ( key , tuple ) ) : key = "." . join ( [ str ( x ) for x in key ] ) else : key += ".0" # scalar values must have a .0 suffix # Translate values # TODO: Fix s400LOFrequency.0, which is not writable due to # being a Counter64 object. if ( "s400ModulationStandard" in key ) : if ( val in standard_snmp_table ) : val = standard_snmp_table [ val ] if ( "s400Modcod" in key ) : if ( val in modcod_snmp_table ) : val = modcod_snmp_table [ val ] if ( "RowStatus" in key ) : if ( val in snmp_row_status_table ) : val = snmp_row_status_table [ val ] if ( val in [ "disable" , "enable" ] ) : val = int ( val == "enable" ) if ( val in [ "disabled" , "enabled" ] ) : val = int ( val == "enabled" ) if ( val in [ "vertical" , "horizontal" ] ) : val = int ( val == "horizontal" ) # Value type if isinstance ( val , str ) : val_type = "s" elif ( ( "LBandFrequency" in key ) or ( "SymbolRate" in key and "SymbolRateAuto" not in key ) or ( "s400MpePid1Pid" in key ) ) : val_type = "u" else : val_type = "i" print ( "> snmpset -v 2c -c private {}:{} {}::{} {} {}" . format ( self . address , self . port , self . mib , key , val_type , val ) ) return obj_types = [ ] for key , val in key_vals : if isinstance ( key , tuple ) : obj = ObjectType ( ObjectIdentity ( self . mib , key [ 0 ] , key [ 1 ] ) . addMibSource ( self . mib_dir ) , val ) else : obj = ObjectType ( ObjectIdentity ( self . mib , key , 0 ) . addMibSource ( self . mib_dir ) , val ) obj_types . append ( obj ) errorIndication , errorStatus , errorIndex , varBinds = next ( setCmd ( self . engine , CommunityData ( 'private' ) , UdpTransportTarget ( ( self . address , self . port ) , timeout = 10.0 ) , ContextData ( ) , * obj_types ) ) if errorIndication : logger . error ( errorIndication ) elif errorStatus : logger . error ( '%s at %s' % ( errorStatus . prettyPrint ( ) , errorIndex and varBinds [ int ( errorIndex ) - 1 ] [ 0 ] or '?' ) ) else : for varBind in varBinds : logger . debug ( ' = ' . join ( [ x . prettyPrint ( ) for x in varBind ] ) )