Skip to content
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

Add vApp network functions #290

Merged
merged 23 commits into from
Mar 5, 2020
Merged

Add vApp network functions #290

merged 23 commits into from
Mar 5, 2020

Conversation

vbauzys
Copy link
Contributor

@vbauzys vbauzys commented Feb 14, 2020

Add new function need for handling vApp networks:

Add AddNetwork, AddNetworkAsync
Add AddOrgNetwork, AddOrgNetworkAsync
Add UpdateNetwork, UpdateNetworkAsync
Add UpdateOrgNetwork, UpdateOrgNetworkAsync
Add RemoveNetwork
Add GetUuidFromHref

Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
@vbauzys vbauzys requested review from dataclouder, lvirbalas and Didainius and removed request for dataclouder and lvirbalas February 14, 2020 12:15
@vbauzys vbauzys self-assigned this Feb 14, 2020
@vbauzys vbauzys requested a review from lvirbalas February 14, 2020 12:15
Signed-off-by: Vaidotas Bauzys <[email protected]>

# Conflicts:
#	CHANGELOG.md
Copy link
Collaborator

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First trivial ask:

The PR subject ("Vapp netw") needs to become a proper sentence with proper words and proper capitalization. Some good examples are here:
hashicorp/terraform-provider-vcd@7a6deb1
hashicorp/terraform-provider-vcd@ae4a431
a453fb9

This is actual to fix now as the last PR got merged with the incomplete PR subject into the log:
hashicorp/terraform-provider-vcd@86fb83f

@vbauzys vbauzys changed the title Vapp netw Add vApp network functions Feb 18, 2020
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Copy link
Collaborator

@Didainius Didainius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First round. I've left many open questions instead of problems yet.

(Changelog confict also waits you :)

govcd/system.go Outdated

// Returns the UUID part of an HREF
// Similar to getBareEntityUuid, but tailored to HREF
func GetUuidFromHref(href string) (string, error) {
Copy link
Collaborator

@Didainius Didainius Feb 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions - do we really need this to be exported? Maybe it could work internally only?
Also - is there any difference between our current private function getUuidFromHref? Can they be wrapped or reused?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This functions used widely in terraform also due that we need get ID from href -> specific vapp network handling. Private function is slight different - regular expression is slight changed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only difference between the regular expressions in public and private functions is that the public one allows text after the UUID.
I think that, instead of adding a function that is 99% the same as another, we should add a parameter to match either open ended or closed strings.
Alternatively, the two functions should have a different name, because getUuidFromHref matches an entity UUID (ID at the end), while GetUuidFromHref matches an UUID from an action HREF (ID/action at the end).

Given that the action is discarded, I suggest this interface:

func GetUuidFromHref(href string, idAtEnd bool) (string, error) {
   searchExpression := `^https://.+/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})`
   if idAtEnd {
      searchExpression +=`$`
   } else {
      searchExpression += `.*$`
   }
   reGetID := regexp.MustCompile(searchExpression)
   // [...]
} 

This way, we use just one function for two needs.

Calls to getUuidFromHref will become GetUuidFromHref(href, true), while calls to GetUuidFromHref will become GetUuidFromHref(href, false)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in favor of a common function as well to avoid duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, change added.

govcd/vapp.go Outdated
NetworkName: newNetworkSettings.Name,
Description: newNetworkSettings.Description,
Configuration: &types.NetworkConfiguration{
FenceMode: types.FenceModeNAT,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct even when isolated network is being created?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improved

Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>

# Conflicts:
#	CHANGELOG.md
govcd/vapp.go Outdated
@@ -786,6 +798,329 @@ func (vapp *VApp) AddIsolatedNetwork(newIsolatedNetworkSettings *VappNetworkSett

}

// AddNetwork creates isolated or nat routed(connected to Org VDC network) network for vApp.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function (and the related Async function) need a better name.
In both AddNetwork and AddOrgNetwork we are passing an OrgVdcNetwork as a parameter, but in one case we are assigning an existing network to the vApp, and in the other we are creating a vApp network.
I think the name in this case should be CreateVappNetwork or AddVappNetwork to avoid confusion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Didainius what is your vote for naming?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are creating a new network here so probably CreateVappNetwork.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

govcd/vapp.go Outdated
return vAppNetworkConfig, nil
}

// RemoveNetworkAsync asyncronously removes any network (be it isolated or connected to an Org Network) from vApp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// RemoveNetworkAsync asyncronously removes any network (be it isolated or connected to an Org Network) from vApp
// RemoveNetworkAsync asynchronously removes any network (be it isolated or connected to an Org Network) from vApp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. updated

govcd/vapp.go Outdated
return vAppNetworkConfig, nil
}

// AddNetworkAsync creates asyncronously isolated or nat routed network for vApp. Returns Task or error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// AddNetworkAsync creates asyncronously isolated or nat routed network for vApp. Returns Task or error
// AddNetworkAsync creates asynchronously isolated or nat routed network for vApp. Returns Task or error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. updated

Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Signed-off-by: Vaidotas Bauzys <[email protected]>
Copy link
Collaborator

@Didainius Didainius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few last comments from me.
Thanks for test fixes

govcd/vapp.go Outdated
@@ -786,6 +798,329 @@ func (vapp *VApp) AddIsolatedNetwork(newIsolatedNetworkSettings *VappNetworkSett

}

// AddNetwork creates isolated or nat routed(connected to Org VDC network) network for vApp.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are creating a new network here so probably CreateVappNetwork.

Copy link
Collaborator

@Didainius Didainius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixes.

Copy link
Contributor

@dataclouder dataclouder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vbauzys vbauzys merged commit 3ba5c93 into vmware:master Mar 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants