cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ustcweizhou <...@git.apache.org>
Subject [GitHub] cloudstack pull request: CLOUDSTACK-9134: set device_id as the fir...
Date Sat, 12 Dec 2015 22:31:55 GMT
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.
    



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message