Module netapp_ontap.resources

Copyright © 2021 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 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 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 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/security/key-managers/{security_key_manager[uuid]}/keys/{node[uuid]}/key-ids KeyManagerKeys
/api/storage/namespaces/{nvme_namespace[uuid]}/metrics PerformanceNamespaceMetric
/api/cluster/software/download SoftwarePackageDownload
/api/security/key-manager-configs KeyManagerConfig
/api/protocols/cifs/group-policies/{svm[uuid]}/central-access-rules GroupPolicyObjectCentralAccessRule
/api/protocols/nfs/export-policies ExportPolicy
/api/protocols/fpolicy Fpolicy
/api/security/roles Role
/api/storage/volumes/{volume[uuid]}/top-metrics/clients TopMetricsClient
/api/svm/migrations/{svm_migration[uuid]}/volumes SvmMigrationVolume
/api/protocols/file-security/permissions/{svm[uuid]}/{file_directory_security[path]} FileDirectorySecurity
/api/cluster/counter/tables/{counter_table[name]}/rows CounterRow
/api/protocols/san/lun-maps/{lun[uuid]}/{igroup[uuid]}/reporting-nodes LunMapReportingNode
/api/application/applications/{application[uuid]}/components/{component[uuid]}/snapshots 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/protocols/cifs/local-users LocalCifsUser
/api/storage/shelves Shelf
/api/storage/volumes Volume
/api/resource-tags/{resource_tag[value]}/resources ResourceTagResource
/api/network/ethernet/ports Port
/api/protocols/cifs/shadowcopy-sets ShadowcopySet
/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/protocols/san/vvol-bindings VvolBinding
/api/network/ip/interfaces IpInterface
/api/svm/svms/{svm[uuid]}/top-metrics/directories TopMetricsSvmDirectory
/api/support/snmp Snmp
/api/protocols/san/lun-maps LunMap
/api/support/configuration-backup/backups ConfigurationBackupFile
/api/protocols/nfs/services NfsService
/api/protocols/fpolicy/{svm[uuid]}/policies FpolicyPolicy
/api/security/authentication/cluster/ad-proxy ClusterAdProxy
/api/cluster/ntp/servers NtpServer
/api/application/consistency-groups/{consistency_group[uuid]}/metrics ConsistencyGroupMetrics
/api/storage/file/clone/split-loads SplitLoad
/api/storage/snaplock/audit-logs SnaplockLog
/api/protocols/nfs/services/{svm[uuid]}/metrics PerformanceSvmNfs
/api/security/authentication/publickeys Publickey
/api/name-services/cache/setting GlobalCacheSetting
/api/security/login/messages LoginMessages
/api/svm/peer-permissions SvmPeerPermission
/api/protocols/san/fcp/services FcpService
/api/storage/aggregates/{aggregate[uuid]}/metrics PerformanceMetric
/api/protocols/nfs/connected-clients NfsClients
/api/support/ems EmsConfig
/api/protocols/cifs/users-and-groups/privileges UserGroupPrivileges
/api/storage/file/copy FileCopy
/api/protocols/vscan/server-status VscanServerStatus
/api/cluster/metrocluster/nodes MetroclusterNode
/api/application/applications Application
/api/name-services/host-record HostRecord
/api/name-services/netgroup-files NetgroupFile
/api/storage/quota/rules QuotaRule
/api/cluster Cluster
/api/protocols/nvme/services NvmeService
/api/security/login/totps Totp
/api/protocols/ndmp/svms NdmpSvm
/api/protocols/san/iscsi/sessions IscsiSession
/api/name-services/unix-groups/{svm[uuid]}/{unix_group[name]}/users UnixGroupUsers
/api/protocols/cifs/local-groups/{svm[uuid]}/{local_cifs_group[sid]}/members LocalCifsGroupMembers
/api/storage/snaplock/file SnaplockFileRetention
/api/cluster/chassis Chassis
/api/application/templates ApplicationTemplate
/api/support/snmp/users SnmpUser
/api/support/auto-update AutoUpdateInfo
/api/security/key-managers/{security_key_manager[uuid]}/auth-keys KeyManagerAuthKey
/api/protocols/cifs/netbios Netbios
/api/name-services/unix-users UnixUser
/api/protocols/nvme/services/{svm[uuid]}/metrics PerformanceNvmeMetric
/api/application/applications/{application[uuid]}/components ApplicationComponent
/api/svm/migrations SvmMigration
/api/support/snmp/traphosts SnmpTraphost
/api/snapmirror/relationships/{relationship[uuid]}/transfers SnapmirrorTransfer
/api/security/certificates SecurityCertificate
/api/name-services/ldap LdapService
/api/protocols/file-security/permissions/{svm[uuid]}/{file_directory_security_acl[path]}/acl FileDirectorySecurityAcl
/api/svm/svms/{svm[uuid]}/top-metrics/users TopMetricsSvmUser
/api/protocols/nvme/subsystem-controllers NvmeSubsystemController
/api/protocols/s3/services S3Service
/api/resource-tags ResourceTag
/api/storage/snaplock/event-retention/operations EbrOperation
/api/protocols/nvme/subsystem-maps NvmeSubsystemMap
/api/support/ems/destinations EmsDestination
/api/cluster/metrocluster/interconnects MetroclusterInterconnect
/api/storage/luns/{lun[uuid]}/attributes LunAttribute
/api/protocols/cifs/group-policies/{svm[uuid]}/restricted-groups GroupPolicyObjectRestrictedGroup
/api/name-services/cache/host/settings HostsSettings
/api/svm/svms/{svm[uuid]}/top-metrics/files TopMetricsSvmFile
/api/network/fc/fabrics/{fabric[name]}/switches FcSwitch
/api/protocols/san/igroups/{igroup[uuid]}/igroups IgroupNested
/api/cluster/ntp/keys NtpKey
/api/protocols/cifs/group-policies PoliciesAndRulesToBeApplied
/api/protocols/s3/services/{svm[uuid]}/policies S3Policy
/api/cluster/licensing/licenses LicensePackage
/api/protocols/vscan/{svm[uuid]}/events VscanEvent
/api/storage/snapshot-policies SnapshotPolicy
/api/cluster/web Web
/api/protocols/ndmp/nodes NdmpNode
/api/protocols/ndmp/svms/{svm[uuid]}/passwords NdmpPassword
/api/cluster/software/packages SoftwarePackage
/api/support/configuration-backup ConfigurationBackup
/api/security/multi-admin-verify/rules MultiAdminVerifyRule
/api/security/ssh/svms SvmSshServer
/api/storage/volume-efficiency-policies VolumeEfficiencyPolicy
/api/storage/aggregates/{aggregate[uuid]}/plexes Plex
/api/security/ipsec/policies IpsecPolicy
/api/protocols/s3/services/{svm[uuid]}/groups S3Group
/api/protocols/cifs/shadow-copies Shadowcopy
/api/security/key-managers/{security_key_manager[uuid]}/key-servers KeyServer
/api/application/applications/{application[uuid]}/snapshots ApplicationSnapshot
/api/cluster/jobs Job
/api/protocols/ndmp ClusterNdmpProperties
/api/protocols/cifs/users-and-groups/bulk-import LocalCifsUsersAndGroupsImport
/api/storage/volumes/{volume[uuid]}/top-metrics/directories TopMetricsDirectory
/api/protocols/cifs/local-groups LocalCifsGroup
/api/cluster/metrics ClusterMetrics
/api/security/key-managers SecurityKeyManager
/api/protocols/cifs/domains/{svm[uuid]}/preferred-domain-controllers CifsDomainPreferredDc
/api/application/consistency-groups ConsistencyGroup
/api/security/roles/{owner[uuid]}/{role[name]}/privileges RolePrivilege
/api/protocols/vscan/{svm[uuid]}/on-demand-policies VscanOnDemand
/api/cluster/software/history SoftwareHistory
/api/security/accounts Account
/api/protocols/nfs/connected-client-settings NfsClientsCache
/api/storage/luns Lun
/api/storage/switches StorageSwitch
/api/support/autosupport Autosupport
/api/storage/volumes/{volume[uuid]}/files FileInfo
/api/network/ip/service-policies IpServicePolicy
/api/storage/snaplock/file-fingerprints SnaplockFileFingerprint
/api/network/ipspaces Ipspace
/api/network/http-proxy NetworkHttpProxy
/api/protocols/active-directory ActiveDirectory
/api/security/ipsec Ipsec
/api/name-services/cache/netgroup/settings NetgroupsSettings
/api/protocols/cifs/group-policies/{svm[uuid]}/objects GroupPolicyObject
/api/protocols/s3/services/{svm[uuid]}/metrics PerformanceS3Metric
/api/network/ethernet/switch/ports SwitchPort
/api/security/gcp-kms GcpKms
/api/name-services/local-hosts LocalHost
/api/support/ems/filters/{ems_filter[name]}/rules EmsFilterRule
/api/storage/flexcache/flexcaches Flexcache
/api/protocols/fpolicy/{svm[uuid]}/events FpolicyEvent
/api/network/fc/logins FcLogin
/api/cluster/metrocluster/svms MetroclusterSvm
/api/support/ems/role-configs EmsRoleConfig
/api/protocols/cifs/services CifsService
/api/protocols/nvme/subsystems/{subsystem[uuid]}/hosts NvmeSubsystemHost
/api/protocols/nfs/kerberos/realms KerberosRealm
/api/protocols/cifs/domains CifsDomain
/api/storage/volumes/{volume[uuid]}/top-metrics/files TopMetricsFile
/api/storage/flexcache/origins FlexcacheOrigin
/api/protocols/san/igroups/{igroup[uuid]}/initiators IgroupInitiator
/api/cluster/mediators Mediator
/api/protocols/locks ClientLock
/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/cluster/metrocluster/dr-groups MetroclusterDrGroup
/api/support/ems/application-logs EmsApplicationLog
/api/protocols/fpolicy/{svm[uuid]}/connections FpolicyConnection
/api/network/ethernet/ports/{port[uuid]}/metrics PortMetrics
/api/security SecurityConfig
/api/name-services/dns Dns
/api/support/ems/messages EmsMessage
/api/cluster/nodes/{node[uuid]}/metrics NodeMetrics
/api/security/authentication/password AccountPassword
/api/protocols/vscan/{svm[uuid]}/on-access-policies VscanOnAccess
/api/protocols/san/portsets/{portset[uuid]}/interfaces PortsetInterface
/api/storage/file/moves FileMove
/api/storage/volumes/{volume[uuid]}/snapshots Snapshot
/api/protocols/vscan Vscan
/api/name-services/cache/unix-group/settings UnixGroupSettings
/api/storage/namespaces NvmeNamespace
/api/protocols/s3/services/{svm[uuid]}/users S3User
/api/cluster/firmware/history FirmwareHistory
/api/storage/luns/{lun[uuid]}/metrics PerformanceLunMetric
/api/protocols/vscan/{svm[uuid]}/scanner-pools VscanScannerPool
/api/storage/qos/policies QosPolicy
/api/network/fc/ports/{fc_port[uuid]}/metrics PerformanceFcPortMetric
/api/storage/snapshot-policies/{snapshot_policy[uuid]}/schedules SnapshotPolicySchedule
/api/protocols/cifs/connections CifsConnection
/api/security/authentication/cluster/ldap ClusterLdap
/api/svm/peers SvmPeer
/api/storage/cluster ClusterSpace
/api/network/fc/interfaces/{fc_interface[uuid]}/metrics PerformanceFcInterfaceMetric
/api/storage/disks Disk
/api/protocols/cifs/home-directory/search-paths CifsSearchPath
/api/storage/snaplock/litigations/{litigation[id]}/files SnaplockLitigationFile
/api/network/ethernet/switches Switch
/api/support/auto-update/configurations AutoUpdateConfiguration
/api/name-services/ldap-schemas LdapSchema
/api/storage/qtrees Qtree
/api/protocols/nvme/subsystems NvmeSubsystem
/api/protocols/ndmp/sessions NdmpSession
/api/cluster/sensors Sensors
/api/storage/bridges StorageBridge
/api/security/key-stores SecurityKeystore
/api/cluster/metrocluster Metrocluster
/api/storage/quota/reports QuotaReport
/api/security/ipsec/security-associations SecurityAssociation
/api/svm/svms/{svm[uuid]}/web WebSvm
/api/storage/pools StoragePool
/api/storage/snaplock/event-retention/policies SnaplockRetentionPolicy
/api/storage/file/clone FileClone
/api/cluster/nodes Node
/api/support/coredump/coredumps Coredump
/api/security/ipsec/ca-certificates IpsecCaCertificate
/api/protocols/audit Audit
/api/network/fc/interfaces FcInterface
/api/security/multi-admin-verify/approval-groups MultiAdminVerifyApprovalGroup
/api/security/multi-admin-verify MultiAdminVerifyConfig
/api/svm/svms Svm
/api/protocols/cifs/services/{svm[uuid]}/metrics PerformanceCifsMetric
/api/name-services/nis NisService
/api/svm/svms/{svm[uuid]}/top-metrics/clients TopMetricsSvmClient
/api/security/anti-ransomware/suspects AntiRansomwareSuspect
/api/name-services/cache/unix-user/settings UnixUserSettings
/api/security/multi-admin-verify/requests MultiAdminVerifyRequest
/api/storage/file/clone/split-status SplitStatus
/api/name-services/cache/group-membership/settings GroupMembershipSettings
/api/name-services/name-mappings NameMapping
/api/protocols/s3/services/{svm[uuid]}/buckets S3BucketSvm
/api/storage/ports StoragePort
/api/protocols/san/igroups Igroup
/api/snapmirror/relationships SnapmirrorRelationship
/api/storage/volumes/{volume[uuid]}/metrics VolumeMetrics
/api/protocols/cifs/group-policies/{svm[uuid]}/central-access-policies GroupPolicyObjectCentralAccessPolicy
/api/protocols/nvme/interfaces NvmeInterface
/api/storage/volumes/{volume[uuid]}/top-metrics/users TopMetricsUser
/api/application/consistency-groups/{consistency_group[uuid]}/snapshots ConsistencyGroupSnapshot
/api/cluster/metrocluster/diagnostics MetroclusterDiagnostics
/api/snapmirror/policies SnapmirrorPolicy
/api/cluster/software Software
/api/storage/tape-devices TapeDevice
/api/protocols/nfs/connected-client-maps NfsClientsMap
/api/support/ems/events EmsEvent
/api/protocols/s3/buckets S3Bucket
/api/network/ip/routes NetworkRoute
/api/cluster/counter/tables CounterTable
/api/protocols/active-directory/{svm[uuid]}/preferred-domain-controllers ActiveDirectoryPreferredDc
/api/network/ethernet/broadcast-domains BroadcastDomain
/api/protocols/san/iscsi/services/{svm[uuid]}/metrics PerformanceIscsiMetric
/api/name-services/unix-groups UnixGroup
/api/network/fc/fabrics Fabric
/api/network/ip/interfaces/{ip_interface[uuid]}/metrics InterfaceMetrics
/api/storage/snaplock/litigations/{litigation[id]}/operations SnaplockLegalHoldOperation
/api/protocols/file-security/effective-permissions EffectivePermission
/api/cluster/licensing/license-managers LicenseManager
/api/protocols/audit/{svm[uuid]}/object-store S3Audit
/api/protocols/nfs/export-policies/{policy[id]}/rules/{export_rule[index]}/clients ExportClient
/api/security/audit/destinations SecurityAuditLogForward
/api/storage/snaplock/litigations SnaplockLitigation
/api/storage/file/clone/tokens Token
/api/storage/qos/workloads QosWorkload
/api/security/authentication/cluster/nis ClusterNisService
/api/protocols/fpolicy/{svm[uuid]}/engines FpolicyEngine
/api/protocols/nfs/export-policies/{policy[id]}/rules ExportRule
/api/security/authentication/cluster/saml-sp SecuritySamlSp
/api/network/ip/subnets IpSubnet
/api/protocols/cifs/shares/{svm[uuid]}/{cifs_share[share]}/acls CifsShareAcl
/api/protocols/cifs/session/files CifsOpenFile
/api/security/audit/messages SecurityAuditLog
/api/security/aws-kms AwsKms
/api/security/audit SecurityAudit
/api/storage/aggregates Aggregate
/api/storage/aggregates/{aggregate[uuid]}/cloud-stores CloudStore
/api/support/auto-update/updates AutoUpdateStatus
/api/cluster/peers ClusterPeer
/api/protocols/san/fcp/services/{svm[uuid]}/metrics PerformanceFcpMetric
/api/protocols/san/iscsi/services IscsiService
/api/protocols/san/iscsi/credentials IscsiCredentials
/api/protocols/cifs/unix-symlink-mapping CifsSymlinkMapping
/api/network/fc/fabrics/{fabric[name]}/zones FcZone
/api/protocols/s3/services/{svm[uuid]}/buckets/{s3_bucket[uuid]}/rules S3BucketLifecycleRule