本文整理汇总了Golang中github.com/vmware/govmomi/property.DefaultCollector函数的典型用法代码示例。如果您正苦于以下问题:Golang DefaultCollector函数的具体用法?Golang DefaultCollector怎么用?Golang DefaultCollector使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DefaultCollector函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: run
func (p *eventProcessor) run(ctx context.Context, tail bool) error {
if len(p.tailers) == 0 {
return nil
}
var err error
var collectors []types.ManagedObjectReference
for _, t := range p.tailers {
collectors = append(collectors, t.collector)
}
if len(p.tailers) > 1 {
// create and populate a ListView
viewMgr := view.NewManager(p.mgr.Client())
var listView *view.ListView
listView, err = viewMgr.CreateListView(ctx, collectors)
if err != nil {
return err
}
count := 0
// Retrieve the property from the objects in the ListView
err = property.WaitForView(ctx, property.DefaultCollector(p.mgr.Client()), listView.Reference(), collectors[0], []string{latestPageProp}, func(c types.ManagedObjectReference, pc []types.PropertyChange) bool {
if err = p.process(c, pc); err != nil {
return false
}
count++
if count == len(collectors) && !tail {
return true
}
return false
})
return err
}
// only one object to follow
err = property.Wait(ctx, property.DefaultCollector(p.mgr.Client()), collectors[0], []string{latestPageProp}, func(pc []types.PropertyChange) bool {
if err = p.process(collectors[0], pc); err != nil {
return false
}
if !tail {
return true
}
return false
})
return err
}
开发者ID:vmware,项目名称:vic,代码行数:53,代码来源:processor.go
示例2: DetachDisk
func (cmd *vmdk) DetachDisk(vm *object.VirtualMachine) (string, error) {
ctx := context.TODO()
var mvm mo.VirtualMachine
pc := property.DefaultCollector(cmd.Client)
err := pc.RetrieveOne(ctx, vm.Reference(), []string{"config.hardware"}, &mvm)
if err != nil {
return "", err
}
spec := new(configSpec)
dsFile := spec.RemoveDisk(&mvm)
task, err := vm.Reconfigure(ctx, spec.ToSpec())
if err != nil {
return "", err
}
err = task.Wait(ctx)
if err != nil {
return "", err
}
return dsFile, nil
}
开发者ID:vmware,项目名称:vic,代码行数:25,代码来源:vmdk.go
示例3: Run
func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
client, err := cmd.Client()
if err != nil {
return err
}
ns, err := cmd.HostNetworkSystem()
if err != nil {
return err
}
var mns mo.HostNetworkSystem
pc := property.DefaultCollector(client)
err = pc.RetrieveOne(context.TODO(), ns.Reference(), []string{"networkInfo.vswitch"}, &mns)
if err != nil {
return err
}
tw := tabwriter.NewWriter(os.Stdout, 2, 0, 2, ' ', 0)
for i, s := range mns.NetworkInfo.Vswitch {
if i > 0 {
fmt.Fprintln(tw)
}
fmt.Fprintf(tw, "Name:\t%s\n", s.Name)
fmt.Fprintf(tw, "Portgroup:\t%s\n", cmd.keys("key-vim.host.PortGroup-", s.Portgroup))
fmt.Fprintf(tw, "Pnic:\t%s\n", cmd.keys("key-vim.host.PhysicalNic-", s.Pnic))
fmt.Fprintf(tw, "MTU:\t%d\n", s.Mtu)
fmt.Fprintf(tw, "Ports:\t%d\n", s.NumPorts)
fmt.Fprintf(tw, "Ports Available:\t%d\n", s.NumPortsAvailable)
}
return tw.Flush()
}
开发者ID:jak-atx,项目名称:vic,代码行数:35,代码来源:info.go
示例4: LocalDatastores
func (h *Helper) LocalDatastores(ctx context.Context, cr *object.ComputeResource) ([]*object.Datastore, error) {
// List datastores for compute resource
dss, err := cr.Datastores(ctx)
if err != nil {
return nil, err
}
// Filter local datastores
var ldss []*object.Datastore
for _, ds := range dss {
var mds mo.Datastore
err = property.DefaultCollector(h.c).RetrieveOne(ctx, ds.Reference(), nil, &mds)
if err != nil {
return nil, err
}
switch i := mds.Info.(type) {
case *types.VmfsDatastoreInfo:
if i.Vmfs.Local != nil && *i.Vmfs.Local == true {
break
}
default:
continue
}
ds.InventoryPath = mds.Name
ldss = append(ldss, ds)
}
return ldss, nil
}
开发者ID:vmware,项目名称:vic,代码行数:31,代码来源:helper.go
示例5: Hosts
func (c ComputeResource) Hosts(ctx context.Context) ([]*HostSystem, error) {
var cr mo.ComputeResource
err := c.Properties(ctx, c.Reference(), []string{"host"}, &cr)
if err != nil {
return nil, err
}
if len(cr.Host) == 0 {
return nil, nil
}
var hs []mo.HostSystem
pc := property.DefaultCollector(c.Client())
err = pc.Retrieve(ctx, cr.Host, []string{"name"}, &hs)
if err != nil {
return nil, err
}
var hosts []*HostSystem
for _, h := range hs {
host := NewHostSystem(c.Client(), h.Reference())
host.InventoryPath = path.Join(c.InventoryPath, h.Name)
hosts = append(hosts, host)
}
return hosts, nil
}
开发者ID:vmware,项目名称:vic,代码行数:29,代码来源:compute_resource.go
示例6: waitForNetworkingActive
func waitForNetworkingActive(client *govmomi.Client, datacenter, name string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
dc, err := getDatacenter(client, datacenter)
if err != nil {
log.Printf("[ERROR] %#v", err)
return nil, "", err
}
finder := find.NewFinder(client.Client, true)
finder = finder.SetDatacenter(dc)
vm, err := finder.VirtualMachine(context.TODO(), name)
if err != nil {
log.Printf("[ERROR] %#v", err)
return nil, "", err
}
var mvm mo.VirtualMachine
collector := property.DefaultCollector(client.Client)
if err := collector.RetrieveOne(context.TODO(), vm.Reference(), []string{"summary"}, &mvm); err != nil {
log.Printf("[ERROR] %#v", err)
return nil, "", err
}
if mvm.Summary.Guest.IpAddress != "" {
log.Printf("[DEBUG] IP address with DHCP: %v", mvm.Summary.Guest.IpAddress)
return mvm.Summary, "active", err
} else {
log.Printf("[DEBUG] Waiting for IP address")
return nil, "pending", err
}
}
}
开发者ID:mafrosis,项目名称:terraform,代码行数:32,代码来源:resource_vsphere_virtual_machine.go
示例7: WaitForIP
func (v VirtualMachine) WaitForIP(ctx context.Context) (string, error) {
var ip string
p := property.DefaultCollector(v.c)
err := property.Wait(ctx, p, v.Reference(), []string{"guest.ipAddress"}, func(pc []types.PropertyChange) bool {
for _, c := range pc {
if c.Name != "guest.ipAddress" {
continue
}
if c.Op != types.PropertyChangeOpAssign {
continue
}
if c.Val == nil {
continue
}
ip = c.Val.(string)
return true
}
return false
})
if err != nil {
return "", err
}
return ip, nil
}
开发者ID:higebu,项目名称:terraform,代码行数:29,代码来源:virtual_machine.go
示例8: IpAddress
// IpAddress attempts to find the guest IP address using esxcli.
// ESX hosts must be configured with the /Net/GuestIPHack enabled.
// For example:
// $ govc host.esxcli -- system settings advanced set -o /Net/GuestIPHack -i 1
func (g *GuestInfo) IpAddress(vm *object.VirtualMachine) (string, error) {
const any = "0.0.0.0"
var mvm mo.VirtualMachine
pc := property.DefaultCollector(g.c)
err := pc.RetrieveOne(context.TODO(), vm.Reference(), []string{"runtime.host", "config.uuid"}, &mvm)
if err != nil {
return "", err
}
h, err := g.hostInfo(mvm.Runtime.Host)
if err != nil {
return "", err
}
// Normalize uuid, esxcli and mo.VirtualMachine have different formats
uuid := strings.Replace(mvm.Config.Uuid, "-", "", -1)
if wid, ok := h.wids[uuid]; ok {
res, err := h.Run([]string{"network", "vm", "port", "list", "--world-id", wid})
if err != nil {
return "", err
}
for _, val := range res.Values {
if ip, ok := val["IPAddress"]; ok {
if ip[0] != any {
return ip[0], nil
}
}
}
}
return any, nil
}
开发者ID:hmahmood,项目名称:govmomi,代码行数:39,代码来源:guest_info.go
示例9: WaitForMAC
// WaitForMac will wait until VM get mac for all attached nics.
// Returns map "Virtual Network Name": "nic MAC address"
func (vm VirtualMachine) WaitForMAC(ctx context.Context) (map[string]string, error) {
devices, err := vm.Device(ctx)
if err != nil {
log.Errorf("Unable to get device listing for VM")
return nil, err
}
nics := devices.SelectByType(&types.VirtualEthernetCard{})
macs := make(map[string]string)
// device name:network name
nicMappings := make(map[string]string)
for _, nic := range nics {
if n, ok := nic.(types.BaseVirtualEthernetCard); ok {
netName, err := vm.getNetworkName(ctx, n)
if err != nil {
log.Errorf("failed to get network name: %s", err)
return nil, err
}
macs[netName] = ""
nicMappings[devices.Name(nic)] = netName
} else {
log.Errorf("Failed to get network name of vNIC: %v", nic)
return nil, err
}
}
p := property.DefaultCollector(vm.Session.Vim25())
// Wait for all NICs to have a MacAddress, which may not be generated yet.
err = property.Wait(ctx, p, vm.Reference(), []string{"config.hardware.device"}, func(pc []types.PropertyChange) bool {
for _, c := range pc {
if c.Op != types.PropertyChangeOpAssign {
continue
}
changedDevices := c.Val.(types.ArrayOfVirtualDevice).VirtualDevice
for _, device := range changedDevices {
if nic, ok := device.(types.BaseVirtualEthernetCard); ok {
mac := nic.GetVirtualEthernetCard().MacAddress
if mac == "" {
continue
}
netName := nicMappings[devices.Name(device)]
macs[netName] = mac
}
}
}
for key, value := range macs {
if value == "" {
log.Debugf("Didn't get mac address for nic on %s, continue", key)
return false
}
}
return true
})
return macs, err
}
开发者ID:kjplatz,项目名称:vic,代码行数:60,代码来源:vm.go
示例10: TestWaitForUpdates
func TestWaitForUpdates(t *testing.T) {
folder := esx.RootFolder
s := New(NewServiceInstance(esx.ServiceContent, folder))
ts := s.NewServer()
defer ts.Close()
ctx := context.Background()
c, err := govmomi.NewClient(ctx, ts.URL, true)
if err != nil {
t.Fatal(err)
}
cb := func(once bool) func([]types.PropertyChange) bool {
return func(pc []types.PropertyChange) bool {
if len(pc) != 1 {
t.Fail()
}
c := pc[0]
if c.Op != types.PropertyChangeOpAssign {
t.Fail()
}
if c.Name != "name" {
t.Fail()
}
if c.Val.(string) != folder.Name {
t.Fail()
}
return once
}
}
pc := property.DefaultCollector(c.Client)
props := []string{"name"}
err = property.Wait(ctx, pc, folder.Reference(), props, cb(true))
if err != nil {
t.Error(err)
}
// incremental updates not yet suppported
err = property.Wait(ctx, pc, folder.Reference(), props, cb(false))
if err == nil {
t.Error("expected error")
}
// test object not found
Map.Remove(folder.Reference())
err = property.Wait(ctx, pc, folder.Reference(), props, cb(true))
if err == nil {
t.Error("expected error")
}
}
开发者ID:jak-atx,项目名称:vic,代码行数:57,代码来源:property_collector_test.go
示例11: Run
func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
c, err := cmd.Client()
if err != nil {
return err
}
finder, err := cmd.Finder()
if err != nil {
return err
}
args := f.Args()
if len(args) == 0 {
args = []string{"*"}
}
var props []string
res := infoResult{
finder: finder,
ctx: ctx,
}
if !cmd.OutputFlag.JSON {
props = []string{
"name",
"vmFolder",
"hostFolder",
"datastoreFolder",
"networkFolder",
"datastore",
"network",
}
}
for _, arg := range args {
objects, err := finder.DatacenterList(ctx, arg)
if err != nil {
return err
}
res.objects = append(res.objects, objects...)
}
if len(res.objects) != 0 {
refs := make([]types.ManagedObjectReference, 0, len(res.objects))
for _, o := range res.objects {
refs = append(refs, o.Reference())
}
pc := property.DefaultCollector(c)
err = pc.Retrieve(ctx, refs, props, &res.Datacenters)
if err != nil {
return err
}
}
return cmd.WriteResult(&res)
}
开发者ID:vmware,项目名称:vic,代码行数:57,代码来源:info.go
示例12: getVirtualMachineManagedObjectReference
func getVirtualMachineManagedObjectReference(ctx context.Context, c *govmomi.Client, vm *object.VirtualMachine, field string, dst interface{}) error {
collector := property.DefaultCollector(c.Client)
// Retrieve required field from VM object
err := collector.RetrieveOne(ctx, vm.Reference(), []string{field}, dst)
if err != nil {
return err
}
return nil
}
开发者ID:ncdc,项目名称:kubernetes,代码行数:10,代码来源:vsphere.go
示例13: List
func (m Manager) List(ctx context.Context) ([]types.LicenseManagerLicenseInfo, error) {
var mlm mo.LicenseManager
err := property.DefaultCollector(m.c).RetrieveOne(ctx, m.Reference(), []string{"licenses"}, &mlm)
if err != nil {
return nil, err
}
return mlm.Licenses, nil
}
开发者ID:MerlinDMC,项目名称:machine,代码行数:10,代码来源:manager.go
示例14: Run
func (cmd *info) Run(f *flag.FlagSet) error {
if f.NArg() == 0 {
return flag.ErrHelp
}
c, err := cmd.Client()
if err != nil {
return err
}
ctx := context.TODO()
finder, err := cmd.Finder()
if err != nil {
return err
}
var res infoResult
var props []string
if cmd.OutputFlag.JSON {
props = nil
} else {
props = []string{
"name",
"config.cpuAllocation",
"config.memoryAllocation",
"runtime.cpu",
"runtime.memory",
}
}
for _, arg := range f.Args() {
objects, err := finder.ResourcePoolList(ctx, arg)
if err != nil {
return err
}
res.objects = append(res.objects, objects...)
}
if len(res.objects) != 0 {
refs := make([]types.ManagedObjectReference, 0, len(res.objects))
for _, o := range res.objects {
refs = append(refs, o.Reference())
}
pc := property.DefaultCollector(c)
err = pc.Retrieve(ctx, refs, props, &res.ResourcePools)
if err != nil {
return err
}
}
return cmd.WriteResult(&res)
}
开发者ID:hickeng,项目名称:govmomi,代码行数:55,代码来源:info.go
示例15: Run
func (cmd *info) Run(f *flag.FlagSet) error {
c, err := cmd.Client()
if err != nil {
return err
}
ctx := context.TODO()
var res infoResult
var props []string
if cmd.OutputFlag.JSON {
props = nil // Load everything
} else {
props = []string{"summary"} // Load summary
}
// We could do without the -host flag, leaving it for compat
host, err := cmd.HostSystemIfSpecified()
if err != nil {
return err
}
// Default only if there is a single host
if host == nil && f.NArg() == 0 {
host, err = cmd.HostSystem()
if err != nil {
return err
}
}
if host != nil {
res.objects = append(res.objects, host)
} else {
res.objects, err = cmd.HostSystems(f.Args())
if err != nil {
return err
}
}
if len(res.objects) != 0 {
refs := make([]types.ManagedObjectReference, 0, len(res.objects))
for _, o := range res.objects {
refs = append(refs, o.Reference())
}
pc := property.DefaultCollector(c)
err = pc.Retrieve(ctx, refs, props, &res.HostSystems)
if err != nil {
return err
}
}
return cmd.WriteResult(&res)
}
开发者ID:kristinn,项目名称:govmomi,代码行数:55,代码来源:info.go
示例16: Run
func (c *info) Run(f *flag.FlagSet) error {
client, err := c.Client()
if err != nil {
return err
}
var hosts []*object.HostSystem
// We could do without the -host flag, leaving it for compat
host, err := c.HostSystemIfSpecified()
if err != nil {
return err
}
// Default only if there is a single host
if host == nil && f.NArg() == 0 {
host, err = c.HostSystem()
if err != nil {
return err
}
}
if host != nil {
hosts = append(hosts, host)
} else {
hosts, err = c.HostSystems(f.Args())
if err != nil {
return err
}
}
var res infoResult
var props []string
if c.OutputFlag.JSON {
props = nil // Load everything
} else {
props = []string{"summary"} // Load summary
}
for _, host := range hosts {
var h mo.HostSystem
pc := property.DefaultCollector(client)
err = pc.RetrieveOne(context.TODO(), host.Reference(), props, &h)
if err != nil {
return err
}
res.HostSystems = append(res.HostSystems, h)
}
return c.WriteResult(&res)
}
开发者ID:MerlinDMC,项目名称:machine,代码行数:54,代码来源:info.go
示例17: NewFinder
func NewFinder(client *vim25.Client, all bool) *Finder {
f := &Finder{
client: client,
recurser: list.Recurser{
Collector: property.DefaultCollector(client),
All: all,
},
}
return f
}
开发者ID:COLDTURNIP,项目名称:kubernetes,代码行数:11,代码来源:finder.go
示例18: WaitForExtraConfig
// WaitForExtraConfig waits until key shows up with the expected value inside the ExtraConfig
func (vm *VirtualMachine) WaitForExtraConfig(ctx context.Context, waitFunc func(pc []types.PropertyChange) bool) error {
// Get the default collector
p := property.DefaultCollector(vm.Vim25())
// Wait on config.extraConfig
// https://www.vmware.com/support/developer/vc-sdk/visdk2xpubs/ReferenceGuide/vim.vm.ConfigInfo.html
err := property.Wait(ctx, p, vm.Reference(), []string{"config.extraConfig"}, waitFunc)
if err != nil {
log.Errorf("Property collector error: %s", err)
return err
}
return nil
}
开发者ID:kjplatz,项目名称:vic,代码行数:14,代码来源:vm.go
示例19: Run
func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
if f.NArg() == 0 {
return flag.ErrHelp
}
c, err := cmd.Client()
if err != nil {
return err
}
finder, err := cmd.Finder()
if err != nil {
return err
}
var res infoResult
var props []string
if cmd.OutputFlag.JSON {
props = nil
} else {
props = []string{
"name",
"config.cpuAllocation",
"config.memoryAllocation",
"runtime.cpu",
"runtime.memory",
}
}
for _, arg := range f.Args() {
vapps, err := finder.VirtualAppList(context.TODO(), arg)
if err != nil {
return err
}
for _, vapp := range vapps {
var p mo.VirtualApp
pc := property.DefaultCollector(c)
err = pc.RetrieveOne(context.TODO(), vapp.Reference(), props, &p)
if err != nil {
return err
}
res.VApps = append(res.VApps, p)
}
}
return cmd.WriteResult(&res)
}
开发者ID:excilsploft,项目名称:govmomi,代码行数:51,代码来源:info.go
示例20: multipleObjectEvents
func multipleObjectEvents(ctx context.Context, m Manager, objects []types.ManagedObjectReference, pageSize int32, tail bool, force bool, prop []string, f func([]types.BaseEvent) error) error {
// create an EventHistoryCollector for each object
var collectors []types.ManagedObjectReference
for _, o := range objects {
filter := types.EventFilterSpec{
Entity: &types.EventFilterSpecByEntity{
Entity: o,
Recursion: types.EventFilterSpecRecursionOptionAll,
},
}
collector, err := m.CreateCollectorForEvents(ctx, filter)
if err != nil {
return fmt.Errorf("[%#v] %s", o, err)
}
defer collector.Destroy(ctx)
err = collector.SetPageSize(ctx, pageSize)
if err != nil {
return err
}
collectors = append(collectors, collector.Reference())
}
// create and populate a ListView
viewMgr := view.NewManager(m.Client())
listView, err := viewMgr.CreateListView(ctx, collectors)
if err != nil {
return err
}
count := 0
// Retrieve the property from the objects in the ListView
return property.WaitForView(ctx, property.DefaultCollector(m.Client()), listView.Reference(), collectors[0], prop, func(pc []types.PropertyChange) bool {
for _, u := range pc {
if u.Name != prop[0] {
continue
}
if u.Val == nil {
continue
}
f(u.Val.(types.ArrayOfEvent).Event)
}
count++
if count == len(collectors) && !tail {
return true
}
return false
})
}
开发者ID:hmahmood,项目名称:govmomi,代码行数:51,代码来源:helper.go
注:本文中的github.com/vmware/govmomi/property.DefaultCollector函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论