From 050b8790dc202a1694559c8ba074eb254cb2afff Mon Sep 17 00:00:00 2001 From: asisbagga <asisbagga@gmail.com> Date: Wed, 10 Feb 2021 18:58:59 +0530 Subject: [PATCH] Issue 233 and Issue 234 Fixed --- CHANGELOG.md | 6 + examples/server_profile.tf | 72 +++- examples/server_profile_template.tf | 85 +++- oneview/data_source_server_profile.go | 209 ++++++++- .../data_source_server_profile_template.go | 275 +++++++++++- oneview/resource_server_profile.go | 405 +++++++++++++---- oneview/resource_server_profile_template.go | 406 +++++++++++++++--- .../oneview-golang/ov/profiles.go | 2 +- 8 files changed, 1287 insertions(+), 173 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56f63202..31835d31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html ### Notes - This release supports API2400 minimally where we can use OneView v5.60 with this SDK. +#### Major changes +1. Added support for new endpoints in logical interconnect resource, logical interconnect data source and logical interconnect group data source. + - PUT /rest/logical-interconnects/{id}/portFlapSettings + ### Oneview Features supported - Ethernet Network - Enclosure @@ -33,6 +37,8 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html - Uplink Set ### Bug fixes & Enhancements: +- [#233] (https://github.com/HewlettPackard/terraform-provider-oneview/issues/233) terraform import oneview_server_profile_template missing settings. +- [#234] (https://github.com/HewlettPackard/terraform-provider-oneview/issues/234) local storage configuration. - [#242] (https://github.com/HewlettPackard/terraform-provider-oneview/issues/242) serverprofile bootmode_secureboot. # [v1.6.0] diff --git a/examples/server_profile.tf b/examples/server_profile.tf index 4324105e..54d5fd6c 100644 --- a/examples/server_profile.tf +++ b/examples/server_profile.tf @@ -3,36 +3,90 @@ provider "oneview" { ov_password = var.password ov_endpoint = var.endpoint ov_sslverify = var.ssl_enabled - ov_apiversion = 2200 + ov_apiversion = 2400 ov_ifmatch = "*" } data "oneview_scope" "scope" { - name = "test" + name = "testing" } - +/* # Creation of Server Profile without template resource "oneview_server_profile" "SP" { name = "TestSP2" hardware_name = "0000A66101, bay 3" type = "ServerProfileV12" - enclosure_group = "test_EG" + enclosure_group = "EG" + bios_option { + manage_bios = "true" + overridden_settings { + id = "TimeFormat" + value = "Utc" + } + } + boot_order = ["HardDisk"] + boot_mode { + manage_mode = "true" + mode = "UEFIOptimized" + pxe_boot_policy = "Auto" + } + local_storage { + controller { + device_slot = "Embedded" + drive_write_cache = "Unmanaged" + initialize = "true" + mode = "RAID" + predictive_spare_rebuild = "Unmanaged" + logical_drives { + accelerator = "Unmanaged" + bootable = "true" + drive_technology = "SasHdd" + name = "TestLd" + num_physical_drives = 2 + raid_level = "RAID1" + } + } + } initial_scope_uris = [data.oneview_scope.scope.uri] } - +*/ # Updating Server profile resource "oneview_server_profile" "SP" { name = "TestSP_Renamed" hardware_name = "0000A66101, bay 3" type = "ServerProfileV12" - enclosure_group = "test_EG" - server_hardware_type = "SY 660 Gen9 2" + enclosure_group = "EG" + server_hardware_type = "SY 660 Gen9 1" + bios_option { + manage_bios = "true" + overridden_settings { + id = "TimeFormat" + value = "Utc" + } + } + local_storage { + controller { + device_slot = "Embedded" + drive_write_cache = "Unmanaged" + initialize = "true" + mode = "RAID" + predictive_spare_rebuild = "Unmanaged" + logical_drives { + accelerator = "Unmanaged" + bootable = "false" + drive_technology = "SasHdd" + name = "TestLdUpdate" + num_physical_drives = 2 + raid_level = "RAID1" + } + } + } initial_scope_uris = [data.oneview_scope.scope.uri] update_type = "put" } - +/* # Patch request - Server profile Refresh resource "oneview_server_profile" "SP" { update_type = "patch" @@ -64,4 +118,4 @@ output "oneview_server_profile_value" { # Eg: terraform import oneview_server_profile.serverProfile Test resource "oneview_server_profile" "serverProfile" { } - +*/ diff --git a/examples/server_profile_template.tf b/examples/server_profile_template.tf index 6bee854e..bc7e88e7 100644 --- a/examples/server_profile_template.tf +++ b/examples/server_profile_template.tf @@ -1,43 +1,94 @@ provider "oneview" { - ov_username = var.username - ov_password = var.password - ov_endpoint = var.endpoint - ov_sslverify = var.ssl_enabled + ov_username = var.username + ov_password = var.password + ov_endpoint = var.endpoint + ov_sslverify = var.ssl_enabled ov_apiversion = 2400 - ov_ifmatch = "*" + ov_ifmatch = "*" } - data "oneview_scope" "scope" { - name = "test" + name = "testing" } -# Create +# Create resource "oneview_server_profile_template" "ServerProfileTemplate" { name = "TestServerProfileTemplate" type = "ServerProfileTemplateV8" - enclosure_group = "test_EG" + enclosure_group = "EG" server_hardware_type = "SY 480 Gen9 1" initial_scope_uris = [data.oneview_scope.scope.uri] + bios_option { + manage_bios = "true" + overridden_settings { + id = "TimeFormat" + value = "Utc" + } + } + boot_order = ["HardDisk"] + boot_mode { + manage_mode = "true" + mode = "UEFIOptimized" + pxe_boot_policy = "Auto" + } + local_storage { + controller { + device_slot = "Embedded" + drive_write_cache = "Unmanaged" + initialize = "true" + mode = "RAID" + predictive_spare_rebuild = "Unmanaged" + logical_drives { + accelerator = "Unmanaged" + bootable = "true" + drive_technology = "SasHdd" + name = "TestLd" + num_physical_drives = 2 + raid_level = "RAID1" + } + } + } } - -# Update +# Update resource "oneview_server_profile_template" "ServerProfileTemplate" { - name = "TestServerProfileTemplate_Renamed" + name = "TestServerProfileTemplateRename" type = "ServerProfileTemplateV8" - enclosure_group = "test_EG" + enclosure_group = "EG" server_hardware_type = "SY 480 Gen9 1" initial_scope_uris = [data.oneview_scope.scope.uri] + bios_option { + manage_bios = "true" + overridden_settings { + id = "TimeFormat" + value = "Utc" + } + } + local_storage { + controller { + device_slot = "Embedded" + drive_write_cache = "Unmanaged" + initialize = "true" + mode = "RAID" + predictive_spare_rebuild = "Unmanaged" + logical_drives { + accelerator = "Unmanaged" + bootable = "false" + drive_technology = "SasHdd" + name = "TestLdUpdate" + num_physical_drives = 2 + raid_level = "RAID1" + } + } + } } -# Datasource +# Datasource data "oneview_server_profile_template" "server_profile_template" { - name = "TestServerProfileTemplate" - depends_on = [oneview_server_profile_template.ServerProfileTemplate] + name = "TestServerProfileTemplateRename" } output "oneiew_server_hardware_type_value" { value = data.oneview_server_profile_template.server_profile_template.uri -} +} diff --git a/oneview/data_source_server_profile.go b/oneview/data_source_server_profile.go index d0b34ffa..e17cc78b 100644 --- a/oneview/data_source_server_profile.go +++ b/oneview/data_source_server_profile.go @@ -1,4 +1,4 @@ -// (C) Copyright 2016 Hewlett Packard Enterprise Development LP +// (C) Copyright 2021 Hewlett Packard Enterprise Development LP // // Licensed under the Apache License, Version 2.0 (the "License"); // You may not use this file except in compliance with the License. @@ -56,13 +56,17 @@ func dataSourceServerProfile() *schema.Resource { Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "consistency_state": { + Type: schema.TypeString, + Optional: true, + }, "manage_bios": { Type: schema.TypeBool, Required: true, }, "overridden_settings": { Optional: true, - Type: schema.TypeSet, + Type: schema.TypeList, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "id": { @@ -76,6 +80,10 @@ func dataSourceServerProfile() *schema.Resource { }, }, }, + "reapply_state": { + Type: schema.TypeString, + Optional: true, + }, }, }, }, @@ -280,6 +288,42 @@ func dataSourceServerProfile() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "reapply_state": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + "controllers": { + Optional: true, + Type: schema.TypeSet, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "device_slot": { + Type: schema.TypeString, + Optional: true, + }, + "drive_write_cache": { + Type: schema.TypeString, + Optional: true, + }, + "import_configuration": { + Type: schema.TypeBool, + Optional: true, + }, + "initialize": { + Type: schema.TypeBool, + Optional: true, + }, + "mode": { + Type: schema.TypeString, + Optional: true, + }, + "predictive_spare_rebuild": { + Type: schema.TypeString, + Optional: true, + }, }, }, }, @@ -288,14 +332,98 @@ func dataSourceServerProfile() *schema.Resource { Type: schema.TypeSet, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "accelerator": { + Type: schema.TypeString, + Optional: true, + }, "bootable": { Type: schema.TypeBool, Optional: true, }, + "drive_number": { + Type: schema.TypeInt, + Optional: true, + }, + "drive_technology": { + Type: schema.TypeString, + Optional: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + }, + "num_physical_drives": { + Type: schema.TypeInt, + Optional: true, + }, + "num_spare_drives": { + Type: schema.TypeInt, + Optional: true, + }, "raid_level": { Type: schema.TypeString, Optional: true, }, + "sas_logical_jbod_id": { + Type: schema.TypeInt, + Optional: true, + }, + }, + }, + }, + "logical_jbod": { + Optional: true, + Type: schema.TypeSet, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "description": { + Type: schema.TypeString, + Optional: true, + }, + "device_slot": { + Type: schema.TypeString, + Optional: true, + }, + "drive_max_size_gb": { + Type: schema.TypeInt, + Optional: true, + }, + "drive_min_size_gb": { + Type: schema.TypeInt, + Optional: true, + }, + "drive_technology": { + Type: schema.TypeString, + Optional: true, + }, + "erase_data": { + Type: schema.TypeBool, + Optional: true, + }, + "id": { + Type: schema.TypeInt, + Optional: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + }, + "num_physical_drives": { + Type: schema.TypeString, + Optional: true, + }, + "persistent": { + Type: schema.TypeBool, + Optional: true, + }, + "sas_logical_jbod_uri": { + Type: schema.TypeString, + Optional: true, + }, + "status": { + Type: schema.TypeString, + Optional: true, + }, }, }, }, @@ -552,6 +680,24 @@ func dataSourceServerProfileRead(d *schema.ResourceData, meta interface{}) error } d.Set("network", networks) } + overriddenSettings := make([]interface{}, 0, len(serverProfile.Bios.OverriddenSettings)) + for _, overriddenSetting := range serverProfile.Bios.OverriddenSettings { + overriddenSettings = append(overriddenSettings, map[string]interface{}{ + "id": overriddenSetting.ID, + "value": overriddenSetting.Value, + }) + } + if serverProfile.Bios != nil { + biosOptions := make([]map[string]interface{}, 0, 1) + biosOptions = append(biosOptions, map[string]interface{}{ + "manage_bios": serverProfile.Bios.ManageBios, + "reapply_state": serverProfile.Bios.ReapplyState, + "consistency_state": serverProfile.Bios.ConsistencyState, + "overridden_settings": overriddenSettings, + }) + + d.Set("bios_option", biosOptions) + } if serverProfile.Boot.ManageBoot { bootOrder := make([]interface{}, 0) @@ -568,6 +714,65 @@ func dataSourceServerProfileRead(d *schema.ResourceData, meta interface{}) error d.Set("name", serverProfile.Name) d.Set("type", serverProfile.Type) d.Set("uri", serverProfile.URI.String()) + d.Set("template", serverProfile.ServerProfileTemplateURI.String()) + localStorages := make([]map[string]interface{}, 0, 1) + localStorages = append(localStorages, map[string]interface{}{ + "reapply_state": serverProfile.LocalStorage.ReapplyState, + }) + + d.Set("local_storage", localStorages) + controllers := make([]map[string]interface{}, 0, len(serverProfile.LocalStorage.Controllers)) + for _, controller := range serverProfile.LocalStorage.Controllers { + + controllers = append(controllers, map[string]interface{}{ + "device_slot": controller.DeviceSlot, + "drive_write_cache": controller.DriveWriteCache, + "import_configuration": controller.ImportConfiguration, + "initialize": controller.Initialize, + "mode": controller.Mode, + "predictive_spare_rebuild": controller.PredictiveSpareRebuild, + }) + logicaldrives := make([]map[string]interface{}, 0, len(controller.LogicalDrives)) + for _, logicaldrive := range controller.LogicalDrives { + + logicaldrives = append(logicaldrives, map[string]interface{}{ + "accelerator": logicaldrive.Accelerator, + "bootable": logicaldrive.Bootable, + "drive_number": logicaldrive.DriveNumber, + "drive_technology": logicaldrive.DriveTechnology, + "name": logicaldrive.Name, + "num_physical_drives": logicaldrive.NumPhysicalDrives, + "num_spare_drives": logicaldrive.NumSpareDrives, + "raid_level": logicaldrive.RaidLevel, + "sas_logical_jbod_id": logicaldrive.SasLogicalJBODId, + }) + } + + d.Set("logical_drives", logicaldrives) + + } + + d.Set("controllers", controllers) + + saslogicaljbods := make([]map[string]interface{}, 0, len(serverProfile.LocalStorage.SasLogicalJBODs)) + for _, saslogicaljbod := range serverProfile.LocalStorage.SasLogicalJBODs { + + saslogicaljbods = append(saslogicaljbods, map[string]interface{}{ + "description": saslogicaljbod.Description, + "device_slot": saslogicaljbod.DeviceSlot, + "drive_max_size_gb": saslogicaljbod.DriveMaxSizeGB, + "drive_min_size_gb": saslogicaljbod.DriveMinSizeGB, + "drive_technology": saslogicaljbod.DriveTechnology, + "erase_data": saslogicaljbod.EraseData, + "id": saslogicaljbod.ID, + "name": saslogicaljbod.Name, + "num_physical_drives": saslogicaljbod.NumPhysicalDrives, + "persistent": saslogicaljbod.Persistent, + "sas_logical_jbod_uri": saslogicaljbod.SasLogicalJBODUri, + "status": saslogicaljbod.Status, + }) + } + d.Set("logical_jbod", saslogicaljbods) return nil } diff --git a/oneview/data_source_server_profile_template.go b/oneview/data_source_server_profile_template.go index 94cc36c4..6514c879 100644 --- a/oneview/data_source_server_profile_template.go +++ b/oneview/data_source_server_profile_template.go @@ -1,4 +1,4 @@ -// (C) Copyright 2019 Hewlett Packard Enterprise Development LP +// (C) Copyright 2021 Hewlett Packard Enterprise Development LP // // Licensed under the Apache License, Version 2.0 (the "License"); // You may not use this file except in compliance with the License. @@ -39,6 +39,54 @@ func dataSourceServerProfileTemplate() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "boot_mode": { + Optional: true, + Type: schema.TypeSet, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "manage_mode": { + Type: schema.TypeBool, + Required: true, + }, + "mode": { + Type: schema.TypeString, + Required: true, + }, + "pxe_boot_policy": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, + "bios_option": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "manage_bios": { + Type: schema.TypeBool, + Required: true, + }, + "overridden_settings": { + Optional: true, + Type: schema.TypeList, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeString, + Optional: true, + }, + "value": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + }, + }, + }, "network": { Optional: true, Type: schema.TypeList, @@ -71,6 +119,155 @@ func dataSourceServerProfileTemplate() *schema.Resource { }, }, }, + "local_storage": { + Optional: true, + Type: schema.TypeSet, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "manage_local_storage": { + Type: schema.TypeBool, + Optional: true, + }, + "initialize": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + "controllers": { + Optional: true, + Type: schema.TypeSet, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "device_slot": { + Type: schema.TypeString, + Optional: true, + }, + "drive_write_cache": { + Type: schema.TypeString, + Optional: true, + }, + "import_configuration": { + Type: schema.TypeBool, + Optional: true, + }, + "initialize": { + Type: schema.TypeBool, + Optional: true, + }, + "mode": { + Type: schema.TypeString, + Optional: true, + }, + "predictive_spare_rebuild": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + "logical_drives": { + Optional: true, + Type: schema.TypeSet, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "accelerator": { + Type: schema.TypeString, + Optional: true, + }, + "bootable": { + Type: schema.TypeBool, + Optional: true, + }, + "drive_number": { + Type: schema.TypeInt, + Optional: true, + }, + "drive_technology": { + Type: schema.TypeString, + Optional: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + }, + "num_physical_drives": { + Type: schema.TypeInt, + Optional: true, + }, + "num_spare_drives": { + Type: schema.TypeInt, + Optional: true, + }, + "raid_level": { + Type: schema.TypeString, + Optional: true, + }, + "sas_logical_jbod_id": { + Type: schema.TypeInt, + Optional: true, + }, + }, + }, + }, + "logical_jbod": { + Optional: true, + Type: schema.TypeSet, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "description": { + Type: schema.TypeString, + Optional: true, + }, + "device_slot": { + Type: schema.TypeString, + Optional: true, + }, + "drive_max_size_gb": { + Type: schema.TypeInt, + Optional: true, + }, + "drive_min_size_gb": { + Type: schema.TypeInt, + Optional: true, + }, + "drive_technology": { + Type: schema.TypeString, + Optional: true, + }, + "erase_data": { + Type: schema.TypeBool, + Optional: true, + }, + "id": { + Type: schema.TypeInt, + Optional: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + }, + "num_physical_drives": { + Type: schema.TypeString, + Optional: true, + }, + "persistent": { + Type: schema.TypeBool, + Optional: true, + }, + "sas_logical_jbod_uri": { + Type: schema.TypeString, + Optional: true, + }, + "status": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, "hide_unused_flex_nics": { Type: schema.TypeBool, Computed: true, @@ -170,5 +367,81 @@ func dataSourceServerProfileTemplateRead(d *schema.ResourceData, meta interface{ d.Set("boot_order", bootOrder) } + overriddenSettings := make([]interface{}, 0, len(spt.Bios.OverriddenSettings)) + for _, overriddenSetting := range spt.Bios.OverriddenSettings { + overriddenSettings = append(overriddenSettings, map[string]interface{}{ + "id": overriddenSetting.ID, + "value": overriddenSetting.Value, + }) + } + if spt.Bios != nil { + biosOptions := make([]map[string]interface{}, 0, 1) + biosOptions = append(biosOptions, map[string]interface{}{ + "manage_bios": spt.Bios.ManageBios, + "overridden_settings": overriddenSettings, + }) + + d.Set("bios_option", biosOptions) + } + + localStorages := make([]map[string]interface{}, 0, 1) + localStorages = append(localStorages, map[string]interface{}{ + "reapply_state": spt.LocalStorage.ReapplyState, + }) + + d.Set("local_storage", localStorages) + controllers := make([]map[string]interface{}, 0, len(spt.LocalStorage.Controllers)) + for _, controller := range spt.LocalStorage.Controllers { + + controllers = append(controllers, map[string]interface{}{ + "device_slot": controller.DeviceSlot, + "drive_write_cache": controller.DriveWriteCache, + "import_configuration": controller.ImportConfiguration, + "initialize": controller.Initialize, + "mode": controller.Mode, + "predictive_spare_rebuild": controller.PredictiveSpareRebuild, + }) + logicaldrives := make([]map[string]interface{}, 0, len(controller.LogicalDrives)) + for _, logicaldrive := range controller.LogicalDrives { + + logicaldrives = append(logicaldrives, map[string]interface{}{ + "accelerator": logicaldrive.Accelerator, + "bootable": logicaldrive.Bootable, + "drive_number": logicaldrive.DriveNumber, + "drive_technology": logicaldrive.DriveTechnology, + "name": logicaldrive.Name, + "num_physical_drives": logicaldrive.NumPhysicalDrives, + "num_spare_drives": logicaldrive.NumSpareDrives, + "raid_level": logicaldrive.RaidLevel, + "sas_logical_jbod_id": logicaldrive.SasLogicalJBODId, + }) + } + + d.Set("logical_drives", logicaldrives) + + } + + d.Set("controllers", controllers) + + saslogicaljbods := make([]map[string]interface{}, 0, len(spt.LocalStorage.SasLogicalJBODs)) + for _, saslogicaljbod := range spt.LocalStorage.SasLogicalJBODs { + + saslogicaljbods = append(saslogicaljbods, map[string]interface{}{ + "description": saslogicaljbod.Description, + "device_slot": saslogicaljbod.DeviceSlot, + "drive_max_size_gb": saslogicaljbod.DriveMaxSizeGB, + "drive_min_size_gb": saslogicaljbod.DriveMinSizeGB, + "drive_technology": saslogicaljbod.DriveTechnology, + "erase_data": saslogicaljbod.EraseData, + "id": saslogicaljbod.ID, + "name": saslogicaljbod.Name, + "num_physical_drives": saslogicaljbod.NumPhysicalDrives, + "persistent": saslogicaljbod.Persistent, + "sas_logical_jbod_uri": saslogicaljbod.SasLogicalJBODUri, + "status": saslogicaljbod.Status, + }) + } + d.Set("logical_jbod", saslogicaljbods) + return nil } diff --git a/oneview/resource_server_profile.go b/oneview/resource_server_profile.go index 265e9c66..647fd2d6 100644 --- a/oneview/resource_server_profile.go +++ b/oneview/resource_server_profile.go @@ -1,4 +1,4 @@ -// (C) Copyright 2016 Hewlett Packard Enterprise Development LP +// (C) Copyright 2021 Hewlett Packard Enterprise Development LP // // Licensed under the Apache License, Version 2.0 (the "License"); // You may not use this file except in compliance with the License. @@ -59,6 +59,10 @@ func resourceServerProfile() *schema.Resource { Type: schema.TypeString, Required: true, }, + "secure_boot": { + Type: schema.TypeString, + Optional: true, + }, }, }, }, @@ -71,6 +75,14 @@ func resourceServerProfile() *schema.Resource { Type: schema.TypeBool, Required: true, }, + "consistency_state": { + Type: schema.TypeString, + Optional: true, + }, + "reapply_state": { + Type: schema.TypeString, + Optional: true, + }, "overridden_settings": { Optional: true, Type: schema.TypeSet, @@ -294,24 +306,126 @@ func resourceServerProfile() *schema.Resource { Optional: true, }, "initialize": { - Type: schema.TypeString, + Type: schema.TypeBool, Optional: true, }, - }, - }, - }, - "logical_drives": { - Optional: true, - Type: schema.TypeSet, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "bootable": { - Type: schema.TypeBool, + "controller": { Optional: true, + Type: schema.TypeSet, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "device_slot": { + Type: schema.TypeString, + Optional: true, + }, + "initialize": { + Type: schema.TypeBool, + Optional: true, + }, + "drive_write_cache": { + Type: schema.TypeString, + Optional: true, + }, + "mode": { + Type: schema.TypeString, + Optional: true, + }, + "predictive_spare_rebuild": { + Type: schema.TypeString, + Optional: true, + }, + "logical_drives": { + Optional: true, + Type: schema.TypeSet, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "bootable": { + Type: schema.TypeBool, + Optional: true, + }, + "accelerator": { + Type: schema.TypeString, + Optional: true, + }, + "drive_technology": { + Type: schema.TypeString, + Optional: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + }, + "num_physical_drives": { + Type: schema.TypeInt, + Optional: true, + }, + "num_spare_drives": { + Type: schema.TypeInt, + Optional: true, + }, + "sas_logical_jbod_id": { + Type: schema.TypeInt, + Optional: true, + }, + "raid_level": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + }, + }, }, - "raid_level": { - Type: schema.TypeString, + "sas_logical_jbod": { Optional: true, + Type: schema.TypeSet, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "description": { + Type: schema.TypeString, + Optional: true, + }, + "device_slot": { + Type: schema.TypeString, + Optional: true, + }, + "drive_max_size_gb": { + Type: schema.TypeInt, + Optional: true, + }, + "drive_min_size_gb": { + Type: schema.TypeInt, + Optional: true, + }, + "drive_technology": { + Type: schema.TypeString, + Optional: true, + }, + "erase_data": { + Type: schema.TypeBool, + Optional: true, + }, + "id": { + Type: schema.TypeInt, + Optional: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + }, + "num_physical_drive": { + Type: schema.TypeInt, + Optional: true, + }, + "persistent": { + Type: schema.TypeBool, + Optional: true, + }, + }, + }, }, }, }, @@ -408,7 +522,7 @@ func resourceServerProfile() *schema.Resource { Type: schema.TypeBool, Optional: true, }, - "templateuri": { + "template_uri": { Type: schema.TypeString, Optional: true, }, @@ -808,6 +922,7 @@ func resourceServerProfileCreate(d *schema.ResourceData, meta interface{}) error ManageMode: rawBootMode["manage_mode"].(bool), Mode: rawBootMode["mode"].(string), PXEBootPolicy: utils.Nstring(rawBootMode["pxe_boot_policy"].(string)), + SecureBoot: rawBootMode["secure_boot"].(string), } } @@ -864,33 +979,67 @@ func resourceServerProfileCreate(d *schema.ResourceData, meta interface{}) error } serverProfile.Firmware = firmware } - // Get local storage data if provided - if _, ok := d.GetOk("local_storage"); ok { - rawLocalStorage := d.Get("local_storage").(*schema.Set).List() - localStorage := ov.LocalStorageOptions{} - for _, raw := range rawLocalStorage { - localStorageItem := raw.(map[string]interface{}) - localStorage = ov.LocalStorageOptions{ - ManageLocalStorage: localStorageItem["manage_local_storage"].(bool), - Initialize: localStorageItem["initialize"].(bool), + rawLocalStorage := d.Get("local_storage").(*schema.Set).List() + localStorage := ov.LocalStorageOptions{} + for _, raw := range rawLocalStorage { + localStorageItem := raw.(map[string]interface{}) + // Gets Local Storage Controller body + rawLocalStorageController := localStorageItem["controller"].(*schema.Set).List() + localStorageEmbeddedController := make([]ov.LocalStorageEmbeddedController, 0) + for _, raw2 := range rawLocalStorageController { + controllerData := raw2.(map[string]interface{}) + // Gets Local Storage Controller's Logical Drives + rawLogicalDrives := controllerData["logical_drives"].(*schema.Set).List() + logicalDrives := make([]ov.LogicalDriveV3, 0) + for _, rawLogicalDrive := range rawLogicalDrives { + logicalDrivesItem := rawLogicalDrive.(map[string]interface{}) + logicalDrives = append(logicalDrives, ov.LogicalDriveV3{ + Bootable: logicalDrivesItem["bootable"].(bool), + RaidLevel: logicalDrivesItem["raid_level"].(string), + Accelerator: logicalDrivesItem["accelerator"].(string), + DriveTechnology: logicalDrivesItem["drive_technology"].(string), + Name: logicalDrivesItem["name"].(string), + NumPhysicalDrives: logicalDrivesItem["num_physical_drives"].(int), + NumSpareDrives: logicalDrivesItem["num_spare_drives"].(int), + SasLogicalJBODId: logicalDrivesItem["sas_logical_jbod_id"].(int), + }) } + localStorageEmbeddedController = append(localStorageEmbeddedController, ov.LocalStorageEmbeddedController{ + DeviceSlot: controllerData["device_slot"].(string), + DriveWriteCache: controllerData["drive_write_cache"].(string), + Initialize: controllerData["initialize"].(bool), + Mode: controllerData["mode"].(string), + PredictiveSpareRebuild: controllerData["predictive_spare_rebuild"].(string), + LogicalDrives: logicalDrives, + }) } - serverProfile.LocalStorage = localStorage - } - - if _, ok := d.GetOk("logical_drives"); ok { - rawLogicalDrives := d.Get("logical_drives").(*schema.Set).List() - logicalDrives := make([]ov.LogicalDrive, 0) - for _, rawLogicalDrive := range rawLogicalDrives { - logicalDrivesItem := rawLogicalDrive.(map[string]interface{}) - logicalDrives = append(logicalDrives, ov.LogicalDrive{ - Bootable: logicalDrivesItem["bootable"].(bool), - RaidLevel: logicalDrivesItem["raid_level"].(string), + // Gets Local Storage Sas Jbods Body + rawLocalStorageSasJbod := localStorageItem["sas_logical_jbod"].(*schema.Set).List() + logicalJbod := make([]ov.LogicalJbod, 0) + for _, raw3 := range rawLocalStorageSasJbod { + sasLogicalJbodData := raw3.(map[string]interface{}) + logicalJbod = append(logicalJbod, ov.LogicalJbod{ + Description: sasLogicalJbodData["description"].(string), + DeviceSlot: sasLogicalJbodData["device_slot"].(string), + DriveMaxSizeGB: sasLogicalJbodData["drive_max_size_gb"].(int), + DriveMinSizeGB: sasLogicalJbodData["drive_min_size_gb"].(int), + DriveTechnology: sasLogicalJbodData["drive_technology"].(string), + EraseData: sasLogicalJbodData["erase_data"].(bool), + ID: sasLogicalJbodData["id"].(int), + Name: sasLogicalJbodData["name"].(string), + NumPhysicalDrives: sasLogicalJbodData["num_physical_drive"].(int), + Persistent: sasLogicalJbodData["persistent"].(bool), }) } - serverProfile.LocalStorage.LogicalDrives = logicalDrives + localStorage = ov.LocalStorageOptions{ + ManageLocalStorage: localStorageItem["manage_local_storage"].(bool), + Initialize: localStorageItem["initialize"].(bool), + Controllers: localStorageEmbeddedController, + SasLogicalJBODs: logicalJbod, + } } + serverProfile.LocalStorage = localStorage // get SAN storage data if provided if _, ok := d.GetOk("san_storage"); ok { @@ -940,14 +1089,14 @@ func resourceServerProfileCreate(d *schema.ResourceData, meta interface{}) error IsCompressed: propertyItem["is_compressed"].(bool), IsAdaptiveOptimizationEnabled: propertyItem["is_adaptive_optimization_enabled"].(bool), IsDataReductionEnabled: propertyItem["is_data_reduction_enabled"].(bool), - Name: propertyItem["name"].(string), - PerformancePolicy: propertyItem["performance_policy"].(string), - ProvisioningType: propertyItem["provisioning_type"].(string), - Size: propertyItem["size"].(int), - SnapshotPool: utils.NewNstring(propertyItem["snapshot_pool"].(string)), - StoragePool: utils.NewNstring(propertyItem["storage_pool"].(string)), - TemplateVersion: propertyItem["template_version"].(string), - VolumeSet: utils.NewNstring(propertyItem["volume_set"].(string)), + Name: propertyItem["name"].(string), + PerformancePolicy: propertyItem["performance_policy"].(string), + ProvisioningType: propertyItem["provisioning_type"].(string), + Size: propertyItem["size"].(int), + SnapshotPool: utils.NewNstring(propertyItem["snapshot_pool"].(string)), + StoragePool: utils.NewNstring(propertyItem["storage_pool"].(string)), + TemplateVersion: propertyItem["template_version"].(string), + VolumeSet: utils.NewNstring(propertyItem["volume_set"].(string)), } } } @@ -998,11 +1147,11 @@ func resourceServerProfileCreate(d *schema.ResourceData, meta interface{}) error VolumeURI: utils.NewNstring(volumeAttachmentItem["volume_uri"].(string)), VolumeStorageSystemURI: utils.NewNstring(volumeAttachmentItem["volume_storage_system_uri"].(string)), AssociatedTemplateAttachmentId: volumeAttachmentItem["associated_template_attachment_id"].(string), - State: volumeAttachmentItem["state"].(string), - Status: volumeAttachmentItem["status"].(string), - StoragePaths: storagePaths, - BootVolumePriority: volumeAttachmentItem["boot_volume_priority"].(string), - Volume: &volumes, + State: volumeAttachmentItem["state"].(string), + Status: volumeAttachmentItem["status"].(string), + StoragePaths: storagePaths, + BootVolumePriority: volumeAttachmentItem["boot_volume_priority"].(string), + Volume: &volumes, }) } serverProfile.SanStorage.VolumeAttachments = volumeAttachments @@ -1131,6 +1280,76 @@ func resourceServerProfileRead(d *schema.ResourceData, meta interface{}) error { d.Set("boot_order", bootOrder) } + overriddenSettings := make([]interface{}, 0, len(serverProfile.Bios.OverriddenSettings)) + for _, overriddenSetting := range serverProfile.Bios.OverriddenSettings { + overriddenSettings = append(overriddenSettings, map[string]interface{}{ + "id": overriddenSetting.ID, + "value": overriddenSetting.Value, + }) + } + if serverProfile.Bios != nil { + biosOptions := make([]map[string]interface{}, 0, 1) + biosOptions = append(biosOptions, map[string]interface{}{ + "manage_bios": serverProfile.Bios.ManageBios, + "reapply_state": serverProfile.Bios.ReapplyState, + "consistency_state": serverProfile.Bios.ConsistencyState, + "overridden_settings": overriddenSettings, + }) + + d.Set("bios_option", biosOptions) + } + + // Gets Local Storage Body + localStorage := make([]map[string]interface{}, 0, 1) + // Gets Storage Controller Body + controllers := make([]map[string]interface{}, 0, len(serverProfile.LocalStorage.Controllers)) + for i := 0; i < len(serverProfile.LocalStorage.Controllers); i++ { + logicalDrives := make([]map[string]interface{}, 0, len(serverProfile.LocalStorage.Controllers[i].LogicalDrives)) + for j := 0; j < len(serverProfile.LocalStorage.Controllers[i].LogicalDrives); j++ { + logicalDrives = append(logicalDrives, map[string]interface{}{ + "bootable": serverProfile.LocalStorage.Controllers[i].LogicalDrives[j].Bootable, + "accelerator": serverProfile.LocalStorage.Controllers[i].LogicalDrives[j].Accelerator, + "drive_technology": serverProfile.LocalStorage.Controllers[i].LogicalDrives[j].DriveTechnology, + "name": serverProfile.LocalStorage.Controllers[i].LogicalDrives[j].Name, + "num_physical_drives": serverProfile.LocalStorage.Controllers[i].LogicalDrives[j].NumPhysicalDrives, + "num_spare_drives": serverProfile.LocalStorage.Controllers[i].LogicalDrives[j].NumSpareDrives, + "sas_logical_jbod_id": serverProfile.LocalStorage.Controllers[i].LogicalDrives[j].SasLogicalJBODId, + "raid_level": serverProfile.LocalStorage.Controllers[i].LogicalDrives[j].RaidLevel, + }) + } + controllers = append(controllers, map[string]interface{}{ + "device_slot": serverProfile.LocalStorage.Controllers[i].DeviceSlot, + "initialize": serverProfile.LocalStorage.Controllers[i].Initialize, + "drive_write_cache": serverProfile.LocalStorage.Controllers[i].DriveWriteCache, + "mode": serverProfile.LocalStorage.Controllers[i].Mode, + "predictive_spare_rebuild": serverProfile.LocalStorage.Controllers[i].PredictiveSpareRebuild, + "logical_drive": logicalDrives, + }) + } + // Gets Sas Logical Jbod Controller Body + sasLogDrives := make([]map[string]interface{}, 0, len(serverProfile.LocalStorage.SasLogicalJBODs)) + for i := 0; i < len(serverProfile.LocalStorage.SasLogicalJBODs); i++ { + sasLogDrives = append(sasLogDrives, map[string]interface{}{ + "description": serverProfile.LocalStorage.SasLogicalJBODs[i].Description, + "device_slot": serverProfile.LocalStorage.SasLogicalJBODs[i].DeviceSlot, + "drive_max_size_gb": serverProfile.LocalStorage.SasLogicalJBODs[i].DriveMaxSizeGB, + "drive_min_size_sb": serverProfile.LocalStorage.SasLogicalJBODs[i].DriveMinSizeGB, + "drive_technology": serverProfile.LocalStorage.SasLogicalJBODs[i].DriveTechnology, + "erase_data": serverProfile.LocalStorage.SasLogicalJBODs[i].EraseData, + "id": serverProfile.LocalStorage.SasLogicalJBODs[i].ID, + "name": serverProfile.LocalStorage.SasLogicalJBODs[i].Name, + "num_physical_drive": serverProfile.LocalStorage.SasLogicalJBODs[i].NumPhysicalDrives, + "persistent": serverProfile.LocalStorage.SasLogicalJBODs[i].Persistent, + }) + } + localStorage = append(localStorage, map[string]interface{}{ + "manage_local_storage": serverProfile.LocalStorage.ManageLocalStorage, + "initialize": serverProfile.LocalStorage.Initialize, + "controller": controllers, + "sas_logical_jbod": sasLogDrives, + }) + d.Set("local_storage", localStorage) + return nil } @@ -1362,34 +1581,66 @@ func resourceServerProfileUpdate(d *schema.ResourceData, meta interface{}) error } serverProfile.Firmware = firmware } - - // Get local storage data if provided if _, ok := d.GetOk("local_storage"); ok { rawLocalStorage := d.Get("local_storage").(*schema.Set).List() localStorage := ov.LocalStorageOptions{} for _, raw := range rawLocalStorage { localStorageItem := raw.(map[string]interface{}) + rawLocalStorageController := localStorageItem["controller"].(*schema.Set).List() + localStorageEmbeddedController := make([]ov.LocalStorageEmbeddedController, 0) + for _, raw2 := range rawLocalStorageController { + controllerData := raw2.(map[string]interface{}) + rawLogicalDrives := controllerData["logical_drives"].(*schema.Set).List() + logicalDrives := make([]ov.LogicalDriveV3, 0) + for _, rawLogicalDrive := range rawLogicalDrives { + logicalDrivesItem := rawLogicalDrive.(map[string]interface{}) + logicalDrives = append(logicalDrives, ov.LogicalDriveV3{ + Bootable: logicalDrivesItem["bootable"].(bool), + RaidLevel: logicalDrivesItem["raid_level"].(string), + Accelerator: logicalDrivesItem["accelerator"].(string), + DriveTechnology: logicalDrivesItem["drive_technology"].(string), + Name: logicalDrivesItem["name"].(string), + NumPhysicalDrives: logicalDrivesItem["num_physical_drives"].(int), + NumSpareDrives: logicalDrivesItem["num_spare_drives"].(int), + SasLogicalJBODId: logicalDrivesItem["sas_logical_jbod_id"].(int), + }) + } + localStorageEmbeddedController = append(localStorageEmbeddedController, ov.LocalStorageEmbeddedController{ + DeviceSlot: controllerData["device_slot"].(string), + DriveWriteCache: controllerData["drive_write_cache"].(string), + Initialize: controllerData["initialize"].(bool), + Mode: controllerData["mode"].(string), + PredictiveSpareRebuild: controllerData["predictive_spare_rebuild"].(string), + LogicalDrives: logicalDrives, + }) + } + rawLocalStorageSasJbod := localStorageItem["sas_logical_jbod"].(*schema.Set).List() + logicalJbod := make([]ov.LogicalJbod, 0) + for _, raw3 := range rawLocalStorageSasJbod { + sasLogicalJbodData := raw3.(map[string]interface{}) + logicalJbod = append(logicalJbod, ov.LogicalJbod{ + Description: sasLogicalJbodData["description"].(string), + DeviceSlot: sasLogicalJbodData["device_slot"].(string), + DriveMaxSizeGB: sasLogicalJbodData["drive_max_size_gb"].(int), + DriveMinSizeGB: sasLogicalJbodData["drive_min_size_gb"].(int), + DriveTechnology: sasLogicalJbodData["drive_technology"].(string), + EraseData: sasLogicalJbodData["erase_data"].(bool), + ID: sasLogicalJbodData["id"].(int), + Name: sasLogicalJbodData["name"].(string), + NumPhysicalDrives: sasLogicalJbodData["num_physical_drive"].(int), + Persistent: sasLogicalJbodData["persistent"].(bool), + }) + } localStorage = ov.LocalStorageOptions{ ManageLocalStorage: localStorageItem["manage_local_storage"].(bool), Initialize: localStorageItem["initialize"].(bool), + Controllers: localStorageEmbeddedController, + SasLogicalJBODs: logicalJbod, } } serverProfile.LocalStorage = localStorage } - if _, ok := d.GetOk("logical_drives"); ok { - rawLogicalDrives := d.Get("logical_drives").(*schema.Set).List() - logicalDrives := make([]ov.LogicalDrive, 0) - for _, rawLogicalDrive := range rawLogicalDrives { - logicalDrivesItem := rawLogicalDrive.(map[string]interface{}) - logicalDrives = append(logicalDrives, ov.LogicalDrive{ - Bootable: logicalDrivesItem["bootable"].(bool), - RaidLevel: logicalDrivesItem["raid_level"].(string), - }) - } - serverProfile.LocalStorage.LogicalDrives = logicalDrives - } - // get SAN storage data if provided if _, ok := d.GetOk("san_storage"); ok { rawSanStorage := d.Get("san_storage").(*schema.Set).List() @@ -1438,14 +1689,14 @@ func resourceServerProfileUpdate(d *schema.ResourceData, meta interface{}) error IsCompressed: propertyItem["is_compressed"].(bool), IsAdaptiveOptimizationEnabled: propertyItem["is_adaptive_optimization_enabled"].(bool), IsDataReductionEnabled: propertyItem["is_data_reduction_enabled"].(bool), - Name: propertyItem["name"].(string), - PerformancePolicy: propertyItem["performance_policy"].(string), - ProvisioningType: propertyItem["provisioning_type"].(string), - Size: propertyItem["size"].(int), - SnapshotPool: utils.NewNstring(propertyItem["snapshot_pool"].(string)), - StoragePool: utils.NewNstring(propertyItem["storage_pool"].(string)), - TemplateVersion: propertyItem["template_version"].(string), - VolumeSet: utils.NewNstring(propertyItem["volume_set"].(string)), + Name: propertyItem["name"].(string), + PerformancePolicy: propertyItem["performance_policy"].(string), + ProvisioningType: propertyItem["provisioning_type"].(string), + Size: propertyItem["size"].(int), + SnapshotPool: utils.NewNstring(propertyItem["snapshot_pool"].(string)), + StoragePool: utils.NewNstring(propertyItem["storage_pool"].(string)), + TemplateVersion: propertyItem["template_version"].(string), + VolumeSet: utils.NewNstring(propertyItem["volume_set"].(string)), } } } @@ -1496,11 +1747,11 @@ func resourceServerProfileUpdate(d *schema.ResourceData, meta interface{}) error VolumeURI: utils.NewNstring(volumeAttachmentItem["volume_uri"].(string)), VolumeStorageSystemURI: utils.NewNstring(volumeAttachmentItem["volume_storage_system_uri"].(string)), AssociatedTemplateAttachmentId: volumeAttachmentItem["associated_template_attachment_id"].(string), - State: volumeAttachmentItem["state"].(string), - Status: volumeAttachmentItem["status"].(string), - StoragePaths: storagePaths, - BootVolumePriority: volumeAttachmentItem["boot_volume_priority"].(string), - Volume: &volumes, + State: volumeAttachmentItem["state"].(string), + Status: volumeAttachmentItem["status"].(string), + StoragePaths: storagePaths, + BootVolumePriority: volumeAttachmentItem["boot_volume_priority"].(string), + Volume: &volumes, }) } serverProfile.SanStorage.VolumeAttachments = volumeAttachments diff --git a/oneview/resource_server_profile_template.go b/oneview/resource_server_profile_template.go index 1ba86a3b..89adbd8c 100644 --- a/oneview/resource_server_profile_template.go +++ b/oneview/resource_server_profile_template.go @@ -1,4 +1,4 @@ -// (C) Copyright 2016 Hewlett Packard Enterprise Development LP +// (C) Copyright 2021 Hewlett Packard Enterprise Development LP // // Licensed under the Apache License, Version 2.0 (the "License"); // You may not use this file except in compliance with the License. @@ -46,15 +46,15 @@ func resourceServerProfileTemplate() *schema.Resource { Schema: map[string]*schema.Schema{ "manage_mode": { Type: schema.TypeBool, - Required: true, + Optional: true, }, "mode": { Type: schema.TypeString, - Required: true, + Optional: true, }, "pxe_boot_policy": { Type: schema.TypeString, - Required: true, + Optional: true, }, }, }, @@ -69,8 +69,8 @@ func resourceServerProfileTemplate() *schema.Resource { Required: true, }, "overridden_settings": { - Optional: true, Type: schema.TypeSet, + Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "id": { @@ -304,24 +304,126 @@ func resourceServerProfileTemplate() *schema.Resource { Optional: true, }, "initialize": { - Type: schema.TypeString, + Type: schema.TypeBool, Optional: true, }, - }, - }, - }, - "logical_drives": { - Optional: true, - Type: schema.TypeSet, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "bootable": { - Type: schema.TypeBool, + "controller": { Optional: true, + Type: schema.TypeSet, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "device_slot": { + Type: schema.TypeString, + Optional: true, + }, + "initialize": { + Type: schema.TypeBool, + Optional: true, + }, + "drive_write_cache": { + Type: schema.TypeString, + Optional: true, + }, + "mode": { + Type: schema.TypeString, + Optional: true, + }, + "predictive_spare_rebuild": { + Type: schema.TypeString, + Optional: true, + }, + "logical_drives": { + Optional: true, + Type: schema.TypeSet, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "bootable": { + Type: schema.TypeBool, + Optional: true, + }, + "accelerator": { + Type: schema.TypeString, + Optional: true, + }, + "drive_technology": { + Type: schema.TypeString, + Optional: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + }, + "num_physical_drives": { + Type: schema.TypeInt, + Optional: true, + }, + "num_spare_drives": { + Type: schema.TypeInt, + Optional: true, + }, + "sas_logical_jbod_id": { + Type: schema.TypeInt, + Optional: true, + }, + "raid_level": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + }, + }, }, - "raid_level": { - Type: schema.TypeString, + "sas_logical_jbod": { Optional: true, + Type: schema.TypeSet, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "description": { + Type: schema.TypeString, + Optional: true, + }, + "device_slot": { + Type: schema.TypeString, + Optional: true, + }, + "drive_max_size_gb": { + Type: schema.TypeInt, + Optional: true, + }, + "drive_min_size_gb": { + Type: schema.TypeInt, + Optional: true, + }, + "drive_technology": { + Type: schema.TypeString, + Optional: true, + }, + "erase_data": { + Type: schema.TypeBool, + Optional: true, + }, + "id": { + Type: schema.TypeInt, + Optional: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + }, + "num_physical_drive": { + Type: schema.TypeInt, + Optional: true, + }, + "persistent": { + Type: schema.TypeBool, + Optional: true, + }, + }, + }, }, }, }, @@ -756,29 +858,69 @@ func resourceServerProfileTemplateCreate(d *schema.ResourceData, meta interface{ } serverProfileTemplate.Firmware = firmware } + // Get local storage data if provided rawLocalStorage := d.Get("local_storage").(*schema.Set).List() localStorage := ov.LocalStorageOptions{} for _, raw := range rawLocalStorage { localStorageItem := raw.(map[string]interface{}) + // Gets Local Storage Controller body + rawLocalStorageController := localStorageItem["controller"].(*schema.Set).List() + localStorageEmbeddedController := make([]ov.LocalStorageEmbeddedController, 0) + for _, raw2 := range rawLocalStorageController { + controllerData := raw2.(map[string]interface{}) + // Gets Local Storage Controller's Logical Drives + rawLogicalDrives := controllerData["logical_drives"].(*schema.Set).List() + logicalDrives := make([]ov.LogicalDriveV3, 0) + for _, rawLogicalDrive := range rawLogicalDrives { + logicalDrivesItem := rawLogicalDrive.(map[string]interface{}) + logicalDrives = append(logicalDrives, ov.LogicalDriveV3{ + Bootable: logicalDrivesItem["bootable"].(bool), + RaidLevel: logicalDrivesItem["raid_level"].(string), + Accelerator: logicalDrivesItem["accelerator"].(string), + DriveTechnology: logicalDrivesItem["drive_technology"].(string), + Name: logicalDrivesItem["name"].(string), + NumPhysicalDrives: logicalDrivesItem["num_physical_drives"].(int), + NumSpareDrives: logicalDrivesItem["num_spare_drives"].(int), + SasLogicalJBODId: logicalDrivesItem["sas_logical_jbod_id"].(int), + }) + } + localStorageEmbeddedController = append(localStorageEmbeddedController, ov.LocalStorageEmbeddedController{ + DeviceSlot: controllerData["device_slot"].(string), + DriveWriteCache: controllerData["drive_write_cache"].(string), + Initialize: controllerData["initialize"].(bool), + Mode: controllerData["mode"].(string), + PredictiveSpareRebuild: controllerData["predictive_spare_rebuild"].(string), + LogicalDrives: logicalDrives, + }) + } + // Gets Local Storage Sas Jbods Body + rawLocalStorageSasJbod := localStorageItem["sas_logical_jbod"].(*schema.Set).List() + logicalJbod := make([]ov.LogicalJbod, 0) + for _, raw3 := range rawLocalStorageSasJbod { + sasLogicalJbodData := raw3.(map[string]interface{}) + logicalJbod = append(logicalJbod, ov.LogicalJbod{ + Description: sasLogicalJbodData["description"].(string), + DeviceSlot: sasLogicalJbodData["device_slot"].(string), + DriveMaxSizeGB: sasLogicalJbodData["drive_max_size_gb"].(int), + DriveMinSizeGB: sasLogicalJbodData["drive_min_size_gb"].(int), + DriveTechnology: sasLogicalJbodData["drive_technology"].(string), + EraseData: sasLogicalJbodData["erase_data"].(bool), + ID: sasLogicalJbodData["id"].(int), + Name: sasLogicalJbodData["name"].(string), + NumPhysicalDrives: sasLogicalJbodData["num_physical_drive"].(int), + Persistent: sasLogicalJbodData["persistent"].(bool), + }) + } localStorage = ov.LocalStorageOptions{ ManageLocalStorage: localStorageItem["manage_local_storage"].(bool), Initialize: localStorageItem["initialize"].(bool), + Controllers: localStorageEmbeddedController, + SasLogicalJBODs: logicalJbod, } } serverProfileTemplate.LocalStorage = localStorage - rawLogicalDrives := d.Get("logical_drives").(*schema.Set).List() - logicalDrives := make([]ov.LogicalDrive, 0) - for _, rawLogicalDrive := range rawLogicalDrives { - logicalDrivesItem := rawLogicalDrive.(map[string]interface{}) - logicalDrives = append(logicalDrives, ov.LogicalDrive{ - Bootable: logicalDrivesItem["bootable"].(bool), - RaidLevel: logicalDrivesItem["raid_level"].(string), - }) - } - serverProfileTemplate.LocalStorage.LogicalDrives = logicalDrives - // get SAN storage data if provided rawSanStorage := d.Get("san_storage").(*schema.Set).List() sanStorage := ov.SanStorageOptions{} @@ -831,14 +973,14 @@ func resourceServerProfileTemplateCreate(d *schema.ResourceData, meta interface{ IsCompressed: propertyItem["is_compressed"].(bool), IsAdaptiveOptimizationEnabled: propertyItem["is_adaptive_optimization_enabled"].(bool), IsDataReductionEnabled: propertyItem["is_data_reduction_enabled"].(bool), - Name: propertyItem["name"].(string), - PerformancePolicy: propertyItem["performance_policy"].(string), - ProvisioningType: propertyItem["provisioning_type"].(string), - Size: propertyItem["size"].(int), - SnapshotPool: utils.NewNstring(propertyItem["snapshot_pool"].(string)), - StoragePool: utils.NewNstring(propertyItem["storage_pool"].(string)), - TemplateVersion: propertyItem["template_version"].(string), - VolumeSet: utils.NewNstring(propertyItem["volume_set"].(string)), + Name: propertyItem["name"].(string), + PerformancePolicy: propertyItem["performance_policy"].(string), + ProvisioningType: propertyItem["provisioning_type"].(string), + Size: propertyItem["size"].(int), + SnapshotPool: utils.NewNstring(propertyItem["snapshot_pool"].(string)), + StoragePool: utils.NewNstring(propertyItem["storage_pool"].(string)), + TemplateVersion: propertyItem["template_version"].(string), + VolumeSet: utils.NewNstring(propertyItem["volume_set"].(string)), } } } @@ -890,11 +1032,11 @@ func resourceServerProfileTemplateCreate(d *schema.ResourceData, meta interface{ VolumeURI: utils.NewNstring(volumeAttachmentItem["volume_uri"].(string)), VolumeStorageSystemURI: utils.NewNstring(volumeAttachmentItem["volume_storage_system_uri"].(string)), AssociatedTemplateAttachmentId: volumeAttachmentItem["associated_template_attachment_id"].(string), - State: volumeAttachmentItem["state"].(string), - Status: volumeAttachmentItem["status"].(string), - StoragePaths: storagePaths, - BootVolumePriority: volumeAttachmentItem["boot_volume_priority"].(string), - Volume: &volumes, + State: volumeAttachmentItem["state"].(string), + Status: volumeAttachmentItem["status"].(string), + StoragePaths: storagePaths, + BootVolumePriority: volumeAttachmentItem["boot_volume_priority"].(string), + Volume: &volumes, }) } serverProfileTemplate.SanStorage.VolumeAttachments = volumeAttachments @@ -1003,6 +1145,74 @@ func resourceServerProfileTemplateRead(d *schema.ResourceData, meta interface{}) d.Set("boot_order", bootOrder) } + overriddenSettings := make([]interface{}, 0, len(spt.Bios.OverriddenSettings)) + for _, overriddenSetting := range spt.Bios.OverriddenSettings { + overriddenSettings = append(overriddenSettings, map[string]interface{}{ + "id": overriddenSetting.ID, + "value": overriddenSetting.Value, + }) + } + if spt.Bios != nil { + biosOptions := make([]map[string]interface{}, 0, 1) + biosOptions = append(biosOptions, map[string]interface{}{ + "manage_bios": spt.Bios.ManageBios, + "overridden_settings": overriddenSettings, + }) + + d.Set("bios_option", biosOptions) + } + + // Gets Local Storage Body + localStorage := make([]map[string]interface{}, 0, 1) + // Gets Storage Controller Body + controllers := make([]map[string]interface{}, 0, len(spt.LocalStorage.Controllers)) + for i := 0; i < len(spt.LocalStorage.Controllers); i++ { + logicalDrives := make([]map[string]interface{}, 0, len(spt.LocalStorage.Controllers[i].LogicalDrives)) + for j := 0; j < len(spt.LocalStorage.Controllers[i].LogicalDrives); j++ { + logicalDrives = append(logicalDrives, map[string]interface{}{ + "bootable": spt.LocalStorage.Controllers[i].LogicalDrives[j].Bootable, + "accelerator": spt.LocalStorage.Controllers[i].LogicalDrives[j].Accelerator, + "drive_technology": spt.LocalStorage.Controllers[i].LogicalDrives[j].DriveTechnology, + "name": spt.LocalStorage.Controllers[i].LogicalDrives[j].Name, + "num_physical_drives": spt.LocalStorage.Controllers[i].LogicalDrives[j].NumPhysicalDrives, + "num_spare_drives": spt.LocalStorage.Controllers[i].LogicalDrives[j].NumSpareDrives, + "sas_logical_jbod_id": spt.LocalStorage.Controllers[i].LogicalDrives[j].SasLogicalJBODId, + "raid_level": spt.LocalStorage.Controllers[i].LogicalDrives[j].RaidLevel, + }) + } + controllers = append(controllers, map[string]interface{}{ + "device_slot": spt.LocalStorage.Controllers[i].DeviceSlot, + "initialize": spt.LocalStorage.Controllers[i].Initialize, + "drive_write_cache": spt.LocalStorage.Controllers[i].DriveWriteCache, + "mode": spt.LocalStorage.Controllers[i].Mode, + "predictive_spare_rebuild": spt.LocalStorage.Controllers[i].PredictiveSpareRebuild, + "logical_drive": logicalDrives, + }) + } + // Gets Sas Logical Jbod Controller Body + sasLogDrives := make([]map[string]interface{}, 0, len(spt.LocalStorage.SasLogicalJBODs)) + for i := 0; i < len(spt.LocalStorage.SasLogicalJBODs); i++ { + sasLogDrives = append(sasLogDrives, map[string]interface{}{ + "description": spt.LocalStorage.SasLogicalJBODs[i].Description, + "device_slot": spt.LocalStorage.SasLogicalJBODs[i].DeviceSlot, + "drive_max_size_gb": spt.LocalStorage.SasLogicalJBODs[i].DriveMaxSizeGB, + "drive_min_size_sb": spt.LocalStorage.SasLogicalJBODs[i].DriveMinSizeGB, + "drive_technology": spt.LocalStorage.SasLogicalJBODs[i].DriveTechnology, + "erase_data": spt.LocalStorage.SasLogicalJBODs[i].EraseData, + "id": spt.LocalStorage.SasLogicalJBODs[i].ID, + "name": spt.LocalStorage.SasLogicalJBODs[i].Name, + "num_physical_drive": spt.LocalStorage.SasLogicalJBODs[i].NumPhysicalDrives, + "persistent": spt.LocalStorage.SasLogicalJBODs[i].Persistent, + }) + } + localStorage = append(localStorage, map[string]interface{}{ + "manage_local_storage": spt.LocalStorage.ManageLocalStorage, + "initialize": spt.LocalStorage.Initialize, + "controller": controllers, + "sas_logical_jbod": sasLogDrives, + }) + d.Set("local_storage", localStorage) + return nil } @@ -1102,6 +1312,33 @@ func resourceServerProfileTemplateUpdate(d *schema.ResourceData, meta interface{ serverProfileTemplate.Boot.Order = bootOrder } + if val, ok := d.GetOk("bios_option"); ok { + // Gets Bios Options + rawBiosOption := val.(*schema.Set).List() + biosOption := ov.BiosOption{} + for _, raw := range rawBiosOption { + rawBiosItem := raw.(map[string]interface{}) + // Gets OverRiddenSettings for Bios Options + overriddenSettings := make([]ov.BiosSettings, 0) + rawoverRiddenSettings := rawBiosItem["overridden_settings"].(*schema.Set).List() + // Gets OverRidden Settings on overriddenSettings + for _, vall := range rawoverRiddenSettings { + rawOverriddenSettingItem := vall.(map[string]interface{}) + overriddenSettings = append(overriddenSettings, ov.BiosSettings{ + ID: rawOverriddenSettingItem["id"].(string), + Value: rawOverriddenSettingItem["value"].(string), + }) + } + // Gets Bios Options with OverRidden Settings on biosOption + biosOption = ov.BiosOption{ + ManageBios: rawBiosItem["manage_bios"].(bool), + OverriddenSettings: overriddenSettings, + } + } + // Applies biosOption to Payload + serverProfileTemplate.Bios = &biosOption + } + if _, ok := d.GetOk("firmware"); ok { rawFirmware := d.Get("firmware").(*schema.Set).List() firmware := ov.FirmwareOption{} @@ -1120,29 +1357,66 @@ func resourceServerProfileTemplateUpdate(d *schema.ResourceData, meta interface{ } serverProfileTemplate.Firmware = firmware } + // Get local storage data if provided rawLocalStorage := d.Get("local_storage").(*schema.Set).List() localStorage := ov.LocalStorageOptions{} for _, raw := range rawLocalStorage { localStorageItem := raw.(map[string]interface{}) + rawLocalStorageController := localStorageItem["controller"].(*schema.Set).List() + localStorageEmbeddedController := make([]ov.LocalStorageEmbeddedController, 0) + for _, raw2 := range rawLocalStorageController { + controllerData := raw2.(map[string]interface{}) + rawLogicalDrives := controllerData["logical_drives"].(*schema.Set).List() + logicalDrives := make([]ov.LogicalDriveV3, 0) + for _, rawLogicalDrive := range rawLogicalDrives { + logicalDrivesItem := rawLogicalDrive.(map[string]interface{}) + logicalDrives = append(logicalDrives, ov.LogicalDriveV3{ + Bootable: logicalDrivesItem["bootable"].(bool), + RaidLevel: logicalDrivesItem["raid_level"].(string), + Accelerator: logicalDrivesItem["accelerator"].(string), + DriveTechnology: logicalDrivesItem["drive_technology"].(string), + Name: logicalDrivesItem["name"].(string), + NumPhysicalDrives: logicalDrivesItem["num_physical_drives"].(int), + NumSpareDrives: logicalDrivesItem["num_spare_drives"].(int), + SasLogicalJBODId: logicalDrivesItem["sas_logical_jbod_id"].(int), + }) + } + localStorageEmbeddedController = append(localStorageEmbeddedController, ov.LocalStorageEmbeddedController{ + DeviceSlot: controllerData["device_slot"].(string), + DriveWriteCache: controllerData["drive_write_cache"].(string), + Initialize: controllerData["initialize"].(bool), + Mode: controllerData["mode"].(string), + PredictiveSpareRebuild: controllerData["predictive_spare_rebuild"].(string), + LogicalDrives: logicalDrives, + }) + } + rawLocalStorageSasJbod := localStorageItem["sas_logical_jbod"].(*schema.Set).List() + logicalJbod := make([]ov.LogicalJbod, 0) + for _, raw3 := range rawLocalStorageSasJbod { + sasLogicalJbodData := raw3.(map[string]interface{}) + logicalJbod = append(logicalJbod, ov.LogicalJbod{ + Description: sasLogicalJbodData["description"].(string), + DeviceSlot: sasLogicalJbodData["device_slot"].(string), + DriveMaxSizeGB: sasLogicalJbodData["drive_max_size_gb"].(int), + DriveMinSizeGB: sasLogicalJbodData["drive_min_size_gb"].(int), + DriveTechnology: sasLogicalJbodData["drive_technology"].(string), + EraseData: sasLogicalJbodData["erase_data"].(bool), + ID: sasLogicalJbodData["id"].(int), + Name: sasLogicalJbodData["name"].(string), + NumPhysicalDrives: sasLogicalJbodData["num_physical_drive"].(int), + Persistent: sasLogicalJbodData["persistent"].(bool), + }) + } localStorage = ov.LocalStorageOptions{ ManageLocalStorage: localStorageItem["manage_local_storage"].(bool), Initialize: localStorageItem["initialize"].(bool), + Controllers: localStorageEmbeddedController, + SasLogicalJBODs: logicalJbod, } } serverProfileTemplate.LocalStorage = localStorage - rawLogicalDrives := d.Get("logical_drives").(*schema.Set).List() - logicalDrives := make([]ov.LogicalDrive, 0) - for _, rawLogicalDrive := range rawLogicalDrives { - logicalDrivesItem := rawLogicalDrive.(map[string]interface{}) - logicalDrives = append(logicalDrives, ov.LogicalDrive{ - Bootable: logicalDrivesItem["bootable"].(bool), - RaidLevel: logicalDrivesItem["raid_level"].(string), - }) - } - serverProfileTemplate.LocalStorage.LogicalDrives = logicalDrives - // get SAN storage data if provided rawSanStorage := d.Get("san_storage").(*schema.Set).List() sanStorage := ov.SanStorageOptions{} @@ -1192,14 +1466,14 @@ func resourceServerProfileTemplateUpdate(d *schema.ResourceData, meta interface{ IsCompressed: propertyItem["is_compressed"].(bool), IsAdaptiveOptimizationEnabled: propertyItem["is_adaptive_optimization_enabled"].(bool), IsDataReductionEnabled: propertyItem["is_data_reduction_enabled"].(bool), - Name: propertyItem["name"].(string), - PerformancePolicy: propertyItem["performance_policy"].(string), - ProvisioningType: propertyItem["provisioning_type"].(string), - Size: propertyItem["size"].(int), - SnapshotPool: utils.NewNstring(propertyItem["snapshot_pool"].(string)), - StoragePool: utils.NewNstring(propertyItem["storage_pool"].(string)), - TemplateVersion: propertyItem["template_version"].(string), - VolumeSet: utils.NewNstring(propertyItem["volume_set"].(string)), + Name: propertyItem["name"].(string), + PerformancePolicy: propertyItem["performance_policy"].(string), + ProvisioningType: propertyItem["provisioning_type"].(string), + Size: propertyItem["size"].(int), + SnapshotPool: utils.NewNstring(propertyItem["snapshot_pool"].(string)), + StoragePool: utils.NewNstring(propertyItem["storage_pool"].(string)), + TemplateVersion: propertyItem["template_version"].(string), + VolumeSet: utils.NewNstring(propertyItem["volume_set"].(string)), } } } @@ -1249,11 +1523,11 @@ func resourceServerProfileTemplateUpdate(d *schema.ResourceData, meta interface{ VolumeURI: utils.NewNstring(volumeAttachmentItem["volume_uri"].(string)), VolumeStorageSystemURI: utils.NewNstring(volumeAttachmentItem["volume_storage_system_uri"].(string)), AssociatedTemplateAttachmentId: volumeAttachmentItem["associated_template_attachment_id"].(string), - State: volumeAttachmentItem["state"].(string), - Status: volumeAttachmentItem["status"].(string), - StoragePaths: storagePaths, - BootVolumePriority: volumeAttachmentItem["boot_volume_priority"].(string), - Volume: &volumes, + State: volumeAttachmentItem["state"].(string), + Status: volumeAttachmentItem["status"].(string), + StoragePaths: storagePaths, + BootVolumePriority: volumeAttachmentItem["boot_volume_priority"].(string), + Volume: &volumes, }) } serverProfileTemplate.SanStorage.VolumeAttachments = volumeAttachments diff --git a/vendor/github.com/HewlettPackard/oneview-golang/ov/profiles.go b/vendor/github.com/HewlettPackard/oneview-golang/ov/profiles.go index c384ba17..0592b4f3 100644 --- a/vendor/github.com/HewlettPackard/oneview-golang/ov/profiles.go +++ b/vendor/github.com/HewlettPackard/oneview-golang/ov/profiles.go @@ -44,7 +44,7 @@ type BootModeOption struct { ManageMode bool `json:"manageMode"` // "manageMode": true, Mode string `json:"mode,omitempty"` // "mode": "BIOS", PXEBootPolicy utils.Nstring `json:"pxeBootPolicy,omitempty"` // "pxeBootPolicy": null - secureBoot string `json:"secureBoot,omitempty"` // Enable or disable UEFI Secure Boot + SecureBoot string `json:"secureBoot,omitempty"` // Enable or disable UEFI Secure Boot } // BootManagement management