Module netapp_ontap.resources

Copyright © 2019 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(host, username, 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")
svm.get()
print(svm.to_dict())

get_collection()

get_collection() will fetch all records of the resource type from the host. It returns a list 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():
    svm.get()
    pprint.pprint(svm.to_dict())

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 will only return true 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.

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 = "offline"
svm.comment = "this svm is offline"
svm.patch()

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
volumes = Volume.patch_collection(
    {'state': 'offline'},
    name = 'testVol*',
    return_records='true')

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()

Resources

URL Resource
/api/storage/luns Lun
/api/support/autosupport Autosupport
/api/network/ip/service-policies IpServicePolicy
/api/protocols/nfs/export-policies ExportPolicy
/api/network/ipspaces Ipspace
/api/protocols/fpolicy Fpolicy
/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/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/support/autosupport/messages AutosupportMessage
/api/support/ems/filters EmsFilter
/api/network/fc/ports FcPort
/api/cloud/targets CloudTarget
/api/cluster/schedules Schedule
/api/network/ip/interfaces IpInterface
/api/protocols/san/lun-maps LunMap
/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/storage/volumes/ Snapshot
/api/protocols/vscan Vscan
/api/storage/namespaces NvmeNamespace
/api/security/login/messages LoginMessages
/api/svm/peer-permissions SvmPeerPermission
/api/protocols/san/fcp/services FcpService
/api/protocols/vscan/ VscanScannerPool
/api/storage/qos/policies QosPolicy
/api/security/authentication/cluster/ldap ClusterLdap
/api/svm/peers SvmPeer
/api/storage/cluster ClusterSpace
/api/storage/disks Disk
/api/protocols/cifs/home-directory/search-paths CifsSearchPath
/api/support/ems EmsConfig
/api/storage/qtrees Qtree
/api/protocols/vscan/server-status VscanServerStatus
/api/protocols/nvme/subsystems NvmeSubsystem
/api/application/applications Application
/api/storage/quota/rules QuotaRule
/api/cluster Cluster
/api/protocols/nvme/services NvmeService
/api/storage/quota/reports QuotaReport
/api/protocols/san/iscsi/sessions IscsiSession
/api/cluster/chassis Chassis
/api/application/templates ApplicationTemplate
/api/storage/file/clone FileClone
/api/cluster/nodes Node
/api/protocols/audit Audit
/api/network/fc/interfaces FcInterface
/api/svm/svms Svm
/api/name-services/nis NisService
/api/application/applications/ ApplicationComponent
/api/name-services/name-mappings NameMapping
/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/snapmirror/policies SnapmirrorPolicy
/api/cluster/software Software
/api/protocols/nvme/subsystem-maps NvmeSubsystemMap
/api/support/ems/events EmsEvent
/api/network/ip/routes NetworkRoute
/api/support/ems/destinations EmsDestination
/api/network/ethernet/broadcast-domains BroadcastDomain
/api/cluster/licensing/licenses LicensePackage
/api/storage/snapshot-policies SnapshotPolicy
/api/protocols/nfs/export-policies/ ExportClient
/api/cluster/software/packages SoftwarePackage
/api/security/audit/destinations SecurityAuditLogForward
/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/protocols/cifs/shares/ CifsShareAcl
/api/security/key-managers/ KeyServer
/api/application/applications/ ApplicationSnapshot
/api/security/audit/messages SecurityAuditLog
/api/cluster/jobs Job
/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/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