diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index d8fde7e830..c1c8105b48 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -103,3 +103,4 @@ vulnerabilityassessmentsettings vulnmgmt wil xssmatchstatement +portgroup diff --git a/go.mod b/go.mod index 42b87bf166..a54bee24f0 100644 --- a/go.mod +++ b/go.mod @@ -82,7 +82,7 @@ require ( github.com/spdx/tools-golang v0.5.5 github.com/spf13/afero v1.11.0 github.com/spf13/cobra v1.8.1 - github.com/spf13/pflag v1.0.5 + github.com/spf13/pflag v1.0.6-0.20201009195203-85dd5c8bc61c github.com/spf13/viper v1.19.0 github.com/stretchr/testify v1.9.0 github.com/toravir/csd v0.0.0-20200911003203-13ae77ad849c diff --git a/go.sum b/go.sum index 6d98f16d18..7c07c92cca 100644 --- a/go.sum +++ b/go.sum @@ -860,8 +860,9 @@ github.com/spf13/cobra v1.3.0/go.mod h1:BrRVncBjOJa/eUcVVm9CE+oC6as8k+VYr4NY7WCi github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/pflag v1.0.6-0.20201009195203-85dd5c8bc61c h1:zqmyTlQyufRC65JnImJ6H1Sf7BDj8bG31EV919NVEQc= +github.com/spf13/pflag v1.0.6-0.20201009195203-85dd5c8bc61c/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.10.0/go.mod h1:SoyBPwAtKDzypXNDFKN5kzH7ppppbGZtls1UpIy5AsM= github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI= github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg= diff --git a/providers/mondoo/go.mod b/providers/mondoo/go.mod index 193c3ffdc9..135b3484f5 100644 --- a/providers/mondoo/go.mod +++ b/providers/mondoo/go.mod @@ -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 github.com/xanzy/ssh-agent v0.3.3 // indirect go.mondoo.com/ranger-rpc v0.6.4 // indirect go.opencensus.io v0.24.0 // indirect diff --git a/providers/mondoo/go.sum b/providers/mondoo/go.sum index ab1198b7bc..1cedf98414 100644 --- a/providers/mondoo/go.sum +++ b/providers/mondoo/go.sum @@ -331,8 +331,8 @@ github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sS github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60= github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/pflag v1.0.6-0.20201009195203-85dd5c8bc61c h1:zqmyTlQyufRC65JnImJ6H1Sf7BDj8bG31EV919NVEQc= +github.com/spf13/pflag v1.0.6-0.20201009195203-85dd5c8bc61c/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= diff --git a/providers/vsphere/resources/datacenter.go b/providers/vsphere/resources/datacenter.go index 482a018e77..ca1bdc53cc 100644 --- a/providers/vsphere/resources/datacenter.go +++ b/providers/vsphere/resources/datacenter.go @@ -4,6 +4,7 @@ package resources import ( + "context" "fmt" "github.com/vmware/govmomi/object" @@ -178,3 +179,92 @@ func (v *mqlVsphereDatacenter) vms() ([]interface{}, error) { return mqlVms, nil } + +func (v *mqlVsphereDatacenter) distributedSwitches() ([]interface{}, error) { + conn := v.MqlRuntime.Connection.(*connection.VsphereConnection) + client := getClientInstance(conn) + + if v.InventoryPath.Error != nil { + return nil, v.InventoryPath.Error + } + path := v.InventoryPath.Data + if path == "" { + path = "/" + } + + vswitches, err := client.GetDistributedVirtualSwitches(context.Background(), path) + if err != nil { + return nil, err + } + + mqlVswitches := make([]interface{}, len(vswitches)) + for i, s := range vswitches { + + config, err := client.GetDistributedVirtualSwitchConfig(context.Background(), s) + if err != nil { + return nil, err + } + configMap, err := resourceclient.DistributedVirtualSwitchConfig(config) + if err != nil { + return nil, err + } + + mqlVswitch, err := CreateResource(v.MqlRuntime, "vsphere.vswitch.dvs", map[string]*llx.RawData{ + "moid": llx.StringData(s.Reference().Encode()), + "name": llx.StringData(s.Name()), + "properties": llx.DictData(configMap), + }) + if err != nil { + return nil, err + } + + // store host inventory path, so that sub resources can use that to quickly query more + r := mqlVswitch.(*mqlVsphereVswitchDvs) + r.hostInventoryPath = s.InventoryPath + + mqlVswitches[i] = mqlVswitch + } + + return mqlVswitches, nil +} + +func (v *mqlVsphereDatacenter) distributedPortGroups() ([]interface{}, error) { + if v.InventoryPath.Error != nil { + return nil, v.InventoryPath.Error + } + path := v.InventoryPath.Data + conn := v.MqlRuntime.Connection.(*connection.VsphereConnection) + client := resourceclient.New(conn.Client()) + + distPGs, err := client.GetDistributedVirtualPortgroups(context.Background(), path) + if err != nil { + return nil, err + } + + mqlPGs := make([]interface{}, len(distPGs)) + for i, distPG := range distPGs { + config, err := client.GetDistributedVirtualPortgroupConfig(context.Background(), distPG) + if err != nil { + return nil, err + } + + configMap, err := resourceclient.DistributedVirtualPortgroupConfig(config) + if err != nil { + return nil, err + } + + name := distPG.Name() + mqlDistPG, err := NewResource(v.MqlRuntime, "vsphere.vswitch.portgroup", map[string]*llx.RawData{ + "moid": llx.StringData(distPG.Reference().Encode()), + "name": llx.StringData(name), + "properties": llx.DictData(configMap), + }) + if err != nil { + return nil, err + } + + mqlPGs[i] = mqlDistPG.(*mqlVsphereVswitchPortgroup) + } + + return mqlPGs, nil +} diff --git a/providers/vsphere/resources/network.go b/providers/vsphere/resources/network.go index b6dadb1e6f..b125fafa39 100644 --- a/providers/vsphere/resources/network.go +++ b/providers/vsphere/resources/network.go @@ -157,10 +157,14 @@ func (v *mqlVsphereVswitchDvs) uplinks() ([]interface{}, error) { return nil, nil } - uplinksRaw := properties["Uplinks"] + uplinksRaw, ok := properties["Uplinks"] + if !ok { + // no uplinks for dvs + return nil, nil + } - // no uplinks for dvs - if properties == nil { + // empty uplinks for dvs + if uplinksRaw == nil { return nil, nil } @@ -177,3 +181,7 @@ func (v *mqlVsphereVswitchDvs) uplinks() ([]interface{}, error) { // get all host adapter return findHostAdapter(v.parentResource, uplinkNames) } + +func (v *mqlVsphereVswitchPortgroup) id() (string, error) { + return v.Name.Data, v.Name.Error +} diff --git a/providers/vsphere/resources/resourceclient/network.go b/providers/vsphere/resources/resourceclient/network.go new file mode 100644 index 0000000000..207ec8d46c --- /dev/null +++ b/providers/vsphere/resources/resourceclient/network.go @@ -0,0 +1,137 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + +package resourceclient + +import ( + "context" + "errors" + "strings" + + "github.com/rs/zerolog/log" + "github.com/vmware/govmomi/find" + "github.com/vmware/govmomi/object" + "github.com/vmware/govmomi/vim25/mo" +) + +func (c *Client) GetDistributedVirtualSwitches(ctx context.Context, path string) ([]*object.DistributedVirtualSwitch, error) { + finder := find.NewFinder(c.Client.Client, true) + mos, err := finder.ManagedObjectListChildren(ctx, path) + if err != nil { + return nil, err + } + if len(mos) == 0 { + return nil, nil + } + + var dvSwitches []*object.DistributedVirtualSwitch + for _, item := range mos { + if !strings.HasSuffix(item.Path, "/network") { + continue + } + log.Debug().Str("object", item.String()).Msg("???") + ref := item.Object.Reference() + log.Debug().Str("ref", ref.Type).Msg("???") + networkMos, err := finder.ManagedObjectListChildren(ctx, item.Path) + if err != nil { + return nil, err + } + for _, networkMo := range networkMos { + log.Debug().Str("networkMo", networkMo.String()).Msg("???") + if networkMo.Object.Reference().Type == "DistributedVirtualSwitch" || networkMo.Object.Reference().Type == "VmwareDistributedVirtualSwitch" { + dvpg, err := finder.Network(ctx, networkMo.Path) + if err != nil { + return nil, err + } + casted, ok := dvpg.(*object.DistributedVirtualSwitch) + if !ok { + return nil, errors.New("not a DistributedVirtualSwitch reference") + } + dvSwitches = append(dvSwitches, casted) + } + } + } + + return dvSwitches, nil +} + +func (c *Client) GetDistributedVirtualSwitchConfig(ctx context.Context, obj *object.DistributedVirtualSwitch) (*mo.DistributedVirtualSwitch, error) { + var moDvSwitch mo.DistributedVirtualSwitch + err := obj.Properties(ctx, obj.Reference(), nil, &moDvSwitch) + if err != nil { + return nil, err + } + + return &moDvSwitch, nil +} + +func DistributedVirtualSwitchConfig(dvSwitch *mo.DistributedVirtualSwitch) (map[string]interface{}, error) { + return PropertiesToDict(dvSwitch) +} + +func (c *Client) GetDistributedVirtualPortgroups(ctx context.Context, path string) ([]*object.DistributedVirtualPortgroup, error) { + finder := find.NewFinder(c.Client.Client, true) + pathParts := strings.Split(path, "/") + if len(pathParts) < 2 { + return nil, nil + } + dcPath := "/" + pathParts[1] + dc, err := c.Datacenter(dcPath) + if err != nil { + return nil, err + } + finder.SetDatacenter(dc) + + mos, err := finder.ManagedObjectListChildren(ctx, dcPath) + if err != nil { + return nil, err + } + if len(mos) == 0 { + return nil, nil + } + + var pgs []*object.DistributedVirtualPortgroup + for _, item := range mos { + if !strings.HasSuffix(item.Path, "/network") { + continue + } + log.Debug().Str("object", item.String()).Msg("???") + ref := item.Object.Reference() + log.Debug().Str("ref", ref.Type).Msg("???") + networkMos, err := finder.ManagedObjectListChildren(ctx, item.Path) + if err != nil { + return nil, err + } + for _, networkMo := range networkMos { + log.Debug().Str("networkMo", networkMo.String()).Msg("???") + if networkMo.Object.Reference().Type == "DistributedVirtualPortgroup" { + dvpg, err := finder.Network(ctx, networkMo.Path) + if err != nil { + return nil, err + } + casted, ok := dvpg.(*object.DistributedVirtualPortgroup) + if !ok { + return nil, errors.New("not a DistributedVirtualPortgroup reference") + } + + pgs = append(pgs, casted) + } + } + } + + return pgs, nil +} + +func (c *Client) GetDistributedVirtualPortgroupConfig(ctx context.Context, obj *object.DistributedVirtualPortgroup) (*mo.DistributedVirtualPortgroup, error) { + var moDvpg mo.DistributedVirtualPortgroup + err := obj.Properties(ctx, obj.Reference(), nil, &moDvpg) + if err != nil { + return nil, err + } + + return &moDvpg, nil +} + +func DistributedVirtualPortgroupConfig(dvpg *mo.DistributedVirtualPortgroup) (map[string]interface{}, error) { + return PropertiesToDict(dvpg) +} diff --git a/providers/vsphere/resources/vsphere.lr b/providers/vsphere/resources/vsphere.lr index 1fb15b3543..e8fd21776f 100644 --- a/providers/vsphere/resources/vsphere.lr +++ b/providers/vsphere/resources/vsphere.lr @@ -132,6 +132,10 @@ private vsphere.datacenter @defaults("moid name") { vms() []vsphere.vm // Clusters in the datacenter clusters() []vsphere.cluster + // Distributed virtual switches + distributedSwitches() []vsphere.vswitch.dvs + // List of distributed virtual port groups + distributedPortGroups() []vsphere.vswitch.portgroup } // vSphere cluster resource @@ -216,6 +220,8 @@ private vsphere.vswitch.standard @defaults("name") { // vSphere distributed virtual switch private vsphere.vswitch.dvs @defaults("name") { + // vSphere managed object ID + moid string // Virtual switch name name string // Virtual switch properties @@ -224,6 +230,16 @@ private vsphere.vswitch.dvs @defaults("name") { uplinks() []vsphere.vmnic } +// vSphere distributed virtual port group +private vsphere.vswitch.portgroup @defaults("name") { + // vSphere managed object ID + moid string + // Port group name + name string + // Port group properties + properties dict +} + // vSphere ESXi physical network interface resource private vsphere.vmnic @defaults("name") { // NIC name diff --git a/providers/vsphere/resources/vsphere.lr.go b/providers/vsphere/resources/vsphere.lr.go index 842a848182..75c1fd9716 100644 --- a/providers/vsphere/resources/vsphere.lr.go +++ b/providers/vsphere/resources/vsphere.lr.go @@ -82,6 +82,10 @@ func init() { // to override args, implement: initVsphereVswitchDvs(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createVsphereVswitchDvs, }, + "vsphere.vswitch.portgroup": { + // to override args, implement: initVsphereVswitchPortgroup(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createVsphereVswitchPortgroup, + }, "vsphere.vmnic": { // to override args, implement: initVsphereVmnic(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createVsphereVmnic, @@ -305,6 +309,12 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "vsphere.datacenter.clusters": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlVsphereDatacenter).GetClusters()).ToDataRes(types.Array(types.Resource("vsphere.cluster"))) }, + "vsphere.datacenter.distributedSwitches": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlVsphereDatacenter).GetDistributedSwitches()).ToDataRes(types.Array(types.Resource("vsphere.vswitch.dvs"))) + }, + "vsphere.datacenter.distributedPortGroups": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlVsphereDatacenter).GetDistributedPortGroups()).ToDataRes(types.Array(types.Resource("vsphere.vswitch.portgroup"))) + }, "vsphere.cluster.moid": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlVsphereCluster).GetMoid()).ToDataRes(types.String) }, @@ -401,6 +411,9 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "vsphere.vswitch.standard.uplinks": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlVsphereVswitchStandard).GetUplinks()).ToDataRes(types.Array(types.Resource("vsphere.vmnic"))) }, + "vsphere.vswitch.dvs.moid": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlVsphereVswitchDvs).GetMoid()).ToDataRes(types.String) + }, "vsphere.vswitch.dvs.name": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlVsphereVswitchDvs).GetName()).ToDataRes(types.String) }, @@ -410,6 +423,15 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "vsphere.vswitch.dvs.uplinks": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlVsphereVswitchDvs).GetUplinks()).ToDataRes(types.Array(types.Resource("vsphere.vmnic"))) }, + "vsphere.vswitch.portgroup.moid": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlVsphereVswitchPortgroup).GetMoid()).ToDataRes(types.String) + }, + "vsphere.vswitch.portgroup.name": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlVsphereVswitchPortgroup).GetName()).ToDataRes(types.String) + }, + "vsphere.vswitch.portgroup.properties": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlVsphereVswitchPortgroup).GetProperties()).ToDataRes(types.Dict) + }, "vsphere.vmnic.name": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlVsphereVmnic).GetName()).ToDataRes(types.String) }, @@ -762,6 +784,14 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlVsphereDatacenter).Clusters, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, + "vsphere.datacenter.distributedSwitches": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlVsphereDatacenter).DistributedSwitches, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, + "vsphere.datacenter.distributedPortGroups": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlVsphereDatacenter).DistributedPortGroups, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, "vsphere.cluster.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlVsphereCluster).__id, ok = v.Value.(string) return @@ -910,6 +940,10 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlVsphereVswitchDvs).__id, ok = v.Value.(string) return }, + "vsphere.vswitch.dvs.moid": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlVsphereVswitchDvs).Moid, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "vsphere.vswitch.dvs.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlVsphereVswitchDvs).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) return @@ -922,6 +956,22 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlVsphereVswitchDvs).Uplinks, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, + "vsphere.vswitch.portgroup.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlVsphereVswitchPortgroup).__id, ok = v.Value.(string) + return + }, + "vsphere.vswitch.portgroup.moid": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlVsphereVswitchPortgroup).Moid, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "vsphere.vswitch.portgroup.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlVsphereVswitchPortgroup).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "vsphere.vswitch.portgroup.properties": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlVsphereVswitchPortgroup).Properties, ok = plugin.RawToTValue[interface{}](v.Value, v.Error) + return + }, "vsphere.vmnic.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlVsphereVmnic).__id, ok = v.Value.(string) return @@ -1871,6 +1921,8 @@ type mqlVsphereDatacenter struct { Hosts plugin.TValue[[]interface{}] Vms plugin.TValue[[]interface{}] Clusters plugin.TValue[[]interface{}] + DistributedSwitches plugin.TValue[[]interface{}] + DistributedPortGroups plugin.TValue[[]interface{}] } // createVsphereDatacenter creates a new instance of this resource @@ -1970,6 +2022,38 @@ func (c *mqlVsphereDatacenter) GetClusters() *plugin.TValue[[]interface{}] { }) } +func (c *mqlVsphereDatacenter) GetDistributedSwitches() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.DistributedSwitches, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("vsphere.datacenter", c.__id, "distributedSwitches") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } + } + + return c.distributedSwitches() + }) +} + +func (c *mqlVsphereDatacenter) GetDistributedPortGroups() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.DistributedPortGroups, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("vsphere.datacenter", c.__id, "distributedPortGroups") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } + } + + return c.distributedPortGroups() + }) +} + // mqlVsphereCluster for the vsphere.cluster resource type mqlVsphereCluster struct { MqlRuntime *plugin.Runtime @@ -2457,6 +2541,7 @@ type mqlVsphereVswitchDvs struct { MqlRuntime *plugin.Runtime __id string mqlVsphereVswitchDvsInternal + Moid plugin.TValue[string] Name plugin.TValue[string] Properties plugin.TValue[interface{}] Uplinks plugin.TValue[[]interface{}] @@ -2499,6 +2584,10 @@ func (c *mqlVsphereVswitchDvs) MqlID() string { return c.__id } +func (c *mqlVsphereVswitchDvs) GetMoid() *plugin.TValue[string] { + return &c.Moid +} + func (c *mqlVsphereVswitchDvs) GetName() *plugin.TValue[string] { return &c.Name } @@ -2523,6 +2612,65 @@ func (c *mqlVsphereVswitchDvs) GetUplinks() *plugin.TValue[[]interface{}] { }) } +// mqlVsphereVswitchPortgroup for the vsphere.vswitch.portgroup resource +type mqlVsphereVswitchPortgroup struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlVsphereVswitchPortgroupInternal it will be used here + Moid plugin.TValue[string] + Name plugin.TValue[string] + Properties plugin.TValue[interface{}] +} + +// createVsphereVswitchPortgroup creates a new instance of this resource +func createVsphereVswitchPortgroup(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlVsphereVswitchPortgroup{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("vsphere.vswitch.portgroup", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlVsphereVswitchPortgroup) MqlName() string { + return "vsphere.vswitch.portgroup" +} + +func (c *mqlVsphereVswitchPortgroup) MqlID() string { + return c.__id +} + +func (c *mqlVsphereVswitchPortgroup) GetMoid() *plugin.TValue[string] { + return &c.Moid +} + +func (c *mqlVsphereVswitchPortgroup) GetName() *plugin.TValue[string] { + return &c.Name +} + +func (c *mqlVsphereVswitchPortgroup) GetProperties() *plugin.TValue[interface{}] { + return &c.Properties +} + // mqlVsphereVmnic for the vsphere.vmnic resource type mqlVsphereVmnic struct { MqlRuntime *plugin.Runtime diff --git a/providers/vsphere/resources/vsphere.lr.manifest.yaml b/providers/vsphere/resources/vsphere.lr.manifest.yaml index ca58d786bc..b90e968661 100644 --- a/providers/vsphere/resources/vsphere.lr.manifest.yaml +++ b/providers/vsphere/resources/vsphere.lr.manifest.yaml @@ -166,6 +166,14 @@ resources: vsphere.datacenter: fields: clusters: {} + distributedPortGroups: + min_mondoo_version: 9.0.0 + distributedPortgroups: + min_mondoo_version: 9.0.0 + distributedSwitches: + min_mondoo_version: 9.0.0 + distributedVirtualPortgroups: + min_mondoo_version: 9.0.0 hosts: {} inventoryPath: {} moid: {} @@ -273,7 +281,11 @@ resources: - vmware-vsphere vsphere.vswitch.dvs: fields: + moid: + min_mondoo_version: 9.0.0 name: {} + portgroups: + min_mondoo_version: 9.0.0 properties: {} uplinks: {} is_private: true @@ -282,6 +294,26 @@ resources: name: - vmware-esxi - vmware-vsphere + vsphere.vswitch.dvs.portgroup: + fields: + config: {} + name: {} + min_mondoo_version: 9.0.0 + platform: + name: + - vmware-esxi + - vmware-vsphere + vsphere.vswitch.portgroup: + fields: + moid: {} + name: {} + properties: {} + is_private: true + min_mondoo_version: 9.0.0 + platform: + name: + - vmware-esxi + - vmware-vsphere vsphere.vswitch.standard: fields: failoverPolicy: {}