'Wrapper utility that returns a test server.
This wrapper utility calls the common create test server and
returns a test server. The purpose of this wrapper is to minimize
the impact on the code of the tests already using this
function.'

def create_server(self, name=None, image_id=None, flavor=None, validatable=False, wait_until='ACTIVE', clients=None, **kwargs):

    if (clients is None):
        clients = self.os_primary
    if (name is None):
        name = data_utils.rand_name((self.__class__.__name__ + '-server'))
    vnic_type = CONF.network.port_vnic_type
    if vnic_type:
        ports = []
        create_port_body = {'binding:vnic_type': vnic_type, 'namestart': 'port-smoke'}
        if kwargs:
            if ('security_groups' in kwargs):
                security_groups = clients.security_groups_client.list_security_groups().get('security_groups')
                sec_dict = dict([(s['name'], s['id']) for s in security_groups])
                sec_groups_names = [s['name'] for s in kwargs.pop('security_groups')]
                security_groups_ids = [sec_dict[s] for s in sec_groups_names]
                if security_groups_ids:
                    create_port_body['security_groups'] = security_groups_ids
            networks = kwargs.pop('networks', [])
        else:
            networks = []
        if (not networks):
            networks = clients.networks_client.list_networks(**{'router:external': False, 'fields': 'id'})['networks']
        for net in networks:
            net_id = net.get('uuid', net.get('id'))
            if ('port' not in net):
                port = self._create_port(network_id=net_id, client=clients.ports_client, **create_port_body)
                ports.append({'port': port['id']})
            else:
                ports.append({'port': net['port']})
        if ports:
            kwargs['networks'] = ports
        self.ports = ports
    tenant_network = self.get_tenant_network()
    (body, _) = compute.create_test_server(clients, tenant_network=tenant_network, wait_until=wait_until, name=name, flavor=flavor, image_id=image_id, **kwargs)
    self.addCleanup(waiters.wait_for_server_termination, clients.servers_client, body['id'])
    self.addCleanup(test_utils.call_and_ignore_notfound_exc, clients.servers_client.delete_server, body['id'])
    server = clients.servers_client.show_server(body['id'])['server']
    return server
