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.find(name="test_vserver")
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/luns Lun
/api/support/autosupport Autosupport
/api/cluster/software/download SoftwarePackageDownload
/api/storage/volumes/ FileInfo
/api/network/ip/service-policies IpServicePolicy
/api/protocols/nfs/export-policies ExportPolicy
/api/storage/snaplock/file-fingerprints SnaplockFileFingerprint
/api/network/ipspaces Ipspace
/api/network/http-proxy NetworkHttpProxy
/api/protocols/fpolicy Fpolicy
/api/security/ipsec Ipsec
/api/security/roles Role
/api/support/ems/filters/ EmsFilterRule
/api/storage/flexcache/flexcaches Flexcache
/api/protocols/fpolicy/ FpolicyEvent
/api/network/fc/logins FcLogin
/api/application/applications/ ApplicationComponentSnapshot
/api/protocols/cifs/shares CifsShare
/api/protocols/cifs/services CifsService
/api/protocols/nvme/subsystems/ NvmeSubsystemHost
/api/protocols/nfs/kerberos/realms KerberosRealm
/api/protocols/nfs/kerberos/interfaces KerberosInterface
/api/security/ssh ClusterSshServer
/api/network/fc/wwpn-aliases WwpnAlias
/api/storage/flexcache/origins FlexcacheOrigin
/api/storage/shelves Shelf
/api/storage/volumes Volume
/api/protocols/san/igroups/ IgroupInitiator
/api/network/ethernet/ports Port
/api/storage/snaplock/compliance-clocks SnaplockComplianceClock
/api/support/autosupport/messages AutosupportMessage
/api/support/ems/filters EmsFilter
/api/network/fc/ports FcPort
/api/network/ip/bgp/peer-groups BgpPeerGroup
/api/cloud/targets CloudTarget
/api/cluster/schedules Schedule
/api/security/azure-key-vaults AzureKeyVault
/api/network/ip/interfaces IpInterface
/api/support/snmp Snmp
/api/protocols/san/lun-maps LunMap
/api/support/configuration-backup/backups ConfigurationBackupFile
/api/security SecurityConfig
/api/name-services/dns Dns
/api/protocols/nfs/services NfsService
/api/support/ems/messages EmsMessage
/api/protocols/fpolicy/ FpolicyPolicy
/api/security/authentication/password AccountPassword
/api/protocols/vscan/ VscanOnAccess
/api/security/authentication/cluster/ad-proxy ClusterAdProxy
/api/cluster/ntp/servers NtpServer
/api/storage/volumes/ Snapshot
/api/protocols/vscan Vscan
/api/storage/namespaces NvmeNamespace
/api/storage/snaplock/audit-logs SnaplockLog
/api/protocols/nfs/services/ PerformanceSvmNfs
/api/security/authentication/publickeys Publickey
/api/protocols/s3/services/ S3User
/api/security/login/messages LoginMessages
/api/svm/peer-permissions SvmPeerPermission
/api/protocols/san/fcp/services FcpService
/api/storage/luns/ PerformanceLunMetric
/api/protocols/vscan/ VscanScannerPool
/api/storage/aggregates/ PerformanceMetric
/api/storage/qos/policies QosPolicy
/api/storage/snapshot-policies/ SnapshotPolicySchedule
/api/security/authentication/cluster/ldap ClusterLdap
/api/svm/peers SvmPeer
/api/storage/cluster ClusterSpace
/api/protocols/nfs/connected-clients NfsClients
/api/storage/disks Disk
/api/protocols/cifs/home-directory/search-paths CifsSearchPath
/api/support/ems EmsConfig
/api/storage/snaplock/litigations/ SnaplockLitigationFile
/api/storage/file/copy FileCopy
/api/storage/qtrees Qtree
/api/protocols/vscan/server-status VscanServerStatus
/api/protocols/nvme/subsystems NvmeSubsystem
/api/protocols/ndmp/sessions NdmpSession
/api/application/applications Application
/api/storage/quota/rules QuotaRule
/api/cluster Cluster
/api/protocols/nvme/services NvmeService
/api/protocols/ndmp/svms NdmpSvm
/api/storage/quota/reports QuotaReport
/api/security/ipsec/security-associations SecurityAssociation
/api/protocols/san/iscsi/sessions IscsiSession
/api/storage/snaplock/event-retention/policies SnaplockRetentionPolicy
/api/storage/snaplock/file SnaplockFileRetention
/api/cluster/chassis Chassis
/api/application/templates ApplicationTemplate
/api/storage/file/clone FileClone
/api/cluster/nodes Node
/api/support/snmp/users SnmpUser
/api/protocols/audit Audit
/api/network/fc/interfaces FcInterface
/api/svm/svms Svm
/api/protocols/cifs/services/ PerformanceCifsMetric
/api/name-services/nis NisService
/api/protocols/nvme/services/ PerformanceNvmeMetric
/api/application/applications/ ApplicationComponent
/api/name-services/name-mappings NameMapping
/api/protocols/s3/services/ S3BucketSvm
/api/support/snmp/traphosts SnmpTraphost
/api/storage/ports StoragePort
/api/snapmirror/relationships/ SnapmirrorTransfer
/api/protocols/san/igroups Igroup
/api/security/certificates SecurityCertificate
/api/name-services/ldap LdapService
/api/snapmirror/relationships SnapmirrorRelationship
/api/storage/volumes/ VolumeMetrics
/api/protocols/nvme/interfaces NvmeInterface
/api/protocols/nvme/subsystem-controllers NvmeSubsystemController
/api/protocols/s3/services S3Service
/api/storage/snaplock/event-retention/operations EbrOperation
/api/snapmirror/policies SnapmirrorPolicy
/api/cluster/software Software
/api/protocols/nvme/subsystem-maps NvmeSubsystemMap
/api/support/ems/events EmsEvent
/api/protocols/s3/buckets S3Bucket
/api/network/ip/routes NetworkRoute
/api/support/ems/destinations EmsDestination
/api/network/ethernet/broadcast-domains BroadcastDomain
/api/protocols/san/iscsi/services/ PerformanceIscsiMetric
/api/cluster/ntp/keys NtpKey
/api/storage/snaplock/litigations/ SnaplockLegalHoldOperation
/api/cluster/licensing/licenses LicensePackage
/api/storage/snapshot-policies SnapshotPolicy
/api/protocols/nfs/export-policies/ ExportClient
/api/protocols/ndmp/nodes NdmpNode
/api/cluster/software/packages SoftwarePackage
/api/security/audit/destinations SecurityAuditLogForward
/api/storage/snaplock/litigations SnaplockLitigation
/api/security/authentication/cluster/nis ClusterNisService
/api/protocols/fpolicy/ FpolicyEngine
/api/support/configuration-backup ConfigurationBackup
/api/protocols/nfs/export-policies/ ExportRule
/api/security/authentication/cluster/saml-sp SecuritySamlSp
/api/storage/aggregates/ Plex
/api/security/ipsec/policies IpsecPolicy
/api/protocols/cifs/shares/ CifsShareAcl
/api/security/key-managers/ KeyServer
/api/application/applications/ ApplicationSnapshot
/api/security/audit/messages SecurityAuditLog
/api/cluster/jobs Job
/api/protocols/ndmp ClusterNdmpProperties
/api/cluster/metrics ClusterMetrics
/api/security/key-managers SecurityKeyManager
/api/security/audit SecurityAudit
/api/storage/aggregates Aggregate
/api/storage/aggregates/ CloudStore
/api/security/roles/ RolePrivilege
/api/cluster/peers ClusterPeer
/api/protocols/vscan/ VscanOnDemand
/api/protocols/san/fcp/services/ PerformanceFcpMetric
/api/cluster/software/history SoftwareHistory
/api/protocols/san/iscsi/services IscsiService
/api/protocols/san/iscsi/credentials IscsiCredentials
/api/protocols/cifs/unix-symlink-mapping CifsSymlinkMapping
/api/security/accounts Account