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 8, 2023
1 parent 6a2dba1 commit 6db0215
Show file tree
Hide file tree
Showing 13 changed files with 941 additions and 0 deletions.
54 changes: 54 additions & 0 deletions docs/data-sources/cluster_licensing_license_data_source.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
page_title: "netapp-ontap_cluster_licensing_license_data_source Data Source - terraform-provider-netapp-ontap"
subcategory: "cluster"
description: |-
ClusterLicensingLicense data source
---

# Netapp Ontap Cluster Licensing License Data Source

ClusterLicensingLicense data source
## Example Usage
```terraform
data "netapp-ontap_cluster_licensing_license_data_source" "cluster_licensing_license" {
# required to know which system to interface with
cx_profile_name = "cluster4"
name = "snapmirror_sync"
}
```


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

### Required

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

### Read-Only

- `licenses` (Attributes List) Licenses of the license (see [below for nested schema](#nestedatt--licenses))
- `scope` (String) Scope of the license
- `state` (String) State of the license

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

Read-Only:

- `active` (Boolean) active of the license
- `compliance` (Attributes) compliance of the license (see [below for nested schema](#nestedatt--licenses--compliance))
- `evaluation` (Boolean) evaluation of the license
- `installed_license` (String) installed_license of the license
- `owner` (String) owner of the license
- `serial_number` (String) Serial Number of the license

<a id="nestedatt--licenses--compliance"></a>
### Nested Schema for `licenses.compliance`

Read-Only:

- `state` (String) state of the license


79 changes: 79 additions & 0 deletions docs/data-sources/cluster_licensing_licenses_data_source.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
page_title: "netapp-ontap_cluster_licensing_licenses_data_source Data Source - terraform-provider-netapp-ontap"
subcategory: "cluster"
description: |-
ClusterLicensingLicenses data source
---

# Netapp Ontap Cluster Licensing Licenses Data Source

ClusterLicensingLicenses data source
## Example Usage
```terraform
data "netapp-ontap_cluster_licensing_licenses_data_source" "cluster_licensing_licenses" {
# required to know which system to interface with
cx_profile_name = "cluster4"
filter = {
name = "snapmirror_sy*"
}
}
```

<!-- 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

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

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

Optional:

- `name` (String) ClusterLicensingLicense name


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

Required:

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

Read-Only:

- `licenses` (Attributes List) Licenses of the license (see [below for nested schema](#nestedatt--cluster_licensing_licenses--licenses))
- `scope` (String) Scope of the license
- `state` (String) State of the license

<a id="nestedatt--cluster_licensing_licenses--licenses"></a>
### Nested Schema for `cluster_licensing_licenses.licenses`

Read-Only:

- `active` (Boolean) active of the license
- `compliance` (Attributes) compliance of the license (see [below for nested schema](#nestedatt--cluster_licensing_licenses--licenses--compliance))
- `evaluation` (Boolean) evaluation of the license
- `installed_license` (String) installed_license of the license
- `owner` (String) owner of the license
- `serial_number` (String) Serial Number of the license

<a id="nestedatt--cluster_licensing_licenses--licenses--compliance"></a>
### Nested Schema for `cluster_licensing_licenses.licenses.compliance`

Read-Only:

- `state` (String) state of the license


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data "netapp-ontap_cluster_licensing_license_data_source" "cluster_licensing_license" {
# required to know which system to interface with
cx_profile_name = "cluster4"
name = "snapmirror_sync"
}
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
}
]
}
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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data "netapp-ontap_cluster_licensing_licenses_data_source" "cluster_licensing_licenses" {
# required to know which system to interface with
cx_profile_name = "cluster4"
#filter = {
# name = "snapmirror_sy*"
#}
}
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
}
]
}
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
}
85 changes: 85 additions & 0 deletions internal/interfaces/cluster_licensing_license.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,91 @@ type ClusterLicensingLicenseResourceBodyDataModelONTAP struct {
Keys []string `mapstructure:"keys"`
}

// ClusterLicensingLicenseDataSourceModelONTAP describes the data source data model.
type ClusterLicensingLicenseDataSourceModelONTAP struct {
Name string `mapstructure:"name"`
Licenses []LicensesModel `mapstructure:"licenses,omitempty"`
State string `mapstructure:"state"`
Scope string `mapstructure:"scope"`
}

// LicensesModel describes data source model.
type LicensesModel struct {
SerialNumber string `mapstructure:"serial_number"`
Owner string `mapstructure:"owner"`
Compliance Compliance `mapstructure:"compliance"`
Active bool `mapstructure:"active"`
Evaluation bool `mapstructure:"evaluation"`
InstalledLicense string `mapstructure:"installed_license"`
}

// Compliance describes data source model.
type Compliance struct {
State string `mapstructure:"state,omitempty"`
}

// ClusterLicensingLicenseFilterModel describes filter model
type ClusterLicensingLicenseFilterModel struct {
Name string `mapstructure:"name"`
}

// GetClusterLicensingLicenseByName to get license by name
func GetClusterLicensingLicenseByName(errorHandler *utils.ErrorHandler, r restclient.RestClient, name string) (*ClusterLicensingLicenseDataSourceModelONTAP, error) {
api := "/cluster/licensing/licenses"
query := r.NewQuery()
query.Set("name", name)
query.Fields([]string{"name", "state", "licenses", "scope"})
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 /cluster/licensing/licenses info", fmt.Sprintf("error on GET %s: %s, statusCode %d", api, err, statusCode))
}

var dataONTAP ClusterLicensingLicenseDataSourceModelONTAP
if err := mapstructure.Decode(response, &dataONTAP); err != nil {
return nil, errorHandler.MakeAndReportError(fmt.Sprintf("failed to decode response from GET %s", api),
fmt.Sprintf("error: %s, statusCode %d, response %#v", err, statusCode, response))
}
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Read /cluster/licensing/licenses data source: %#v", dataONTAP))
return &dataONTAP, nil
}

// GetListClusterLicensingLicenses to get aggregate info for all resources matching a filter
func GetListClusterLicensingLicenses(errorHandler *utils.ErrorHandler, r restclient.RestClient, filter *ClusterLicensingLicenseFilterModel) ([]ClusterLicensingLicenseDataSourceModelONTAP, error) {
api := "/cluster/licensing/licenses"
query := r.NewQuery()
query.Fields([]string{"name", "state", "licenses", "scope"})
if filter != nil {
var filterMap map[string]interface{}
if err := mapstructure.Decode(filter, &filterMap); err != nil {
return nil, errorHandler.MakeAndReportError("error encoding /cluster/licensing/licenses 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 /cluster/licensing/licenses info", fmt.Sprintf("error on GET %s: %s, statusCode %d", api, err, statusCode))
}

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

tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Read /cluster/licensing/licenses data source: %#v", dataONTAP))
return dataONTAP, nil
}

// GetClusterLicensingLicenses to get /cluster/licensing/licenses info
func GetClusterLicensingLicenses(errorHandler *utils.ErrorHandler, r restclient.RestClient) ([]ClusterLicensingLicenseKeyDataModelONTAP, error) {
api := "/cluster/licensing/licenses"
Expand Down
Loading

0 comments on commit 6db0215

Please sign in to comment.