Ordering list in yang

how to order in yang, suppose a there is a entry present list in the list and we are deleting one entry and replacing the same list with with two entries . among two entries one is already present in list order is not taking place

Regarding ordering, see YANG RFC 7950 Section

  • 7.7.1. Ordering
  • 7.7.7. The “ordered-by” Statement
  • 7.7.10. Usage Example (leaf-lists NETCONF)
  • 7.8.7. Usage Example (lists NETCONF)

order by user is not taking effect in this case
ex: list abc {
ordered-by user;
leaf{
type string{
}
}
}

suppose consider the list has two entries for the leaf which is configured say 1st entry “jack” 2nd entry “son” ,
later in the CLI i will configure in the way 1st entry as “son” and second entry as “jack”,
it is not getting stored in the way as “son” as the first element and “jack” as the second element, it is taking the old order
how can we handle this case can you please help

initial in the list “jack” and “son”
after the configuration in the order “son” and “jack”

the final entry in the list is getting displayed as “jack” and “son”

but not taking the new order which is “son” and “jack”

Give us some CLI input/output to show what the issue is.

step1 :CLI input initially
Configured two names for the list
step2: CLI output will be in the same order what it is configured.
step3: CLI input : configure the same input given in the step1 in the reverse order(1st as second and second as first)
step4: CLI output is same as the initial output even though the ordered-by user is used.
ex; conf t
name jon
name son
CLI output :
names jon
son
CLI input : conf t
name son
name jon

CLI Output:
names jon
son

==============
even though in the list i have used ordered-by user it is not displaying as “son” and "jon "

Your misunderstanding is in step 3.

  1. If you just configure elements that are already existing in the list that will be a no-op.
  2. If you are using the C-style CLI, the order of input doesn’t matter.

Based on the example in the RFC 7950:

  • 7.8.7. Usage Example (lists NETCONF)

Given the following list:

module example-config {
  yang-version 1.1;
  namespace "urn:example:config";
  prefix "co";

  revision 2020-06-14;
  
  list user {
    key "name";
    ordered-by user;
    description
      "This is a list of users in the system.";

    leaf name {
      type string;
    }
    leaf type {
      type string;
    }
    leaf full-name {
      type string;
    }
  }
}

With the following config:

(config)# show full-configuration co:user
co:user wilma
 type      admin
 full-name "Wilma Flintstone"
!
co:user barney
 type      admin
 full-name "Barney Rubble"
!
co:user fred
 type      admin
 full-name "Fred Flintstone"
!

To move user “wilma” last:

# move co:user wilma last
(config)# show config
no co:user wilma
co:user wilma
 type      admin
 full-name "Wilma Flintstone"
!

(config)# commit
Commit complete.

(config)# show full-configuration co:user 
co:user barney
 type      admin
 full-name "Barney Rubble"
!
co:user fred
 type      admin
 full-name "Fred Flintstone"
!
co:user wilma
 type      admin
 full-name "Wilma Flintstone"
!

New list entries will always be created last in the list by default. See https://tools.ietf.org/html/rfc7950#section-7.7.9 fourth paragraph.

(config)# co:user pebbles type child full-name "Pebbles Flintstone"
(config)# show config
co:user pebbles
 type      child
 full-name "Pebbles Flintstone"
!

(config)# commit
Commit complete.

(config)# show full-configuration co:user 
co:user barney
 type      admin
 full-name "Barney Rubble"
!
co:user fred
 type      admin
 full-name "Fred Flintstone"
!
co:user wilma
 type      admin
 full-name "Wilma Flintstone"
!
co:user pebbles
 type      child
 full-name "Pebbles Flintstone"
!

Now let’s create a new user “betty” and move “betty” after “barney” before we commit:

(config)# co:user betty type admin full-name "Betty Rubble"        
(config)# move co:user betty after barney                  
(config)# show config
! after barney
co:user betty
 type      admin
 full-name "Betty Rubble"
!

(config)# commit                         
Commit complete.

(config)# show full-configuration co:user
co:user barney
 type      admin
 full-name "Barney Rubble"
!
co:user betty
 type      admin
 full-name "Betty Rubble"
!
co:user fred
 type      admin
 full-name "Fred Flintstone"
!
co:user wilma
 type      admin
 full-name "Wilma Flintstone"
!
co:user pebbles
 type      child
 full-name "Pebbles Flintstone"
!

what is the steps to take care ordering in the case of i-style CLI ?

there no way we can take care of ordering? if so how can we handle

Same steps but skip the “commit”
Note that when you create a new list entry, it will always go last.

What do you mean when you write “take care of ordering”?