'Create a new Gandi node
:keyword    name:   String with a name for this new node (required)
:type       name:   ``str``
:keyword    image:  OS Image to boot on node. (required)
:type       image:  :class:`NodeImage`
:keyword    location: Which data center to create a node in. If empty,
undefined behavior will be selected. (optional)
:type       location: :class:`NodeLocation`
:keyword    size:   The size of resources allocated to this node.
(required)
:type       size:   :class:`NodeSize`
:keyword    login: user name to create for login on machine (required)
:type       login: ``str``
:keyword    password: password for user that\'ll be created (required)
:type       password: ``str``
:keyword    inet_family: version of ip to use, default 4 (optional)
:type       inet_family: ``int``
:keyword    keypairs: IDs of keypairs or Keypairs object
:type       keypairs: list of ``int`` or :class:`.KeyPair`
:rtype: :class:`Node`'

def create_node(self, **kwargs):

    if ((not kwargs.get('login')) and (not kwargs.get('keypairs'))):
        raise GandiException(1020, 'Login    and    password    or    ssh    keypair    must    be    defined    for    node    creation')
    location = kwargs.get('location')
    if (location and isinstance(location, NodeLocation)):
        dc_id = int(location.id)
    else:
        raise GandiException(1021, 'location    must    be    a    subclass    of    NodeLocation')
    size = kwargs.get('size')
    if ((not size) and (not isinstance(size, NodeSize))):
        raise GandiException(1022, 'size    must    be    a    subclass    of    NodeSize')
    keypairs = kwargs.get('keypairs', [])
    keypair_ids = [(k if isinstance(k, int) else k.extra['id']) for k in keypairs]
    instance = INSTANCE_TYPES.get(size.id)
    cores = (instance['cpu'] if instance else int(size.id))
    src_disk_id = int(kwargs['image'].id)
    disk_spec = {'datacenter_id': dc_id, 'name': ('disk_%s' % kwargs['name'])}
    vm_spec = {'datacenter_id': dc_id, 'hostname': kwargs['name'], 'memory': int(size.ram), 'cores': cores, 'bandwidth': int(size.bandwidth), 'ip_version': kwargs.get('inet_family', 4)}
    if (kwargs.get('login') and kwargs.get('password')):
        vm_spec.update({'login': kwargs['login'], 'password': kwargs['password']})
    if keypair_ids:
        vm_spec['keys'] = keypair_ids
    (op_disk, op_iface, op_vm) = self.connection.request('hosting.vm.create_from', vm_spec, disk_spec, src_disk_id).object
    if self._wait_operation(op_vm['id']):
        node = self._node_info(op_vm['vm_id'])
        ifaces = node.get('ifaces')
        if (len(ifaces) > 0):
            ips = ifaces[0].get('ips')
            if (len(ips) > 0):
                node['ip'] = ips[0]['ip']
        return self._to_node(node)
    return None
