Browse Source

Changes to host member config spec

Vmware SDK refers to pnic devices in using
keys. However the create_spec of  a DVS, required
the pnic backing of hosts members to list the
name of the device, not the key.
Also we need to handle the case where the
host requested does not exists.

Change-Id: I4a94ac67c7c44f4829ffa9ec4175f75a35a2876b
Adolfo Duarte 1 year ago
parent
commit
ce784096c6

+ 2
- 2
networking_vsphere/tests/unit/utils/test_vim_objects.py View File

@@ -231,12 +231,12 @@ class TestDistributedVirtualSwitch(TestBase):
231 231
         self.assertEqual(len(results), 1)
232 232
         mocked_get_type.assert_any_call('DVSNameArrayUplinkPortPolicy')
233 233
         self.assertEqual(len(results.uplinkPortName),
234
-                         len(self.sut.pnic_devices))
234
+                         len(self.sut.pnic_keys))
235 235
 
236 236
     def test_uplink_port_names(self):
237 237
         self.assertEqual(self.sut.uplink_port_names,
238 238
                          ['dvUplink0', 'dvUplink1'])
239
-        self.sut.pnic_devices = []
239
+        self.sut.pnic_keys = []
240 240
         self.assertEqual(self.sut.uplink_port_names, ['dvUplink'])
241 241
 
242 242
     @mock.patch.object(networking_vsphere.utils.vim_objects.VcenterProxy,

+ 12
- 9
networking_vsphere/utils/vim_objects.py View File

@@ -88,7 +88,7 @@ class VcenterProxy(object):
88 88
                                        self.session.vim,
89 89
                                        moref,
90 90
                                        property_name
91
-                                       )[0]
91
+                                       )
92 92
 
93 93
     @staticmethod
94 94
     def make_moref(value, type_):
@@ -118,7 +118,7 @@ class VcenterProxy(object):
118 118
         :param host: host
119 119
         :return: returns a list of pnic mobs
120 120
         """
121
-        return self.get_property(host.obj, "config.network.pnic")
121
+        return self.get_property(host.obj, "config.network.pnic")[0]
122 122
 
123 123
     def get_used_pnics_keys_in_host(self, host):
124 124
         """Returns keys pointing to used pnics in host
@@ -141,7 +141,7 @@ class VcenterProxy(object):
141 141
         :param host:
142 142
         :return: a set of keys pointing to all pnics on host
143 143
         """
144
-        return {pnic.key for pnic in self.get_host_pnics(host)}
144
+        return {pnic.key for pnic in self.get_host_pnics(host) if host}
145 145
 
146 146
     def get_free_pnics_keys_in_host(self, host):
147 147
         """Returns keys pointing to free pnics in host
@@ -172,8 +172,8 @@ class DistributedVirtualSwitch(VcenterProxy):
172 172
         self.type = 'dvSwitch'
173 173
         if pnic_devices is None:
174 174
             pnic_devices = []
175
-        self.pnic_devices = {"key-vim.host.PhysicalNic-" + device
176
-                             for device in pnic_devices}
175
+        self.pnic_keys = {"key-vim.host.PhysicalNic-" + device
176
+                          for device in pnic_devices}
177 177
         self.max_mtu = max_mtu
178 178
         self.host_names = host_names
179 179
         self.description = description
@@ -217,7 +217,8 @@ class DistributedVirtualSwitch(VcenterProxy):
217 217
     def list_of_host_member_config_specs(self):
218 218
         if self.hosts is None:
219 219
             return []
220
-        return [self.host_member_config_spec_for(host) for host in self.hosts]
220
+        return [self.host_member_config_spec_for(host) for host in self.hosts
221
+                if host]
221 222
 
222 223
     def host_member_config_spec_for(self, host):
223 224
         spec = self.get_type("DistributedVirtualSwitchHostMemberConfigSpec")
@@ -234,7 +235,9 @@ class DistributedVirtualSwitch(VcenterProxy):
234 235
     def get_available_pnic_devices(self, host):
235 236
         _free = self.get_free_pnics_keys_in_host(host)
236 237
 
237
-        return _free.intersection(self.pnic_devices)
238
+        _available_keys = _free.intersection(self.pnic_keys)
239
+        return [_key.replace("key-vim.host.PhysicalNic-", "")
240
+                for _key in _available_keys]
238 241
 
239 242
     def host_member_pnic_backing(self, p_devices):
240 243
         pnic_backing = self.get_type(
@@ -256,9 +259,9 @@ class DistributedVirtualSwitch(VcenterProxy):
256 259
 
257 260
     @property
258 261
     def uplink_port_names(self):
259
-        if self.pnic_devices:
262
+        if self.pnic_keys:
260 263
             return [''.join(['dvUplink', str(c)]) for c, nic in
261
-                    enumerate(self.pnic_devices)]
264
+                    enumerate(self.pnic_keys)]
262 265
         return ['dvUplink']
263 266
 
264 267
     @property

Loading…
Cancel
Save