# Module `netapp_ontap.resources`

Copyright © 2020 NetApp Inc. All rights reserved.

All of the modules in this package represent individual object models which can be imported and used for communicating with the REST APIs. To see their interface, look at `Resource`.

## Constructor

Once you've imported the resources you want to work with into your application and set the host connection, the next step is to create an instance of the resource you want to perform operations on. A resource represents a snapshot of an object that exist on the host. Any keyword arguments passed into the constructor will be set as properties of that instance.

    # Create an instance of the cluster resource
    from netapp_ontap.resources import Cluster
    from netapp_ontap import config, HostConnection
    config.CONNECTION = HostConnection(host, username="username", password="password")
    cluster = Cluster()
    cluster.get()

## to_dict()

to_dict() is a function that will return a dictionary representation of the object's state. It serializes the current state of the object which is a `netapp_ontap.resource.Resource` type into a 'dict' type, allowing you to view the information in a readable format. If you only want certain fields in the dictionary, 'only' may be passed in as a tuple of strings.

## from_dict()

from_dict() is a function that can be used to construct a resource from a dictionary. It does the opposite of to_dict(), it will deserialize a dictionary to a `netapp_ontap.resource.Resource` type. This can be used when constructing an object that you want to post to a resource. Field validation is done when you call from_dict. Enums, strings, and integers of the object will be validated When invalid data is passed in, a ValidationError will be raised.

## Verb methods

The following operations are supported by this library. However, for a specific resource, you might only be able to call a subset of these functions.

### get()

get() will fetch the details of an object from the host. For the required keys (if any) that need to be set, refer to the resource's page to see what those are.

    svm = Svm(uuid="44034ec2-46eb-4e0c-b2e8-6215abd6a9ad")
    svm.get()
    print(svm)

### get_collection()

get_collection() will fetch all records of the resource type from the host. It returns a generator which you can then iterate through to view information about each object on the host. By default, only key values are returned for each resource. You can specify 'fields=field1,field2,…' to retrieve more fields for each resource.

    for svm in Svm.get_collection():
        pprint.pprint(svm.to_dict())

### count_collection()

count_collection() will return the number of records in the collection for the given resource

    num_svms = Svm.count_collection()
    assert Svm.count_collection(name="non-existent") == 0

### find()

find() will find an instance of an object of the desired resource on the host given a query. A query will be constructed with the provided key/value pairs and will be sent to the host. The find() operation is a wrapper on get_collection. It returns an instance of the resource if exactly one matching record is found, so you are expected to provide the necessary query parameters to filter get_collection() down to exactly one record. If 0 matches are found, it returns `None`. If more than one match is found a `netapp_ontap.error.NetAppRestError` is raised.

    svm = Svm.find(name="test_vserver")

### patch()

patch() will modify any fields of an object that have been changed by the client application. You can modify a field of an object by setting it to the desired value, then calling the patch() on it. Only the fields of the object that have changed since the last iteraction with the host will be sent in the PATCH request body. To see which fields are modifiable, you can reference the ONTAP REST API Documentation.

    svm = Svm.find(name="test_vserver")
    svm.state = "stopped"
    svm.comment = "this svm is offline"
    svm.patch()

If you pass in parameters through the patch method that are read in as formData then the request will be of multipart/form-data content-type. Swagger 2.0 does not care whether it is a Post or Patch method. Due to the swagger 2.0 specifications, data type of both formData and body cannot be present in the same request. If the type of formdata parameter is file then it will be read as a string literal by default unless you prefix an '@' to the string. Whenever the string starts with an '@' then it will assume it is a path to a file and try to open and read the contents of the file instead. For example resource.patch(file1="/u/name/1.txt") will be sent as a string literal while resource.patch(file1="@/u/name/1.txt") will open and read the file and send the contents instead.

    resource = FileInfo("1234", "my_file.txt")
    resource.patch(file1="@/u/name/1.txt")

### patch_collection()

patch_collection() will patch all objects in a collection which match a given query with the request body.

    # modify the state of all volumes whose name begins with 'testVol' on vserver vs1
    Volume.patch_collection({'state': 'offline'}, name='testVol*')

### delete()

delete() will send a request to delete the object from the host.

    aggr = Aggregate.find(name='test_aggr')
    aggr.delete()

### delete_collection()

delete_collection() will delete all objects on the host which match the provided query.

    svm = Svm.delete_collection(name='test_vserver')

### post()

post() will create a new object on the host. During post(), the resource will update it's location and key fields. This allows you to perform other instance methods such as get(), patch(), or delete() following the post() operation. In order to POST to a resource, you first have to create an object, then you may call post() on it. The operation will send the object to the host as a request to create a new object of the resource type.

    volume = Volume.from_dict({
        'name': 'vol1',
        'svm': {'name':'vs1'},
        'aggregates': [{'name'}:'aggr1'
    }]
    volume.post()

If you pass in parameters through the post method that are read in as formData then the request will be of multipart/form-data content-type. Due to the swagger 2.0 specifications, data type of both formData and body cannot be present in the same request. If the type of formdata parameter is file then it will be read as a string literal by default unless you prefix an @ to the string. Whenever the string starts with an @ then it will assume it is a path to a file and try to open and read the contents of the file instead. For example resource.post("file1"="/u/name/1.txt") will be sent as a string literal while resource.post("file1"="@/u/name/1.txt") will open and read the file and send the contents instead.

Two path keys are required for this example, volume.uuid and path

    resource = FileInfo("1234", "my_file.txt")
    resource.post(file1="@/u/name/1.txt")

## Resources

URL | Resource
--- | ---
/api/storage/namespaces/ | `PerformanceNamespaceMetric`
/api/cluster/software/download | `SoftwarePackageDownload`
/api/protocols/nfs/export-policies | `ExportPolicy`
/api/protocols/fpolicy | `Fpolicy`
/api/security/roles | `Role`
/api/protocols/file-security/permissions | `FileDirectorySecurity`
/api/application/applications/ | `ApplicationComponentSnapshot`
/api/protocols/cifs/sessions | `CifsSession`
/api/cluster/licensing/capacity-pools | `CapacityPool`
/api/protocols/cifs/shares | `CifsShare`
/api/protocols/nfs/kerberos/interfaces | `KerberosInterface`
/api/security/ssh | `ClusterSshServer`
/api/network/fc/wwpn-aliases | `WwpnAlias`
/api/storage/shelves | `Shelf`
/api/storage/volumes | `Volume`
/api/network/ethernet/ports | `Port`
/api/storage/snaplock/compliance-clocks | `SnaplockComplianceClock`
/api/network/fc/ports | `FcPort`
/api/protocols/san/portsets | `Portset`
/api/network/ip/bgp/peer-groups | `BgpPeerGroup`
/api/cloud/targets | `CloudTarget`
/api/network/ip/interfaces | `IpInterface`
/api/support/snmp | `Snmp`
/api/protocols/san/lun-maps | `LunMap`
/api/support/configuration-backup/backups | `ConfigurationBackupFile`
/api/protocols/nfs/services | `NfsService`
/api/protocols/fpolicy/ | `FpolicyPolicy`
/api/security/authentication/cluster/ad-proxy | `ClusterAdProxy`
/api/cluster/ntp/servers | `NtpServer`
/api/storage/snaplock/audit-logs | `SnaplockLog`
/api/protocols/nfs/services/ | `PerformanceSvmNfs`
/api/security/authentication/publickeys | `Publickey`
/api/security/login/messages | `LoginMessages`
/api/svm/peer-permissions | `SvmPeerPermission`
/api/protocols/san/fcp/services | `FcpService`
/api/storage/aggregates/ | `PerformanceMetric`
/api/protocols/nfs/connected-clients | `NfsClients`
/api/support/ems | `EmsConfig`
/api/storage/monitored-files/ | `PerformanceMonitoredFilesMetric`
/api/storage/file/copy | `FileCopy`
/api/protocols/vscan/server-status | `VscanServerStatus`
/api/cluster/metrocluster/nodes | `MetroclusterNode`
/api/application/applications | `Application`
/api/storage/quota/rules | `QuotaRule`
/api/cluster | `Cluster`
/api/protocols/nvme/services | `NvmeService`
/api/protocols/ndmp/svms | `NdmpSvm`
/api/protocols/san/iscsi/sessions | `IscsiSession`
/api/name-services/unix-groups/ | `UnixGroupUsers`
/api/storage/snaplock/file | `SnaplockFileRetention`
/api/cluster/chassis | `Chassis`
/api/application/templates | `ApplicationTemplate`
/api/support/snmp/users | `SnmpUser`
/api/name-services/unix-users | `UnixUser`
/api/protocols/nvme/services/ | `PerformanceNvmeMetric`
/api/application/applications/ | `ApplicationComponent`
/api/support/snmp/traphosts | `SnmpTraphost`
/api/snapmirror/relationships/ | `SnapmirrorTransfer`
/api/security/certificates | `SecurityCertificate`
/api/name-services/ldap | `LdapService`
/api/protocols/file-security/permissions/ | `FileDirectorySecurityAcl`
/api/protocols/nvme/subsystem-controllers | `NvmeSubsystemController`
/api/protocols/s3/services | `S3Service`
/api/storage/snaplock/event-retention/operations | `EbrOperation`
/api/protocols/nvme/subsystem-maps | `NvmeSubsystemMap`
/api/support/ems/destinations | `EmsDestination`
/api/cluster/metrocluster/interconnects | `MetroclusterInterconnect`
/api/protocols/san/igroups/ | `IgroupNested`
/api/cluster/ntp/keys | `NtpKey`
/api/protocols/s3/services/ | `S3Policy`
/api/cluster/licensing/licenses | `LicensePackage`
/api/storage/snapshot-policies | `SnapshotPolicy`
/api/protocols/ndmp/nodes | `NdmpNode`
/api/protocols/ndmp/svms/ | `NdmpPassword`
/api/cluster/software/packages | `SoftwarePackage`
/api/support/configuration-backup | `ConfigurationBackup`
/api/storage/volume-efficiency-policies | `VolumeEfficiencyPolicy`
/api/storage/aggregates/ | `Plex`
/api/security/ipsec/policies | `IpsecPolicy`
/api/protocols/s3/services/ | `S3Group`
/api/security/key-managers/ | `KeyServer`
/api/application/applications/ | `ApplicationSnapshot`
/api/cluster/jobs | `Job`
/api/protocols/ndmp | `ClusterNdmpProperties`
/api/cluster/metrics | `ClusterMetrics`
/api/security/key-managers | `SecurityKeyManager`
/api/security/roles/ | `RolePrivilege`
/api/protocols/vscan/ | `VscanOnDemand`
/api/cluster/software/history | `SoftwareHistory`
/api/security/accounts | `Account`
/api/storage/luns | `Lun`
/api/storage/switches | `StorageSwitch`
/api/support/autosupport | `Autosupport`
/api/storage/volumes/ | `FileInfo`
/api/network/ip/service-policies | `IpServicePolicy`
/api/storage/snaplock/file-fingerprints | `SnaplockFileFingerprint`
/api/network/ipspaces | `Ipspace`
/api/network/http-proxy | `NetworkHttpProxy`
/api/security/ipsec | `Ipsec`
/api/protocols/s3/services/ | `PerformanceS3Metric`
/api/network/ethernet/switch/ports | `SwitchPort`
/api/security/gcp-kms | `GcpKms`
/api/support/ems/filters/ | `EmsFilterRule`
/api/storage/flexcache/flexcaches | `Flexcache`
/api/protocols/fpolicy/ | `FpolicyEvent`
/api/network/fc/logins | `FcLogin`
/api/protocols/cifs/services | `CifsService`
/api/protocols/nvme/subsystems/ | `NvmeSubsystemHost`
/api/protocols/nfs/kerberos/realms | `KerberosRealm`
/api/storage/flexcache/origins | `FlexcacheOrigin`
/api/protocols/san/igroups/ | `IgroupInitiator`
/api/cluster/mediators | `Mediator`
/api/support/autosupport/messages | `AutosupportMessage`
/api/support/ems/filters | `EmsFilter`
/api/cluster/metrocluster/operations | `MetroclusterOperation`
/api/cluster/schedules | `Schedule`
/api/security/azure-key-vaults | `AzureKeyVault`
/api/storage/monitored-files | `MonitoredFile`
/api/cluster/metrocluster/dr-groups | `MetroclusterDrGroup`
/api/network/ethernet/ports/ | `PortMetrics`
/api/security | `SecurityConfig`
/api/name-services/dns | `Dns`
/api/support/ems/messages | `EmsMessage`
/api/cluster/nodes/ | `NodeMetrics`
/api/security/authentication/password | `AccountPassword`
/api/protocols/vscan/ | `VscanOnAccess`
/api/protocols/san/portsets/ | `PortsetInterface`
/api/storage/file/move | `FileMove`
/api/storage/volumes/ | `Snapshot`
/api/protocols/vscan | `Vscan`
/api/storage/namespaces | `NvmeNamespace`
/api/protocols/s3/services/ | `S3User`
/api/cluster/firmware/history | `FirmwareHistory`
/api/storage/luns/ | `PerformanceLunMetric`
/api/protocols/vscan/ | `VscanScannerPool`
/api/storage/qos/policies | `QosPolicy`
/api/network/fc/ports/ | `PerformanceFcPortMetric`
/api/storage/snapshot-policies/ | `SnapshotPolicySchedule`
/api/security/authentication/cluster/ldap | `ClusterLdap`
/api/svm/peers | `SvmPeer`
/api/storage/cluster | `ClusterSpace`
/api/network/fc/interfaces/ | `PerformanceFcInterfaceMetric`
/api/storage/disks | `Disk`
/api/protocols/cifs/home-directory/search-paths | `CifsSearchPath`
/api/storage/snaplock/litigations/ | `SnaplockLitigationFile`
/api/network/ethernet/switches | `Switch`
/api/storage/qtrees | `Qtree`
/api/protocols/nvme/subsystems | `NvmeSubsystem`
/api/protocols/ndmp/sessions | `NdmpSession`
/api/storage/bridges | `StorageBridge`
/api/cluster/metrocluster | `Metrocluster`
/api/storage/quota/reports | `QuotaReport`
/api/security/ipsec/security-associations | `SecurityAssociation`
/api/storage/snaplock/event-retention/policies | `SnaplockRetentionPolicy`
/api/storage/file/clone | `FileClone`
/api/cluster/nodes | `Node`
/api/protocols/file-access-tracing/events | `FileAccessEvent`
/api/protocols/audit | `Audit`
/api/network/fc/interfaces | `FcInterface`
/api/protocols/file-access-tracing/filters | `FileAccessFilter`
/api/svm/svms | `Svm`
/api/protocols/cifs/services/ | `PerformanceCifsMetric`
/api/name-services/nis | `NisService`
/api/name-services/name-mappings | `NameMapping`
/api/protocols/s3/services/ | `S3BucketSvm`
/api/storage/ports | `StoragePort`
/api/protocols/san/igroups | `Igroup`
/api/snapmirror/relationships | `SnapmirrorRelationship`
/api/storage/volumes/ | `VolumeMetrics`
/api/protocols/nvme/interfaces | `NvmeInterface`
/api/cluster/metrocluster/diagnostics | `MetroclusterDiagnostics`
/api/snapmirror/policies | `SnapmirrorPolicy`
/api/cluster/software | `Software`
/api/storage/tape-devices | `TapeDevice`
/api/support/ems/events | `EmsEvent`
/api/protocols/s3/buckets | `S3Bucket`
/api/network/ip/routes | `NetworkRoute`
/api/network/ethernet/broadcast-domains | `BroadcastDomain`
/api/protocols/san/iscsi/services/ | `PerformanceIscsiMetric`
/api/name-services/unix-groups | `UnixGroup`
/api/network/ip/interfaces/ | `InterfaceMetrics`
/api/storage/snaplock/litigations/ | `SnaplockLegalHoldOperation`
/api/protocols/file-security/effective-permissions | `EffectivePermission`
/api/cluster/licensing/license-managers | `LicenseManager`
/api/protocols/nfs/export-policies/ | `ExportClient`
/api/security/audit/destinations | `SecurityAuditLogForward`
/api/storage/snaplock/litigations | `SnaplockLitigation`
/api/security/authentication/cluster/nis | `ClusterNisService`
/api/protocols/fpolicy/ | `FpolicyEngine`
/api/protocols/nfs/export-policies/ | `ExportRule`
/api/security/authentication/cluster/saml-sp | `SecuritySamlSp`
/api/protocols/cifs/shares/ | `CifsShareAcl`
/api/security/audit/messages | `SecurityAuditLog`
/api/security/audit | `SecurityAudit`
/api/storage/aggregates | `Aggregate`
/api/storage/aggregates/ | `CloudStore`
/api/cluster/peers | `ClusterPeer`
/api/protocols/san/fcp/services/ | `PerformanceFcpMetric`
/api/protocols/san/iscsi/services | `IscsiService`
/api/protocols/san/iscsi/credentials | `IscsiCredentials`
/api/protocols/cifs/unix-symlink-mapping | `CifsSymlinkMapping`