[ https://issues.apache.org/jira/browse/CLOUDSTACK-9134?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15054685#comment-15054685 ]
ASF GitHub Bot commented on CLOUDSTACK-9134: -------------------------------------------- Github user ustcweizhou commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/1209#discussion_r47437641 --- Diff: engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java --- @@ -222,11 +222,20 @@ public String getIpAddress(long networkId, long instanceId) { } @Override - public int countNics(long instanceId) { - SearchCriteria<Integer> sc = CountBy.create(); - sc.setParameters("vmId", instanceId); - List<Integer> results = customSearch(sc, null); - return results.get(0); + public int getFreeDeviceId(long instanceId) { + Filter searchFilter = new Filter(NicVO.class, "deviceId", true, null, null); + SearchCriteria<Integer> sc = deviceIdSearch.create(); + sc.setParameters("instance", instanceId); + List<Integer> deviceIds = customSearch(sc, searchFilter); + + int freeDeviceId = 0; + for (int deviceId : deviceIds) { --- End diff -- @borisroman we get the list of deviceId order by asc at first, eg, 0,1,2,4 then we check the list, for index i, if (deviceIds[i] != i), then i is the first free ip. in my example, the first free device_id is 3 (because deviceIds[3] = 4, not 3) then we assign 3 as the device_id of new nic. > ip and route are not applied to the right NIC in VR after restarting a VPC > tier > ------------------------------------------------------------------------------- > > Key: CLOUDSTACK-9134 > URL: https://issues.apache.org/jira/browse/CLOUDSTACK-9134 > Project: CloudStack > Issue Type: Bug > Security Level: Public(Anyone can view this level - this is the > default.) > Reporter: Wei Zhou > Assignee: Wei Zhou > > I created three tiers: tier1 /tier 2/ tier3 with corresponding network: > tier1: 192.168.0.0/24 > tier2: 192.168.1.0/24 > tier3: 192.168.2.0/24 > when I restart the tier 2 (in network tab, choose the tier, restart it with > cleanup), the ip and router are wrong: > root@r-7587-VM:~# ip a > 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN > link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 > inet 127.0.0.1/8 scope host lo > 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP > qlen 1000 > link/ether 0e:00:a9:fe:03:1a brd ff:ff:ff:ff:ff:ff > inet 169.254.3.26/16 brd 169.254.255.255 scope global eth0 > 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP > qlen 1000 > link/ether 06:1b:30:00:00:1e brd ff:ff:ff:ff:ff:ff > inet 10.11.115.119/24 brd 10.11.115.255 scope global eth1 > 4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP > qlen 1000 > link/ether 02:00:01:59:00:0b brd ff:ff:ff:ff:ff:ff > inet 192.168.0.49/24 brd 192.168.0.255 scope global eth2 > inet 192.168.0.1/24 brd 192.168.0.255 scope global secondary eth2 > 6: eth4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP > qlen 1000 > link/ether 02:00:64:46:00:04 brd ff:ff:ff:ff:ff:ff > inet 192.168.2.104/24 brd 192.168.2.255 scope global eth4 > inet 192.168.1.49/24 brd 192.168.1.255 scope global eth4 > inet 192.168.2.254/24 brd 192.168.2.255 scope global secondary eth4 > inet 192.168.1.254/24 brd 192.168.1.255 scope global secondary eth4 > 8: eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP > qlen 1000 > link/ether 02:00:30:af:00:10 brd ff:ff:ff:ff:ff:ff > inet 192.168.1.254/24 brd 192.168.1.255 scope global eth3 > root@r-7587-VM:~# ip route > default via 10.11.115.254 dev eth1 > 10.11.115.0/24 dev eth1 proto kernel scope link src 10.11.115.119 > 169.254.0.0/16 dev eth0 proto kernel scope link src 169.254.3.26 > 192.168.0.0/24 dev eth2 proto kernel scope link src 192.168.0.49 > 192.168.1.0/24 dev eth4 proto kernel scope link src 192.168.1.49 > 192.168.1.0/24 dev eth3 proto kernel scope link src 192.168.1.254 > 192.168.2.0/24 dev eth4 proto kernel scope link src 192.168.2.104 > the ip and router of tier2 should be applied to eth3, but sometimes it is > applied to eth4. > -------------- > if I restart the tier1 after that, the issue continues: > root@r-7587-VM:~# ip a;ip route > 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN > link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 > inet 127.0.0.1/8 scope host lo > 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP > qlen 1000 > link/ether 0e:00:a9:fe:03:1a brd ff:ff:ff:ff:ff:ff > inet 169.254.3.26/16 brd 169.254.255.255 scope global eth0 > 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP > qlen 1000 > link/ether 06:1b:30:00:00:1e brd ff:ff:ff:ff:ff:ff > inet 10.11.115.119/24 brd 10.11.115.255 scope global eth1 > 6: eth4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP > qlen 1000 > link/ether 02:00:64:46:00:04 brd ff:ff:ff:ff:ff:ff > inet 192.168.2.104/24 brd 192.168.2.255 scope global eth4 > inet 192.168.1.49/24 brd 192.168.1.255 scope global eth4 > inet 192.168.2.254/24 brd 192.168.2.255 scope global secondary eth4 > inet 192.168.1.254/24 brd 192.168.1.255 scope global secondary eth4 > 8: eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP > qlen 1000 > link/ether 02:00:30:af:00:10 brd ff:ff:ff:ff:ff:ff > inet 192.168.1.254/24 brd 192.168.1.255 scope global eth3 > 9: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP > qlen 1000 > link/ether 02:00:07:4c:00:0d brd ff:ff:ff:ff:ff:ff > default via 10.11.115.254 dev eth1 > 10.11.115.0/24 dev eth1 proto kernel scope link src 10.11.115.119 > 169.254.0.0/16 dev eth0 proto kernel scope link src 169.254.3.26 > 192.168.1.0/24 dev eth4 proto kernel scope link src 192.168.1.49 > 192.168.1.0/24 dev eth3 proto kernel scope link src 192.168.1.254 > 192.168.2.0/24 dev eth4 proto kernel scope link src 192.168.2.104 > -------- > this also happenes if we change the network offering of vpc tier (the tier > will restart) -- This message was sent by Atlassian JIRA (v6.3.4#6332)