Skip to content

Commit

Permalink
Sync bitbucket and GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
carchi8py committed Aug 1, 2023
1 parent d581244 commit 2808bbe
Show file tree
Hide file tree
Showing 13 changed files with 869 additions and 1 deletion.
44 changes: 44 additions & 0 deletions docs/data-sources/svm_data_source.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "netapp-ontap_svm_data_source Data Source - terraform-provider-netapp-ontap"
subcategory: "svm"
description: |-
Retrieves the configuration of SVM.
---

# Data Source svm

Retrieves the configuration of SVM.

## Example Usage
```terraform
data "netapp-ontap_svm_data_source" "svm" {
# required to know which system to interface with
cx_profile_name = "cluster4"
name = "ansibleSVM"
}
```



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `cx_profile_name` (String) Connection profile name
- `name` (String) Svm name

### Read-Only

- `aggregates` (List of String) Aggregates to be assigned use for vserver
- `comment` (String) Comment for vserver to be created
- `id` (String) The ID of this resource.
- `ipspace` (String) The name of the ipspace to manage
- `language` (String) Language to use for vserver
- `max_volumes` (String) Maximum number of volumes that can be created on the vserver. Expects an integer or unlimited
- `snapshot_policy` (String) The name of the snapshot policy to manage
- `subtype` (String) The subtype for vserver to be created
- `uuid` (String) Vserver identifier


69 changes: 69 additions & 0 deletions docs/data-sources/svms_data_source.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "netapp-ontap_svms_data_source Data Source - terraform-provider-netapp-ontap"
subcategory: "svms"
description: |-
Retrieves the configuration of SVMs.
---

# Data Source svms

Retrieves the configuration of SVMs.

## Example Usage
```terraform
data "netapp-ontap_svms_data_source" "svms" {
# required to know which system to interface with
cx_profile_name = "cluster4"
filter = {
name = "ansibleSVM"
}
}
```



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `cx_profile_name` (String) Connection profile name

### Optional

- `filter` (Attributes) (see [below for nested schema](#nestedatt--filter))

### Read-Only

- `svms` (Attributes List) (see [below for nested schema](#nestedatt--svms))

<a id="nestedatt--filter"></a>
### Nested Schema for `filter`

Optional:

- `name` (String) Svm name


<a id="nestedatt--svms"></a>
### Nested Schema for `svms`

Required:

- `cx_profile_name` (String) Connection profile name
- `name` (String) Svm name

Read-Only:

- `aggregates` (List of String) Aggregates to be assigned use for vserver
- `comment` (String) Comment for vserver to be created
- `id` (String)
- `ipspace` (String) The name of the ipspace to manage
- `language` (String) Language to use for vserver
- `max_volumes` (String) Maximum number of volumes that can be created on the vserver. Expects an integer or unlimited
- `snapshot_policy` (String) The name of the snapshot policy to manage
- `subtype` (String) The subtype for vserver to be created
- `uuid` (String) Vserver identifier


5 changes: 5 additions & 0 deletions examples/data-sources/netapp-ontap_svm/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data "netapp-ontap_svm_data_source" "svm" {
# required to know which system to interface with
cx_profile_name = "cluster4"
name = "ansibleSVM"
}
44 changes: 44 additions & 0 deletions examples/data-sources/netapp-ontap_svm/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
terraform {
required_providers {
netapp-ontap = {
source = "NetApp/netapp-ontap"
version = "0.0.1"
}
}
}


provider "netapp-ontap" {
# A connection profile defines how to interface with an ONTAP cluster or vserver.
# At least one is required.
connection_profiles = [
{
name = "cluster1"
hostname = "********219"
username = var.username
password = var.password
validate_certs = var.validate_certs
},
{
name = "cluster2"
hostname = "********222"
username = var.username
password = var.password
validate_certs = var.validate_certs
},
{
name = "cluster3"
hostname = "10.193.176.159"
username = var.username
password = var.password
validate_certs = var.validate_certs
},
{
name = "cluster4"
hostname = "10.193.180.108"
username = var.username
password = var.password
validate_certs = var.validate_certs
}
]
}
11 changes: 11 additions & 0 deletions examples/data-sources/netapp-ontap_svm/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Terraform will prompt for values, unless a tfvars file is present.
variable "username" {
type = string
}
variable "password" {
type = string
sensitive = true
}
variable "validate_certs" {
type = bool
}
7 changes: 7 additions & 0 deletions examples/data-sources/netapp-ontap_svms/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data "netapp-ontap_svms_data_source" "svms" {
# required to know which system to interface with
cx_profile_name = "cluster4"
filter = {
name = "ansibleSVM"
}
}
44 changes: 44 additions & 0 deletions examples/data-sources/netapp-ontap_svms/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
terraform {
required_providers {
netapp-ontap = {
source = "NetApp/netapp-ontap"
version = "0.0.1"
}
}
}


provider "netapp-ontap" {
# A connection profile defines how to interface with an ONTAP cluster or vserver.
# At least one is required.
connection_profiles = [
{
name = "cluster1"
hostname = "********219"
username = var.username
password = var.password
validate_certs = var.validate_certs
},
{
name = "cluster2"
hostname = "********222"
username = var.username
password = var.password
validate_certs = var.validate_certs
},
{
name = "cluster3"
hostname = "10.193.176.159"
username = var.username
password = var.password
validate_certs = var.validate_certs
},
{
name = "cluster4"
hostname = "10.193.180.108"
username = var.username
password = var.password
validate_certs = var.validate_certs
}
]
}
11 changes: 11 additions & 0 deletions examples/data-sources/netapp-ontap_svms/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Terraform will prompt for values, unless a tfvars file is present.
variable "username" {
type = string
}
variable "password" {
type = string
sensitive = true
}
variable "validate_certs" {
type = bool
}
75 changes: 75 additions & 0 deletions internal/interfaces/svm.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ type SvmResourceModel struct {
Aggregates []map[string]string `mapstructure:"aggregates,omitempty"`
}

// SvmGetDataSourceModel describes the data source model.
type SvmGetDataSourceModel struct {
Name string `mapstructure:"name"`
UUID string `mapstructure:"uuid"`
Ipspace Ipspace `mapstructure:"ipspace"`
SnapshotPolicy SnapshotPolicy `mapstructure:"snapshot_policy"`
SubType string `mapstructure:"subtype,omitempty"`
Comment string `mapstructure:"comment,omitempty"`
Language string `mapstructure:"language,omitempty"`
Aggregates []Aggregate `mapstructure:"aggregates,omitempty"`
MaxVolumes string `mapstructure:"max_volumes,omitempty"`
}

// Ipspace describes the resource data model.
type Ipspace struct {
Name string `mapstructure:"name,omitempty"`
Expand All @@ -44,6 +57,11 @@ type SnapshotPolicy struct {
Name string `mapstructure:"name,omitempty"`
}

// SvmDataSourceFilterModel describes the data source data model for queries.
type SvmDataSourceFilterModel struct {
Name string `mapstructure:"name"`
}

// GetSvm to get svm info by uuid
func GetSvm(errorHandler *utils.ErrorHandler, r restclient.RestClient, uuid string) (*SvmGetDataModelONTAP, error) {
statusCode, response, err := r.GetNilOrOneRecord("svm/svms/"+uuid, nil, nil)
Expand Down Expand Up @@ -76,6 +94,63 @@ func GetSvmByName(errorHandler *utils.ErrorHandler, r restclient.RestClient, nam
return dataONTAP, nil
}

// GetSvmByNameDataSource to get data source svm info
func GetSvmByNameDataSource(errorHandler *utils.ErrorHandler, r restclient.RestClient, name string) (*SvmGetDataSourceModel, error) {
api := "svm/svms"
query := r.NewQuery()
query.Fields([]string{"name", "ipspace", "snapshot_policy", "subtype", "comment", "language", "max_volumes", "aggregates"})
query.Add("name", name)
statusCode, response, err := r.GetNilOrOneRecord(api, query, nil)
if err == nil && response == nil {
err = fmt.Errorf("no response for GET %s", api)
}
if err != nil {
return nil, errorHandler.MakeAndReportError("error reading vserver info", fmt.Sprintf("error on GET svm/svms: %s, statusCode %d", err, statusCode))
}

var dataONTAP SvmGetDataSourceModel
if err := mapstructure.Decode(response, &dataONTAP); err != nil {
return nil, errorHandler.MakeAndReportError("failed to decode response from GET svm by name", fmt.Sprintf("error: %s, statusCode %d, response %#v", err, statusCode, response))
}
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Read vserver info: %#v", dataONTAP))
return &dataONTAP, nil
}

// GetSvmsByName to get data source list svm info
func GetSvmsByName(errorHandler *utils.ErrorHandler, r restclient.RestClient, filter *SvmDataSourceFilterModel) ([]SvmGetDataSourceModel, error) {
api := "svm/svms"
query := r.NewQuery()
query.Fields([]string{"name", "ipspace", "snapshot_policy", "subtype", "comment", "language", "max_volumes", "aggregates"})

if filter != nil {
var filterMap map[string]interface{}
if err := mapstructure.Decode(filter, &filterMap); err != nil {
return nil, errorHandler.MakeAndReportError("error encoding svms filter info", fmt.Sprintf("error on filter %#v: %s", filter, err))
}
query.SetValues(filterMap)
}

statusCode, response, err := r.GetZeroOrMoreRecords(api, query, nil)
if err == nil && response == nil {
err = fmt.Errorf("no response for GET %s", api)
}
if err != nil {
return nil, errorHandler.MakeAndReportError("error reading svm info", fmt.Sprintf("error on GET svm/svms: %s, statusCode %d", err, statusCode))
}

var dataONTAP []SvmGetDataSourceModel
for _, info := range response {
var record SvmGetDataSourceModel
if err := mapstructure.Decode(info, &record); err != nil {
return nil, errorHandler.MakeAndReportError("failed to decode response from GET svms by name", fmt.Sprintf("error: %s, statusCode %d, response %#v", err, statusCode, response))
}
dataONTAP = append(dataONTAP, record)
}

tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Read vserver info: %#v", dataONTAP))
return dataONTAP, nil
}

// CreateSvm to create vserver
func CreateSvm(errorHandler *utils.ErrorHandler, r restclient.RestClient, data SvmResourceModel) (*SvmGetDataModelONTAP, error) {
var body map[string]interface{}
Expand Down
Loading

0 comments on commit 2808bbe

Please sign in to comment.