Example #1
0
def check_missing_interface(switch, interfaces, remedy):
    #
    # The switch value could be a compound key reference to a
    # switch, if there's a '|' in the switch valud, try to guess
    # which entry is the switch

    if type(interfaces) == str or type(interfaces) == unicode:
        interfaces = [interfaces]

    parts = switch.split('|')
    if len(parts) > 1:
        for part in parts:
            if utif.COMMAND_DPID_RE.match(part):
                switch = part
                break
        else:
            switch = part[0]

    bigdb = bigsh.bigdb
    try:
        (schema, result) = \
            bigdb.schema_and_result('core/switch', {'dpid' : switch })

        final_result = result.expect_single_result()
        if final_result == None:
            raise error.ArgumentValidationError("switch not connected")
    except:
        # no switch
        if debug.description() or debug.cli():
            traceback.print_exc()
        bigsh.warning('switch %s currently not active, '
                      'interface %s may not exist' %
                      (switch, ', '.join(interfaces)))
        return

    if not 'interface' in final_result:
        bigsh.warning('switch %s currently not active, '
                      'interface %s may not exist' %
                      (switch, ', '.join(interfaces)))
        return

    known_interfaces = [x['name'] for x in final_result['interface']]
    if_names = [x.lower() for x in known_interfaces]
    for interface in interfaces:
        if not interface.lower() in if_names:
            # pre-servce case, try to identify unique ranges
            ranges = interface_ranges(known_interfaces)

            bigsh.warning('active switch has no interface "%s", '
                          'known: %s' % (interface, ', '.join(ranges)) +
                          remedy)
            return
Example #2
0
def warn_missing_interface(value, data, field, is_no, obj_value, many=False):
    if not is_no:
        bigdb = bigsh.bigdb

        if debug.description() or debug.cli():
            print 'warn_missing_interface:', value, data, field, is_no, \
                                             obj_value, many
        # need switch, if_name
        pk_data = {}
        bigdb.add_mode_stack_paths(pk_data)
        switch = pk_data.get('switch')
        if switch == None:
            switch = pk_data.get('dpid')
        if switch == None:
            switch = data.get('switch')
        if switch == None:
            switch = data.get('dpid')
        if bigdb.enabled and switch == None:
            for (n, v) in data.items() + pk_data.items():
                if n.find('/') >= 0:
                    parts = n.split('/')
                    for suffix in ['switch', 'switch-dpid', 'switch-id']:
                        if parts[-1] == suffix:
                            switch = v
        if switch == None:
            if debug.description():
                print 'warn_missing_interface:', data
            raise error.ArgumentValidationError(
                "Can't identify switch for validation")
        force = True if data.get('force', '') != '' else False
        # check to see if the interface is a list or a range,
        ifs = value.split(',')
        range_re = re.compile(r'([A-Za-z0-9-/\.:]*?)(\d+)-(\d+)$')
        if many:
            interfaces = []
            remedy = ''
            for if_name in ifs:
                # check for trailing "-<integer>" which is intended to
                # identify a range, if so split that into multiple entites
                m = range_re.match(if_name)
                if m:
                    print 'TAIL MATCH', m.group(1), m.group(2), m.group(3)
                    for suffix in range(int(m.group(2)), int(m.group(3)) + 1):
                        interfaces.append('%s%s' % (m.group(1), suffix))
                else:
                    interfaces.append(if_name)
        else:
            remedy = '\nUse \"exit; no interface %s\" to remove' % value
            interfaces = [value]

        check_missing_interface(switch, interfaces, remedy)
    data[field] = value
def check_missing_interface(switch, interfaces, remedy):
    #
    # The switch value could be a compound key reference to a
    # switch, if there's a '|' in the switch valud, try to guess
    # which entry is the switch

    if type(interfaces) == str or type(interfaces) == unicode:
        interfaces = [interfaces]

    parts = switch.split('|')
    if len(parts) > 1:
        for part in parts:
            if utif.COMMAND_DPID_RE.match(part):
                switch = part
                break
        else:
            switch = part[0]

    bigdb = bigsh.bigdb
    try:
        (schema, result) = \
            bigdb.schema_and_result('core/switch', {'dpid' : switch })

        final_result = result.expect_single_result()
        if final_result == None:
            raise error.ArgumentValidationError("switch not connected")
    except:
        # no switch
        if debug.description() or debug.cli():
            traceback.print_exc()
        bigsh.warning('switch %s currently not active, '
                      'interface %s may not exist' %
                      (switch, ', '.join(interfaces)))
        return

    if not 'interface' in final_result:
        bigsh.warning('switch %s currently not active, '
                      'interface %s may not exist' %
                      (switch, ', '.join(interfaces)))
        return
        
    known_interfaces = [x['name'] for x in final_result['interface']]
    if_names = [x.lower() for x in known_interfaces]
    for interface in interfaces:
        if not interface.lower() in if_names:
            # pre-servce case, try to identify unique ranges
            ranges = interface_ranges(known_interfaces)

            bigsh.warning( 'active switch has no interface "%s", ' 
                      'known: %s' % (interface, ', '.join(ranges)) + 
                      remedy)
            return
Example #4
0
def convert_integer_comma_ranges(value, path, field, field_range, data):
    if debug.cli():
        print 'convert_integer_comma_ranges:', value, path, field, field_range, data

    list_of_integers = []
    for r in value.split(','):
        m = CICR_RANGE_RE.match(r)
        if (m):
            lower = int(m.group(1))
            upper = int(m.group(2))

            list_of_integers += range(int(lower), int(upper) + 1)
        else:
            m = CICR_SINGLE_RE.match(r)
            list_of_integers.append(int(m.group(1)))
    # with the list_of_integers, determine what the value should be.
    bigdb = bigsh.bigdb
    field_path = '%s/%s' % (path, field)
    (schema, item_index) = bigdb.schema_of_path(field_path, {})
    node_type = schema.get('nodeType')
    if node_type == 'LEAF_LIST':
        data[field_path] = list_of_integers
    elif node_type == 'LIST':
        # find the integer to set.
        print schema.keys()
        list_element_node = schema.get('listElementSchemaNode')
        list_children_nodes = list_element_node.get('childNodes')
        # examine all the children for this node. look for a field with
        # the same range.   Assume field_range is a two-tuple of (low, high)
        candidates = []
        for (child_name, child_value) in list_children_nodes.items():
            child_node_type = child_value.get('nodeType')
            child_type_details = child_value.get('typeSchemaNode')
            validators = child_type_details.get('typeValidator')
            if validators:
                # look for a range validator.
                for validator in validators:
                    if validator['type'] == 'RANGE_VALIDATOR':
                        ranges = validator['ranges']
                        for r in ranges:
                            if r.get('start') == field_range[0] and \
                               r.get('end') == field_range[1]:
                                candidates.append(child_name)
        if len(candidates) == 1:
            value_name = candidates[0]
            data[field_path] = [{value_name: v} for v in list_of_integers]
        else:
            print 'convert_integer_comma_ranges: ' \
                  'no candiate with range matching: ', field_range
    else:
        print 'convert_integer_comma_ranges: no management for ', node_type
def convert_integer_comma_ranges(value, path, field, field_range, data):
    if debug.cli():
        print 'convert_integer_comma_ranges:', value, path, field, field_range, data

    list_of_integers = []
    for r in value.split(','):
        m = CICR_RANGE_RE.match(r);
        if (m):
            lower = int(m.group(1))
            upper = int(m.group(2))

            list_of_integers += range(int(lower), int(upper) + 1)
        else:
            m = CICR_SINGLE_RE.match(r)
            list_of_integers.append(int(m.group(1)))
    # with the list_of_integers, determine what the value should be.
    bigdb = bigsh.bigdb
    field_path = '%s/%s' % (path, field)
    (schema, item_index) = bigdb.schema_of_path(field_path, {})
    node_type = schema.get('nodeType')
    if node_type == 'LEAF_LIST':
        data[field_path] = list_of_integers
    elif node_type == 'LIST':
        # find the integer to set.
        print schema.keys()
        list_element_node = schema.get('listElementSchemaNode')
        list_children_nodes = list_element_node.get('childNodes')
        # examine all the children for this node. look for a field with
        # the same range.   Assume field_range is a two-tuple of (low, high)
        candidates = []
        for (child_name, child_value) in list_children_nodes.items():
            child_node_type = child_value.get('nodeType')
            child_type_details = child_value.get('typeSchemaNode')
            validators = child_type_details.get('typeValidator')
            if validators:
                # look for a range validator.
                for validator in validators:
                    if validator['type'] == 'RANGE_VALIDATOR':
                        ranges = validator['ranges']
                        for r in ranges:
                            if r.get('start') == field_range[0] and \
                               r.get('end') == field_range[1]:
                                candidates.append(child_name)
        if len(candidates) == 1:
            value_name = candidates[0]
            data[field_path] = [{value_name: v} for v in list_of_integers]
        else:
            print 'convert_integer_comma_ranges: ' \
                  'no candiate with range matching: ', field_range
    else:
        print 'convert_integer_comma_ranges: no management for ', node_type
def warn_missing_interface(value, data, field, is_no, obj_value, many = False):
    if not is_no:
        bigdb = bigsh.bigdb

        if debug.description() or debug.cli():
            print 'warn_missing_interface:', value, data, field, is_no, \
                                             obj_value, many
        # need switch, if_name 
        pk_data = {}
        bigdb.add_mode_stack_paths(pk_data)
        switch = pk_data.get('switch')
        if switch == None:
            switch = pk_data.get('dpid')
        if switch == None:
            switch = data.get('switch')
        if switch == None:
            switch = data.get('dpid')
        if bigdb.enabled and switch == None:
            for (n,v) in data.items() + pk_data.items():
                if n.find('/') >= 0:
                    parts = n.split('/')
                    for suffix in ['switch', 'switch-dpid', 'switch-id']:
                        if parts[-1] == suffix:
                            switch = v
        if switch == None:
            if debug.description():
                print 'warn_missing_interface:', data
            raise error.ArgumentValidationError("Can't identify switch for validation")
        force = True if data.get('force', '') != '' else False
        # check to see if the interface is a list or a range, 
        ifs = value.split(',')
        range_re = re.compile(r'([A-Za-z0-9-/\.:]*?)(\d+)-(\d+)$')
        if many:
            interfaces = []
            remedy = ''
            for if_name in ifs:
                # check for trailing "-<integer>" which is intended to
                # identify a range, if so split that into multiple entites
                m = range_re.match(if_name)
                if m:
                    print 'TAIL MATCH', m.group(1), m.group(2), m.group(3)
                    for suffix in range(int(m.group(2)), int(m.group(3))+1):
                        interfaces.append('%s%s' % (m.group(1), suffix))
                else:
                    interfaces.append(if_name)
        else:
            remedy = '\nUse \"exit; no interface %s\" to remove' % value
            interfaces = [value]
            
        check_missing_interface(switch, interfaces, remedy)
    data[field] = value
def feature_enabled(feature):
    """
    Return True when a particular feature is enabled.
    @param feature name of the feature ('bvs', 'bigtap', 'ha', etc)
    """

    if feature in feature_registry:
        (enabled, initializer, args) = feature_registry[feature]
        # initialized?
        if initializer and not feature in feature_registry_initialized:
            feature_registry_initialized[feature] = True
            (initializer)(featrue, **args)

        return (enabled)(feature, **args)

    if debug.cli() or debug.description():
        print 'feature_enabled: missing configuration for:', feature
    return False
Example #8
0
def feature_enabled(feature):
    """
    Return True when a particular feature is enabled.
    @param feature name of the feature ('bvs', 'bigtap', 'ha', etc)
    """

    if feature in feature_registry:
        (enabled, initializer, args) = feature_registry[feature]
        # initialized?
        if initializer and not feature in feature_registry_initialized:
            feature_registry_initialized[feature] = True
            (initializer)(featrue, **args)

        return (enabled)(feature, **args)

    if debug.cli() or debug.description():
        print 'feature_enabled: missing configuration for:', feature
    return False