github.com/netdata/go.d.plugin@v0.58.1/modules/vsphere/resources/resources.go (about)

     1  // SPDX-License-Identifier: GPL-3.0-or-later
     2  
     3  package resources
     4  
     5  import (
     6  	"github.com/vmware/govmomi/performance"
     7  	"github.com/vmware/govmomi/vim25/types"
     8  )
     9  
    10  /*
    11  
    12  ```
    13  Virtual Datacenter Architecture Representation (partial).
    14  
    15  <root>
    16  +-DC0 # Virtual datacenter
    17     +-datastore # Datastore folder (created by system)
    18     | +-Datastore1
    19     |
    20     +-host # Host folder (created by system)
    21     | +-Folder1 # Host and Cluster folder
    22     | | +-NestedFolder1
    23     | | | +-Cluster1
    24     | | | | +-Host1
    25     | +-Cluster2
    26     | | +-Host2
    27     | | | +-VM1
    28     | | | +-VM2
    29     | | | +-hadoop1
    30     | +-Host3 # Dummy folder for non-clustered host (created by system)
    31     | | +-Host3
    32     | | | +-VM3
    33     | | | +-VM4
    34     | | |
    35     +-vm # VM folder (created by system)
    36     | +-VM1
    37     | +-VM2
    38     | +-Folder2 # VM and Template folder
    39     | | +-hadoop1
    40     | | +-NestedFolder1
    41     | | | +-VM3
    42     | | | +-VM4
    43  ```
    44  */
    45  
    46  type Resources struct {
    47  	DataCenters DataCenters
    48  	Folders     Folders
    49  	Clusters    Clusters
    50  	Hosts       Hosts
    51  	VMs         VMs
    52  }
    53  
    54  type (
    55  	Datacenter struct {
    56  		Name string
    57  		ID   string
    58  	}
    59  
    60  	Folder struct {
    61  		Name     string
    62  		ID       string
    63  		ParentID string
    64  	}
    65  
    66  	HierarchyValue struct {
    67  		ID, Name string
    68  	}
    69  
    70  	ClusterHierarchy struct {
    71  		DC HierarchyValue
    72  	}
    73  	Cluster struct {
    74  		Name     string
    75  		ID       string
    76  		ParentID string
    77  		Hier     ClusterHierarchy
    78  	}
    79  
    80  	HostHierarchy struct {
    81  		DC      HierarchyValue
    82  		Cluster HierarchyValue
    83  	}
    84  	Host struct {
    85  		Name          string
    86  		ID            string
    87  		ParentID      string
    88  		Hier          HostHierarchy
    89  		OverallStatus string
    90  		MetricList    performance.MetricList
    91  		Ref           types.ManagedObjectReference
    92  	}
    93  
    94  	VMHierarchy struct {
    95  		DC      HierarchyValue
    96  		Cluster HierarchyValue
    97  		Host    HierarchyValue
    98  	}
    99  
   100  	VM struct {
   101  		Name          string
   102  		ID            string
   103  		ParentID      string
   104  		Hier          VMHierarchy
   105  		OverallStatus string
   106  		MetricList    performance.MetricList
   107  		Ref           types.ManagedObjectReference
   108  	}
   109  )
   110  
   111  func (v HierarchyValue) IsSet() bool          { return v.ID != "" && v.Name != "" }
   112  func (v *HierarchyValue) Set(id, name string) { v.ID = id; v.Name = name }
   113  
   114  func (h ClusterHierarchy) IsSet() bool { return h.DC.IsSet() }
   115  func (h HostHierarchy) IsSet() bool    { return h.DC.IsSet() && h.Cluster.IsSet() }
   116  func (h VMHierarchy) IsSet() bool      { return h.DC.IsSet() && h.Cluster.IsSet() && h.Host.IsSet() }
   117  
   118  type (
   119  	DataCenters map[string]*Datacenter
   120  	Folders     map[string]*Folder
   121  	Clusters    map[string]*Cluster
   122  	Hosts       map[string]*Host
   123  	VMs         map[string]*VM
   124  )
   125  
   126  func (dcs DataCenters) Put(dc *Datacenter)        { dcs[dc.ID] = dc }
   127  func (dcs DataCenters) Get(id string) *Datacenter { return dcs[id] }
   128  func (fs Folders) Put(folder *Folder)             { fs[folder.ID] = folder }
   129  func (fs Folders) Get(id string) *Folder          { return fs[id] }
   130  func (cs Clusters) Put(cluster *Cluster)          { cs[cluster.ID] = cluster }
   131  func (cs Clusters) Get(id string) *Cluster        { return cs[id] }
   132  func (hs Hosts) Put(host *Host)                   { hs[host.ID] = host }
   133  func (hs Hosts) Remove(id string)                 { delete(hs, id) }
   134  func (hs Hosts) Get(id string) *Host              { return hs[id] }
   135  func (vs VMs) Put(vm *VM)                         { vs[vm.ID] = vm }
   136  func (vs VMs) Remove(id string)                   { delete(vs, id) }
   137  func (vs VMs) Get(id string) *VM                  { return vs[id] }