Module netapp_ontap.resources.file_info

Copyright © 2022 NetApp Inc. All rights reserved.

Overview

This API is used to read a file, write to a file, retrieve a list of files and directories, and retrieve or modify certain properties of files and directories. The path field is used to specify the path to the directory or file to be acted on. The path field requires using "%2E" to represent "." and "%2F" to represent "/" for the path provided.

File data

Read and write data from/to a named file. To read a file, the Accept request HTTP header must be specified as multipart/form-data, and a value for the length query property, which represents the number of bytes to be read, must be specified. The API will fail if the length of data being read/written exceeds 1 MB. This API should only be used on normal files or streams associated with files. The results for other file types, such as LUNs is undefined.
The following APIs are used to read or write data to a file:

  • GET /api/storage/volumes/{volume.uuid}/files/{path}?byte_offset=0&length=40 -H "Accept: multipart/form-data"
  • POST /api/storage/volumes/{volume.uuid}/files/{path} -H "Content-Type: multipart/form-data" –form "file=the data to be written to the new file"
  • PATCH /api/storage/volumes/{volume.uuid}/files/{path}?byte_offset=10 -H "Content-Type: multipart/form-data" –form "file=the new data to be written or overwritten to the existing file starting at byte_offset"

Listing directories and files

A list of files and directories and their properties can be retrieved for a specified path.
The following APIs are used to view a list of files and directories:

  • GET /api/storage/volumes/{volume.uuid}/files
  • GET /api/storage/volumes/{volume.uuid}/files/{path}
  • GET /api/storage/volumes/{volume.uuid}/files/{path}?fields=*

File information

The metadata and detailed information about a single directory or file can be retrieved by setting the return_metadata query property to true. The information returned includes type, creation_time, modified_time, changed_time, accessed_time, unix_permissions, ownder_id, group_id, size, hard_links_count, inode_number, is_empty, bytes_used, unique_bytes, inode_generation, is_vm_aligned, is_junction, links, and analytics (if requested).
The following API is used to view the properties of a single file or directory:

  • GET /api/storage/volumes/{volume.uuid}/files/{path}?return_metadata=true

File usage

Custom details about the usage of a file can be retrieved by specifying a value for the byte_offset and length query properties.
The following API is used to view the unique bytes, and bytes used, by a file based on the range defined by byte_offset and length:

  • GET /api/storage/volumes/{volume.uuid}/files/{path}?return_metadata=true&byte_offset={int}&length={int}

Create a directory

The following API is used to create a directory:

  • POST /api/storage/volumes/{volume.uuid}/files/{path} -d '{ "type" : "directory", "unix-permissions" : "644"}'

Delete an entire directory

A directory can be deleted. The behavior of this call is equivalent to rm -rf.
The following API is used to delete an entire directory:

  • DELETE /api/storage/volumes/{volume.uuid}/files/{path}?recurse=true

Delete a file or an empty directory

The following API is used to delete a file or an empty directory:

  • DELETE /api/storage/volumes/{volume.uuid}/files/{path}
  • DELETE /api/storage/volumes/{volume.uuid}/files/{path}?recurse=false

File system analytics

File system analytics provide a quick method for obtaining information summarizing properties of all files within any directory tree of a volume. When file system analytics are enabled on a volume, analytics.* fields may be requested, and will be populated in the response records corresponding to directories. The API does not support file system analytics for requests that are made beyond the boundary of the specified volume.uuid.
The following APIs are used to obtain analytics information for a directory:

  • GET /api/storage/volumes/{volume.uuid}/files/{path}?fields=analytics
  • GET /api/storage/volumes/{volume.uuid}/files/{path}?fields=**

QoS

QoS policies and settings enforce Service Level Objectives (SLO) on a file. A pre-created QoS policy can be used by specifying the qos.name or qos.uuid properties.
The following APIs are used to assign a QoS policy to a file:

  • PATCH /api/storage/volumes/{volume.uuid}/files/{path} -d '{ "qos_policy.name" : "policy" }'
  • PATCH /api/storage/volumes/{volume.uuid}/files/{path} -d '{ "qos_policy.uuid" : "b89bc5dd-94a3-11e8-a7a3-0050568edf84" }'

The following APIs are used to create a symlink and read the contents of a symlink:

  • POST /api/storage/volumes/{volume.uuid}/files/{path} -d '{ "target" : "directory2/file1" }'
  • GET /api/storage/volumes/{volume.uuid}/files/{path}?return_metadata=true&fields=target

Rename a file or a directory

The following API can be used to rename a file or a directory. Note that you need to provide the path relative to the root of the volume in the path body parameter.

  • PATCH /api/storage/volumes/{volume.uuid}/files/{path} -d '{ "path" : "directory1/directory2" }'
  • PATCH /api/storage/volumes/{volume.uuid}/files/{path} -d '{ "path" : "directory1/directory2/file1" }'

Examples

Writing to a new file

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo("54c06ce2-5430-11ea-90f9-005056a73aff")
    resource.post(hydrate=True, data="the data to be written to the new file")
    print(resource)

Writing to an existing file

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo("54c06ce2-5430-11ea-90f9-005056a73aff", path="aNewFile")
    resource.patch(hydrate=True, data="*here is a little more data", byte_offset=39)

Reading a file

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo("54c06ce2-5430-11ea-90f9-005056a73aff", path="aNewFile")
    resource.get(byte_offset=0, length=100)
    print(resource)

Creating a directory

You can use the POST request to create a directory.

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo("cb6b1b39-8d21-11e9-b926-05056aca658")
    resource.type = "directory"
    resource.unix_permissions = "644"
    resource.post(hydrate=True)
    print(resource)

FileInfo({"path": "dir1", "unix_permissions": 644, "type": "directory"})

Creating a stream on a file

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo("54c06ce2-5430-11ea-90f9-005056a73aff")
    resource.post(
        hydrate=True,
        data="the data to be written to the new file",
        overwrite=True,
        byte_offset=-1,
        stream_name="someStream",
    )
    print(resource)

Retrieving the list of files in a directory

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo("cb6b1b39-8d21-11e9-b926-05056aca658", path="d1/d2/d3")
    resource.get()
    print(resource)

[
    FileInfo(
        {
            "path": "d1/d2/d3",
            "_links": {
                "self": {
                    "href": "/api/storage/volumes/cb6b1b39-8d21-11e9-b926-005056aca658/files/d1%2Fd2%2Fd3%2F%2E"
                },
                "metadata": {
                    "href": "/api/storage/volumes/e8274d79-3bba-11ea-b780-005056a7d72a/files/d1%2Fd2%2Fd3%2F%2E?return_metadata=true"
                },
            },
            "type": "directory",
            "name": ".",
        }
    ),
    FileInfo(
        {
            "path": "d1/d2/d3",
            "_links": {
                "self": {
                    "href": "/api/storage/volumes/cb6b1b39-8d21-11e9-b926-005056aca658/files/d1%2Fd2%2Fd3%2F%2E%2E"
                },
                "metadata": {
                    "href": "/api/storage/volumes/e8274d79-3bba-11ea-b780-005056a7d72a/files/d1%2Fd2%2Fd3%2F%2E%2E?return_metadata=true"
                },
            },
            "type": "directory",
            "name": "..",
        }
    ),
    FileInfo(
        {
            "path": "d1/d2/d3",
            "_links": {
                "metadata": {
                    "href": "/api/storage/volumes/e8274d79-3bba-11ea-b780-005056a7d72a/files/d1%2Fd2%2Fd3%2File1?return_metadata=true"
                }
            },
            "type": "file",
            "name": "f1",
        }
    ),
    FileInfo(
        {
            "path": "d1/d2/d3",
            "_links": {
                "self": {
                    "href": "/api/storage/volumes/cb6b1b39-8d21-11e9-b926-005056aca658/files/d1%2Fd2%2Fd3%2Fd5"
                },
                "metadata": {
                    "href": "/api/storage/volumes/e8274d79-3bba-11ea-b780-005056a7d72a/files/d1%2Fd2%2Fd3%2Fd5?return_metadata=true"
                },
            },
            "type": "directory",
            "name": "d5",
        }
    ),
]

Retrieving a list of files based on file type

You can filter the list of files you retrieve based on multiple file types by including a query parameter in the following format type="file|symlink"

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo("cb6b1b39-8d21-11e9-b926-05056aca658", path="d1/d2/d3")
    resource.get(type="file|directory")
    print(resource)

[
    FileInfo(
        {
            "path": "d1/d2/d3",
            "_links": {
                "self": {
                    "href": "/api/storage/volumes/cb6b1b39-8d21-11e9-b926-005056aca658/files/d1%2Fd2%2Fd3%2F%2E"
                },
                "metadata": {
                    "href": "/api/storage/volumes/e8274d79-3bba-11ea-b780-005056a7d72a/files/d1%2Fd2%2Fd3%2F%2E?return_metadata=true"
                },
            },
            "type": "directory",
            "name": ".",
        }
    ),
    FileInfo(
        {
            "path": "d1/d2/d3",
            "_links": {
                "self": {
                    "href": "/api/storage/volumes/cb6b1b39-8d21-11e9-b926-005056aca658/files/d1%2Fd2%2Fd3%2F%2E%2E"
                },
                "metadata": {
                    "href": "/api/storage/volumes/e8274d79-3bba-11ea-b780-005056a7d72a/files/d1%2Fd2%2Fd3%2F%2E%2E?return_metadata=true"
                },
            },
            "type": "directory",
            "name": "..",
        }
    ),
    FileInfo(
        {
            "path": "d1/d2/d3",
            "_links": {
                "metadata": {
                    "href": "/api/storage/volumes/e8274d79-3bba-11ea-b780-005056a7d72a/files/d1%2Fd2%2Fd3%2File1?return_metadata=true"
                }
            },
            "type": "file",
            "name": "f1",
        }
    ),
    FileInfo(
        {
            "path": "d1/d2/d3",
            "_links": {
                "self": {
                    "href": "/api/storage/volumes/cb6b1b39-8d21-11e9-b926-005056aca658/files/d1%2Fd2%2Fd3%2Fd5"
                },
                "metadata": {
                    "href": "/api/storage/volumes/e8274d79-3bba-11ea-b780-005056a7d72a/files/d1%2Fd2%2Fd3%2Fd5?return_metadata=true"
                },
            },
            "type": "directory",
            "name": "d5",
        }
    ),
]

Retrieving the properties of a directory or a file

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo("cb6b1b39-8d21-11e9-b926-05056aca658", path="d1/d2/d3/f1")
    resource.get(return_metadata=True)
    print(resource)

[
    FileInfo(
        {
            "path": "d1/d2/d3/f1",
            "unique_bytes": 4096,
            "inode_generation": 214488325,
            "is_vm_aligned": False,
            "group_id": 30,
            "modified_time": "2019-06-12T21:27:28-04:00",
            "owner_id": 54738,
            "creation_time": "2019-06-12T21:27:28-04:00",
            "size": 200,
            "unix_permissions": 644,
            "inode_number": 1233,
            "accessed_time": "2019-06-12T21:27:28-04:00",
            "changed_time": "2019-06-12T21:27:28-04:00",
            "hard_links_count": 1,
            "bytes_used": 4096,
            "type": "file",
            "is_junction": False,
            "name": "",
        }
    )
]

You can use the POST request to create a symlink.

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo("cb6b1b39-8d21-11e9-b926-05056aca658")
    resource.target = "d1/f1"
    resource.post(hydrate=True)
    print(resource)

FileInfo({"path": "symlink1", "target": "d1/f1"})

You can use the GET request to view the target of a symlink.

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo("cb6b1b39-8d21-11e9-b926-05056aca658", path="symlink1")
    resource.get(return_metadata=True, fields="target")
    print(resource)

[FileInfo({"path": "symlink1", "target": "d1/f1"})]

Retrieving the usage information for a file

You can use the GET request to retrieve the unique bytes held in a file with or without specifing the offset.

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo("cb6b1b39-8d21-11e9-b926-05056aca658", path="f1")
    resource.get(return_metadata=True, byte_offset=100, length=200)
    print(resource)

[
    FileInfo(
        {
            "path": "d1/d2/d3/f1",
            "unique_bytes": 4096,
            "inode_generation": 214488325,
            "is_vm_aligned": False,
            "group_id": 30,
            "modified_time": "2019-06-12T21:27:28-04:00",
            "owner_id": 54738,
            "creation_time": "2019-06-12T21:27:28-04:00",
            "size": 200,
            "unix_permissions": 644,
            "inode_number": 1233,
            "accessed_time": "2019-06-12T21:27:28-04:00",
            "changed_time": "2019-06-12T21:27:28-04:00",
            "hard_links_count": 1,
            "bytes_used": 4096,
            "type": "file",
            "is_junction": False,
        }
    )
]

Retrieving all information (including analytics) for a directory

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo("1ef5d1b2-f9d7-11e9-8043-00505682f860", path="d1")
    resource.get(return_metadata=True, fields="**")
    print(resource)

[
    FileInfo(
        {
            "analytics": {
                "subdir_count": 18,
                "by_modified_time": {
                    "bytes_used": {
                        "labels": [
                            "2019-W42",
                            "2019-W41",
                            "2019-W40",
                            "2019-W39",
                            "2019-W38",
                            "2019-10",
                            "2019-09",
                            "2019-08",
                            "2019-Q4",
                            "2019-Q3",
                            "2019-Q2",
                            "2019-Q1",
                            "2019",
                            "2018",
                            "2017",
                            "2016",
                            "--2015",
                            "unknown",
                        ],
                        "percentages": [
                            0.0,
                            0.0,
                            0.0,
                            0.0,
                            1.48,
                            0.0,
                            6.7,
                            9.8,
                            0.0,
                            27.63,
                            29.55,
                            32.82,
                            90.0,
                            0.0,
                            0.0,
                            0.0,
                            10.0,
                            0.0,
                        ],
                        "values": [
                            0,
                            0,
                            0,
                            0,
                            3112960,
                            0,
                            14041088,
                            20545536,
                            0,
                            57933824,
                            61947904,
                            68804608,
                            188686336,
                            0,
                            0,
                            0,
                            20971520,
                            0,
                        ],
                    }
                },
                "by_accessed_time": {
                    "bytes_used": {
                        "labels": [
                            "2019-W42",
                            "2019-W41",
                            "2019-W40",
                            "2019-W39",
                            "2019-W38",
                            "2019-10",
                            "2019-09",
                            "2019-08",
                            "2019-Q4",
                            "2019-Q3",
                            "2019-Q2",
                            "2019-Q1",
                            "2019",
                            "2018",
                            "2017",
                            "2016",
                            "--2015",
                            "unknown",
                        ],
                        "percentages": [
                            49.01,
                            0.89,
                            0.59,
                            1.04,
                            0.74,
                            50.5,
                            4.31,
                            3.86,
                            50.5,
                            11.43,
                            15.45,
                            12.62,
                            90.0,
                            0.0,
                            0.0,
                            0.0,
                            10.0,
                            0.0,
                        ],
                        "values": [
                            102760448,
                            1867776,
                            1245184,
                            2179072,
                            1556480,
                            105873408,
                            9027584,
                            8093696,
                            105873408,
                            23969792,
                            32382976,
                            26460160,
                            188686336,
                            0,
                            0,
                            0,
                            20971520,
                            0,
                        ],
                    }
                },
                "bytes_used": 209657856,
                "file_count": 668,
            },
            "path": "d1",
            "inode_generation": 214514951,
            "is_vm_aligned": False,
            "group_id": 65533,
            "modified_time": "2019-10-28T23:10:30+00:00",
            "owner_id": 1002,
            "volume": {
                "_links": {
                    "self": {
                        "href": "/api/storage/volumes/1ef5d1b2-f9d7-11e9-8043-00505682f860"
                    }
                },
                "uuid": "1ef5d1b2-f9d7-11e9-8043-00505682f860",
            },
            "creation_time": "2019-10-28T23:04:13+00:00",
            "size": 4096,
            "unix_permissions": 755,
            "is_empty": False,
            "inode_number": 96,
            "accessed_time": "2019-10-28T23:10:38+00:00",
            "changed_time": "2019-10-28T23:10:30+00:00",
            "hard_links_count": 5,
            "bytes_used": 4096,
            "type": "directory",
            "is_junction": False,
        }
    )
]

Retrieving file system analytics information for a set of histogram buckets

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo("cb6b1b39-8d21-11e9-b926-05056aca658", path="d3")
    resource.get(
        type="directory",
        fields="analytics",
        **{"analytics.histogram_by_time_labels": "2019-Q3,2019-Q2,2019-Q1,2018-Q4"}
    )
    print(resource)

[
    FileInfo(
        {
            "analytics": {
                "subdir_count": 14,
                "by_modified_time": {
                    "bytes_used": {
                        "percentages": [0.02, 12.17, 80.31, 0.02],
                        "values": [57344, 29720576, 196141056, 57344],
                    }
                },
                "by_accessed_time": {
                    "bytes_used": {
                        "percentages": [0.03, 99.97, 0.0, 0.0],
                        "values": [69632, 244170752, 0, 0],
                    }
                },
                "bytes_used": 244240384,
                "file_count": 44,
            },
            "path": "d3",
            "_links": {
                "self": {
                    "href": "/api/storage/volumes/cb6b1b39-8d21-11e9-b926-005056aca658/files/d3%2F%2E"
                },
                "metadata": {
                    "href": "/api/storage/volumes/cb6b1b39-8d21-11e9-b926-005056aca658/files/d3%2F%2E?return_metadata=true"
                },
            },
            "type": "directory",
            "name": ".",
        }
    ),
    FileInfo(
        {
            "analytics": {
                "subdir_count": 23,
                "by_modified_time": {
                    "bytes_used": {
                        "percentages": [0.0, 57.88, 7.07, 0.04],
                        "values": [61440, 1756479488, 214622208, 1191936],
                    }
                },
                "by_accessed_time": {
                    "bytes_used": {
                        "percentages": [0.01, 99.99, 0.0, 0.0],
                        "values": [282624, 3034292224, 0, 0],
                    }
                },
                "bytes_used": 3034574848,
                "file_count": 515,
            },
            "path": "d3",
            "_links": {
                "self": {
                    "href": "/api/storage/volumes/cb6b1b39-8d21-11e9-b926-005056aca658/files/d3%2F%2E%2E"
                },
                "metadata": {
                    "href": "/api/storage/volumes/cb6b1b39-8d21-11e9-b926-005056aca658/files/d3%2F%2E%2E?return_metadata=true"
                },
            },
            "type": "directory",
            "name": "..",
        }
    ),
    FileInfo(
        {
            "analytics": {
                "subdir_count": 4,
                "by_modified_time": {
                    "bytes_used": {
                        "percentages": [0.0, 62.2, 0.0, 0.0],
                        "values": [0, 29638656, 0, 0],
                    }
                },
                "by_accessed_time": {
                    "bytes_used": {
                        "percentages": [0.0, 100.0, 0.0, 0.0],
                        "values": [0, 47648768, 0, 0],
                    }
                },
                "bytes_used": 47648768,
                "file_count": 10,
            },
            "path": "d3",
            "_links": {
                "self": {
                    "href": "/api/storage/volumes/cb6b1b39-8d21-11e9-b926-005056aca658/files/d3%2Fd5"
                },
                "metadata": {
                    "href": "/api/storage/volumes/cb6b1b39-8d21-11e9-b926-005056aca658/files/d3%2Fd5?return_metadata=true"
                },
            },
            "type": "directory",
            "name": "d5",
        }
    ),
]

Identifying the largest subdirectories

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo("1ef5d1b2-f9d7-11e9-8043-00505682f860", path="d1")
    resource.get(
        fields="analytics.bytes_used",
        type="directory",
        order_by="analytics.bytes_used desc",
    )
    print(resource)

[
    FileInfo(
        {
            "analytics": {"bytes_used": 56623104},
            "path": "d1",
            "type": "directory",
            "name": "..",
        }
    ),
    FileInfo(
        {
            "analytics": {"bytes_used": 35651584},
            "path": "d1",
            "type": "directory",
            "name": ".",
        }
    ),
    FileInfo(
        {
            "analytics": {"bytes_used": 17825792},
            "path": "d1",
            "type": "directory",
            "name": "biggest",
        }
    ),
    FileInfo(
        {
            "analytics": {"bytes_used": 10485760},
            "path": "d1",
            "type": "directory",
            "name": "bigger",
        }
    ),
    FileInfo(
        {
            "analytics": {"bytes_used": 5242880},
            "path": "d1",
            "type": "directory",
            "name": "big",
        }
    ),
]

Assigning a QoS policy to a file

You can use the PATCH request to assign a QoS policy to a file.

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo("cb6b1b39-8d21-11e9-b926-05056aca658", path="directory1/file1")
    resource.qos_policy = {"name": "policy"}
    resource.patch()

Retrieving QoS information for a file

You can use the GET request for all fields with return_metadata="true" to retrieve QoS information for the file.

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo("cb6b1b39-8d21-11e9-b926-05056aca658", path="file")
    resource.get(return_metadata=True, fields="**")
    print(resource)

[
    FileInfo(
        {
            "path": "file",
            "inode_generation": 219748425,
            "is_vm_aligned": False,
            "group_id": 0,
            "modified_time": "2020-03-24T18:15:40-04:00",
            "owner_id": 0,
            "qos_policy": {
                "name": "pg1",
                "uuid": "00725264-688f-11ea-8f10-005056a7b8ac",
            },
            "volume": {"uuid": "c05eb66a-685f-11ea-8508-005056a7b8ac"},
            "creation_time": "2020-03-17T10:58:40-04:00",
            "size": 1048576,
            "unix_permissions": 644,
            "inode_number": 96,
            "accessed_time": "2020-03-24T18:15:40-04:00",
            "changed_time": "2020-03-24T18:15:40-04:00",
            "hard_links_count": 2,
            "bytes_used": 1056768,
            "type": "lun",
            "is_junction": False,
            "is_snapshot": False,
        }
    )
]

Deleting an entire directory

You can use the DELETE request to remove an entire directory recursively.

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo(
        "cb6b1b39-8d21-11e9-b926-05056aca658", path="directory1/directory2"
    )
    resource.delete(recurse=True)

Deleting an entire directory with specified throttling threshold

You can specify the maximum number of directory delete operations per second when removing an entire directory recursively.

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo(
        "cb6b1b39-8d21-11e9-b926-05056aca658", path="directory1/directory2"
    )
    resource.delete(recurse=True, throttle_deletion=100)

Deleting an empty directory

You can use the DELETE request to remove an empty directory.

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo(
        "cb6b1b39-8d21-11e9-b926-05056aca658", path="directory1/directory2"
    )
    resource.delete()

Deleting a file

You can use the DELETE request to remove a file.

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo("cb6b1b39-8d21-11e9-b926-05056aca658", path="directory1/file2")
    resource.delete()

Renaming a file

You can use the PATCH request to rename a file.

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo(
        "cb6b1b39-8d21-11e9-b926-05056aca658", path="directory1/directory2/file1"
    )
    resource.path = "directory1/file2"
    resource.patch()

Renaming a directory

You can use the PATCH request to rename a directory.

from netapp_ontap import HostConnection
from netapp_ontap.resources import FileInfo

with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
    resource = FileInfo(
        "cb6b1b39-8d21-11e9-b926-05056aca658", path="directory1/directory2"
    )
    resource.path = "d3/d4"
    resource.patch()

Classes

class FileInfo (*args, **kwargs)

Information about a single file.

Initialize the instance of the resource.

Any keyword arguments are set on the instance as properties. For example, if the class was named 'MyResource', then this statement would be true:

MyResource(name='foo').name == 'foo'

Args

*args
Each positional argument represents a parent key as used in the URL of the object. That is, each value will be used to fill in a segment of the URL which refers to some parent object. The order of these arguments must match the order they are specified in the URL, from left to right.
**kwargs
each entry will have its key set as an attribute name on the instance and its value will be the value of that attribute.

Ancestors

Static methods

def count_collection(*args, connection: HostConnection = None, **kwargs) -> int

Fetch a count of all objects of this type from the host.

This calls GET on the object to determine the number of records. It is more efficient than calling get_collection() because it will not construct any objects. Query parameters can be passed in as kwargs to determine a count of objects that match some filtered criteria.

Args

*args
Each entry represents a parent key which is used to build the path to the child object. If the URL definition were /api/foos/{foo.name}/bars, then to get the count of bars for a particular foo, the foo.name value should be passed.
connection
The HostConnection object to use for this API call. If unset, tries to use the connection which is set globally for the library or from the current context.
**kwargs
Any key/value pairs passed will be sent as query parameters to the host. These query parameters can affect the count. A return_records query param will be ignored.

Returns

On success, returns an integer count of the objects of this type. On failure, returns -1.

Raises

NetAppRestError: If the API call returned a status code >= 400, or if there is no connection available to use either passed in or on the library.

def delete_collection(*args, records: Iterable[_ForwardRef('FileInfo')] = None, body: Union[Resource, dict] = None, poll: bool = True, poll_interval: Union[int, NoneType] = None, poll_timeout: Union[int, NoneType] = None, connection: HostConnection = None, **kwargs) -> NetAppResponse

Deletes an existing file or directory. Query-based DELETE operations are not supported.

Learn more


Delete all objects in a collection which match the given query.

All records on the host which match the query will be deleted.

Args

*args
Each entry represents a parent key which is used to build the path to the child object. If the URL definition were /api/foos/{foo.name}/bars, then to delete the collection of bars for a particular foo, the foo.name value should be passed.
records
Can be provided in place of a query. If so, this list of objects will be deleted from the host.
body
The body of the delete request. This could be a Resource instance or a dictionary object.
poll
If set to True, the call will not return until the asynchronous job on the host has completed. Has no effect if the host did not return a job response.
poll_interval
If the operation returns a job, this specifies how often to query the job for updates.
poll_timeout
If the operation returns a job, this specifies how long to continue monitoring the job's status for completion.
connection
The HostConnection object to use for this API call. If unset, tries to use the connection which is set globally for the library or from the current context.
**kwargs
Any key/value pairs passed will be sent as query parameters to the host. Only resources matching this query will be deleted.

Returns

A NetAppResponse object containing the details of the HTTP response.

Raises

NetAppRestError: If the API call returned a status code >= 400

def find(*args, connection: HostConnection = None, **kwargs) -> Resource

Retrieves a list of files and directories for a given directory or returns only the properties of a single given directory or file of a volume.

Expensive properties

There is an added cost to retrieving values for these properties. They are not included by default in GET results and must be explicitly requested using the fields query property. See Requesting specific fields to learn more. * analytics * qos_policy.name * qos_policy.uuid

Learn more


Find an instance of an object on the host given a query.

The host will be queried with the provided key/value pairs to find a matching resource. If 0 are found, None will be returned. If more than 1 is found, an error will be raised or returned. If there is exactly 1 matching record, then it will be returned.

Args

*args
Each entry represents a parent key which is used to build the path to the child object. If the URL definition were /api/foos/{foo.name}/bars, then to find a bar for a particular foo, the foo.name value should be passed.
connection
The HostConnection object to use for this API call. If unset, tries to use the connection which is set globally for the library or from the current context.
**kwargs
Any key/value pairs passed will be sent as query parameters to the host.

Returns

A Resource object containing the details of the object or None if no matches were found.

Raises

NetAppRestError: If the API call returned more than 1 matching resource.

def get_collection(*args, connection: HostConnection = None, max_records: int = None, **kwargs) -> Iterable[Resource]

Retrieves a list of files and directories for a given directory or returns only the properties of a single given directory or file of a volume.

Expensive properties

There is an added cost to retrieving values for these properties. They are not included by default in GET results and must be explicitly requested using the fields query property. See Requesting specific fields to learn more. * analytics * qos_policy.name * qos_policy.uuid

Learn more


Fetch a list of all objects of this type from the host.

This is a lazy fetch, making API calls only as necessary when the result of this call is iterated over. For instance, if max_records is set to 5, then iterating over the collection causes an API call to be sent to the server once for every 5 records. If the client stops iterating before getting to the 6th record, then no additional API calls are made.

Args

*args
Each entry represents a parent key which is used to build the path to the child object. If the URL definition were /api/foos/{foo.name}/bars, then to get the collection of bars for a particular foo, the foo.name value should be passed.
connection
The HostConnection object to use for this API call. If unset, tries to use the connection which is set globally for the library or from the current context.
max_records
The maximum number of records to return per call
**kwargs
Any key/value pairs passed will be sent as query parameters to the host.

Returns

A list of Resource objects

Raises

NetAppRestError: If there is no connection available to use either passed in or on the library. This would be not be raised when get_collection() is called, but rather when the result is iterated.

def patch_collection(body: dict, *args, records: Iterable[_ForwardRef('FileInfo')] = None, poll: bool = True, poll_interval: Union[int, NoneType] = None, poll_timeout: Union[int, NoneType] = None, connection: HostConnection = None, **kwargs) -> NetAppResponse

Writes to an existing file with the supplied data or modifies the size, name, space reservation information, QoS policy, or hole range information of a file. Query-based PATCH operations are not supported.

Learn more


Patch all objects in a collection which match the given query.

All records on the host which match the query will be patched with the provided body.

Args

body
A dictionary of name/value pairs to set on all matching members of the collection. The body argument will be ignored if records is provided.
*args
Each entry represents a parent key which is used to build the path to the child object. If the URL definition were /api/foos/{foo.name}/bars, then to patch the collection of bars for a particular foo, the foo.name value should be passed.
records
Can be provided in place of a query. If so, this list of objects will be patched on the host.
poll
If set to True, the call will not return until the asynchronous job on the host has completed. Has no effect if the host did not return a job response.
poll_interval
If the operation returns a job, this specifies how often to query the job for updates.
poll_timeout
If the operation returns a job, this specifies how long to continue monitoring the job's status for completion.
connection
The HostConnection object to use for this API call. If unset, tries to use the connection which is set globally for the library or from the current context.
**kwargs
Any key/value pairs passed will be sent as query parameters to the host. Only resources matching this query will be patched.

Returns

A NetAppResponse object containing the details of the HTTP response.

Raises

NetAppRestError: If the API call returned a status code >= 400

def post_collection(records: Iterable[_ForwardRef('FileInfo')], *args, hydrate: bool = False, poll: bool = True, poll_interval: Union[int, NoneType] = None, poll_timeout: Union[int, NoneType] = None, connection: HostConnection = None, **kwargs) -> Union[List[FileInfo], NetAppResponse]

Creates a new file with the supplied data, creates a new directory or creates a new symlink.

Learn more


Send this collection of objects to the host as a creation request.

Args

records
A list of Resource objects to send to the server to be created.
*args
Each entry represents a parent key which is used to build the path to the child object. If the URL definition were /api/foos/{foo.name}/bars, then to create a bar for a particular foo, the foo.name value should be passed.
hydrate
If set to True, after the response is received from the call, a a GET call will be made to refresh all fields of each object. When hydrate is set to True, poll must also be set to True.
poll
If set to True, the call will not return until the asynchronous job on the host has completed. Has no effect if the host did not return a job response.
poll_interval
If the operation returns a job, this specifies how often to query the job for updates.
poll_timeout
If the operation returns a job, this specifies how long to continue monitoring the job's status for completion.
connection
The HostConnection object to use for this API call. If unset, tries to use the connection which is set globally for the library or from the current context.
**kwargs
Any key/value pairs passed will be sent as query parameters to the host. Only resources matching this query will be patched.

Returns

A list of Resource objects matching the provided
type which have been created by the host and returned. This is _not_
 
the same list that was provided, so to continue using the object, you
 

should save this list. If poll is set to False, then a NetAppResponse object is returned instead.

Raises

NetAppRestError: If the API call returned a status code >= 400

Methods

def delete(self, body: Union[Resource, dict] = None, poll: bool = True, poll_interval: Union[int, NoneType] = None, poll_timeout: Union[int, NoneType] = None, **kwargs) -> NetAppResponse

Deletes an existing file or directory. Query-based DELETE operations are not supported.

Learn more


Send a deletion request to the host for this object.

Args

body
The body of the delete request. This could be a Resource instance or a dictionary object.
poll
If set to True, the call will not return until the asynchronous job on the host has completed. Has no effect if the host did not return a job response.
poll_interval
If the operation returns a job, this specifies how often to query the job for updates.
poll_timeout
If the operation returns a job, this specifies how long to continue monitoring the job's status for completion.
**kwargs
Any key/value pairs passed will be sent as query parameters to the host.

Returns

A NetAppResponse object containing the details of the HTTP response.

Raises

NetAppRestError: If the API call returned a status code >= 400

def get(self, **kwargs) -> NetAppResponse

Retrieves a list of files and directories for a given directory or returns only the properties of a single given directory or file of a volume.

Expensive properties

There is an added cost to retrieving values for these properties. They are not included by default in GET results and must be explicitly requested using the fields query property. See Requesting specific fields to learn more. * analytics * qos_policy.name * qos_policy.uuid

Learn more


Fetch the details of the object from the host.

Requires the keys to be set (if any). After returning, new or changed properties from the host will be set on the instance.

Returns

A NetAppResponse object containing the details of the HTTP response.

Raises

NetAppRestError: If the API call returned a status code >= 400

def patch(self, hydrate: bool = False, poll: bool = True, poll_interval: Union[int, NoneType] = None, poll_timeout: Union[int, NoneType] = None, **kwargs) -> NetAppResponse

Writes to an existing file with the supplied data or modifies the size, name, space reservation information, QoS policy, or hole range information of a file. Query-based PATCH operations are not supported.

Learn more


Send the difference in the object's state to the host as a modification request.

Calculates the difference in the object's state since the last time we interacted with the host and sends this in the request body.

Args

hydrate
If set to True, after the response is received from the call, a a GET call will be made to refresh all fields of the object.
poll
If set to True, the call will not return until the asynchronous job on the host has completed. Has no effect if the host did not return a job response.
poll_interval
If the operation returns a job, this specifies how often to query the job for updates.
poll_timeout
If the operation returns a job, this specifies how long to continue monitoring the job's status for completion.
**kwargs
Any key/value pairs passed will normally be sent as query parameters to the host. If any of these pairs are parameters that are sent as formdata then only parameters of that type will be accepted and all others will be discarded.

Returns

A NetAppResponse object containing the details of the HTTP response.

Raises

NetAppRestError: If the API call returned a status code >= 400

def post(self, hydrate: bool = False, poll: bool = True, poll_interval: Union[int, NoneType] = None, poll_timeout: Union[int, NoneType] = None, **kwargs) -> NetAppResponse

Creates a new file with the supplied data, creates a new directory or creates a new symlink.

Learn more


Send this object to the host as a creation request.

Args

hydrate
If set to True, after the response is received from the call, a a GET call will be made to refresh all fields of the object.
poll
If set to True, the call will not return until the asynchronous job on the host has completed. Has no effect if the host did not return a job response.
poll_interval
If the operation returns a job, this specifies how often to query the job for updates.
poll_timeout
If the operation returns a job, this specifies how long to continue monitoring the job's status for completion.
**kwargs
Any key/value pairs passed will normally be sent as query parameters to the host. If any of these pairs are parameters that are sent as formdata then only parameters of that type will be accepted and all others will be discarded.

Returns

A NetAppResponse object containing the details of the HTTP response.

Raises

NetAppRestError: If the API call returned a status code >= 400

Inherited members

class FileInfoSchema (*, only: Union[Sequence[str], Set[str]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Dict = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: str = None)

The fields of the FileInfo object

Ancestors

  • netapp_ontap.resource.ResourceSchema
  • marshmallow.schema.Schema
  • marshmallow.base.SchemaABC

Class variables

accessed_time GET

Last access time of the file in date-time format.

Example: 2019-06-12T15:00:16.000+0000

analytics GET POST PATCH

The analytics field of the file_info.

bytes_used GET

The actual number of bytes used on disk by this file. If byte_offset and length parameters are specified, this will return the bytes used by the file within the given range.

Example: 4096

changed_time GET

Last time data or attributes changed on the file in date-time format.

Example: 2019-06-12T15:00:16.000+0000

constituent GET POST PATCH

The constituent field of the file_info.

creation_time GET

Creation time of the file in date-time format.

Example: 2019-06-12T15:00:16.000+0000

fill_enabled GET PATCH

Returns "true" if the space reservation is enabled. The field overwrite_enabled must also be set to the same value as this field.

group_id GET

The integer ID of the group of the file owner.

Example: 30

The number of hard links to the file.

Example: 1

inode_generation GET

Inode generation number.

Example: 214753547

inode_number GET

The file inode number.

Example: 1695

is_empty GET POST PATCH

Specifies whether or not a directory is empty. A directory is considered empty if it only contains entries for "." and "..". This element is present if the file is a directory. In some special error cases, such as when the volume goes offline or when the directory is moved while retrieving this info, this field might not get set.

Example: false

is_junction GET

Returns "true" if the directory is a junction.

Example: false

is_snapshot GET

Returns "true" if the directory is a Snapshot copy.

Example: false

is_vm_aligned GET

Returns true if the file is vm-aligned. A vm-aligned file is a file that is initially padded with zero-filled data so that its actual data starts at an offset other than zero. The amount by which the start offset is adjusted depends on the vm-align setting of the hosting volume.

Example: false

The links field of the file_info.

modified_time GET

Last data modification time of the file in date-time format.

Example: 2019-06-12T15:00:16.000+0000

name GET POST PATCH

Name of the file.

Example: test_file

overwrite_enabled GET PATCH

Returns "true" if the space reservation for overwrites is enabled. The field fill_enabled must also be set to the same value as this field.

owner_id GET

The integer ID of the file owner.

Example: 54738

path GET POST PATCH

Path of the file.

Example: d1/d2/d3

qos_policy GET PATCH

The qos_policy field of the file_info.

size GET PATCH

The size of the file, in bytes.

Example: 200

target GET POST PATCH

The relative or absolute path contained in a symlink, in the form /.

Example: some_directory/some_other_directory/some_file

type GET POST

Type of the file.

Valid choices:

  • file
  • directory
  • blockdev
  • chardev
  • symlink
  • socket
  • fifo
  • stream
  • lun
unique_bytes GET

Number of bytes uniquely held by this file. If byte_offset and length parameters are specified, this will return bytes uniquely held by the file within the given range.

Example: 4096

unix_permissions GET POST PATCH

UNIX permissions to be viewed as an octal number. It consists of 4 digits derived by adding up bits 4 (read), 2 (write), and 1 (execute). The first digit selects the set user ID(4), set group ID (2), and sticky (1) attributes. The second digit selects permissions for the owner of the file; the third selects permissions for other users in the same group; the fourth selects permissions for other users not in the group.

Example: 493

volume GET POST PATCH

The volume field of the file_info.