ONTAP Rest API Discussions

How to move a file with Netapp Ontap API?

brianrussell
1,313 Views

Hi 
I can't see from the docs how to move a file using the Python Netapp API.

 

I would have thought:

resources = FileInfo.get_collection(volume, path)
resource = next(resources)
resource.path = '/new/path'
resource.patch(hydrate=True)

would have worked but sadly no.

 

What's the correct procedure?

 

 

1 ACCEPTED SOLUTION

Ontapforrum
1,129 Views

I guess, you mean using REST API ?

 

Have you tried the steps as mentioned here.

netapp_ontap.resources.file_move API documentation

View solution in original post

2 REPLIES 2

Ontapforrum
1,130 Views

I guess, you mean using REST API ?

 

Have you tried the steps as mentioned here.

netapp_ontap.resources.file_move API documentation

brianrussell
1,108 Views

From Python netapp-ontap library which calls the REST API. 

"/Move" moves files between flex volumes? I don't need to do that, I just need to move files  within the same volume.

 

The docs say you can do this with the REST API like this to move /alice/bob/bb.txt to /alice/bob/charlie/bb.txt

curl -k --request PATCH \
  --url https://server.domain/api/storage/volumes/7da9eb81-6daa-4323-9eab-7bbce73da0f2/files/%2Falice%2Fbob%2Fbb.txt \
  --header 'Accept: application/json' \
  --header 'Authorization: Basic ******************' \
  --header 'User-Agent: httpyac' \
  --data '{
    "path" : "/alice/bob/charlie/bb.txt" 
}'

This works.

And there is an example in the docs, and the comments within the netapp python library that tells you to do this from python like this:

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo(
        "7da9eb81-6daa-4323-9eab-7bbce73da0f2", path="alice/bob/bb.txt"
    )
    resource.path = "alice/bob/charlie.txt"
    resource.patch()

BUT this fails with

Caused by HTTPError('500 Server Error: Internal Server Error for url: https://server.domain:443/api/storage/volumes/7da9eb81-6daa-4323-9eab-7bbce73da0f2/files/%2Falice%2Fbob'): Failed to rename "/alice/bob" to 
"/alice/bob/charlie". Reason: Invalid argument

The library correctly detects that path has changed and makes the body of the REST API request, but it fails to append the filename to the URL and thus is trying to rename the directory containing the file, rather than the file itself.

By the way, in the docs the import also should read

from netapp_ontap.host_connection import HostConnection

 

So I think this is a bug in the netapp-ontap Python Library

Public