Пример #1
0
def update_switch(fab_id, switch_id, data, user):
    switch = Switch.objects.get(pk=switch_id)

    # check if switch is already booted
    if switch.boot_detail:
        if any([switch.name != data[NAME], switch.model.id != data[MODEL], switch.serial_num != data[SERIAL_NUM]]):
            raise IgniteException(ERR_NO_NAME_CHANGE)

    # check if switch already exists with new name
    # switch name is searched across all fabrics
    if (switch.name != data[NAME] and
            Switch.objects.filter(topology__is_fabric=True, dummy=False,
                                  name=data[NAME])):
        raise IgniteException(ERR_SW_NAME_IN_USE)

    switch.name = data[NAME]

    # check if switch already exists with new serial num
    # note: serial numbers are unique across fabrics
    if (data[SERIAL_NUM] and switch.serial_num != data[SERIAL_NUM] and
            Switch.objects.filter(dummy=False, serial_num=data[SERIAL_NUM])):
        raise IgniteException(ERR_SERIAL_NUM_IN_USE)
    # check if serial_num exists in discovery rules
    find_dup_serial_discovery([data[SERIAL_NUM]])
    switch.serial_num = data[SERIAL_NUM]

    new_model = get_switch(data[MODEL])

    # is there a change in model?
    change = True if new_model != switch.model else False
    logger.debug("%schange in switch model", "no " if not change else "")

    # save new values
    switch.model = new_model
    switch.image_profile = (image.get_profile(data[IMAGE_PROFILE])
                            if data[IMAGE_PROFILE] else None)
    switch.config_profile = (config.get_profile(data[CONFIG_PROFILE])
                             if data[CONFIG_PROFILE] else None)
    switch.feature_profile = (feature.get_profile(data[FEATURE_PROFILE])
                              if data[FEATURE_PROFILE] else None)
    switch.workflow = (workflow.get_workflow(data[WORKFLOW])
                       if data[WORKFLOW] else None)

    switch.save()

    if change:
        BaseTopology.get_object(fab_id, user).update_model(switch)
    else:
        Fabric.objects.filter(pk=fab_id).update(updated_by=user)
Пример #2
0
def get_rma_detail(old_serial_num):
    #check if switch exist with the searched serial number
    switch = get_rma_switch(old_serial_num)
    if switch:
        switch.match = SWITCH
        switch.switch_detail = switch
        if switch.boot_detail:
            #booting of switch is in progress
            if switch.boot_detail.boot_status == BOOT_PROGRESS:
                logger.debug(ERR_SWITCH_BOOT_IN_PROGRESS)
                raise IgniteException(ERR_SWITCH_BOOT_IN_PROGRESS)
            try:
                group_switches = GroupSwitch.objects.filter(grp_switch_id=switch.id).values_list('group_id', flat=True).distinct()
                for group_switch in group_switches:
                    group = Group.objects.get(pk=group_switch)
                    if group.ref_count>0:
                        raise IgniteException(ERR_SWITCH_IN_USE_JOB_SCHEDULE)
            except GroupSwitch.DoesNotExist:
                pass
        else:
            rule = find_dup_serial_discovery([old_serial_num], rma_case=True)
            if rule:
                switch.rule = rule.id
                logger.debug("switch found as not booted and discovery rule also exist")
        return switch
    return None
Пример #3
0
def get_rma_detail(old_serial_num):
    #check if switch exist with the searched serial number
    switch = get_rma_switch(old_serial_num)
    if switch:
        switch.match = SWITCH
        switch.switch_detail = switch
        if switch.boot_detail:
            #booting of switch is in progress
            if switch.boot_detail.boot_status == BOOT_PROGRESS:
                logger.debug(ERR_SWITCH_BOOT_IN_PROGRESS)
                raise IgniteException(ERR_SWITCH_BOOT_IN_PROGRESS)
            try:
                group_switches = GroupSwitch.objects.filter(
                    grp_switch_id=switch.id).values_list('group_id',
                                                         flat=True).distinct()
                for group_switch in group_switches:
                    group = Group.objects.get(pk=group_switch)
                    if group.ref_count > 0:
                        logger.debug(ERR_SWITCH_IN_USE_JOB_SCHEDULE)
                        raise IgniteException(ERR_SWITCH_IN_USE_JOB_SCHEDULE)
            except GroupSwitch.DoesNotExist:
                pass
        else:
            rule = find_dup_serial_discovery([old_serial_num], rma_case=True)
            if rule:
                switch.rule = rule.id
                logger.debug(
                    "switch found as not booted and discovery rule also exist")
        return switch
    return None
Пример #4
0
def get_rma_rule(sn):
    #check if rule exist
    rule = find_dup_serial_discovery([sn], rma_case=True)
    if rule:
        rule.match = RULE
        rule.rule = rule.id
        logger.debug("switch does not exist with searched serial number but discovery rule exist")
        return rule
    return None
Пример #5
0
def get_rma_rule(sn):
    #check if rule exist
    rule = find_dup_serial_discovery([sn], rma_case=True)
    if rule:
        rule.match = RULE
        rule.rule = rule.id
        logger.debug(
            "switch does not exist with searched serial number but discovery rule exist"
        )
        return rule
    return None
Пример #6
0
def update_rma_rule(old_serial_num, new_serial_num, id=0):
    if id:
        try:
            rule = DiscoveryRule.objects.get(id=id)
        except DiscoveryRule.DoesNotExist:
            raise IgniteException(ERR_DISOVERY_RULE_EXIST)
    else:
        rule = find_dup_serial_discovery([old_serial_num], rma_case=True)

    if rule:
        rule.subrules = [r.replace(old_serial_num, new_serial_num) for r in rule.subrules]
        rule.save()
        logger.debug("Discovery rule found")
        return True
Пример #7
0
def update_rma_rule(old_serial_num, new_serial_num, id=0):
    if id:
        try:
            rule = DiscoveryRule.objects.get(id=id)
        except DiscoveryRule.DoesNotExist:
            logger.debug(ERR_DISOVERY_RULE_EXIST)
            raise IgniteException(ERR_DISOVERY_RULE_EXIST)
    else:
        rule = find_dup_serial_discovery([old_serial_num], rma_case=True)

    if rule:
        rule.subrules = [
            r.replace(old_serial_num, new_serial_num) for r in rule.subrules
        ]
        rule.save()
        logger.debug("Discovery rule found")
        return True
Пример #8
0
def update_switch(fab_id, switch_id, data, user):
    switch = Switch.objects.get(pk=switch_id)

    # check if switch is already booted
    if switch.boot_detail:
        if data[CONFIG_TYPE] == RUNNING_CONFIG:
            logger.debug("input config type- " + data[CONFIG_TYPE])
            if SwitchConfig.objects.filter(switch_id=switch_id):
                switch.config_type = data[CONFIG_TYPE]
            else:
                logger.error(ERR_RUN_CONFIG_NOT_AVAL)
                raise IgniteException(ERR_RUN_CONFIG_NOT_AVAL)
        else:
            switch.config_type = data[CONFIG_TYPE]

        if any([
                switch.name != data[NAME], switch.model.id != data[MODEL],
                switch.serial_num != data[SERIAL_NUM]
        ]):
            raise IgniteException(ERR_NO_NAME_CHANGE)

    # check if switch already exists with new name
    # switch name is searched across all fabrics
    if (switch.name != data[NAME] and Switch.objects.filter(
            topology__is_fabric=True, dummy=False, name=data[NAME])):
        raise IgniteException(ERR_SW_NAME_IN_USE)

    switch.name = data[NAME]

    # check if switch already exists with new serial num
    # note: serial numbers are unique across fabrics
    if (data[SERIAL_NUM] and switch.serial_num != data[SERIAL_NUM] and
            Switch.objects.filter(dummy=False, serial_num=data[SERIAL_NUM])):
        raise IgniteException(ERR_SERIAL_NUM_IN_USE)
    # check if serial_num exists in discovery rules
    find_dup_serial_discovery([data[SERIAL_NUM]])
    switch.serial_num = data[SERIAL_NUM]

    new_model = get_switch(data[MODEL])

    # is there a change in model?
    change = True if new_model != switch.model else False
    logger.debug("%schange in switch model", "no " if not change else "")

    if change:
        if data[MODEL] == 1:
            logger.debug("Unknown switch model can not be assigned")
            raise IgniteException(ERR_CAN_NOT_ASSIGN_UNKOWN_MODEL)

    # save new values
    switch.model = new_model
    switch.image_profile = (image.get_profile(data[IMAGE_PROFILE])
                            if data[IMAGE_PROFILE] else None)
    switch.config_profile = (config.get_profile(data[CONFIG_PROFILE])
                             if data[CONFIG_PROFILE] else None)
    switch.feature_profile = (feature.get_profile(data[FEATURE_PROFILE])
                              if data[FEATURE_PROFILE] else None)
    switch.workflow = (workflow.get_workflow(data[WORKFLOW])
                       if data[WORKFLOW] else None)

    switch.save()

    if change:
        BaseTopology.get_object(fab_id, user).update_model(switch)
    else:
        Fabric.objects.filter(pk=fab_id).update(updated_by=user)