@@ -63,10 +63,22 @@ func (nm *networkManager) newNetworkImplHnsV1(nwInfo *NetworkInfo, extIf *extern
6363 )
6464
6565 networkAdapterName := extIf .Name
66+
67+ // Pass adapter name here if it is not empty, this is cause if we don't tell HNS which adapter to use
68+ // it will just pick one randomly, this is a problem for customers that have multiple adapters
69+ if nwInfo .AdapterName != "" {
70+ networkAdapterName = nwInfo .AdapterName
71+ }
72+
6673 // FixMe: Find a better way to check if a nic that is selected is not part of a vSwitch
74+ // per hns team, the hns calls fails if passed a vSwitch interface
6775 if strings .HasPrefix (networkAdapterName , vEthernetAdapterPrefix ) {
76+ log .Printf ("[net] vSwitch detected, setting adapter name to empty" )
6877 networkAdapterName = ""
6978 }
79+
80+ log .Printf ("[net] Adapter name used with HNS is : %s" , networkAdapterName )
81+
7082 // Initialize HNS network.
7183 hnsNetwork := & hcsshim.HNSNetwork {
7284 Name : nwInfo .Id ,
@@ -216,8 +228,20 @@ func (nm *networkManager) configureHcnNetwork(nwInfo *NetworkInfo, extIf *extern
216228
217229 // Set hcn network adaptor name policy
218230 // FixMe: Find a better way to check if a nic that is selected is not part of a vSwitch
219- if ! strings .HasPrefix (extIf .Name , vEthernetAdapterPrefix ) {
220- netAdapterNamePolicy , err := policy .GetHcnNetAdapterPolicy (extIf .Name )
231+ // per hns team, the hns calls fails if passed a vSwitch interface
232+ // Pass adapter name here if it is not empty, this is cause if we don't tell HNS which adapter to use
233+ // it will just pick one randomly, this is a problem for customers that have multiple adapters
234+ if nwInfo .AdapterName != "" || ! strings .HasPrefix (extIf .Name , vEthernetAdapterPrefix ) {
235+ var adapterName string
236+ if nwInfo .AdapterName != "" {
237+ adapterName = nwInfo .AdapterName
238+ } else {
239+ adapterName = extIf .Name
240+ }
241+
242+ log .Printf ("[net] Adapter name used with HNS is : %s" , adapterName )
243+
244+ netAdapterNamePolicy , err := policy .GetHcnNetAdapterPolicy (adapterName )
221245 if err != nil {
222246 log .Printf ("[net] Failed to serialize network adapter policy due to error: %v" , err )
223247 return nil , err
0 commit comments