

@contextlib.contextmanager
def hosting_device(self, template_id, management_port_id=None, fmt=None, admin_state_up=True, no_delete=False, set_port_device_id=True, **kwargs):
    if (not fmt):
        fmt = self.fmt
    res = self._create_hosting_device(fmt, template_id, management_port_id, admin_state_up, **kwargs)
    if (res.status_int >= 400):
        raise webob.exc.HTTPClientError(code=res.status_int)
    hosting_device = self.deserialize((fmt or self.fmt), res)
    if ((set_port_device_id is True) and (management_port_id is not None)):
        data = {
            'port': {
                'device_id': hosting_device['hosting_device']['id'],
                'device_owner': 'Nova',
            },
        }
        req = self.new_update_request('ports', data, management_port_id)
        res = self.deserialize(self.fmt, req.get_response(self.api))
    (yield hosting_device)
    if (not no_delete):
        self._delete('hosting_devices', hosting_device['hosting_device']['id'])

dataset/ETHPy150Open openstack/networking-cisco/networking_cisco/tests/unit/cisco/device_manager/test_db_device_manager.py DeviceManagerTestCaseMixin.hosting_device/original