def create(gandi, datacenter, bandwidth, ip_version, vlan, ip, attach,
           background):
    """Create a public or private ip
    """
    if ip_version != 4 and vlan:
        gandi.echo('You must have an --ip-version to 4 when having a vlan.')
        return

    if ip and not vlan:
        gandi.echo('You must have a --vlan when giving an --ip.')
        return

    vm_ = gandi.iaas.info(attach) if attach else None

    if datacenter and vm_:
        dc_id = gandi.datacenter.usable_id(datacenter)
        if dc_id != vm_['datacenter_id']:
            gandi.echo('The datacenter you provided does not match the '
                       'datacenter of the vm you want to attach to.')
            return

    if not datacenter:
        datacenter = vm_['datacenter_id'] if vm_ else 'LU'

    try:
        gandi.datacenter.is_opened(datacenter, 'iaas')
    except DatacenterLimited as exc:
        gandi.echo('/!\ Datacenter %s will be closed on %s, '
                   'please consider using another datacenter.' %
                   (datacenter, exc.date))

    return gandi.ip.create(ip_version, datacenter, bandwidth, attach,
                           vlan, ip, background)
Create a public or private ip