Skip to content

Commit

Permalink
Manager reset resource (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
prajwalpatil25 authored Nov 24, 2023
1 parent 95e0b97 commit 11066f0
Show file tree
Hide file tree
Showing 10 changed files with 575 additions and 0 deletions.
71 changes: 71 additions & 0 deletions docs/resources/manager_reset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "redfish_manager_reset Resource - terraform-provider-redfish"
subcategory: ""
description: |-
Resource to reset the iDRAC.
---

# redfish_manager_reset (Resource)

Resource to reset the iDRAC.

## Example Usage

```terraform
/*
Copyright (c) 2023 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://mozilla.org/MPL/2.0/
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
resource "redfish_manager_reset" "manager_reset" {
for_each = var.rack1
redfish_server {
user = each.value.user
password = each.value.password
endpoint = each.value.endpoint
ssl_insecure = each.value.ssl_insecure
}
id = "iDRAC.Embedded.1"
reset_type = "GracefulRestart"
}
```

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

### Required

- `id` (String) The value of the Id property of the Manager resource
- `reset_type` (String) The type of the reset operation to be performed. Accepted value: GracefulRestart

### Optional

- `redfish_server` (Block List) List of server BMCs and their respective user credentials (see [below for nested schema](#nestedblock--redfish_server))

<a id="nestedblock--redfish_server"></a>
### Nested Schema for `redfish_server`

Required:

- `endpoint` (String) Server BMC IP address or hostname

Optional:

- `password` (String, Sensitive) User password for login
- `ssl_insecure` (Boolean) This field indicates whether the SSL/TLS certificate must be verified or not
- `user` (String) User name for login
25 changes: 25 additions & 0 deletions examples/resources/redfish_manager_reset/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright (c) 2023 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://mozilla.org/MPL/2.0/
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

terraform {
required_providers {
redfish = {
version = "1.1.0"
source = "registry.terraform.io/dell/redfish"
}
}
}
30 changes: 30 additions & 0 deletions examples/resources/redfish_manager_reset/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright (c) 2023 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://mozilla.org/MPL/2.0/
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

resource "redfish_manager_reset" "manager_reset" {
for_each = var.rack1

redfish_server {
user = each.value.user
password = each.value.password
endpoint = each.value.endpoint
ssl_insecure = each.value.ssl_insecure
}

id = "iDRAC.Embedded.1"
reset_type = "GracefulRestart"
}
31 changes: 31 additions & 0 deletions examples/resources/redfish_manager_reset/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright (c) 2023 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://mozilla.org/MPL/2.0/
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

rack1 = {
"my-server-2" = {
user = "admin"
password = "passw0rd"
endpoint = "https://my-server-1.myawesomecompany.org"
ssl_insecure = true
},
"my-server-2" = {
user = "admin"
password = "passw0rd"
endpoint = "https://my-server-2.myawesomecompany.org"
ssl_insecure = true
},
}
25 changes: 25 additions & 0 deletions examples/resources/redfish_manager_reset/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright (c) 2023 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://mozilla.org/MPL/2.0/
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

variable "rack1" {
type = map(object({
user = string
password = string
endpoint = string
ssl_insecure = bool
}))
}
12 changes: 12 additions & 0 deletions redfish/models/manager_reset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package models

import (
"github.com/hashicorp/terraform-plugin-framework/types"
)

// RedfishManagerReset to construct terraform schema for manager reset resource.
type RedfishManagerReset struct {
Id types.String `tfsdk:"id"`
ResetType types.String `tfsdk:"reset_type"`
RedfishServer []RedfishServer `tfsdk:"redfish_server"`
}
27 changes: 27 additions & 0 deletions redfish/provider/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"errors"
"fmt"
"log"
"net"
"net/url"
"terraform-provider-redfish/redfish/models"
"time"

Expand Down Expand Up @@ -254,3 +256,28 @@ func (p powerOperator) PowerOperation(resetType string, maximumWaitTime int64, c
tflog.Warn(p.ctx, "The system failed to update the server's power status within the maximum wait time specified!")
return system.PowerState, nil
}

// checkServerStatus checks iDRAC server status after provided interval until the provided timeout time
func checkServerStatus(ctx context.Context, endpoint string, interval int, timeout int) error {
var err error
addr, err := url.Parse(endpoint)
if err != nil {
return err
}

// Intial sleep until iDRAC reboot is triggered
time.Sleep(30 * time.Second)

for start := time.Now(); time.Since(start) < (time.Duration(timeout) * time.Second); {
tflog.Trace(ctx, "Checking server status...")
time.Sleep(time.Duration(interval) * time.Second)
_, err = net.Dial("tcp", net.JoinHostPort(addr.Hostname(), addr.Scheme))
if err == nil {
return nil
}
errctx := tflog.SetField(ctx, "error", err.Error())
tflog.Trace(errctx, "Site unreachable")
}

return err
}
1 change: 1 addition & 0 deletions redfish/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func (*redfishProvider) Resources(_ context.Context) []func() resource.Resource
NewDellIdracAttributesResource,
NewRedfishStorageVolumeResource,
NewBiosResource,
NewManagerResetResource,
}
}

Expand Down
Loading

0 comments on commit 11066f0

Please sign in to comment.