Skip to content

Commit

Permalink
Merge pull request #497 from HewlettPackard/portname_relative_value
Browse files Browse the repository at this point in the history
Portname relative value
  • Loading branch information
nabhajit-ray authored Sep 8, 2022
2 parents f69a696 + b1887a5 commit 366d2ec
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 42 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions docs/d/relative_value.html.markdown
Original file line number Diff line number Diff line change
@@ -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
103 changes: 61 additions & 42 deletions examples/logical_interconnect_groups/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}
}
59 changes: 59 additions & 0 deletions oneview/data_source_relatve_value.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions oneview/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 366d2ec

Please sign in to comment.