diff --git a/CHANGELOG.md b/CHANGELOG.md index 11502b36..f9c04285 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,26 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html) -# [v8.4.0-13](unreleased) +======= + +# [v.8.4.0-13] (unreleased) + +### Notes +- This release supports API5400 minimally where we can use OneView v8.40 with this SDK. + +======= + +#### Major Changes + +1. Modified the patch operation for server profile. Please check the docs https://github.com/HewlettPackard/terraform-provider-oneview/blob/master/docs/r/server_profile.html.markdown + ### Bug fixes & Enhancements: - [#523](https://github.com/HewlettPackard/terraform-provider-oneview/issues/523 )oneview_firmware_drivers data source is broken - [#524](https://github.com/HewlettPackard/terraform-provider-oneview/issues/524 ) Data object retrieval for firmware_drivers bug - [#535](https://github.com/HewlettPackard/terraform-provider-oneview/issues/535 ) Crash in logical interconnect group + # [v.8.3.0-13] ### Notes diff --git a/docs/r/server_profile.html.markdown b/docs/r/server_profile.html.markdown index 3d846e9c..133317e3 100644 --- a/docs/r/server_profile.html.markdown +++ b/docs/r/server_profile.html.markdown @@ -87,17 +87,13 @@ resource "oneview_server_profile" "default" { template = "${oneview_server_profile_template.test.name}" } ``` -Patch request for server profile +Update request for server profile ```hcl resource "oneview_server_profile" "default" { - update_type = "patch" - options = [ - { - op = "replace" - path = "/refreshState" - value = "RefreshPending" + operation_type { + name = "reapply_SAN_storage" + } - ] name = "TestSP" type = "ServerProfileV10" server_hardware_type = "SY 480 Gen9 3" @@ -106,22 +102,51 @@ resource "oneview_server_profile" "default" { } ``` -## Argument Reference +Update request for renaming logical drive name +```hcl +resource "oneview_server_profile" "default" { + operation_type { + name = "rename_logical_drive" + logical_drive_value{ + device_slot_name="Embedded" + current_logical_drive_name="ld2" + new_logical_drive_name="ld3" + } + + } + name = "TestSP" + type = "ServerProfileV10" + server_hardware_type = "SY 480 Gen9 3" + enclosure_group = "SYN03_EC" + hardware_name = "SYN03_Frame3, bay 1" +} +``` +Following update operation can be performed by giving the update string for given type of update. +| NO | Type of Update | Update String | + | ----------- | -------------- | ------------- | + | 1 | `Update the server profile from the server profile template.` | 'update_from_template' | + | 2 | `Stage a server profile to update from its server profile template the next time the server is powered off via OneView.` | 'update_from_template_stage' | + | 3 | `Cancel the staging on an update from template for a server profile that was previously staged. ` | 'cancel_update_from_template' | + | 4 | `Refresh the server profile` | 'refresh' | + | 5 | `Reapply the server profile's firmware` | 'reapply_firmware' | + | 6 | `Reapply the server profile's connections` | 'reapply_connection' | + | 7 | `Reapply the server profile's adapters and boot settings` | 'reapply_adpater_boot_settings' | + | 8 | `Rename a server profile's logical drive` | 'rename_logical_drive' | + | 9 | `Reapply the server profile's local storage` | 'reapply_local_storage' | + | 10 | `Reapply the server profile's SAN storage` | 'reapply_SAN_storage' | + | 11 | `Reapply the server profile's bios settings` | 'reapply_bios_settings' | + | 12 | `Regenerate CHAP Secrets` | 'regenerate_CHAP_secrets' | + | 13 | `Reapply the server iLO settings` | 'reapply_ilo_settings' | +## Argument Reference +- - - The following arguments are supported: * `name` - (Required) A unique name for the resource. * `template` - (Optional) The name of the template you will use for the server profile. -* `update_type` - (Required) Type of update of Server Profile. - - | NO | Type of Update | Update String | - | ----------- | -------------- | ------------- | - | 1 (Default) | `Update` | 'put' | - | 2 | `Patch` | 'patch' | - -- - - +* `Operation_type` - (Optional) patch operation can be performed by giving the update string for given type of update. - - - diff --git a/examples/server_profiles/update_resource.tf b/examples/server_profiles/update_resource.tf index eac7a28b..8cb654cc 100644 --- a/examples/server_profiles/update_resource.tf +++ b/examples/server_profiles/update_resource.tf @@ -7,7 +7,7 @@ provider "oneview" { ov_ifmatch = "*" } -# Creation of Server Profile without template +#Creation of Server Profile without template resource "oneview_server_profile" "SP" { name = "Test-SP" hardware_name = "0000A66102, bay 3" @@ -82,20 +82,36 @@ resource "oneview_server_profile" "SP" { } } + +# Patch request to reapply the server profile's SAN storage, local storage and rename the logical drive /* -# Patch request - Server profile Refresh -resource "oneview_server_profile" "SP" { - update_type = "patch" - options = [ - { - op = "replace" - path = "/refreshState" - value = "RefreshPending" +resource "oneview_server_profile" "SP" { + + name = "SP" + type = "ServerProfileV12" + enclosure_group = "EG" + hardware_name = "0000A66101, bay 3" + + operation_type { + name = "reapply_SAN_storage" + } - ] - name = "TestSP_Renamed" - type = "ServerProfileV12" - enclosure_group = "EG-Synergy-Local" - hardware_name = "Synergy-Encl-2, bay 8" + operation_type { + name = "reapply_local_storage" + + } + operation_type { + name = "rename_logical_drive" + logical_drive_value{ + device_slot_name="Embedded" + current_logical_drive_name="ld2" + new_logical_drive_name="ld3" + } + + } } */ + + + + diff --git a/go.mod b/go.mod index ba8d36b6..ceee9245 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/HewlettPackard/terraform-provider-oneview go 1.15 require ( - github.com/HewlettPackard/oneview-golang v8.3.0+incompatible + github.com/HewlettPackard/oneview-golang v8.3.1-0.20230529095956-f6039fe84f3f+incompatible github.com/docker/machine v0.16.2 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-getter v1.6.2 // indirect diff --git a/go.sum b/go.sum index 168f50c0..efa50953 100644 --- a/go.sum +++ b/go.sum @@ -34,8 +34,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/HewlettPackard/oneview-golang v8.3.0+incompatible h1:EBDvVLJmH9O4wbxPyxWrdFcYR4OCh2yqaPUvi9kIQTk= -github.com/HewlettPackard/oneview-golang v8.3.0+incompatible/go.mod h1:GJcjWgNHrKtt2lUl4xcaV3NRiuBlG138DNrFygXj4JE= +github.com/HewlettPackard/oneview-golang v8.3.1-0.20230529095956-f6039fe84f3f+incompatible h1:8COeVoPlFSy1Bo79TazBKGLhj2L1gLcLHHAh/BnFuuc= +github.com/HewlettPackard/oneview-golang v8.3.1-0.20230529095956-f6039fe84f3f+incompatible/go.mod h1:GJcjWgNHrKtt2lUl4xcaV3NRiuBlG138DNrFygXj4JE= github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE= github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= diff --git a/oneview/resource_server_profile.go b/oneview/resource_server_profile.go index a4c82296..26444191 100644 --- a/oneview/resource_server_profile.go +++ b/oneview/resource_server_profile.go @@ -18,6 +18,7 @@ import ( "log" "reflect" "strconv" + "strings" "github.com/HewlettPackard/oneview-golang/ov" "github.com/HewlettPackard/oneview-golang/utils" @@ -931,31 +932,38 @@ func resourceServerProfile() *schema.Resource { return }, }, - "options": { - Optional: true, + "operation_type": { Type: schema.TypeSet, + Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "op": { - Required: true, - Type: schema.TypeString, - }, - "path": { + "name": { Required: true, Type: schema.TypeString, }, - "value": { - Required: true, - Type: schema.TypeString, + "logical_drive_value": { + Optional: true, + Type: schema.TypeSet, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "device_slot_name": { + Optional: true, + Type: schema.TypeString, + }, + "current_logical_drive_name": { + Optional: true, + Type: schema.TypeString, + }, + "new_logical_drive_name": { + Optional: true, + Type: schema.TypeString, + }, + }, + }, }, }, }, }, - "update_type": { - Type: schema.TypeString, - Default: "put", - Optional: true, - }, "associated_server": { Type: schema.TypeString, Computed: true, @@ -2719,34 +2727,76 @@ func resourceServerProfileRead(d *schema.ResourceData, meta interface{}) error { func resourceServerProfileUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - updateType := d.Get("update_type").(string) + patchOperation := map[string][]string{ + + "update_from_template": {"replace", "/templateCompliance", "Compliant"}, + "update_from_template_stage": {"replace", "/templateCompliance", "PendingCompliance"}, + "cancel_update_from_template": {"replace", "/templateCompliance", "PendingComplianceCancelled"}, + "refresh": {"replace", "/refreshState", "RefreshPending"}, + "reapply_firmware": {"replace", "/firmware/reapplyState", "ApplyPending"}, + "reapply_connection": {"replace", "/connectionSettings/reapplyState", "ApplyPending"}, + "reapply_adpater_boot_settings": {"replace", "/serverHardwareReapplyState", "ApplyPending"}, + "rename_logical_drive": {"replace", "/localStorage/controllers/{deviceSlot}/logicalDrives/{currentLogicalDriveName}/name", "newLogicalDriveName"}, + "reapply_local_storage": {"replace", "/localStorage/reapplyState", "ApplyPending"}, + "reapply_SAN_storage": {"replace", "/sanStorage/reapplyState", "ApplyPending"}, + "reapply_bios_settings": {"replace", "/bios/reapplyState", "ApplyPending"}, + "regenerate_CHAP_secrets": {"replace", "/sanstorage/regenerateChapSecrets", ""}, + "reapply_ilo_settings": {"replace", "/managementProcessor/reapplyState", "ApplyPending"}, + } + // Check for patch operation + if val, ok := d.GetOk("operation_type"); ok { + deviceSlotName := "" + currentLogicalDriveName := "" + newLogicalDriveName := "" - if updateType == "patch" { serverProfile := ov.ServerProfile{ Name: d.Get("name").(string), Type: d.Get("type").(string), URI: utils.NewNstring(d.Get("uri").(string)), } - - rawOptions := d.Get("options").(*schema.Set).List() + rawOptions := val.(*schema.Set).List() options := make([]ov.Options, len(rawOptions)) for i, rawData := range rawOptions { option := rawData.(map[string]interface{}) - options[i] = ov.Options{ - Op: option["op"].(string), - Path: option["path"].(string), - Value: option["value"].(string)} - } + // Check if rename of logical drive operation is there + if logicalDriveValue, ok := option["logical_drive_value"]; ok { + logicalDriveValueList := logicalDriveValue.(*schema.Set).List() + for _, raw := range logicalDriveValueList { + rawlgdValue := raw.(map[string]interface{}) + deviceSlotName = rawlgdValue["device_slot_name"].(string) + currentLogicalDriveName = rawlgdValue["current_logical_drive_name"].(string) + newLogicalDriveName = rawlgdValue["new_logical_drive_name"].(string) + } + } + if patchOp, ok := patchOperation[option["name"].(string)]; ok { + if option["name"] == "" { + log.Printf("operation not found %s", option["name"].(string)) + return nil + } + //If operation is rename of logical drive replace the device slot , logical drive name from the path + if option["name"] == "rename_logical_drive" { + myString := patchOp[1] + replacer := strings.NewReplacer("{deviceSlot}", deviceSlotName, "{currentLogicalDriveName}", currentLogicalDriveName) + patchOp[1] = replacer.Replace(myString) + patchOp[2] = strings.Replace(patchOp[2], "newLogicalDriveName", newLogicalDriveName, 1) + + } + options[i] = ov.Options{ + Op: patchOp[0], + Path: patchOp[1], + Value: patchOp[2], + } + } + } error := config.ovClient.PatchServerProfile(serverProfile, options) d.SetId(d.Get("name").(string)) if error != nil { d.SetId("") return error } - } - - if updateType == "put" { + // Put operation is asked and not patch operation + } else { serverProfile, err := config.ovClient.GetProfileByName(d.Id()) var serverHardware ov.ServerHardware diff --git a/vendor/modules.txt b/vendor/modules.txt index dd2c8185..ff0c3d3b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -8,7 +8,7 @@ cloud.google.com/go/internal/trace cloud.google.com/go/internal/version # cloud.google.com/go/storage v1.10.0 cloud.google.com/go/storage -# github.com/HewlettPackard/oneview-golang v8.3.0+incompatible +# github.com/HewlettPackard/oneview-golang v8.3.1-0.20230529095956-f6039fe84f3f+incompatible ## explicit github.com/HewlettPackard/oneview-golang/liboneview github.com/HewlettPackard/oneview-golang/ov