diff --git a/vmware_nsxlib/tests/unit/v3/test_resources.py b/vmware_nsxlib/tests/unit/v3/test_resources.py index 3f985f05..9635ead0 100644 --- a/vmware_nsxlib/tests/unit/v3/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/test_resources.py @@ -275,14 +275,15 @@ class LogicalPortTestCase(nsxlib_testcase.NsxClientTestCase): fake_port['address_bindings'] = binding_repr mocked_resource = self._mocked_lport() - + description = 'dummy' switch_profile = resources.SwitchingProfile mocked_resource.create( fake_port['logical_switch_id'], fake_port['attachment']['id'], address_bindings=pkt_classifiers, switch_profile_ids=switch_profile.build_switch_profile_ids( - mock.Mock(), *profile_dicts)) + mock.Mock(), *profile_dicts), + description=description) resp_body = { 'logical_switch_id': fake_port['logical_switch_id'], @@ -292,7 +293,8 @@ class LogicalPortTestCase(nsxlib_testcase.NsxClientTestCase): 'id': fake_port['attachment']['id'] }, 'admin_state': 'UP', - 'address_bindings': fake_port['address_bindings'] + 'address_bindings': fake_port['address_bindings'], + 'description': description } test_client.assert_json_call( diff --git a/vmware_nsxlib/tests/unit/v3/test_switch.py b/vmware_nsxlib/tests/unit/v3/test_switch.py index 3fa8a39c..ec6b95c0 100644 --- a/vmware_nsxlib/tests/unit/v3/test_switch.py +++ b/vmware_nsxlib/tests/unit/v3/test_switch.py @@ -29,7 +29,7 @@ class NsxLibSwitchTestCase(nsxlib_testcase.NsxClientTestCase): _tz_id = "8f602f97-ee3e-46b0-9d9f-358955f03608" def _create_body(self, admin_state=nsx_constants.ADMIN_STATE_UP, - vlan_id=None): + vlan_id=None, description=None): body = { "transport_zone_id": NsxLibSwitchTestCase._tz_id, "replication_mode": "MTEP", @@ -39,16 +39,21 @@ class NsxLibSwitchTestCase(nsxlib_testcase.NsxClientTestCase): } if vlan_id: body['vlan'] = vlan_id + if description is not None: + body['description'] = description return body def test_create_logical_switch(self): """Test creating a switch returns the correct response and 200 status """ + desc = 'dummy' with mock.patch.object(self.nsxlib.client, 'create') as create: self.nsxlib.logical_switch.create( - nsx_v3_mocks.FAKE_NAME, NsxLibSwitchTestCase._tz_id, []) - create.assert_called_with('logical-switches', self._create_body()) + nsx_v3_mocks.FAKE_NAME, NsxLibSwitchTestCase._tz_id, [], + description=desc) + create.assert_called_with('logical-switches', + self._create_body(description=desc)) def test_create_logical_switch_admin_down(self): """Test creating switch with admin_state down""" diff --git a/vmware_nsxlib/v3/core_resources.py b/vmware_nsxlib/v3/core_resources.py index 54e0e5dd..2774d6e6 100644 --- a/vmware_nsxlib/v3/core_resources.py +++ b/vmware_nsxlib/v3/core_resources.py @@ -121,7 +121,7 @@ class NsxLibLogicalSwitch(utils.NsxLibApiBase): def create(self, display_name, transport_zone_id, tags, replication_mode=nsx_constants.MTEP, admin_state=True, vlan_id=None, ip_pool_id=None, - mac_pool_id=None): + mac_pool_id=None, description=None): # TODO(salv-orlando): Validate Replication mode and admin_state # NOTE: These checks might be moved to the API client library if one # that performs such checks in the client is available @@ -144,6 +144,9 @@ class NsxLibLogicalSwitch(utils.NsxLibApiBase): if mac_pool_id: body['mac_pool_id'] = mac_pool_id + if description is not None: + body['description'] = description + return self.client.create(self.get_path(), body) def delete(self, lswitch_id): @@ -157,7 +160,8 @@ class NsxLibLogicalSwitch(utils.NsxLibApiBase): _do_delete() - def update(self, lswitch_id, name=None, admin_state=None, tags=None): + def update(self, lswitch_id, name=None, admin_state=None, tags=None, + description=None): # Using internal method so we can access max_attempts in the decorator @utils.retry_upon_exception( exceptions.StaleRevision, @@ -174,6 +178,8 @@ class NsxLibLogicalSwitch(utils.NsxLibApiBase): lswitch['admin_state'] = nsx_constants.ADMIN_STATE_DOWN if tags is not None: lswitch['tags'] = tags + if description is not None: + lswitch['description'] = description return self.client.update(self.get_path(lswitch_id), lswitch) return _do_update() diff --git a/vmware_nsxlib/v3/resources.py b/vmware_nsxlib/v3/resources.py index 86bb0a75..10d80b06 100644 --- a/vmware_nsxlib/v3/resources.py +++ b/vmware_nsxlib/v3/resources.py @@ -80,7 +80,8 @@ class LogicalPort(utils.NsxLibApiBase): admin_state=True, tags=None, address_bindings=None, switch_profile_ids=None, - attachment=None): + attachment=None, + description=None): tags = tags or [] address_bindings = address_bindings or [] switch_profile_ids = switch_profile_ids or [] @@ -124,6 +125,9 @@ class LogicalPort(utils.NsxLibApiBase): if attachment is not False: body['attachment'] = attachment + if description is not None: + body['description'] = description + return body def _prepare_attachment(self, attachment_type, vif_uuid, @@ -160,9 +164,9 @@ class LogicalPort(utils.NsxLibApiBase): admin_state=True, name=None, address_bindings=None, parent_vif_id=None, traffic_tag=None, switch_profile_ids=None, vif_type=None, app_id=None, - allocate_addresses=nsx_constants.ALLOCATE_ADDRESS_NONE): + allocate_addresses=nsx_constants.ALLOCATE_ADDRESS_NONE, + description=None): tags = tags or [] - body = {'logical_switch_id': lswitch_id} # NOTE(arosen): If parent_vif_id is specified we need to use # CIF attachment type. @@ -175,7 +179,8 @@ class LogicalPort(utils.NsxLibApiBase): admin_state=admin_state, tags=tags, address_bindings=address_bindings, switch_profile_ids=switch_profile_ids, - attachment=attachment)) + attachment=attachment, + description=description)) return self.client.create(self.get_path(), body=body) def delete(self, lport_id): @@ -196,7 +201,8 @@ class LogicalPort(utils.NsxLibApiBase): attachment_type=nsx_constants.ATTACHMENT_VIF, parent_vif_id=None, traffic_tag=None, vif_type=None, app_id=None, - allocate_addresses=nsx_constants.ALLOCATE_ADDRESS_NONE): + allocate_addresses=nsx_constants.ALLOCATE_ADDRESS_NONE, + description=None): # Using internal method so we can access max_attempts in the decorator @utils.retry_upon_exception( exceptions.StaleRevision, @@ -220,7 +226,8 @@ class LogicalPort(utils.NsxLibApiBase): admin_state=admin_state, tags=tags, address_bindings=addr_bindings, switch_profile_ids=switch_profile_ids, - attachment=attachment)) + attachment=attachment, + description=description)) # If revision_id of the payload that we send is older than what # NSX has, we will get a 412: Precondition Failed.