예제 #1
0
def deviceValidate(device, version):
    '''This function validates if the device matches one of the versions
    supported by the device package. This function should do a compare (regular
    expression match) the version fetched from the device with version
    string passed in the param.

    @param device: dict
        a device dictionary
    @param version: str
         a regular expression for the supported versions of the device.
         e.g: '1.0'
     @return: dict
        {'state': <state>, 'version': <version>}
    '''
    env.debug("[Version argument]\n%s" % version)

    result = {}
    asa_version, error = read_asa_version(device)
    if asa_version:
        result['version'] = asa_version
        match = re.compile(version).match(asa_version)
        result['state'] = Status.SUCCESS if match else Status.PERMANENT
        if not match:
            result['faults'] = [
                (get_config_root_key({}), 0,
                 'Device running un-supported ASA version %s' % asa_version)
            ]
    else:  #not able to connect
        result['state'] = Status.TRANSIENT
        result['faults'] = [(get_config_root_key({}), 0, error)]
    return result
예제 #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 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 deviceValidate(device,
                   version):
    '''This function validates if the device matches one of the versions
    supported by the device package. This function should do a compare (regular
    expression match) the version fetched from the device with version
    string passed in the param.

    @param device: dict
        a device dictionary
    @param version: str
         a regular expression for the supported versions of the device.
         e.g: '1.0'
     @return: dict
        {'state': <state>, 'version': <version>}
    '''
    env.debug("[Version argument]\n%s" % version)

    result = {}
    asa_version, error = read_asa_version(device)
    if asa_version:
        result['version'] = asa_version
        match =  re.compile(version).match(asa_version)
        result['state'] = Status.SUCCESS if match else Status.PERMANENT
        if not match:
            result['faults'] = [(get_config_root_key({}), 0, 'Device running un-supported ASA version %s' % asa_version)]
    else: #not able to connect
        result['state'] = Status.TRANSIENT
        result['faults'] = [(get_config_root_key({}), 0, error)]
    return result
예제 #5
0
def serviceHealth(device, configuration):
    '''This function is called periodically to report health of the service function
    on the device.

    @param device:
        a device dictionary
    @param configuration: dict
        It contains device configuration, group configuration for a particular
        graph instance and function configuration. The configuration dictionary follows
        the format described above.
    @return: dict
        It is dictionary of function health represented as an integer within (0-100) range.
        Format of the dictionary is as follows

          { (path): health,  ...}

          path: Is a list identifying a function within the graph. Example
          [ vdev, vgrp, vfunc ]

          vdev - Device Name. Passed in the configuration dictionary
          vgrp - Function Group name passed in the configuration dictionary
          vfunc - function name passed in configuration dictionary

        The health dictionary will contain an entry for each function rendered on the
        device for the given graph
    '''
    result = {}
    version, error = read_asa_version(device)
    if not version:  #fail to connect
        result['faults'] = [(get_config_root_key(configuration), 0, error)]
        result[
            'state'] = Status.TRANSIENT  #same as that from xxxxAudit and xxxxModify
    else:
        result['health'] = []
        result['state'] = Status.SUCCESS
        for f in get_config_firewall_keys(configuration):
            result['health'].append((f, 100))
    return result
def serviceHealth(device,
                  configuration):
    '''This function is called periodically to report health of the service function
    on the device.

    @param device:
        a device dictionary
    @param configuration: dict
        It contains device configuration, group configuration for a particular
        graph instance and function configuration. The configuration dictionary follows
        the format described above.
    @return: dict
        It is dictionary of function health represented as an integer within (0-100) range.
        Format of the dictionary is as follows

          { (path): health,  ...}

          path: Is a list identifying a function within the graph. Example
          [ vdev, vgrp, vfunc ]

          vdev - Device Name. Passed in the configuration dictionary
          vgrp - Function Group name passed in the configuration dictionary
          vfunc - function name passed in configuration dictionary

        The health dictionary will contain an entry for each function rendered on the
        device for the given graph
    '''
    result = {}
    version, error = read_asa_version(device)
    if not version: #fail to connect
        result['faults'] = [(get_config_root_key(configuration), 0, error)]
        result['state'] = Status.TRANSIENT #same as that from xxxxAudit and xxxxModify
    else:
        result['health'] = []
        result['state'] = Status.SUCCESS
        for f in get_config_firewall_keys(configuration):
            result['health'].append((f, 100))
    return result
예제 #7
0
def serviceCounters(device, configuration):
    '''
    This function is called periodically to report statistics associated with
    the service functions rendered on the device.

    @param device:
        a device dictionary
    @param configuration: dict
        It contains device configuration, group configuration for a particular
        graph instance and function 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.
              The path is a list identifying a specific instance of a connector.
              It includes device name, group name, etc. as shown below:

              path = [ vdev, vgrp, vfunc, conn ]

              vdev - Device Name. Passed in the configuration dictionary
              vgrp - Function Group name passed in the configuration dictionary
              vfunc - function name passed in configuration dictionary
              conn - connector name within the function

            counters: {
              'rxpackets': <rxpackets>,
              'rxerrors': <rxerrors>,
              'rxdrops': <rxdrops>,
              'txpackets': <txpackets>,
              'txerrors': <txerrors>,
              'txdrops': <txdrops>
            }
    '''
    result = {'counters': []}

    asa = DeviceModel()
    ifc_cfg = massage_param_dict(asa, configuration)
    asa.populate_model(ifc_cfg.keys()[0], ifc_cfg.values()[0])

    connectors = get_all_connectors(asa)
    if connectors:
        cli_holder = []
        for connector in connectors:
            cli_holder.append(
                CLIInteraction('show interface ' + connector.get_nameif()))
        dispatcher = HttpDispatch(device)
        try:
            messenger = dispatcher.make_command_messenger(cli_holder)
            cli_results = messenger.get_results()
        except HTTPError as e:
            env.debug('serviceCounters: %s' % e)
            result['state'] = Status.TRANSIENT
            return result

        result['state'] = Status.SUCCESS
        for connector, cli_result in zip(connectors, cli_results):
            path = connector.get_config_path()
            counters = parse_connector_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
예제 #8
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 serviceCounters(device,
                    configuration):
    '''
    This function is called periodically to report statistics associated with
    the service functions rendered on the device.

    @param device:
        a device dictionary
    @param configuration: dict
        It contains device configuration, group configuration for a particular
        graph instance and function 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.
              The path is a list identifying a specific instance of a connector.
              It includes device name, group name, etc. as shown below:

              path = [ vdev, vgrp, vfunc, conn ]

              vdev - Device Name. Passed in the configuration dictionary
              vgrp - Function Group name passed in the configuration dictionary
              vfunc - function name passed in configuration dictionary
              conn - connector name within the function

            counters: {
              'rxpackets': <rxpackets>,
              'rxerrors': <rxerrors>,
              'rxdrops': <rxdrops>,
              'txpackets': <txpackets>,
              'txerrors': <txerrors>,
              'txdrops': <txdrops>
            }
    '''
    result = {'counters': []}

    asa = DeviceModel()
    ifc_cfg = massage_param_dict(asa, configuration)
    asa.populate_model(ifc_cfg.keys()[0], ifc_cfg.values()[0])

    connectors = get_all_connectors(asa)
    if connectors:
        cli_holder = []
        for connector in connectors:
            cli_holder.append(CLIInteraction('show interface '
                                             + connector.get_nameif()))
        dispatcher = HttpDispatch(device)
        try:
            messenger = dispatcher.make_command_messenger(cli_holder)
            cli_results = messenger.get_results()
        except HTTPError as e:
            env.debug('serviceCounters: %s' % e)
            result['state'] = Status.TRANSIENT
            return result

        result['state'] = Status.SUCCESS
        for connector, cli_result in zip(connectors, cli_results):
            path = connector.get_config_path()
            counters = parse_connector_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