Esempio n. 1
0
def deviceAudit(device, interfaces, configuration):
    ''' deviceAudit is called to synchronize configuration between IFC and the device.
    IFC invokes this call when device recovers from hard fault like reboot,
    mgmt connectivity loss etc.

    This call can be made as a result of IFC cluster failover event.

    Device script is expected to fetch the device configuration and reconcile with the
    configuration passed by IFC.

    In this call IFC will pass entire device configuration across all graphs. The device
    should insert/modify any missing configuration on the device. It should remove any extra
    configuration found on the device.

    @param device: dict
        a device dictionary
    @param interfaces: list of strings
        a list of interfaces for this device.
        e.g. [ 'E0/0', 'E0/1', 'E1/0', 'E1/0' ]
    @param configuration: dict
        Entire configuration on the device.
    @return: Faults dictionary

    '''
    env.debug("[Interfaces argument]\n%s" % pretty_dict(interfaces))

    return audit_operation(device, interfaces, configuration)
Esempio n. 2
0
def deviceHealth(device, interfaces, configuration):
    ''' This function polls the device. API should return a weighted device health score
    in range (0-100)

    @param device:  dict
        a device dictionary
    @return: int
        a weighted device health score in range (0-100)
    Example:
        Poll CPU usage, free memory, disk usage etc.
    '''
    env.debug("[Interfaces argument]\n%s" % pretty_dict(interfaces))

    # Note that there is no root for device configuration, so the returned path
    # is always an empty list.

    result = {}
    version, error = read_asa_version(device)
    if not version:  #fail to connect
        result['faults'] = [([], 0, error)]
        result['health'] = [([], 0)]
        result[
            'state'] = Status.TRANSIENT  #same as that from xxxxAudit and xxxxModify
    else:
        result['state'] = Status.SUCCESS
        # check for cluster to see if it is ready
        cluster_health = ClusterConfig.get_health(device, configuration)
        if cluster_health:
            result['health'] = [cluster_health]
        else:
            result['health'] = [([], 100)]
    return result
def deviceAudit(device,
                interfaces,
                configuration):
    ''' deviceAudit is called to synchronize configuration between IFC and the device.
    IFC invokes this call when device recovers from hard fault like reboot,
    mgmt connectivity loss etc.

    This call can be made as a result of IFC cluster failover event.

    Device script is expected to fetch the device configuration and reconcile with the
    configuration passed by IFC.

    In this call IFC will pass entire device configuration across all graphs. The device
    should insert/modify any missing configuration on the device. It should remove any extra
    configuration found on the device.

    @param device: dict
        a device dictionary
    @param interfaces: list of strings
        a list of interfaces for this device.
        e.g. [ 'E0/0', 'E0/1', 'E1/0', 'E1/0' ]
    @param configuration: dict
        Entire configuration on the device.
    @return: Faults dictionary

    '''
    env.debug("[Interfaces argument]\n%s" % pretty_dict(interfaces))

    return audit_operation(device, interfaces, configuration)
def deviceHealth(device,
                interfaces,
                configuration):
    ''' This function polls the device. API should return a weighted device health score
    in range (0-100)

    @param device:  dict
        a device dictionary
    @return: int
        a weighted device health score in range (0-100)
    Example:
        Poll CPU usage, free memory, disk usage etc.
    '''
    env.debug("[Interfaces argument]\n%s" % pretty_dict(interfaces))

    # Note that there is no root for device configuration, so the returned path
    # is always an empty list.

    result = {}
    version, error = read_asa_version(device)
    if not version: #fail to connect
        result['faults'] = [([], 0, error)]
        result['health'] = [([], 0)]
        result['state'] = Status.TRANSIENT #same as that from xxxxAudit and xxxxModify
    else:
        result['state'] = Status.SUCCESS
        # check for cluster to see if it is ready
        cluster_health = ClusterConfig.get_health(device, configuration)
        if cluster_health:
            result['health'] = [cluster_health]
        else:
            result['health'] = [([], 100)]
    return result
Esempio n. 5
0
    def trace(*argv):
        env.debug("***** API Called: %s" % f.__name__)
        device = argv[0]

        env.debug("[Device argument]\n%s" %
                  json.dumps(hide_passwords(copy.deepcopy(device)), indent=3))
        config = get_config_dict(argv[1:])
        if config:
            env.debug("[Configuration argument]\n%s" % pretty_dict(config))

        return f(*argv)
    def trace(*argv):
        env.debug("***** API Called: %s" % f.__name__)
        device = argv[0]

        env.debug("[Device argument]\n%s" %
                  json.dumps(hide_passwords(copy.deepcopy(device)),
                             indent=3))
        config  = get_config_dict(argv[1:])
        if config:
            env.debug("[Configuration argument]\n%s" % pretty_dict(config))

        return f(*argv)
Esempio n. 7
0
def deviceModify(device, interfaces, configuration):
    ''' Update global device configuration
    @param device: dict
        a device dictionary
        @warning:  'creds' attribute should be (name, password) pair?!
    @param interfaces: list of strings
        a list of interfaces for this device.
        e.g. [ 'E0/0', 'E0/1', 'E1/0', 'E1/0' ]
    @param configuration: dict
        Device configuration configured by the user. This is configuration that does not
        depend on a graph/function. Example:
         syslog server IP
         HA peer IP
         HA mode
         Port-Channel
    @return: Faults dictionary
    '''
    env.debug("[Interfaces argument]\n%s" % pretty_dict(interfaces))

    return modify_operation(device, interfaces, configuration)
def deviceModify(device,
                 interfaces,
                 configuration):
    ''' Update global device configuration
    @param device: dict
        a device dictionary
        @warning:  'creds' attribute should be (name, password) pair?!
    @param interfaces: list of strings
        a list of interfaces for this device.
        e.g. [ 'E0/0', 'E0/1', 'E1/0', 'E1/0' ]
    @param configuration: dict
        Device configuration configured by the user. This is configuration that does not
        depend on a graph/function. Example:
         syslog server IP
         HA peer IP
         HA mode
         Port-Channel
    @return: Faults dictionary
    '''
    env.debug("[Interfaces argument]\n%s" % pretty_dict(interfaces))

    return modify_operation(device, interfaces, configuration)
                                               'state': 1},
                                            (Type.CONN, 'internal', 'C4'): {
                                              'transaction': 10000,
                                              'value': {},
                                              'state': 1}},
                                        'state': 1}},

                                  'state': 1}}}}
    asa = DeviceModel()

    def create_missing_ifc_delta(ifc_cfg):
        'Transformer to fill in the missing folders'
        asa.populate_model(ifc_cfg.keys()[0], ifc_cfg.values()[0])
        asa.create_missing_ifc_delta_cfg()
        return ifc_cfg

    def set_cfg_state_2_DESTROY(ifc_cfg):
        'Transformer to set the State of each entry to DETROY'
        set_cfg_state(ifc_cfg, State.DESTROY)
        return ifc_cfg

    ifc_cfg = massage_param_dict(asa, config,
                                 transformers=[set_cfg_state_2_DESTROY,
                                               create_missing_ifc_delta])

    from utils.util import pretty_dict
    print pretty_dict(ifc_cfg)

#    print("Test functional configuration  with Timeouts: %s"  % [str(x) for x in clis])

Esempio n. 10
0
def deviceCounters(device, interfaces, configuration):
    '''
    This function is called periodically to report statistics associated with
    the physical interfaces of the device.

    @param device:
        a device dictionary
    @param interfaces:
        A list of the physical interfaces
        The format is:
            {
                (cifType, '', <interface name>) : {
                    'state': <state>,
                    'label': <label>
                },
                ...
            }
    @param configuration: dict
        It contains device configuration. The configuration dictionary follows
        the format described above.
    @return: dict
            The format of the dictionary is as follows
            {
              'state': <state>
              'counters': [(path, counters), ...]
            }

            path: Identifies the object to which the counter is associated.

            counters: {
              'rxpackets': <rxpackets>,
              'rxerrors': <rxerrors>,
              'rxdrops': <rxdrops>,
              'txpackets': <txpackets>,
              'txerrors': <txerrors>,
              'txdrops': <txdrops>
            }
    '''
    env.debug("[Interfaces argument]\n%s" % pretty_dict(interfaces))

    result = {'counters': []}
    if interfaces:
        cli_holder = []
        for interface in interfaces:
            cli_holder.append(
                CLIInteraction('show interface ' +
                               interface[2].replace('_', '/')))
        dispatcher = HttpDispatch(device)
        try:
            messenger = dispatcher.make_command_messenger(cli_holder)
            cli_results = messenger.get_results()
        except HTTPError as e:
            env.debug('deviceCounters: %s' % e)
            result['state'] = Status.TRANSIENT
            return result

        result['state'] = Status.SUCCESS
        for interface, cli_result in zip(interfaces, cli_results):
            if cli_result and cli_result.err_type == CLIResult.INFO:
                path = [(Type.CIF, '', interface[2])]
                counters = parse_interface_counters(cli_result.err_msg)
                result['counters'].append((path, counters))
    else:
        # Check if there is connectivity to the device
        version = read_asa_version(device)[0]
        result['state'] = Status.SUCCESS if version else Status.TRANSIENT

    return result
def deviceCounters(device,
                   interfaces,
                   configuration):
    '''
    This function is called periodically to report statistics associated with
    the physical interfaces of the device.

    @param device:
        a device dictionary
    @param interfaces:
        A list of the physical interfaces
        The format is:
            {
                (cifType, '', <interface name>) : {
                    'state': <state>,
                    'label': <label>
                },
                ...
            }
    @param configuration: dict
        It contains device configuration. The configuration dictionary follows
        the format described above.
    @return: dict
            The format of the dictionary is as follows
            {
              'state': <state>
              'counters': [(path, counters), ...]
            }

            path: Identifies the object to which the counter is associated.

            counters: {
              'rxpackets': <rxpackets>,
              'rxerrors': <rxerrors>,
              'rxdrops': <rxdrops>,
              'txpackets': <txpackets>,
              'txerrors': <txerrors>,
              'txdrops': <txdrops>
            }
    '''
    env.debug("[Interfaces argument]\n%s" % pretty_dict(interfaces))

    result = {'counters': []}
    if interfaces:
        cli_holder = []
        for interface in interfaces:
            cli_holder.append(CLIInteraction('show interface ' +
                                             interface[2].replace('_', '/')))
        dispatcher = HttpDispatch(device)
        try:
            messenger = dispatcher.make_command_messenger(cli_holder)
            cli_results = messenger.get_results()
        except HTTPError as e:
            env.debug('deviceCounters: %s' % e)
            result['state'] = Status.TRANSIENT
            return result

        result['state'] = Status.SUCCESS
        for interface, cli_result in zip(interfaces, cli_results):
            if cli_result and cli_result.err_type == CLIResult.INFO:
                path = [(Type.CIF, '', interface[2])]
                counters = parse_interface_counters(cli_result.err_msg)
                result['counters'].append((path, counters))
    else:
        # Check if there is connectivity to the device
        version = read_asa_version(device)[0]
        result['state'] = Status.SUCCESS if version else Status.TRANSIENT

    return result
Esempio n. 12
0
                            'state': 1
                        }
                    },
                    'state': 1
                }
            }
        }
    }
    asa = DeviceModel()

    def create_missing_ifc_delta(ifc_cfg):
        'Transformer to fill in the missing folders'
        asa.populate_model(ifc_cfg.keys()[0], ifc_cfg.values()[0])
        asa.create_missing_ifc_delta_cfg()
        return ifc_cfg

    def set_cfg_state_2_DESTROY(ifc_cfg):
        'Transformer to set the State of each entry to DETROY'
        set_cfg_state(ifc_cfg, State.DESTROY)
        return ifc_cfg

    ifc_cfg = massage_param_dict(
        asa,
        config,
        transformers=[set_cfg_state_2_DESTROY, create_missing_ifc_delta])

    from utils.util import pretty_dict
    print pretty_dict(ifc_cfg)

#    print("Test functional configuration  with Timeouts: %s"  % [str(x) for x in clis])