diff --git a/CHANGELOG.md b/CHANGELOG.md index f20341c4d..c273c6b8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html - This release supports API4400 minimally where we can use OneView v7.20 with this SDK. #### Major Changes +1. Added datasource to get the relative value for a given portname and interconnect type. + ### Bug fixes & Enhancements: - [#467](https://github.com/HewlettPackard/terraform-provider-oneview/issues/467) Adding/Removing/Updating an uplinkset to a LIG will also modify the whole LIG diff --git a/docs/d/relative_value.html.markdown b/docs/d/relative_value.html.markdown new file mode 100644 index 000000000..b6d2abb3f --- /dev/null +++ b/docs/d/relative_value.html.markdown @@ -0,0 +1,35 @@ +--- +layout: "oneview" +page_title: "Oneview: Uplink port relative value" +sidebar_current: "docs-relative_value" +description: |- + Gets relative value of a given port name +--- + +# oneview\_relative value + +Use this data source to get the relative value for a given port name + +## Example Usage + +```hcl +data "oneview_relative_value" "rv"{ + port_name="Q2:1" + interconnect_type_name="Virtual Connect SE 40Gb F8 Module for Synergy" +} + +output "oneview_relative_value" { + value = "${oneview_relative_value.rv.port_num}" +} +``` + +## Argument Reference + +* `port_name` - (Required) The name of the enclsoure. +* `interconnect_type_name`- (Required)" The name of interconnect type + +## Attributes Reference + +* `port_name` - (Required) The name of the enclsoure. +* `interconnect_type_name`- (Required)" The name of interconnect type +* `port_num` - The relative value corresponding to the port name \ No newline at end of file diff --git a/examples/logical_interconnect_groups/main.tf b/examples/logical_interconnect_groups/main.tf index 1c0669857..9601f8c8b 100644 --- a/examples/logical_interconnect_groups/main.tf +++ b/examples/logical_interconnect_groups/main.tf @@ -8,18 +8,34 @@ provider "oneview" { } data "oneview_ethernet_network" "eth" { - name = "Auto-Ethernet-1" + name = "Auto-Ethernet-1" } data "oneview_fc_network" "fc" { - name = "FC_FA" + name = "FC_FA" } -# Create Logical Interconnect Group +data "oneview_fc_network" "fc1" { + name = "FC_FA1" +} + +data "oneview_relative_value" "rv1"{ + port_name="Q1" + interconnect_type_name="Virtual Connect SE 40Gb F8 Module for Synergy" +} +data "oneview_relative_value" "rv2"{ + port_name="Q2:1" + interconnect_type_name="Virtual Connect SE 40Gb F8 Module for Synergy" +} +data "oneview_relative_value" "rv3"{ + port_name="Q2:2" + interconnect_type_name="Virtual Connect SE 40Gb F8 Module for Synergy" +} +#Create Logical Interconnect Group resource "oneview_logical_interconnect_group" "logical_interconnect_group" { type = "logical-interconnect-groupV8" - name = "Auto-LIG-02" + name = "Auto-LIG-09-1" interconnect_bay_set = 3 enclosure_indexes = [1, 2, 3] redundancy_type = "HighlyAvailable" @@ -61,49 +77,52 @@ resource "oneview_logical_interconnect_group" "logical_interconnect_group" { prevent_flooding = true proxy_reporting = true } - + + uplink_set { + ethernet_network_type = "Tagged" + lacp_timer = "Short" + mode = "Auto" + name = "UplinkSet1" + network_type = "Ethernet" + network_uris = [ + data.oneview_ethernet_network.eth.uri, + ] + logical_port_config { + bay_num = 3 + desired_fec_mode = "Auto" + desired_speed = "Auto" + enclosure_num = 1 + port_num = data.oneview_relative_value.rv1.port_num + primary_port = false + } + } + + + uplink_set { ethernet_network_type = "NotApplicable" mode = "Auto" - name = "UplinkSet2" + name = "UplinkSet2" network_type = "FibreChannel" - network_uris = [ - data.oneview_fc_network.fc.uri, + network_uris = [ + data.oneview_fc_network.fc.uri, ] - -# from OV6.3 we have changed the way we provide port_num, instaed of list we have to provide integer value for each logical_port_config + # from OV6.3 we have changed the way we provide port_num, instaed of list we have to provide integer value for each logical_port_config logical_port_config { - bay_num = 3 - desired_speed = "Auto" - enclosure_num = 1 - port_num = 68 - primary_port = false - } - + bay_num = 3 + desired_speed = "Auto" + desired_fec_mode = "Auto" + enclosure_num = 1 + port_num = data.oneview_relative_value.rv2.port_num + primary_port = false + } logical_port_config { - bay_num = 3 - desired_speed = "Auto" - enclosure_num = 1 - port_num = 67 - primary_port = false - } - } - uplink_set { - ethernet_network_type = "Tagged" - lacp_timer = "Short" - mode = "Auto" - name = "UplinkSet1" - network_type = "Ethernet" - network_uris = [ - data.oneview_ethernet_network.eth.uri, - ] - - logical_port_config { - bay_num = 3 - desired_speed = "Auto" - enclosure_num = 1 - port_num = 61 - primary_port = false - } - } + bay_num = 3 + desired_speed = "Auto" + desired_fec_mode = "Auto" + enclosure_num = 1 + port_num = data.oneview_relative_value.rv3.port_num + primary_port = false + } + } } diff --git a/oneview/data_source_relatve_value.go b/oneview/data_source_relatve_value.go new file mode 100644 index 000000000..672634df8 --- /dev/null +++ b/oneview/data_source_relatve_value.go @@ -0,0 +1,59 @@ +// (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. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-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. + +package oneview + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func dataSourceRelativeValue() *schema.Resource { + return &schema.Resource{ + Read: dataSourceRelativeValueRead, + + Schema: map[string]*schema.Schema{ + "port_name": { + Type: schema.TypeString, + Required: true, + }, + "interconnect_type_name": { + Type: schema.TypeString, + Required: true, + }, + "port_num": { + Type: schema.TypeInt, + Computed: true, + }, + }, + } +} + +func dataSourceRelativeValueRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + portName := d.Get("port_name").(string) + interconnectTypeName := d.Get("interconnect_type_name").(string) + interconnectType, _ := config.ovClient.GetInterconnectTypeByName(interconnectTypeName) + portNum, err := config.ovClient.GetRelativeValue(portName, interconnectType.URI) + + if err != nil { + d.SetId("") + return err + } + + d.SetId(portName) + + d.Set("port_name", portName) + d.Set("port_num", portNum) + d.Set("interrconnect_type", interconnectType) + + return nil +} diff --git a/oneview/provider.go b/oneview/provider.go index a8b33a645..ae309f3ab 100644 --- a/oneview/provider.go +++ b/oneview/provider.go @@ -106,6 +106,7 @@ func Provider() *schema.Provider { "oneview_uplink_set": dataSourceUplinkSet(), "oneview_volume": dataSourceVolume(), "oneview_version": dataSourceVersion(), + "oneview_relative_value": dataSourceRelativeValue(), }, ResourcesMap: map[string]*schema.Resource{