@@ -5588,7 +5588,7 @@ func (h *SHost) PerformAddNetif(
55885588 mac := input .Mac
55895589 vlan := input .VlanId
55905590
5591- wire := input .WireId
5591+ wireId := input .WireId
55925592 if len (input .WireId ) > 0 {
55935593 wireObj , err := WireManager .FetchByIdOrName (ctx , userCred , input .WireId )
55945594 if err != nil {
@@ -5598,7 +5598,7 @@ func (h *SHost) PerformAddNetif(
55985598 return nil , errors .Wrap (err , "FetchByIdOrName" )
55995599 }
56005600 }
5601- wire = wireObj .GetId ()
5601+ wireId = wireObj .GetId ()
56025602 }
56035603 ipAddr := input .IpAddr
56045604 if len (ipAddr ) > 0 && ! regutils .MatchIP4Addr (ipAddr ) {
@@ -5630,25 +5630,25 @@ func (h *SHost) PerformAddNetif(
56305630 }
56315631 }
56325632
5633- err = h .addNetif (ctx , userCred , mac , vlan , wire , ipAddr , ip6Addr , int (rate ), nicType , index , isLinkUp ,
5633+ err = h .addNetif (ctx , userCred , mac , vlan , wireId , ipAddr , ip6Addr , int (rate ), nicType , index , isLinkUp ,
56345634 int16 (mtu ), reset , netIf , bridge , reserve , requireDesignatedIp , requireIpv6 , strictIpv6 )
56355635 return nil , errors .Wrap (err , "addNetif" )
56365636}
56375637
56385638func (h * SHost ) addNetif (ctx context.Context , userCred mcclient.TokenCredential ,
5639- mac string , vlanId int , wire string , ipAddr string , ip6Addr string ,
5639+ mac string , vlanId int , wireId string , ipAddr string , ip6Addr string ,
56405640 rate int , nicType compute.TNicType , index int , linkUp tristate.TriState , mtu int16 ,
56415641 reset bool , strInterface * string , strBridge * string ,
56425642 reserve bool , requireDesignatedIp bool , requireIpv6 bool , strictIpv6 bool ,
56435643) error {
56445644 var sw * SWire
5645- if len (wire ) > 0 {
5646- iWire , err := WireManager .FetchByIdOrName ( ctx , userCred , wire )
5645+ if len (wireId ) > 0 {
5646+ iWire , err := WireManager .FetchById ( wireId )
56475647 if err != nil {
56485648 if err == sql .ErrNoRows {
5649- return httperrors .NewResourceNotFoundError2 (WireManager .Keyword (), wire )
5649+ return httperrors .NewResourceNotFoundError2 (WireManager .Keyword (), wireId )
56505650 } else {
5651- return httperrors .NewInternalServerError ("find Wire %s error: %s" , wire , err )
5651+ return httperrors .NewInternalServerError ("find Wire %s error: %s" , wireId , err )
56525652 }
56535653 }
56545654 sw = iWire .(* SWire )
@@ -5673,7 +5673,7 @@ func (h *SHost) addNetif(ctx context.Context, userCred mcclient.TokenCredential,
56735673 var v4net , v6net * SNetwork
56745674 swNets , err := sw .getNetworks (ctx , userCred , userCred , NetworkManager .AllowScope (userCred ))
56755675 if err != nil {
5676- return httperrors .NewInputParameterError ("no networks on wire %s" , wire )
5676+ return httperrors .NewInputParameterError ("no networks on wire %s" , wireId )
56775677 }
56785678 for i := range swNets {
56795679 if v4net == nil && v4addr != nil && swNets [i ].IsAddressInRange (* v4addr ) {
@@ -5694,7 +5694,7 @@ func (h *SHost) addNetif(ctx context.Context, userCred mcclient.TokenCredential,
56945694 if len (ip6Addr ) > 0 {
56955695 addrs = append (addrs , ip6Addr )
56965696 }
5697- return httperrors .NewBadRequestError ("IP %s not attach to wire %s" , strings .Join (addrs , "," ), wire )
5697+ return httperrors .NewBadRequestError ("IP %s not attach to wire %s" , strings .Join (addrs , "," ), wireId )
56985698 }
56995699 if v4net != nil && v6net != nil && v4net .Id != v6net .Id {
57005700 return httperrors .NewConflictError ("IPv4 %s and IPv6 %s must be on the same network" , ipAddr , ip6Addr )
@@ -6137,7 +6137,7 @@ func (hh *SHost) attach2Network(
61376137 defer lockman .ReleaseObject (ctx , net )
61386138
61396139 var freeIp4 , freeIp6 string
6140- if (! opt .strictIpv6 || len (ipAddr ) > 0 ) && (bn == nil || bn .IpAddr != ipAddr ) {
6140+ if (! opt .strictIpv6 || len (ipAddr ) > 0 ) && (bn == nil || bn .IpAddr != ipAddr ) && net . HasIPv4Addr () {
61416141 // allocate ipv4 address
61426142 usedAddrs := net .GetUsedAddresses (ctx )
61436143 if ipAddr != "" {
@@ -6158,7 +6158,7 @@ func (hh *SHost) attach2Network(
61586158 }
61596159 freeIp4 = freeIp
61606160 }
6161- if (opt .requireIpv6 || len (ip6Addr ) > 0 ) && (bn == nil || bn .Ip6Addr != ip6Addr ) {
6161+ if (opt .requireIpv6 || len (ip6Addr ) > 0 ) && (bn == nil || bn .Ip6Addr != ip6Addr ) && net . HasIPv6Addr () {
61626162 usedAddrs6 := net .GetUsedAddresses6 (ctx )
61636163 if ip6Addr != "" {
61646164 // converted baremetal can resuse related guest network ip
0 commit comments