Tag Archives: switch

Error: Please renew the default configurations. [How to Solve]

Problems arising

The current configuration is shown in the following figure:

[SW1]int g0/0/1
[SW1-GigabitEthernet0/0/1]
[SW1-GigabitEthernet0/0/1]dis this
#
interface GigabitEthernet0/0/1
 port link-type trunk
 undo port trunk allow-pass vlan 1
 port trunk allow-pass vlan 2 to 4094
#
return

When the port link type needs to be modified or deleted, an error is reported   Error: please update the default configuration

[SW1-GigabitEthernet0/0/1]
[SW1-GigabitEthernet0/0/1]port link-type access 
Error: Please renew the default configurations.
[SW1-GigabitEthernet0/0/1]
[SW1-GigabitEthernet0/0/1]undo port link-type 
Error: Please renew the default configurations.

Causes of occurrence

The reason for the error is that you have added the port to a VLAN, so you will report an error when changing or deleting it.

For example, if you want to delete “parent folder”, you have to delete “child folder” first. It means to delete it layer by layer. The same is true of Huawei’s configuration commands, which are undo level by level.

|--Parent Folder
|---- subfolder

Solution

To undo all commands except “port link type trunk”, you can change the link type or undo the command.

[SW1-GigabitEthernet0/0/1]dis this
#
interface GigabitEthernet0/0/1
 port link-type trunk
 undo port trunk allow-pass vlan 1
#
return
[SW1-GigabitEthernet0/0/1]
[SW1-GigabitEthernet0/0/1]undo port trunk allow-pass vlan all
[SW1-GigabitEthernet0/0/1]
[SW1-GigabitEthernet0/0/1]port trunk allow-pass vlan 1
[SW1-GigabitEthernet0/0/1]
[SW1-GigabitEthernet0/0/1]dis this
#
interface GigabitEthernet0/0/1
 port link-type trunk
#
return
[SW1-GigabitEthernet0/0/1]
[SW1-GigabitEthernet0/0/1]undo port link-type 
[SW1-GigabitEthernet0/0/1]
[SW1-GigabitEthernet0/0/1]dis this
#
interface GigabitEthernet0/0/1
#
return

The Vue project cannot use a component name that contains the word switch

Application scenario: you need to create a new version switching page in the Vue project, which is translated as versionswitch according to the Chinese name, so you build a versionswitch.vue. You find that errors have been reported all the time, and if you change the name to vesionchange.vue, no errors have been reported. After a search, it is found that components cannot be named with switch, nor can they be named with switchye .

Python switch / case statement implementation method

Different from Java, C/C + + and other languages, python does not provide switch/case statements, which makes me feel very strange. We can implement the switch/case statement in the following ways.

Use if elif… elif… Else to realize switch/case

You can use if elif… Elif.. else sequence to replace the switch/case statement, this is the easiest way to think of. However, with the increase of branches and frequent modification, this alternative method is not very good for debugging and maintenance.

Switch/case using dictionary

Switch/case can be realized by dictionary, which is easy to maintain and can reduce the amount of code. The following is the switch/case implementation using dictionary simulation:


def num_to_string(num):
    numbers = {
        0 : "zero",
        1 : "one",
        2 : "two",
        3 : "three"
    }

    return numbers.get(num, None)

if __name__ == "__main__":
    print num_to_string(2)
    print num_to_string(5)

The results are as follows:

two
None

Python dictionary can also include functions or lambda expressions. The code is as follows:

def success(msg):
    print msg

def debug(msg):
    print msg

def error(msg):
    print msg

def warning(msg):
    print msg

def other(msg):
    print msg

def notify_result(num, msg):
    numbers = {
        0 : success,
        1 : debug,
        2 : warning,
        3 : error
    }

    method = numbers.get(num, other)
    if method:
        method(msg)

if __name__ == "__main__":
    notify_result(0, "success")
    notify_result(1, "debug")
    notify_result(2, "warning")
    notify_result(3, "error")
    notify_result(4, "other")

The results are as follows:

success
debug
warning
error
other

Through the above example, it can be proved that the switch/case statement can be fully implemented through Python dictionary, and it is flexible enough. especially at runtime, it is convenient to add or delete a switch/case option in the dictionary.

Switch/case can be implemented by using scheduling method in class

If you are not sure which method to use in a class, you can use a scheduling method to determine it at run time. The code is as follows:

class switch_case(object):

    def case_to_function(self, case):
        fun_name = "case_fun_" + str(case)
        method = getattr(self, fun_name, self.case_fun_other)
        return method

    def case_fun_1(self, msg):
        print msg

    def case_fun_2(self, msg):
        print msg

    def case_fun_other(self, msg):
        print msg


if __name__ == "__main__":
    cls = switch_case()
    cls.case_to_function(1)("case_fun_1")
    cls.case_to_function(2)("case_fun_2")
    cls.case_to_function(3)("case_fun_other")

The results are as follows:

case_fun_1
case_fun_2
case_fun_other

summary

Personally, using dictionary to realize switch/case is the most flexible, but it is also difficult to understand.

Implementation of Python switch / case statements

It struck me as odd that, unlike languages such as Java, C\C++, Switch /case statements are not available in Python. We can implement the switch/ Case statement in several ways.
Use the if… Elif… Elif… Else to realize the switch/case
You can use if… Elif… elif.. An else sequence instead of a switch/case statement is the easiest way to think about it. However, with more branches and frequent modifications, this alternative is not easy to debug and maintain.
Use a dictionary to implement switch/ Case
A dictionary can be used to implement switch/ Case in a way that is easy to maintain and reduces the amount of code. The following is a switch/ Case implementation using a dictionary simulation:


def num_to_string(num):
    numbers = {
        0 : "zero",
        1 : "one",
        2 : "two",
        3 : "three"
    }

    return numbers.get(num, None)

if __name__ == "__main__":
    print num_to_string(2)
    print num_to_string(5)

The execution results are as follows:

two
None

The Python dictionary can also include functions or Lambda expressions, as follows:

def success(msg):
    print msg

def debug(msg):
    print msg

def error(msg):
    print msg

def warning(msg):
    print msg

def other(msg):
    print msg

def notify_result(num, msg):
    numbers = {
        0 : success,
        1 : debug,
        2 : warning,
        3 : error
    }

    method = numbers.get(num, other)
    if method:
        method(msg)

if __name__ == "__main__":
    notify_result(0, "success")
    notify_result(1, "debug")
    notify_result(2, "warning")
    notify_result(3, "error")
    notify_result(4, "other")

The execution results are as follows:

success
debug
warning
error
other

The above example shows that the Switch /case statement can be fully implemented with a Python dictionary, and is flexible enough. is especially handy at run time to add or remove a switch/case option from a dictionary.
Switch/Case can be implemented in a class using scheduling methods
If you are not sure which method to use in a class, you can use a scheduling method at run time to determine. The code is as follows:

class switch_case(object):

    def case_to_function(self, case):
        fun_name = "case_fun_" + str(case)
        method = getattr(self, fun_name, self.case_fun_other)
        return method

    def case_fun_1(self, msg):
        print msg

    def case_fun_2(self, msg):
        print msg

    def case_fun_other(self, msg):
        print msg


if __name__ == "__main__":
    cls = switch_case()
    cls.case_to_function(1)("case_fun_1")
    cls.case_to_function(2)("case_fun_2")
    cls.case_to_function(3)("case_fun_other")

The execution results are as follows:

case_fun_1
case_fun_2
case_fun_other

conclusion
Personally, using a dictionary to implement the switch/case is the most flexible, but it is also difficult to understand.

C++ error: jump to case label crosses initialization

A compiler, the compiler error error: jump to case label [- fpermissive], the error: crosses initialization of 'XXXX' </ code>, to simple combing the related content

I. Problem code

int main()
{
  int test = 2;
  switch(test)
  {
    case 1:
      int i = 1;  
      cout << i;
      break;
    case 2:
      cout << i;  
      break;
    default:
      cout << "error" << endl;
  }
}

//test.cpp: In function 'int main()':
//test.cpp: error: jump to case label [-fpermissive]
//   case 2:
//        ^
//test.cpp: error:   crosses initialization of 'int i'
//    int b = 1;
//test.cpp: error: jump to case label [-fpermissive]
//   default:
//   ^
//test.cpp:11:8: error:   crosses initialization of 'int i'
//    int b = 1;

As can be seen from the above code, since there is no separate block in switch to qualify the declaration period of variable I, the scope of the variable is the initialization point to the end of switch. In this case, the compiler will report an error because we are not sure whether this variable will be used in other cases and whether it was initialized before it was used. For example, if test has a value of 2 and case 2 is executed directly, an undefined variable will cause an exception. This is a compiler error crosses initialization </ code>.
After inspection, it is found that the compiler will report an error
no matter whether the other branches contain defined variables or not, as long as the variables are not braced in the case.

int main()
{
  int test = 2;
  switch(test)
  {
    case 1:
      int i = 1; 
      cout << i;  
      break;
    case 2:
      cout << 3; 
      break;
    default:
      cout << "error" << endl;
  }
}

//test.cpp: In function 'int main()':
//test.cpp: error: jump to case label [-fpermissive]
//   case 2:
//        ^
//test.cpp: error:   crosses initialization of 'int i'
//    int i = 1;
//test.cpp: error: jump to case label [-fpermissive]
//   default:
//   ^
//test.cpp: error:   crosses initialization of 'int i'
//    int i = 1;

The code of case 1 is enclosed with {}, and the scope of variable I is clearly set to avoid access by other cases
2. The scope of variable I is put outside the switch, and every case in the switch can be accessed
The
switch statement is a kind of goto statement, so goto has the same properties. The following goto statement will not be executed, variable I will definitely be defined, but will report the same error as above. This means that there can be no variables between goto and the tag. Variables must appear before the goto or after the tag.

int main()
{
    if(0)
    {
        goto end;
    }

    int i = 1;

    end:
       cout << i;
}

//test.cpp: In function 'int main()':
//test.cpp error: jump to label 'end' [-fpermissive]
//   end:
//   ^
//test.cpp error:   from here [-fpermissive]
//          goto end;
//               ^
//test.cpp: error:   crosses initialization of 'int i'
//     int i = 1;

In the above example, it is possible to initialize a variable before the goto tag or after the end tag

How to solve the failed to start switch root error during centos8.1 startup?

boot today found CentOS8.1 system can not boot!! I recall that I updated some system packages yesterday. At that time, the updated system was not restarted, and the updated system was not detected. It was an oversight!

take a closer look at the log and it turns out that the Switch Root is wrong, as shown below:

prompt error log generation, a simple look, want to get the U disk first, then follow up.

is inserted into the U disk, no device is detected, exit is performed, and sda is identified after repeated twice. As shown below:

then U disk mounted to/sysroot, prompt data to test with U disk,, FSCK detection, the log file/run/initramfs/rdsosreport. TXT is copied to the U disk, and then uninstall U disk. As shown below:

try manually mounting CentOS8 system disk to /sysroot and find the partition mount corresponding to CentOS8. As shown below:

then exit and the system starts normally! Fortunately, it’s not a big problem.

come in the system, think under the analysis of the cause, to fundamentally solve it…

open the log file rdsosreport.txt in the U disk, find the error fragment log analysis:

[   79.300190] xxx systemd[1]: Reached target Switch Root.[   79.300600] xxx systemd[1]: Starting Switch Root...[   79.304948] xxx systemctl[2113]: Failed to switch root: Specified switch root path '/sysroot' does not seem to be an OS tree. os-release file is missing.[   79.305456] xxx systemd[1]: initrd-switch-root.service: Main process exited, code=exited, status=1/FAILURE[   79.305593] xxx systemd[1]: initrd-switch-root.service: Failed with result 'exit-code'.[   79.305789] xxx systemd[1]: Failed to start Switch Root.[   79.305811] xxx systemd[1]: initrd-switch-root.service: Triggering OnFailure= dependencies.[   79.306342] xxx systemd[1]: Starting Setup Virtual Console...[   79.364641] xxx systemd[1]: Started Setup Virtual Console.[   79.365205] xxx systemd[1]: Started Emergency Shell.[   79.365348] xxx systemd[1]: Reached target Emergency Mode.[   79.380910] xxx systemd[1]: Received SIGRTMIN+21 from PID 1675 (plymouthd).

see the key record:

 Failed to switch root: Specified switch root path '/sysroot' does not seem to be an OS tree. os-release file is missing.

because the root path was not mounted successfully, /sysroot had no content, and the os-release file was not found.

, can you imagine if the os-release file for the system is gone?Open the /etc/cenos-release file and find the content, that’s not the problem with this file!

[root@server ~]# cat /etc/os-release NAME="CentOS Linux"VERSION="8 (Core)"ID="centos"ID_LIKE="rhel fedora"VERSION_ID="8"PLATFORM_ID="platform:el8"PRETTY_NAME="CentOS Linux 8 (Core)"ANSI_COLOR="0;31"CPE_NAME="cpe:/o:centos:centos:8"HOME_URL="https://www.centos.org/"BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-8"CENTOS_MANTISBT_PROJECT_VERSION="8"REDHAT_SUPPORT_PRODUCT="centos"REDHAT_SUPPORT_PRODUCT_VERSION="8"

continue to search, efi directory to see centos related files are there any questions?The size of the GRUbenv file is zero. Is that the problem?!

[root@server ~]# ls -al /boot/efi/EFI/centos/total 5364drwx------. 3 root root    4096 Feb 21 23:01 .drwx------. 6 root root    4096 May 11  2019 ..-rwx------. 1 root root     134 Jun  7  2019 BOOTX64.CSVdrwx------. 2 root root    4096 Feb  5 09:46 fonts-rwx------. 1 root root    9570 Feb 13 22:08 grub.cfg-rwx------. 1 root root       0 Feb 21 23:01 grubenv-rwx------. 1 root root 1876872 Feb  5 09:46 grubx64.efi-rwx------. 1 root root 1160136 Jun  7  2019 mmx64.efi-rwx------. 1 root root 1205152 Jun  7  2019 shimx64-centos.efi-rwx------. 1 root root 1211224 Jun  7  2019 shimx64.efi

then edits the grubenv file and adds the following.

# GRUB Environment Blocksaved_entry=16611cc1c45441e1a5aa9fa702a005ff-4.18.0-147.5.1.el8_1.x86_64kernelopts=root=UUID=5d5f3d63-4aed-45f1-85a9-e875c29c114a ro resume=UUID=ddeaf98e-c239-46be-95c3-d36156c1b0f6 rhgb quietboot_success=0boot_indeterminate=0################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################

main parameter description (do not write wrong! :

saved_entry:是默认的引导项kernelopts:root填写/分区的UUID,resume填写swap分区的UUID

restart, normal start, no more error. Problem solved!

============

Note: if you do not know how to edit this file, you can regenerate grub by executing the following:

[root@server EFI]# grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg Generating grub configuration file ...Found Windows Boot Manager on /dev/nvme0n1p1@/EFI/Microsoft/Boot/bootmgfw.efiAdding boot menu entry for EFI firmware configurationdone

generates grubenv as follows, there will be some incomplete parameters oh.

# GRUB Environment Blockkernelopts=root=UUID=5d5f3d63-4aed-45f1-85a9-e875c29c114a ro resume=UUID=ddeaf98e-c239-46be-95c3-d36156c1b0f6 rhgb quiet################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################

summary:

  1. to calmly analyze problems, to learn to analyze and solve problems, this ability is very important.

  2. systematically study, master the knowledge of a field is very necessary. The idea and process of solving the problem depends on your understanding of the system!

note: this article is original and shall not be reproduced on any platform without permission. For reprint, contact the author ~

The title