-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support GetAll for ethernet resource #313
Open
yuvirani
wants to merge
7
commits into
master
Choose a base branch
from
Ethernet_Get_All
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9f15f18
Support getAll for ethernet resource
yuvirani dbdfb7f
Fix Members
yuvirani c18f453
Add GetById
yuvirani 345f1e1
Remove get_type
yuvirani 5d00853
Import schema from file
yuvirani 22c2807
Schema with members attribute
yuvirani 18c1148
Create folder for schema
yuvirani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package common_schema | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func EthernetSchema() *schema.Resource { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported function EthernetSchema should have comment or be unexported |
||
return &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"vlan_id": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
ForceNew: true, | ||
}, | ||
"purpose": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "General", | ||
}, | ||
"private_network": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: false, | ||
}, | ||
"smart_link": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: false, | ||
}, | ||
"ethernet_network_type": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "Tagged", | ||
}, | ||
"type": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "ethernet-networkV3", | ||
}, | ||
"connection_template_uri": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"created": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"modified": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"uri": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"category": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"state": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"fabric_uri": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"etag": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"scopesuri": { | ||
Optional: true, | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"initial_scope_uris": { | ||
Optional: true, | ||
Type: schema.TypeSet, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
Set: schema.HashString, | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,92 +13,24 @@ package oneview | |
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/HewlettPackard/terraform-provider-oneview/oneview/common_schema" | ||
) | ||
|
||
func dataSourceEthernetNetwork() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceEthernetNetworkRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"vlan_id": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"purpose": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"private_network": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"smart_link": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"ethernet_network_type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"connection_template_uri": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"created": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"modified": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"uri": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Optional: true, | ||
}, | ||
"category": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"state": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"fabric_uri": { | ||
Type: schema.TypeString, | ||
"members": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
}, | ||
"etag": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"scopesuri": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"initial_scope_uris": { | ||
Computed: true, | ||
Type: schema.TypeSet, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
|
||
Elem: &schema.Resource{ | ||
Schema: common_schema.EthernetSchema().Schema, | ||
}, | ||
Set: schema.HashString, | ||
}, | ||
}, | ||
} | ||
|
@@ -107,29 +39,70 @@ func dataSourceEthernetNetwork() *schema.Resource { | |
func dataSourceEthernetNetworkRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
name := d.Get("name").(string) | ||
eNet, err := config.ovClient.GetEthernetNetworkByName(name) | ||
if err != nil || eNet.URI.IsNil() { | ||
d.SetId("") | ||
|
||
if len(name) > 0 { | ||
eNet, err := config.ovClient.GetEthernetNetworkByName(name) | ||
if err != nil { | ||
d.SetId("") | ||
return nil | ||
} | ||
members := make([]map[string]interface{}, 0, 1) | ||
members = append(members, map[string]interface{}{ | ||
"name": eNet.Name, | ||
"purpose": eNet.Purpose, | ||
"vlan_id": eNet.VlanId, | ||
"smart_link": eNet.SmartLink, | ||
"private_network": eNet.PrivateNetwork, | ||
"ethernet_network_type": eNet.EthernetNetworkType, | ||
"type": eNet.Type, | ||
"created": eNet.Created, | ||
"modified": eNet.Modified, | ||
"uri": eNet.URI.String(), | ||
"connection_template_uri": eNet.ConnectionTemplateUri, | ||
"state": eNet.State, | ||
"status": eNet.Status, | ||
"category": eNet.Category, | ||
"fabric_uri": eNet.FabricUri, | ||
"etag": eNet.ETAG, | ||
"scopesuri": eNet.ScopesUri, | ||
}) | ||
d.Set("members", members) | ||
d.Set("name", eNet.Name) | ||
d.SetId(name) | ||
return nil | ||
|
||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if block ends with a return statement, so drop this else and outdent its block |
||
eNetList, err := config.ovClient.GetEthernetNetworks("", "", "", "") | ||
|
||
if err != nil { | ||
d.SetId("") | ||
return nil | ||
} | ||
members := make([]map[string]interface{}, 0, len(eNetList.Members)) | ||
for _, eNet := range eNetList.Members { | ||
members = append(members, map[string]interface{}{ | ||
"name": eNet.Name, | ||
"purpose": eNet.Purpose, | ||
"vlan_id": eNet.VlanId, | ||
"smart_link": eNet.SmartLink, | ||
"private_network": eNet.PrivateNetwork, | ||
"ethernet_network_type": eNet.EthernetNetworkType, | ||
"type": eNet.Type, | ||
"created": eNet.Created, | ||
"modified": eNet.Modified, | ||
"uri": eNet.URI.String(), | ||
"connection_template_uri": eNet.ConnectionTemplateUri, | ||
"state": eNet.State, | ||
"status": eNet.Status, | ||
"category": eNet.Category, | ||
"fabric_uri": eNet.FabricUri, | ||
"etag": eNet.ETAG, | ||
"scopesuri": eNet.ScopesUri, | ||
}) | ||
} | ||
d.Set("members", members) | ||
d.Set("name", "EthernetList") | ||
d.SetId(string(eNetList.Members[0].URI)) | ||
return nil | ||
} | ||
d.Set("name", eNet.Name) | ||
d.Set("vlan_id", eNet.VlanId) | ||
d.Set("purpose", eNet.Purpose) | ||
d.Set("smart_link", eNet.SmartLink) | ||
d.Set("private_network", eNet.PrivateNetwork) | ||
d.Set("ethernet_network_type", eNet.EthernetNetworkType) | ||
d.Set("type", eNet.Type) | ||
d.Set("created", eNet.Created) | ||
d.Set("modified", eNet.Modified) | ||
d.Set("uri", eNet.URI.String()) | ||
d.Set("connection_template_uri", eNet.ConnectionTemplateUri.String()) | ||
d.Set("status", eNet.Status) | ||
d.Set("category", eNet.Category) | ||
d.Set("state", eNet.State) | ||
d.Set("fabric_uri", eNet.FabricUri.String()) | ||
d.Set("etag", eNet.ETAG) | ||
d.Set("scopesuri", eNet.ScopesUri.String()) | ||
d.Set("initial_scope_uris", eNet.InitialScopeUris) | ||
d.SetId(name) | ||
return nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't use an underscore in package name