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

Please add NumUplinkPorts= parameter to dvs.create #2314

Closed
haydonryan opened this issue Mar 9, 2021 · 9 comments · Fixed by #2771
Closed

Please add NumUplinkPorts= parameter to dvs.create #2314

haydonryan opened this issue Mar 9, 2021 · 9 comments · Fixed by #2771

Comments

@haydonryan
Copy link
Contributor

Hi There,

I noticed that when using PowerShell you are able to specify the number of uplink ports on a Distributed Virtual Switch. Would it be possible to add that to govc as well, please?

Thanks in advance.

@dougm
Copy link
Member

dougm commented Mar 10, 2021

In general, it is possible for govc to provide the same functionality as PowerCLI, since both use the same APIs. But we as maintainers of govc don't know the entire API landscape, so any additional details/context you can provide would be most helpful. Such as:

  • example PowerCLI command including input/output
  • links to any relevant PowerCLI docs for the command(s)

@haydonryan
Copy link
Contributor Author

I'm not surprised I tried to look through the vSphere API and instantly got lost on how big it is. Thinking of possibly doing a PR myself but that could take a while, since I'm not super advanced with golang and it's been a while..

I was following Will Lamb's guide setting up Tanzu, but trying to convert it to govc:
New-VDSwitch -Server $vc -Name $VDSName -Location (Get-Datacenter -Name $DatacenterName) -NumUplinkPorts 1
https://github.com/lamw/vsphere-with-tanzu-homelab-scripts/blob/4396f568dd8d35966cc310b60dd1e5e56dd47e16/setup_vcsa.ps1#L35

@dougm
Copy link
Member

dougm commented Mar 11, 2021

If you want to create a PR that'd be great, here's some info on how to start. That PowerCLI snippet helps a lot. I ran vcsim like so:

% vcsim -l :8989 -trace-file vcsim.log

Created the DVS like so:

PS /root> Connect-VIServer -Server 10.0.0.241 -User user -Password 'pass' -Port 8989
PS /root> New-VDSwitch -Name VDS -Location (Get-Datacenter -Name DC0) -NumUplinkPorts 1

From vcsim.log, xmlformat of the CreateDVS_Task request:

  <CreateDVS_Task xmlns="urn:vim25">
   <_this type="Folder">folder-6</_this>
   <spec>
    <configSpec xsi:type="VMwareDVSConfigSpec">
     <name>VDS</name>
     <uplinkPortPolicy xsi:type="DVSNameArrayUplinkPortPolicy">
      <uplinkPortName>dvUplink1</uplinkPortName>
     </uplinkPortPolicy>
     <contact/>
    </configSpec>
   </spec>
  </CreateDVS_Task>

Doing that in govc would be something like the following (untested):

modified   govc/dvs/create.go
@@ -94,6 +94,15 @@ func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {
 		}
 	}
 
+	numUplinkPorts := 1 // TODO: cmd.numUplinkPorts
+	if numUplinkPorts > 0 {
+		var policy types.DVSNameArrayUplinkPortPolicy
+		for i := 0; i < numUplinkPorts; i++ {
+			policy.UplinkPortName = append(policy.UplinkPortName, fmt.Sprintf("dvUplink%d", i+1))
+		}
+		cmd.configSpec.UplinkPortPolicy = &policy
+	}
+
 	folder, err := cmd.FolderOrDefault("network")
 	if err != nil {
 		return err

@haydonryan
Copy link
Contributor Author

I'm happy to give it a go, it's just going to take a bit to be able to focus/learn (currently changing jobs)

@haydonryan
Copy link
Contributor Author

Your code worked :) I tested it, and plumbed the flag into the variable. I did change the name of the uplink to match the default in Center. Is there an easy way to put both our names on the commit since you wrote the meat of the code?

haydonryan added a commit to haydonryan/govmomi that referenced this issue Jun 29, 2021
adding flag to control number of uplink ports when creating a new distributed switch

Closes: vmware#2314
@github-actions
Copy link
Contributor

This issue is stale because it has been open for 90 days with no
activity. It will automatically close after 30 more days of
inactivity. Mark as fresh by adding the comment /remove-lifecycle stale.

@haydonryan
Copy link
Contributor Author

haydonryan commented Sep 22, 2021

I'm just really slow with this due to an increased workload. apologies.

@haydonryan
Copy link
Contributor Author

/remove-lifecycle stale

@github-actions
Copy link
Contributor

This issue is stale because it has been open for 90 days with no
activity. It will automatically close after 30 more days of
inactivity. Mark as fresh by adding the comment /remove-lifecycle stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment