<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def create_openstack_network(self, subnet, network, tenant_id, tenant_name, direction):
 """Helper function to create openstack network. The net_id and subnet_id is returned. Upon failure, the subnet is deallocated. """

        try:
            gw = str(netaddr.IPAddress(subnet['cidr'].split('/')[0]) + 2)
            net_id, subnet_id = self.os_helper.create_network(
                network['name'], tenant_id, subnet['cidr'], gw=gw)
            if net_id is None or subnet_id is None:
                self.release_subnet(subnet['cidr'], direction)
            return net_id, subnet_id
        except Exception as exc:
            self.release_subnet(subnet['cidr'], direction)
            LOG.error("Create network for tenant %(tenant)s "
                      "network %(name)s direction %(dir)s failed "
                      "exc %(exc)s ",
                      {'tenant': tenant_name, 'name': network['name'],
                       'dir': direction, 'exc': str(exc)})
            return None, None