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 distributed virtual switches and portgroups #4813

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

czunker
Copy link
Contributor

@czunker czunker commented Nov 5, 2024

This adds these to the vShere datacenter.
Now you can query:

vsphere.datacenters { distributedPortgroups { name properties } }

and

vsphere.datacenters {distributedSwitches {*} }

This comment has been minimized.

Copy link
Contributor

github-actions bot commented Nov 5, 2024

Test Results

3 131 tests  ±0   3 130 ✅ ±0   1m 27s ⏱️ -2s
  371 suites ±0       1 💤 ±0 
   28 files   ±0       0 ❌ ±0 

Results for commit 960c6b4. ± Comparison against base commit 8e42171.

♻️ This comment has been updated with latest results.

@czunker czunker requested a review from mm-weber November 5, 2024 07:53
@mm-weber
Copy link
Contributor

mm-weber commented Nov 6, 2024

Great stuff, thank you @czunker !

There's just two minor things I noticed while testing:

  1. It seems the same portgroup is shown twice below a datacenter:
    image

  2. The provider panics when using this command vsphere.datacenters {distributedSwitches {*} }
    -> yet I can access the elements as desired if I know the name, e.g. vsphere.datacenters {distributedSwitches {properties} } works as expected.

cnquery> vsphere.datacenters {distributedSwitches {*} }
panic: reflect: call of reflect.Value.Type on zero Value

goroutine 170 [running]:
reflect.Value.typeSlow({0x0?, 0x0?, 0x25af0c3?})
	/home/manuel/.gvm/gos/go1.23.1/src/reflect/value.go:2687 +0x10e
reflect.Value.Type(...)
	/home/manuel/.gvm/gos/go1.23.1/src/reflect/value.go:2682
go.mondoo.com/cnquery/v11/providers/vsphere/resources.(*mqlVsphereVswitchDvs).uplinks(0xc002b7c000)
	/home/manuel/go/src/go.mondoo.io/cnquery/providers/vsphere/resources/network.go:169 +0x166
go.mondoo.com/cnquery/v11/providers/vsphere/resources.(*mqlVsphereVswitchDvs).GetUplinks.func1()
	/home/manuel/go/src/go.mondoo.io/cnquery/providers/vsphere/resources/vsphere.lr.go:2592 +0x8b
go.mondoo.com/cnquery/v11/providers-sdk/v1/plugin.GetOrCompute[...](0xc002b7c080?, 0xc0031f6174)
	/home/manuel/go/src/go.mondoo.io/cnquery/providers-sdk/v1/plugin/runtime.go:269 +0x3a
go.mondoo.com/cnquery/v11/providers/vsphere/resources.(*mqlVsphereVswitchDvs).GetUplinks(0xc0031f60e0?)
	/home/manuel/go/src/go.mondoo.io/cnquery/providers/vsphere/resources/vsphere.lr.go:2581 +0x39
go.mondoo.com/cnquery/v11/providers/vsphere/resources.init.func78({0x2931c30?, 0xc002b7c000?})
	/home/manuel/go/src/go.mondoo.io/cnquery/providers/vsphere/resources/vsphere.lr.go:421 +0x30
go.mondoo.com/cnquery/v11/providers/vsphere/resources.GetData({0x2931c30, 0xc002b7c000}, {0xc0004e4d00, 0x7}, 0x200000003?)
	/home/manuel/go/src/go.mondoo.io/cnquery/providers/vsphere/resources/vsphere.lr.go:569 +0x16b
go.mondoo.com/cnquery/v11/providers-sdk/v1/plugin.(*Service).GetData(0x249fb80?, 0xc003320f50)
	/home/manuel/go/src/go.mondoo.io/cnquery/providers-sdk/v1/plugin/service.go:189 +0x323
go.mondoo.com/cnquery/v11/providers.(*Runtime).watchAndUpdate(0xc0007ffc80, {0xc0031ca9f2, 0x13}, {0xc002eddee0, 0x10}, {0xc0004e4d00, 0x7}, {0x0?, 0xc0031f64f0?})
	/home/manuel/go/src/go.mondoo.io/cnquery/providers/runtime.go:402 +0x2cc
go.mondoo.com/cnquery/v11/providers.(*Runtime).WatchAndUpdate(0xc0007ffc80, {0x292de58, 0xc00154ef00}, {0xc0004e4d00, 0x7}, {0xc0031da7c0, 0x32}, 0xc00333a990)
	/home/manuel/go/src/go.mondoo.io/cnquery/providers/runtime.go:367 +0xb2
go.mondoo.com/cnquery/v11/llx.runResourceFunction(0xc003320ee0, 0xc00333a720?, 0xc00332e0a0, 0x300000004)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/builtin.go:800 +0x26d
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runBoundFunction(0xc003320ee0, 0xc00333a720, 0xc00332e0a0, 0x300000004)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/builtin.go:874 +0xe5
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runFunction(0xc003320ee0, 0xc00332e0a0, 0x300000004)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:816 +0x173
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runChunk(0xc003320ee0, 0x1fe5ac0?, 0x300000004)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:833 +0x225
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runRef(0xc00333c0d0?, 0x46d05d?)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:858 +0xd9
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runChain(0xc003320ee0, 0x25ae00e?)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:890 +0x9c
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).run(0xc003320ee0)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:358 +0x32d
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runFunctionBlock(0xc003320cb0, {0xc0022d1b78, 0x1, 0xc00333a750?}, 0x300000000, 0xc0008712c0)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:589 +0x17c
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runFunctionBlocks(0xc003320cb0, {0xc0008712a8, 0x1, 0x0?}, 0x300000000, 0xc0005d5e00?)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:560 +0x107
go.mondoo.com/cnquery/v11/llx.arrayBlockListV2(0xc003320cb0, 0xc00333a690, 0xc00332e0f0, 0x200000003)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/builtin_array.go:147 +0x579
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runBoundFunction(0xc003320cb0, 0xc00333a690, 0xc00332e0f0, 0x200000003)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/builtin.go:861 +0x108
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runFunction(0xc003320cb0, 0xc00332e0f0, 0x200000003)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:816 +0x173
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runChunk(0xc003320cb0, 0x1fe5ac0?, 0x200000003)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:833 +0x225
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runRef(0xc00333c000?, 0xc00333c0a0?)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:858 +0xd9
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runChain(0xc003320cb0, 0xc00333a480?)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:890 +0x9c
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).triggerChain(0xc003320cb0, 0x200000002, 0xc00333a690)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:962 +0x365
go.mondoo.com/cnquery/v11/llx.runResourceFunction.func1({0x1e50420, 0xc000871290}, {0x0, 0x0})
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/builtin.go:819 +0x219
go.mondoo.com/cnquery/v11/providers.(*Runtime).WatchAndUpdate(0xc0007ffc80, {0x292de58, 0xc00154ee60}, {0xc0031ca5d0, 0x13}, {0xc0031da740, 0x31}, 0xc00333a5d0)
	/home/manuel/go/src/go.mondoo.io/cnquery/providers/runtime.go:369 +0xe2
go.mondoo.com/cnquery/v11/llx.runResourceFunction(0xc003320cb0, 0xc00333a2d0?, 0xc0031c5ae0, 0x200000002)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/builtin.go:800 +0x26d
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runBoundFunction(0xc003320cb0, 0xc00333a2d0, 0xc0031c5ae0, 0x200000002)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/builtin.go:874 +0xe5
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runFunction(0xc003320cb0, 0xc0031c5ae0, 0x200000002)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:816 +0x173
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runChunk(0xc003320cb0, 0x1fe5ac0?, 0x200000002)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:833 +0x225
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runRef(0xc00333c000?, 0x46d05d?)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:858 +0xd9
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runChain(0xc003320cb0, 0x25ae00e?)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:890 +0x9c
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).run(0xc003320cb0)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:358 +0x32d
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runFunctionBlock(0xc003320930, {0xc0022d1b58, 0x1, 0xc00333a330?}, 0x200000000, 0xc000871218)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:589 +0x17c
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runFunctionBlocks(0xc003320930, {0xc00333a2a0, 0x2, 0x0?}, 0x200000000, 0xc0005d5e00?)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:560 +0x107
go.mondoo.com/cnquery/v11/llx.arrayBlockListV2(0xc003320930, 0xc00333a210, 0xc00332e140, 0x100000003)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/builtin_array.go:147 +0x579
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runBoundFunction(0xc003320930, 0xc00333a210, 0xc00332e140, 0x100000003)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/builtin.go:861 +0x108
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runFunction(0xc003320930, 0xc00332e140, 0x100000003)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:816 +0x173
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runChunk(0xc003320930, 0x1fe5ac0?, 0x100000003)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:833 +0x225
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runRef(0xc002e7fed0?, 0xc00154ee40?)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:858 +0xd9
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runChain(0xc003320930, 0xc003317ef0?)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:890 +0x9c
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).triggerChain(0xc003320930, 0x100000002, 0xc00333a210)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:962 +0x365
go.mondoo.com/cnquery/v11/llx.runResourceFunction.func1({0x1e50420, 0xc000871200}, {0x0, 0x0})
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/builtin.go:819 +0x219
go.mondoo.com/cnquery/v11/providers.(*Runtime).WatchAndUpdate(0xc0007ffc80, {0x292de58, 0xc00154ee20}, {0xc002eddaa0, 0xb}, {0xc0031da700, 0x31}, 0xc00333a120)
	/home/manuel/go/src/go.mondoo.io/cnquery/providers/runtime.go:369 +0xe2
go.mondoo.com/cnquery/v11/llx.runResourceFunction(0xc003320930, 0xc00333a090?, 0xc0031c59a0, 0x100000002)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/builtin.go:800 +0x26d
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runBoundFunction(0xc003320930, 0xc00333a090, 0xc0031c59a0, 0x100000002)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/builtin.go:874 +0xe5
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runFunction(0xc003320930, 0xc0031c59a0, 0x100000002)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:816 +0x173
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runChunk(0xc003320930, 0x1fe5ac0?, 0x100000002)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:833 +0x225
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runRef(0xc002e7fed0?, 0xc003317ef0?)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:858 +0xd9
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).runChain(0xc003320930, 0x25ae00e?)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:890 +0x9c
go.mondoo.com/cnquery/v11/llx.(*blockExecutor).run(0xc003320930)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:358 +0x32d
go.mondoo.com/cnquery/v11/llx.(*MQLExecutorV2).Run(0xc00332c000?)
	/home/manuel/go/src/go.mondoo.io/cnquery/llx/llx.go:288 +0x53
go.mondoo.com/cnquery/v11/mql/internal.(*executionManager).executeCodeBundle(0xc00332c420, 0xc0031b4d20, 0xc003317e30, {0x0, 0x0})
	/home/manuel/go/src/go.mondoo.io/cnquery/mql/internal/execution_manager.go:170 +0x4cc
go.mondoo.com/cnquery/v11/mql/internal.(*executionManager).Start.func1()
	/home/manuel/go/src/go.mondoo.io/cnquery/mql/internal/execution_manager.go:88 +0x1cb
created by go.mondoo.com/cnquery/v11/mql/internal.(*executionManager).Start in goroutine 1
	/home/manuel/go/src/go.mondoo.io/cnquery/mql/internal/execution_manager.go:57 +0x65

@czunker czunker force-pushed the czunker/vsphere_dvs branch from d5b3444 to aaee31d Compare November 7, 2024 14:56

This comment has been minimized.

@czunker czunker force-pushed the czunker/vsphere_dvs branch from aaee31d to c6b5429 Compare November 7, 2024 15:13
@czunker
Copy link
Contributor Author

czunker commented Nov 7, 2024

Thanks for testing @mm-weber

The issues are fixed:

... -c "vsphere.datacenters { distributedPortgroups { name } }"
→ loaded configuration from /etc/opt/mondoo/mondoo.yml using source default
vsphere.datacenters: [
  0: {
    distributedPortgroups: [
      0: {
        name: "DPortGroup-DeleteME"
      }
      1: {
        name: "DSwitch-DeleteMe-DVUplinks-6145"
      }
    ]
  }
  1: {
    distributedPortgroups: []
  }
]
-c "vsphere.datacenters {distributedSwitches {*} }" 
→ loaded configuration from /etc/opt/mondoo/mondoo.yml using source default
vsphere.datacenters: [
  0: {
    distributedSwitches: [
      0: {
        properties: {
          alarmActionsEnabled: true
          availableField: null
          capability: {
            compatibleHostComponentProductInfo: [
              0: {
                productLineId: "embeddedEsx"
                version: "e.x.p"
              }
              1: {
                productLineId: "embeddedEsx"
                version: "6.6<"
              }
            ]

@czunker czunker force-pushed the czunker/vsphere_dvs branch from c6b5429 to f25b8a0 Compare November 7, 2024 15:17
@@ -128,7 +128,7 @@ require (
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/skeema/knownhosts v1.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/pflag v1.0.6-0.20201009195203-85dd5c8bc61c // indirect
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Otherwise the tests failed:

--> [mondoo] generate CLI json
go: updates to go.mod needed; to update it:
	go mod tidy
make: *** [Makefile:379: providers/build/mondoo] Error 1
Error: Process completed with exit code 2.

@czunker czunker force-pushed the czunker/vsphere_dvs branch from f25b8a0 to 33dbc5e Compare November 8, 2024 05:24
Copy link
Contributor

@mm-weber mm-weber left a comment

Choose a reason for hiding this comment

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

This works nicely!
Thank you @czunker !

Copy link
Member

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

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

Thank you @czunker I added a nit for the resource field. Otherwise looks great.

// Distributed virtual switches
distributedSwitches() []vsphere.vswitch.dvs
// List of distributed virtual port groups
distributedPortgroups() []vsphere.vswitch.portgroup
Copy link
Member

Choose a reason for hiding this comment

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

maybe distributedPortGroups

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed.
VMware uses separate words for it:

A distributed port group ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mm-weber FYI
You might need to change this also in the policy.

This adds these to the vShere datacenter

Signed-off-by: Christian Zunker <christian@mondoo.com>
@czunker czunker force-pushed the czunker/vsphere_dvs branch from 4dc6e7f to 960c6b4 Compare November 13, 2024 08:45
@czunker czunker merged commit 6bc317c into main Nov 13, 2024
15 checks passed
@czunker czunker deleted the czunker/vsphere_dvs branch November 13, 2024 08:59
@github-actions github-actions bot locked and limited conversation to collaborators Nov 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants